How happytechchannel/happy_tech_mastering_api_with_flutter works
Project Type and Purpose
• This is a cross-platform mobile (and desktop/web) client built with Flutter.
• It implements a UI layer (screens & widgets), state management (Cubit/BLoC), and a data layer that calls REST endpoints via Dio and caches responses.
Top-Level Architecture
• Frontend: Flutter framework code under lib/ plus platform embedding in android/, ios/, linux/, macos/, windows/, web/.
• Core/Data: API client, interceptors, endpoints, cache helper, and error handling in lib/core/.
• State Management: Cubit classes in lib/cubit/.
• Domain/Models: Data models in lib/models/.
• Repository: Abstraction over data sources in lib/repositories/.
• UI: Screens and reusable widgets in lib/screens/ and lib/widgets/.
Key Components
a. Presentation Layer
• Flutter Engine & Widgets (platform channels omitted for simplicity)
• UI Screens (SignInScreen, SignUpScreen, ProfileScreen)
• Widgets (CustomInputField, PickImageWidget, etc.)
b. State Layer
• UserCubit / UserState handling UI events & state transitions
c. Domain Layer
• UserRepository interface and implementation
d. Data Layer
• API Consumer (Dio setup in dio_consumer.dart)
• API Interceptors (api_interceptors.dart)
• Endpoints definition (end_points.dart)
• Cache Helper (cache_helper.dart)
e. External Systems
• Remote REST API (hosted server)
• Local Storage (shared preferences or similar via cache helper)
Interactions & Data Flow
1. User taps a button in a Flutter Screen →
2. Screen dispatches an event to UserCubit. →
3. UserCubit calls UserRepository. →
4. UserRepository chooses between cache or remote:
– Checks CacheHelper; if stale or missing, calls API Consumer →
– DioConsumer sends HTTP request to external REST API →
– API responds JSON → Interceptors handle auth/refresh tokens →
– JSON parsed into Model (SignInModel, UserModel) →
5. Repository stores result in CacheHelper and returns model to Cubit →
6. UserCubit emits new UserState →
7. Screen rebuilds with updated data.
Architectural Patterns & Principles
• Layered Architecture (Presentation → State → Domain → Data)
• Repository Pattern (separates data sources)
• BLoC/Cubit Pattern (manages state & events)
• Dependency Injection (pass repository & API consumer into Cubit)
• Separation of Concerns (UI, business logic, data access, caching, error handling)