yanko-belov/code-craft
Overview
This skill captures the Single Responsibility Principle (SRP) guidance for TypeScript code. It helps you decide when to split classes, modules, or functions so each has exactly one reason to change. Use it to avoid god classes and keep code maintainable and testable.
How this skill works
It inspects design intent and common symptoms: whether a class does multiple things, how many public methods it has, file size, and whether descriptions require "AND". It recommends concrete refactors: extract focused services, avoid adding unrelated methods, and document technical debt when immediate refactoring is impossible. It also gives scripts for resisting pressure to violate SRP.
When to use it
- Creating a new class, module, or service
- Adding methods to an existing class
- Reviewing code that seems to do multiple things
- When you feel pressure to "just add it here"
- When a class has multiple reasons to change
Best practices
- Describe the class in one sentence; if it includes "AND", split it
- Never add functionality that introduces a second reason to change
- Extract on touch: when modifying, pull related behavior into a new class
- Create focused classes even under time or authority pressure and document concerns
- Use specific names (Avoid vague Manager/Handler/Processor/Service without domain)
Example use cases
- Refactoring a 500-line OrderService into OrderService, PaymentService, InventoryService, NotificationService
- Adding email delivery: create NotificationService instead of tacking sendEmail onto UserManager
- Code review: flag classes with >200 lines or >5–7 public methods for extraction
- Implementing a new feature: add a new service rather than expanding an unrelated class
- Handling disputes over design: use the provided script to push back and record decisions
FAQ
Create a focused class for the change—this is usually not slower—and avoid adding unrelated responsibilities to existing classes. If impossible, document the debt and create a ticket to refactor.
How do I start refactoring a god class safely?
Don’t make it worse. When you touch part of the class, extract that part into a new class or service and update callers gradually. Add tests and document remaining work.
28 skills
This skill helps you apply the single-responsibility principle by guiding you to split classes and modules, reducing change coupling and maintenance.
This skill helps you apply the Dependency Inversion Principle in TypeScript by promoting interface-based design and injecting dependencies instead of
This skill helps you design focused interfaces by applying the Interface Segregation Principle, avoiding throw and no-op methods and promoting cohesive,
This skill helps you resist feature bloat by enforcing YAGNI principles, guiding minimal viable implementations until requirements actually demand change.
This skill helps you apply the Liskov Substitution Principle by avoiding broken inheritance and favoring interfaces and composition for reliable subclassing.
This skill helps you apply the Open/Closed Principle by guiding you to add new behavior via extensions rather than modifying existing code.
This skill helps you identify and extract duplicate logic to enforce a single source of truth across codebases, reducing bugs and maintenance.
This skill helps you replace overengineered solutions with simple, clear code that works and ships faster.
This skill enforces encapsulation in TypeScript by guiding you to hide internal state and expose behavior through validated methods.
This skill tracks every code-craft application to build a practice record and support analytics across sessions.
This skill helps you write safer TypeScript code by avoiding deep property access and encouraging explicit data access patterns.
This skill helps you place error handling at architectural boundaries, enabling graceful degradation and preventing cascading failures.
This skill enforces immutable patterns by returning new objects for updates, preventing bugs and improving React state predictability.
This skill helps you prevent N+1 queries by enforcing eager loading and providing patterns to fetch related data in a single query.
This skill helps you enforce test isolation by guiding you to create independent tests, avoid shared state, and run reliably.
This skill helps you design RESTful endpoints by enforcing correct HTTP methods, avoiding verbs in URLs, and promoting semantic, cache-friendly APIs.
This skill helps you replace inheritance with composition by guiding you to assemble behaviors via interfaces and injectables for flexible class design.
This skill helps you implement lazy loading to load data on demand, improving initial load times and perceived performance.
This skill helps you identify and remediate race conditions by applying atomic, transactional, and locking patterns across code paths.
This skill helps you implement safe, structured API error responses that avoid leaks and improve client understanding.
This skill enforces clear arrange-act-assert test structure by guiding you to separate phases for readability and maintainability.
This skill helps you design precise exception hierarchies in TypeScript, enabling targeted catch blocks and safer error handling across layers.
This skill promotes fail-fast error handling in TypeScript by throwing at the source and surfacing clear errors to boundaries.
This skill helps you implement idempotency for critical mutations using idempotency keys to prevent duplicates and ensure safe retries.
This skill guides you to never hardcode secrets, enforcing environment variables and startup validation to prevent leaks and secure credentials.
This skill helps prevent deadlocks by enforcing consistent lock ordering and timeouts across services, ensuring operations complete reliably.
This skill helps you implement caching with robust invalidation strategies to boost performance while ensuring data freshness.
This skill helps you design and evolve APIs safely by enforcing versioning, deprecation, and non-breaking changes across clients.