Overview
The App Courier codebase follows a modular, feature-based structure within thelib/ directory. Each module has a clear responsibility, making the codebase maintainable and scalable.
Root Structure
Core Directory
Thecore/ directory contains shared infrastructure used throughout the app:
Core Submodules
api/
Contains API communication infrastructure:- api_client.dart: Dio-based HTTP client with interceptors for authentication and error handling
- api_endpoints.dart: Centralized API endpoint constants
constants/
Reusable UI components and styling constants:- Form field components with consistent styling
- Color palette and theme colors
- Typography styles
- Spacing and sizing constants
utils/
Helper functions and utilities:- api_utils.dart: Error message extraction, response parsing
- validators.dart: Form field validation functions
- download_pdf.dart & view_pdf.dart: Document handling
widgets/
Reusable widget components shared across screens:- Custom form widgets
- Search components
- Loading and error states
- Data display cards
Data Directory
Models Directory
Contains all data models with JSON serialization:- Dart class with typed properties
fromJson()factory constructortoJson()method for API requests- Optional: Multiple factory constructors for different API responses
Providers Directory
State management providers using the Provider pattern:- Extend
ChangeNotifier - Manage loading states
- Handle errors
- Coordinate with services
Routes Directory
Navigation configuration:- Route name constants
- Route to widget mapping
- Route parameter handling
Screens Directory
UI screens organized by user module:Screen Organization
Screens are grouped by user type:- auth/: Public screens for authentication
- Modulos-Admin/: Admin-only screens for management
- Modulos-Cliente/: Client portal screens
- Modulos-Motorizado/: Driver app screens
Services Directory
API communication services:- Receives
ApiClientvia constructor - Makes HTTP requests to specific endpoints
- Parses JSON responses into models
- Throws exceptions for errors
File Naming Conventions
General Rules
- snake_case: All file names use lowercase with underscores
- Descriptive names: Files named after their primary class/purpose
- Suffix conventions:
_screen.dart: Screen/page widgets_provider.dart: Provider classes_service.dart: Service classes_model.dartor just.dart: Models
Examples
Import Conventions
Imports follow this order:Key Files
main.dart
App entry point - initializes providers and starts the app:lib/main.dart:26
app.dart
Main app widget - configures MaterialApp:lib/app.dart:4
api_client.dart
Centralized HTTP client:lib/core/api/api_client.dart:4
Navigation Between Modules
The app uses different entry points for different user types:Adding New Features
When adding a new feature, follow this structure:- Create model in
models/ - Create service in
services/ - Create provider in
providers/ - Add endpoints to
api_endpoints.dart - Create screens in appropriate
screens/subdirectory - Add routes to
app_routes.dart - Register provider in
main.dart