Always follow these rules. They ensure code quality and architectural consistency.
Clean Architecture
Simple Manager Mobile follows Clean Architecture principles strictly.
Layer Flow
The flow must always follow this pattern:
Screen → Hook → Service → Repository → Database
UI must never access database directly. Always go through the proper layers.
Layer Responsibilities
Presentation Layer
- Screens: UI components that display data and handle user interactions
- Hooks: Custom React hooks that interface with services
- Components: Reusable UI elements
Application Layer
- Services: Business logic and orchestration
- Validators: Input validation and business rules
Validation must exist in the service layer, not in the UI or repository.
Infrastructure Layer
- Repositories: Database operations only
- Database: Database setup and configuration
Repositories must only contain database logic. No business logic should exist here.
Domain Layer
- Entities: Core business objects and types
State Management
Do not introduce global state libraries. Use React’s built-in state management.
The project intentionally avoids Redux, Zustand, or similar libraries to keep the architecture simple.
Component Style
Prefer React hooks over classes. All new components should be functional components.
Architecture Example
Here’s how the layers work together for the Records feature:
Screen Layer
// RecordsScreen.tsx
const { records, create, update, remove } = useRecords();
Hook Layer
// useRecords.ts
const service = useMemo(() => new RecordService(), []);
const create = async (title: string, type: string) => {
await service.create(title, type);
await load();
};
Service Layer
// RecordService.ts
async create(title: string, type: string) {
// Business logic and validation
const record: Record = { /* ... */ };
await this.repository.create(record);
return record;
}
Repository Layer
// RecordRepository.ts
async create(record: Record) {
// Database operations only
await database.runAsync(/* SQL */);
}
Key Takeaways
- Respect layer boundaries - Each layer has a specific responsibility
- No shortcuts - Always follow the full flow from screen to database
- Keep it simple - No unnecessary state management libraries
- Validate early - Validation belongs in the service layer
- Pure repositories - Database logic only, no business rules