๐๏ธ Project Architecture¶
This project follows a robust Clean Architecture pattern, structured to ensure separation of concerns, modularity, and scalability. What sets this implementation apart is its modular design, where each feature lives in an isolated module with its own layers, routes, and logic.
๐งฑ Clean Architecture Layers¶
Each module and shared component follows the classic Clean Architecture principles:
- Domain Layer โ Business logic, entities, and contracts (abstract repositories, use cases)
- Data Layer โ Concrete implementations for repositories, local/remote data sources
- Feature Layer โ UI, state management (BLoC), and presentation logic
This separation enables each layer to be independently testable, replaceable, and loosely coupled.
๐ฆ Modular Design¶
The app is split into independent modules, each responsible for a specific domain (e.g., Auth, Posts, etc.).
โ Why Modules?¶
- ๐งฉ Self-contained: Each module contains its own domain, data, and feature layers.
- ๐ฅ Team-friendly: Multiple teams can work on different modules independently.
- โ Pluggable: Modules can be easily added or removed without touching the core app.
- ๐ Organized: Cleaner structure and simpler onboarding for new developers.
๐๏ธ Module Structure¶
A typical module (e.g., auth) is structured like this:
modules/
โโโ auth/
โโโ data/ # Data sources, models, repositories
โโโ domain/ # Entities, use cases, repository contracts
โโโ features/ # BLoC, UI, screens
โโโ auth_module.dart # Module entry (DI and initializations)
โโโ auth_routes.dart # Module routes and nav registration
๐ Module Registration¶
Each module registers itself through:
- *_module.dart โ Used to initialize dependencies (e.g., repositories, use cases)
- *_routes.dart โ Used to register routes and navigation tabs in the global app router
This enables complete decoupling of routing and logic between modules.
๐ Shared Components¶
Common logic is placed in the _shared directory:
- blocs/ โ Reusable BLoCs across modules
- widgets/ โ Shared widgets
- utils/ โ Utility functions
- data/ & domain/ โ Shared services and models
- features/ โ Shared features not tied to a specific module
๐ Module Lifecycle¶
Each module follows a consistent lifecycle:
- โ Define use cases, entities, and contracts in the domain/
- ๐ Implement data sources and repositories in the data/
- ๐จ Build BLoCs and UI in the features/
- ๐ ๏ธ Initialize dependencies in *_module.dart
- ๐งญ Register routes in *_routes.dart
๐งช Testability¶
The separation of layers and modules allows:
- Easy unit testing of business logic and use cases
- Mocking of repositories in isolation
- Clean widget and BLoC testing within each feature
๐งญ Visual Overview¶
lib/
โโโ _core/ # Core setup (DI, routing, theming)
โโโ _shared/ # Reusable logic and components
โโโ modules/ # Feature-based modules (e.g., auth, posts)
โโโ app.dart #
โโโ main.dart # Entry point
๐ฏ Summary¶
This architecture makes it easy to:
- Scale the app with new features
- Collaborate across large teams
- Maintain and test code reliably
- Customize or remove modules cleanly
You can find example modules like auth and posts in the respective folders. Each one is fully isolated and demonstrates the intended Clean Modular Architecture pattern.