Core Principles
- •Dependency Rule: Source code dependencies always point inwards.
- •Data/Presentation -> Domain
- •Domain -> NEVER DEPENDS ON ANYTHING
- •Separation of Concerns: Business logic is isolated from UI and DB details.
Layers
1. Domain (The Core)
- •Entities: Pure TypeScript classes or interfaces representing business objects.
- •Use Cases: Application-specific business rules.
- •Repository Interfaces: Abstract definitions of how to access data.
2. Data (The Gateway)
- •Implementations: Concrete implementations of Repository Interfaces.
- •Data Sources: APIs, Databases, Local Storage.
- •Mappers: Transform data models (DB schema) into Domain Entities.
3. Presentation (The UI)
- •ViewModels/Hooks: Connect UI to Use Cases.
- •Views: React Components that render state.
CRITICAL RULES
1. No Frameworks in Domain
- •NEVER import from
react,react-native, ordrizzle-ormin thesrc/domainfolder. - •ALWAYS keep the Domain pure.
2. Dependency Injection
- •ALWAYS inject dependencies (like repositories) into Use Cases via constructor or factory function.
3. Repository Pattern
- •ALWAYS define the interface in Domain (
domain/repositories/IUserRepository.ts). - •ALWAYS implement it in Data (
data/repositories/UserRepositoryImpl.ts).