# nhathuy157/student_app architecture

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

- Interactive diagram: https://gitdiagram.com/nhathuy157/student_app
- Repository: https://github.com/nhathuy157/student_app

## Overview

##### Project Type and Purpose
- This is a full-stack, cross-platform Flutter application (“student_app”) targeting mobile (Android, iOS), desktop (Windows, macOS, Linux) and web.
- Purpose: a multi-feature student portal combining hotel search/booking, job listings, campus mapping, in-app shop, and user authentication—backed by Firebase services.

##### File Structure
- Top-level “android”, “ios”, “web”, “windows”, “macos”, “linux” folders: Flutter build targets.
- “lib/” directory: core Flutter code, subdivided into:
- config (routes, themes, strings)
- constants (app-wide constants)
- controller (state management/controllers)
- model (data classes modeling hotel, job, map, shop, user, etc.)
- modules (UI screens and widgets by feature: home, hotel, job, map, shop, admin, auth)
- service (service layer handling authentication, Firebase CRUD, local JSON, fake data)
- widgets (shared stateless/stateful components)
- “assets/”: static JSON data, fonts, images partitioned by feature.
- “firebase/”: backend configuration for Firestore, Realtime Database, Storage rules, Cloud Functions.
- “pubspec.yaml/lock”: dependency declarations.

##### README
- A default Flutter README; no architecture details. We’ll infer architecture from file structure and common Flutter + Firebase patterns.

a. Main Components
- Flutter Frontend
- UI Modules (screens & widgets by feature)
- State Controllers (GetX/BLoC/MVVM – here likely GetX given “controller” naming)
- Models (hotel, job, map, shop, user, etc.)
- Service Layer (auth_service, action services, JSON manager)
- Local Assets (JSON, images, fonts)
- Backend Services (Firebase)
- Authentication (Firebase Auth)
- Firestore (real-time data storage for jobs, hotels, shop listings)
- Realtime Database (if used—check database.rules.json)
- Cloud Storage (images, map assets)
- Cloud Functions (server-side logic in firebase/functions)
- External Services
- Google Maps API (for map rendering, directions)
- Optional third-party job/hotel APIs if extended later

b. Relationships and Interactions
- UI → Controller: user gestures trigger controller methods
- Controller → Service Layer: controllers call auth_service, action services, JSON manager
- Service Layer → Firebase SDK: service invokes Firebase Auth, Firestore, Realtime DB, Cloud Storage, or local JSON
- Service Layer → Cloud Functions: for complex backend operations (e.g., data aggregation)
- Flutter Frontend → Google Maps SDK: map widgets import and display tiles/directions
- Firebase → Cloud Functions: triggered by database writes or HTTP calls

c. Architectural Patterns / Design Principles
- Separation of Concerns: UI layer (modules/widgets) vs. business logic (controllers) vs. data access (services)
- MVVM-like or GetX pattern: controllers manage state, models encapsulate data, views bind to controllers
- Feature-based modularization: each major feature resides in its own module folder
- Backend as a Service (BaaS): Firebase handles auth, data, storage, functions

d. Key Technologies
- Flutter & Dart
- Firebase SDKs (auth, firestore, database, storage, functions)
- Google Maps Flutter plugin
- JSON local assets for offline/fallback data
- Cloud Functions (Node.js / JavaScript)

##### Detailed Breakdown of Essential Architectural Elements
- Authentication Flow: Sign-In page → AuthController → AuthService → Firebase Auth → returns AuthUser → Controller updates UI.
- Data Flow for Feature (e.g., Job Listings): JobPage UI → JobController → JobActionService → Firestore/jobs → returns List<JobModel> → UI renders via JobWidget.
- Map Feature: MapPage → MapController → BuildingAction, RoomAction → local JSON / Firestore → Google Maps SDK for rendering.
- Shop Feature: ShopPage → ShopController → ProductActionService → Firestore/shop_products → Cloud Storage for product images.
- Admin Actions: Admin UI → AdminController → Cloud Functions / Firestore writes.

