separation-of-concerns

benaor's avatarfrom benaor

Separation of Concerns principle for TypeScript code review and refactoring. Use when detecting mixed responsibilities, business logic in UI components, infrastructure code in domain layer, or tightly coupled modules. Helps improve modularity and maintainability. Related to Clean Architecture layers.

⭐2stars🔀0forks📁View on GitHub🕐Updated Jan 10, 2026⬇️1downloads

When & Why to Use This Skill

This Claude skill facilitates professional TypeScript code reviews and refactoring by applying the Separation of Concerns (SoC) principle. It helps developers identify and decouple mixed responsibilities, such as business logic embedded in UI components or infrastructure code leaking into the domain layer. By adhering to Clean Architecture standards, it significantly enhances code modularity, maintainability, and long-term scalability.

Use Cases

  • Refactoring Bloated Components: Identify and extract complex business logic and state management from React or framework-specific UI components into dedicated hooks or domain services.
  • Architectural Audits: Review existing TypeScript codebases to ensure strict boundaries between Presentation, Domain, and Infrastructure layers, preventing tight coupling.
  • Decoupling External Dependencies: Isolate third-party API integrations, SDKs, and database queries within the Infrastructure layer to protect core business rules from external changes.
  • Improving Testability: Separate pure domain logic from framework-specific code (like React or Express), making it easier to write robust unit tests without complex mocking of UI or external services.
  • Standardizing Code Quality: Use as a checklist during pull requests to ensure new code follows modular design patterns and avoids common architectural anti-patterns.
nameseparation-of-concerns
descriptionSeparation of Concerns principle for TypeScript code review and refactoring. Use when detecting mixed responsibilities, business logic in UI components, infrastructure code in domain layer, or tightly coupled modules. Helps improve modularity and maintainability. Related to Clean Architecture layers.

Separation of Concerns

Divide a system into distinct sections, each addressing a separate concern. A concern is a set of information that affects the code.

Common Concerns to Separate

  • UI/Presentation: How things look
  • Business logic/Domain: What things do
  • Data access: Where things are stored
  • Navigation: How to move between screens
  • State management: How data flows
  • External services: Third-party integrations

Violation Signs

  • Components fetching data AND rendering AND handling business rules
  • Business logic importing React or framework-specific code
  • Database queries mixed with validation logic
  • UI components aware of API endpoint URLs
  • Navigation logic inside business rules

→ See layers-example.md for complete before/after refactoring.

Layer Dependencies

┌─────────────────────────────────────────┐
│           Presentation Layer            │
│  (Screens, Components, Hooks, ViewModels)│
└─────────────────────┬───────────────────┘
                      │ depends on
                      ▼
┌─────────────────────────────────────────┐
│             Domain Layer                │
│    (Entities, UseCases, Ports)          │
└─────────────────────┬───────────────────┘
                      │ depends on
                      ▼
┌─────────────────────────────────────────┐
│          Infrastructure Layer           │
│   (Adapters, Repositories, Services)    │
└─────────────────────────────────────────┘

Domain has NO dependencies on Presentation or Infrastructure

Quick Checks by Layer

Layer Should NOT contain
Domain React imports, HTTP clients, AsyncStorage, navigation
Presentation Direct API calls, SQL queries, business rules
Infrastructure UI components, business decisions, routing

When Concerns Can Stay Together

  • Prototypes: Speed over architecture for throwaway code
  • Simple utilities: Pure functions without dependencies
  • Trivial components: A button that just styles and calls onPress
  • Co-location benefit: Sometimes keeping related code together aids understanding

The key question: "If I change this concern, how many unrelated things break?"