Separation of Concerns principle for TypeScript code review and refactoring...
Divide a system into distinct sections, each addressing a separate concern. A concern is a set of information that affects the code.
→ See layers-example.md for complete before/after refactoring.
┌─────────────────────────────────────────┐
│ 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
| 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 |
The key question: "If I change this concern, how many unrelated things break?"