# trieuluan/hui_application architecture

> Architecture diagram of the GitHub repository trieuluan/hui_application, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/trieuluan/hui_application
- Repository: https://github.com/trieuluan/hui_application

## Overview

##### Project Type and Purpose
- This is a client-side, cross-platform Flutter application targeting mobile (Android/iOS), desktop (Windows/Mac/Linux), and web.
- It implements user authentication (login, registration, OTP) and navigation (splash, intro, home), backed by REST/Firebase services.

##### File Structure
- Top-level “android”, “ios”, “linux”, “macos”, “windows”, “web” folders: platform-specific embedding of the Flutter engine.
- “lib/” is the single Dart codebase, subdivided into:
- core/ (configuration, constants, networking, utilities, validators)
- features/auth/ (models, providers, screens, utils for authentication)
- routes/ (app routing definitions)
- screens/ (app-wide UI views: splash, intro, home)
- services/ (business logic helper classes, e.g., AuthManager)
- widgets/ (reusable UI components)
- Configuration files: `firebase.json`, `google-services.json`, platform Gradle/Xcode configs, `pubspec.yaml`.

##### README
- Standard Flutter scaffold; no custom architectural notes. The file tree reveals the real architecture: layered client app with network and persistence integration.

a. Main Components
1. Flutter Engine & Embedder Layers (per platform):
- Android (Kotlin MainActivity), iOS (Swift AppDelegate), Windows/Linux/Mac hosts.
2. Application Layer (Dart code in lib/):
- Presentation: Screens & Widgets
- State Management: Riverpod/Provider (auth_provider)
- Domain/Services: AuthManager, AuthService
- Data Layer: ApiClient, HTTP/REST, Firebase SDK
3. External Systems:
- Firebase Authentication / Firestore / REST APIs
- Remote Backend Endpoints (defined in core/constants/endpoints.dart)
b. Relationships & Data Flows
- User taps UI → Screen widget calls Provider → Provider invokes Service → Service uses ApiClient → HTTP request to Firebase/REST → Response returns up to Service → Provider updates state → UI rebuilds.
- Routing: main.dart → PlatformApp → MaterialApp (app_routes) → initialRoute (splash) → subsequent navigation.
- Auth persistence: auth_provider reads/writes local storage (SharedPreferences or secure storage via auth_persistence).
c. Architectural Patterns & Principles
- Layered architecture: Presentation → State → Domain (Services) → Data (API) → External.
- Single-codebase multi-platform embedding via Flutter embedder.
- Dependency inversion: higher layers depend on abstractions (AuthService interface).
- Separation of concerns: core/ vs. feature/ vs. widgets/.
d. Key Technologies & Frameworks
- Flutter & Dart
- Provider/Riverpod (state management)
- HTTP client or Dio via ApiClient
- Firebase SDK (auth, analytics)
- Platform channels (if any native code is invoked)

