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?"