# nhat-tien/bus_online_new architecture

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

- Interactive diagram: https://gitdiagram.com/nhat-tien/bus_online_new
- Repository: https://github.com/nhat-tien/bus_online_new

## Overview

##### Project type and purpose
- This is a multi‐platform Flutter client app named “bus_online.”
- It targets Android, iOS, web, Linux, macOS and Windows.
- Its goal is a bus-booking/tracking application with registration, login, route lookup, ticket management, scanner, and driver/customer panels.

##### High-level structure from file tree
- Platform folders (android/, ios/, web/, linux/, macos/, windows/) each contain the native embedding and build configuration.
- lib/ holds the Dart code, subdivided into:
- components/ – reusable UI widgets
- pages/ – screen widgets by feature
- controllers/ – state managers (business logic)
- services/ – API clients (auth, customer, driver, route)
- models/ – data classes transported to/from services
- storage/ – local persistence (user session)
- utils/ – formatting and helpers
- Supporting files: pubspec.yaml, migration.sql (DB schema?), CI in .github/workflows, analysis_options.yaml.

##### Architectural pattern
- Layered/MVVM (View → Controller/ViewModel → Service → External API).
- Componentized widget library for consistent UI.
- Controllers orchestrate calls to services and update Views; Services wrap HTTP/JSON to remote REST endpoints; Storage handles caching or token storage.

##### Main components
A. Platform Runners:
- Android (Gradle → MainActivity.kt)
- iOS (AppDelegate.swift)
- Web, Linux, macOS, Windows runners
B. Flutter Core:
1) UI Layer
– Widget Components (lib/components)
– Pages (lib/pages)
2) Controller Layer (lib/controllers)
3) Service Layer (lib/services)
4) Local Storage (lib/storage)
5) Utility Layer (lib/utils)
C. External Services/API:
– Auth API
– Customer API
– Driver API
– Route/Ticket API

##### Relationships and data flow
- UI Widgets ←→ Pages (compose widgets into screens)
- Pages ↔ Controllers (state and user events)
- Controllers ↔ Services (REST calls)
- Services ↔ External API endpoints (HTTP/JSON)
- Controllers ↔ Storage (read/write session or cached data)
- Utils are called by Controllers or UI for formatting/parsing

##### Important design principles
- Separation of concerns: UI vs business logic vs data access
- Reusability: place shared widgets in components/
- Scalability: isolate each service for potential micro-frontend splits

## Diagram (Mermaid)

```mermaid
graph TD
    %% Platform Runners
    subgraph "Platform Runners"
        Android["Android Runner"]:::external
        iOS["iOS Runner"]:::external
        Web["Web Runner"]:::external
        Linux["Linux Runner"]:::external
        macOS["macOS Runner"]:::external
        Windows["Windows Runner"]:::external
    end

    %% Core Engine
    VM["Flutter Engine / Dart VM"]

    %% Flutter Layers
    subgraph "UI Layer"
        Components["Component Widgets"]:::ui
        Pages["Pages (Screens)"]:::ui
    end

    Controllers["Controllers"]:::controller

    subgraph "Data Access Layer"
        Services["Services"]:::dataaccess
        Storage[(User Storage)]:::dataaccess
    end

    Utils["Utils"]:::dataaccess

    %% External APIs and Schema
    AuthAPI["Auth API"]:::external
    CustomerAPI["Customer API"]:::external
    DriverAPI["Driver API"]:::external
    RouteAPI["Route/Ticket API"]:::external
    DB["migration.sql"]:::external

    %% Connections: Platform to Flutter Engine
    Android --> VM
    iOS --> VM
    Web --> VM
    Linux --> VM
    macOS --> VM
    Windows --> VM

    %% Intra-engine flows
    Components --> Pages
    Pages --> Controllers
    Controllers --> Services
    Services --> Controllers
    Controllers --> Storage
    Controllers --> Utils

    %% Services to External APIs
    Services -->|"HTTP/JSON"| AuthAPI
    Services -->|"HTTP/JSON"| CustomerAPI
    Services -->|"HTTP/JSON"| DriverAPI
    Services -->|"HTTP/JSON"| RouteAPI

    %% Optional schema reference
    DB

    %% Click Events
    click Android "https://github.com/nhat-tien/bus_online_new/blob/main/android/app/src/main/kotlin/com/example/bus_online/MainActivity.kt"
    click iOS "https://github.com/nhat-tien/bus_online_new/blob/main/ios/Runner/AppDelegate.swift"
    click Web "https://github.com/nhat-tien/bus_online_new/blob/main/web/index.html"
    click Linux "https://github.com/nhat-tien/bus_online_new/blob/main/linux/runner/main.cc"
    click macOS "https://github.com/nhat-tien/bus_online_new/blob/main/macos/Runner/AppDelegate.swift"
    click Windows "https://github.com/nhat-tien/bus_online_new/blob/main/windows/runner/main.cpp"
    click Components "https://github.com/nhat-tien/bus_online_new/tree/main/lib/components/"
    click Pages "https://github.com/nhat-tien/bus_online_new/tree/main/lib/pages/"
    click Controllers "https://github.com/nhat-tien/bus_online_new/tree/main/lib/controllers/"
    click Services "https://github.com/nhat-tien/bus_online_new/tree/main/lib/services/"
    click Storage "https://github.com/nhat-tien/bus_online_new/blob/main/lib/storage/user_storage.dart"
    click Utils "https://github.com/nhat-tien/bus_online_new/tree/main/lib/utils/"
    click AuthAPI "https://github.com/nhat-tien/bus_online_new/blob/main/lib/services/auth_service.dart"
    click CustomerAPI "https://github.com/nhat-tien/bus_online_new/blob/main/lib/services/customer_service.dart"
    click DriverAPI "https://github.com/nhat-tien/bus_online_new/blob/main/lib/services/driver_service.dart"
    click RouteAPI "https://github.com/nhat-tien/bus_online_new/blob/main/lib/services/tuyen_service.dart"
    click DB "https://github.com/nhat-tien/bus_online_new/blob/main/migration.sql"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef controller fill:#90EE90,stroke:#333,stroke-width:1px
    classDef dataaccess fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#666,stroke-width:1px,stroke-dasharray: 2 2
```