##### Detailed Elements
- Platform Embedders: Android, iOS, Windows, macOS, Linux, Web
- main.dart → PlatformApp → MaterialApp + app_routes
- Presentation Layer: splash_screen, intro_screen, login_screen, home_screen
- State Layer: auth_provider (noting use of Freezed for AuthState)
- Domain Layer: AuthManager, AuthService (token refresh, persistence)
- Data Layer: ApiClient (base URL, interceptors), endpoints constants
- External: Firebase Auth, any REST endpoints (e.g., defined in endpoints.dart), local persistence store
- Assets: animations, fonts, images (optional, for completeness)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Platform Embedders"
        Android["Android: MainActivity"]:::platform
        iOS["iOS: AppDelegate"]:::platform
        Linux["Linux: main.cc"]:::platform
        macOS["macOS: AppDelegate"]:::platform
        Windows["Windows: main.cpp"]:::platform
        Web["Web Host: index.html"]:::platform
    end

    subgraph "Entry Point & Routing"
        Main["main.dart"]:::entry
        PlatformApp["PlatformApp"]:::entry
        Routes["app_routes.dart"]:::entry
    end

    subgraph "Presentation Layer"
        Splash["SplashScreen"]:::presentation
        Intro["IntroScreen"]:::presentation
        Home["HomeScreen"]:::presentation
        Login["LoginScreen"]:::presentation
        Register["RegisterScreen"]:::presentation
        OTP["OTPCodeScreen"]:::presentation
    end

    subgraph "Widgets"
        TextField["AppTextField"]:::widget
        ReactiveField["AppReactiveTextField"]:::widget
        PhoneInput["PhoneInputField"]:::widget
        IntlPhone["ReactiveIntlPhoneField"]:::widget
    end

    subgraph "State Management"
        AuthProvider["AuthProvider"]:::state
    end

    subgraph "Domain Services"
        AuthManager["AuthManager"]:::domain
        AuthService["AuthService"]:::domain
    end

    subgraph "Data Layer"
        ApiClient["ApiClient"]:::data
        Endpoints["Endpoints"]:::data
    end

    subgraph "Core Config & Utils"
        AppConfig["AppConfig"]:::core
        Constants["Constants"]:::core
        Snackbar["SnackbarUtil"]:::core
        ValidatorCustom["ValidatorCustom"]:::core
        Validators["Validators"]:::core
    end

    subgraph "Feature Utils"
        AuthPersistence["AuthPersistence"]:::feature
    end

    subgraph "External Systems"
        Firebase["Firebase Auth & Firestore"]:::external
        REST["External REST API"]:::external
        LocalStore["Local Persistence"]:::external
    end

    Android --> Main
    iOS --> Main
    Linux --> Main
    macOS --> Main
    Windows --> Main
    Web --> Main

    Main --> PlatformApp --> Routes
    Routes --> Splash
    Splash --> Intro
    Intro --> Login
    Login --> Register
    Register --> OTP
    OTP --> Home

    Splash --> AuthProvider
    Intro --> AuthProvider
    Login --> AuthProvider
    Register --> AuthProvider
    OTP --> AuthProvider
    Home --> AuthProvider

    AuthProvider --> AuthManager
    AuthProvider --> AuthService
    AuthProvider --> AuthPersistence
    AuthManager --> ApiClient
    AuthService --> ApiClient
    ApiClient --> Endpoints
    ApiClient --> Firebase
    ApiClient --> REST
    AuthPersistence --> LocalStore

    Login --> ValidatorCustom
    Register --> ValidatorCustom
    OTP --> ValidatorCustom
    Login --> Snackbar
    Register --> Snackbar

    Constants --> ApiClient
    AppConfig --> ApiClient

    click Android "https://github.com/trieuluan/hui_application/blob/main/android/app/src/main/kotlin/com/example/hui_application/MainActivity.kt"
    click iOS "https://github.com/trieuluan/hui_application/blob/main/ios/Runner/AppDelegate.swift"
    click Linux "https://github.com/trieuluan/hui_application/blob/main/linux/runner/main.cc"
    click macOS "https://github.com/trieuluan/hui_application/blob/main/macos/Runner/AppDelegate.swift"
    click Windows "https://github.com/trieuluan/hui_application/blob/main/windows/runner/main.cpp"
    click Web "https://github.com/trieuluan/hui_application/blob/main/web/index.html"
    click Main "https://github.com/trieuluan/hui_application/blob/main/lib/main.dart"
    click PlatformApp "https://github.com/trieuluan/hui_application/blob/main/lib/platform_app.dart"
    click Routes "https://github.com/trieuluan/hui_application/blob/main/lib/routes/app_routes.dart"
    click Splash "https://github.com/trieuluan/hui_application/blob/main/lib/screens/splash_screen.dart"
    click Intro "https://github.com/trieuluan/hui_application/blob/main/lib/screens/intro_screen.dart"
    click Home "https://github.com/trieuluan/hui_application/blob/main/lib/screens/home/home_screen.dart"
    click Login "https://github.com/trieuluan/hui_application/blob/main/lib/features/auth/screens/login_screen.dart"
    click Register "https://github.com/trieuluan/hui_application/blob/main/lib/features/auth/screens/register_screen.dart"
    click OTP "https://github.com/trieuluan/hui_application/blob/main/lib/features/auth/screens/otp_code_screen.dart"
    click TextField "https://github.com/trieuluan/hui_application/blob/main/lib/widgets/app_text_field.dart"
    click ReactiveField "https://github.com/trieuluan/hui_application/blob/main/lib/widgets/app_reactive_text_field.dart"
    click PhoneInput "https://github.com/trieuluan/hui_application/blob/main/lib/widgets/phone_input_field.dart"
    click IntlPhone "https://github.com/trieuluan/hui_application/blob/main/lib/widgets/reactive_intl_phone_field.dart"
    click AuthProvider "https://github.com/trieuluan/hui_application/blob/main/lib/features/auth/providers/auth_provider.dart"
    click AuthManager "https://github.com/trieuluan/hui_application/blob/main/lib/services/auth_manager.dart"
    click AuthService "https://github.com/trieuluan/hui_application/blob/main/lib/core/network/auth_service.dart"
    click ApiClient "https://github.com/trieuluan/hui_application/blob/main/lib/core/network/api_client.dart"
    click Endpoints "https://github.com/trieuluan/hui_application/blob/main/lib/core/constants/endpoints.dart"
    click AppConfig "https://github.com/trieuluan/hui_application/blob/main/lib/core/config/app_config.dart"
    click Constants "https://github.com/trieuluan/hui_application/blob/main/lib/core/config/constants.dart"
    click Snackbar "https://github.com/trieuluan/hui_application/blob/main/lib/core/utils/snackbar_util.dart"
    click ValidatorCustom "https://github.com/trieuluan/hui_application/blob/main/lib/core/validators/validator_custom.dart"
    click Validators "https://github.com/trieuluan/hui_application/blob/main/lib/core/validators/validators.dart"
    click AuthPersistence "https://github.com/trieuluan/hui_application/blob/main/lib/features/auth/utils/auth_persistence.dart"

    classDef platform fill:#f9f,stroke:#333
    classDef entry fill:#bbf,stroke:#333
    classDef presentation fill:#8fd,stroke:#333
    classDef widget fill:#dfd,stroke:#333
    classDef state fill:#bfc,stroke:#333
    classDef domain fill:#fcf,stroke:#333
    classDef data fill:#fdb,stroke:#333
    classDef core fill:#ddd,stroke:#333
    classDef feature fill:#ffd,stroke:#333
    classDef external fill:#aaa,stroke:#333
```
