# Flutter App Constitution ## Purpose This document establishes the foundational principles and standards for developing the Geutebruck API Flutter mobile application. These guidelines ensure code quality, maintainability, and exceptional user experience. ## Core Principles ### 1. Code Quality - **Clean Code**: Follow Flutter and Dart style guides (effective_dart) - **Modularity**: Organize code into reusable widgets and services - **Separation of Concerns**: Implement clear boundaries between UI, business logic, and data layers - **DRY Principle**: Avoid code duplication through proper abstraction - **SOLID Principles**: Apply object-oriented design principles where appropriate ### 2. Architecture - **Pattern**: Use **BLoC (Business Logic Component)** pattern for state management - Separates presentation from business logic - Testable and predictable state management - Reactive programming with streams - **Layered Architecture**: - **Presentation Layer**: Widgets and UI components - **Business Logic Layer**: BLoCs and Cubits - **Data Layer**: Repositories and data sources - **Domain Layer**: Models and business entities ### 3. Testing Standards - **Test Coverage**: Minimum 80% code coverage - **Test Types**: - **Unit Tests**: All business logic, repositories, and utilities - **Widget Tests**: All custom widgets and screens - **Integration Tests**: Critical user flows - **Test-Driven Development (TDD)**: Write tests before implementation where feasible - **Mocking**: Use mockito for dependency injection in tests ### 4. User Experience - **Material Design 3**: Follow Material Design guidelines for consistency - **Responsive Design**: Support multiple screen sizes (phones, tablets) - **Accessibility**: Support screen readers, proper contrast ratios, semantic labels - **Performance**: - App startup time < 3 seconds - List scrolling at 60 FPS - Image loading with progressive rendering - Efficient API calls with caching - **Offline-First**: Cache data locally, sync when online - **Error Handling**: Graceful error messages with retry options ### 5. Security - **Secure Storage**: Use flutter_secure_storage for sensitive data (JWT tokens, passwords) - **HTTPS Only**: All API communication over TLS - **Token Management**: Automatic token refresh before expiration - **Input Validation**: Sanitize all user inputs - **No Hardcoded Secrets**: Use environment variables and configuration files ### 6. API Integration - **REST Client**: Use dio package for HTTP requests - **Error Handling**: Standardized error parsing and user-friendly messages - **Retry Logic**: Automatic retry with exponential backoff for failed requests - **Request Cancellation**: Cancel pending requests on screen navigation - **Response Caching**: Implement caching strategy for frequently accessed data ### 7. Code Organization ``` lib/ ├── core/ │ ├── constants/ │ ├── errors/ │ ├── network/ │ └── utils/ ├── data/ │ ├── models/ │ ├── repositories/ │ └── data_sources/ ├── domain/ │ ├── entities/ │ └── repositories/ ├── presentation/ │ ├── blocs/ │ ├── screens/ │ └── widgets/ └── main.dart ``` ### 8. Dependency Management - **Minimal Dependencies**: Only add well-maintained, popular packages - **Version Locking**: Use exact versions in pubspec.yaml - **Regular Updates**: Review and update dependencies monthly - **Null Safety**: Enforce sound null safety ### 9. Documentation - **Code Comments**: Document complex logic and non-obvious decisions - **API Documentation**: Generate documentation using dartdoc - **README**: Comprehensive setup and running instructions - **Change Log**: Document all changes in CHANGELOG.md ### 10. Version Control - **Git Flow**: Use feature branches with descriptive names - **Commit Messages**: Follow conventional commits format - **Pull Requests**: Require code review before merging - **CI/CD**: Automated testing and deployment pipelines ## Governance ### Technical Decisions - Architecture changes require team consensus - New dependencies require justification and approval - Breaking changes require migration plan ### Code Review Standards - All code must be reviewed before merging - Reviewers check for: - Adherence to principles - Test coverage - Code clarity and documentation - Performance implications ### Performance Budgets - App size: < 50MB - Memory usage: < 200MB during normal operation - Network requests: Batched and optimized - Battery consumption: Minimal background activity ## Exceptions Exceptions to these principles require: 1. Clear justification 2. Documentation of trade-offs 3. Approval from technical lead 4. Technical debt tracking