##### Summary
- Feature-specific components together to improve readability.
- Platform-specific builds (Android / iOS / web runners) if the deployment pipeline is relevant.

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Client - Flutter Frontend"
    direction TB
    subgraph "UI Modules"
      direction TB
      Home["Home Feature"]:::ui
      Hotel["Hotel Feature"]:::ui
      Job["Job Feature"]:::ui
      MapUI["Map Feature"]:::ui
      Shop["Shop Feature"]:::ui
      Admin["Admin Feature"]:::ui
      AuthUI["Authentication UI"]:::ui
      Account["Account Info UI"]:::ui
      SchoolInfo["School Info UI"]:::ui
      Welcome["Welcome Screen UI"]:::ui
    end
    subgraph "State Controllers"
      Controllers["Controllers\n(lib/controller)"]:::ctrl
    end
    subgraph "Data Models"
      Models["Models\n(lib/model)"]:::model
    end
    subgraph "Service Layer"
      ActionService["Action Services\n(lib/service/action)"]:::service
      AuthService["Auth Services\n(lib/service/auth)"]:::service
      OtherService["Other Services\n(lib/service/other)"]:::service
    end
    Assets["Local Assets\n(assets/data, assets/images)"]:::datastore
  end

  subgraph "Backend - Firebase + External"
    direction TB
    Auth["Firebase Auth"]:::datastore
    Firestore["Firestore"]:::datastore
    RealtimeDB["Realtime DB"]:::datastore
    Storage["Cloud Storage"]:::datastore
    Functions["Cloud Functions"]:::functions
    External["Google Maps API"]:::external
  end

  %% Interactions
  Home -->|uses| Controllers
  Hotel -->|uses| Controllers
  Job -->|uses| Controllers
  MapUI -->|uses| Controllers
  Shop -->|uses| Controllers
  Admin -->|uses| Controllers
  AuthUI -->|uses| Controllers
  Account -->|uses| Controllers
  SchoolInfo -->|uses| Controllers
  Welcome -->|uses| Controllers

  Controllers -->|calls| ActionService
  Controllers -->|calls| AuthService
  Controllers -->|calls| OtherService

  ActionService -->|CRUD| Firestore
  ActionService -->|CRUD| RealtimeDB
  ActionService -->|store/retrieve| Storage
  AuthService -->|authenticate| Auth
  OtherService -->|local JSON| Assets
  OtherService -->|misc| Firestore

  MapUI -->|map data| External

  Functions -->|triggered by| Firestore
  Functions -->|triggered by| RealtimeDB
  ActionService -->|invoke| Functions

  %% Click Events
  click Home "https://github.com/nhathuy157/student_app/tree/main/lib/modules/home"
  click Hotel "https://github.com/nhathuy157/student_app/tree/main/lib/modules/hotel"
  click Job "https://github.com/nhathuy157/student_app/tree/main/lib/modules/job"
  click MapUI "https://github.com/nhathuy157/student_app/tree/main/lib/modules/map"
  click Shop "https://github.com/nhathuy157/student_app/tree/main/lib/modules/shop"
  click Admin "https://github.com/nhathuy157/student_app/tree/main/lib/modules/admin"
  click AuthUI "https://github.com/nhathuy157/student_app/tree/main/lib/modules/sign_in_sign_up"
  click Account "https://github.com/nhathuy157/student_app/tree/main/lib/modules/info_account"
  click SchoolInfo "https://github.com/nhathuy157/student_app/tree/main/lib/modules/info_school"
  click Welcome "https://github.com/nhathuy157/student_app/tree/main/lib/modules/welcome"
  click Controllers "https://github.com/nhathuy157/student_app/tree/main/lib/controller"
  click Models "https://github.com/nhathuy157/student_app/tree/main/lib/model"
  click ActionService "https://github.com/nhathuy157/student_app/tree/main/lib/service/action"
  click AuthService "https://github.com/nhathuy157/student_app/tree/main/lib/service/auth"
  click OtherService "https://github.com/nhathuy157/student_app/tree/main/lib/service/other"
  click Assets "https://github.com/nhathuy157/student_app/tree/main/assets/data"
  click Functions "https://github.com/nhathuy157/student_app/blob/main/firebase/functions/index.js"

  %% Styles
  classDef ui fill:#D0E8FF,stroke:#009,stroke-width:1px
  classDef ctrl fill:#DFFFD0,stroke:#090,stroke-width:1px
  classDef model fill:#F0F0F0,stroke:#666,stroke-width:1px
  classDef service fill:#FFE0B2,stroke:#E65C00,stroke-width:1px
  classDef datastore fill:#E8E8E8,stroke:#999,stroke-width:1px
  classDef functions fill:#E6DBF7,stroke:#7D3C98,stroke-width:1px
  classDef external fill:#FFF4CC,stroke:#B18904,stroke-width:1px
```
