# chunhthanhde/cinema-booking architecture

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

- Interactive diagram: https://gitdiagram.com/chunhthanhde/cinema-booking
- Repository: https://github.com/chunhthanhde/cinema-booking

## Overview

<explanation>
1. Identify the project type and purpose  
   - This is a cross‑platform mobile (and web/desktop) client application named **Cinema Booking** built with **Flutter**, following **Clean Architecture** + **BLoC**.  
   - Purpose: allow users to search movies, view details, auth via Firebase, book seats and time‑slots, and manage tickets.

2. Analyze the file structure  
   - Top‑level “android”, “ios”, “linux”, “macos”, “windows”, “web” folders → Flutter multi‑target client.  
   - `lib/` folder organized into layers:  
     • **common**: shared widgets, helpers, global BLoCs (authentication, theme)  
     • **core**: API provider (Dio/Retrofit), configs, constants, local storage helpers, usecase abstractions  
     • **data**: models (JSON DTOs), repository implementations, data sources (remote via Retrofit, mock, local)  
     • **domain**: entities, abstract repository interfaces, use case classes  
     • **presentation**: UI screens and feature‑specific BLoCs (login, home, movie_detail, booking, tickets, etc.)  
   - Configuration: `service_locator.dart` (GetIt DI), `router.dart` (GoRouter navigation), `main.dart` kicks off app.

3. Examine README insights  
   - Contains an ERD (Draw.io) linking User, Booking, Movie, Cinema, ShowTime, Seats, Ticket.  
   - High‑level Clean Bloc Architecture ASCII diagram provided.  
   - Tech stack: Firebase Auth/Firestore, Dio/Retrofit REST API, SharedPreferences, Sqflite, BLoC, Equatable, Freezed, JSON Serializable, GoRouter, YouTube Player, Google Maps, etc.

4. How to create the system design diagram  
   a. **Main components**  
      - **Client App** (Flutter)  
        • Presentation Layer (Widgets, Screens, BLoCs)  
        • Domain Layer (UseCases, Entities)  
        • Data Layer (Repositories, DataSources)  
        • Core Layer (API client, Configs, DI, Local DB)  
      - **External Services**  
        • REST API Server (movie/catalog, booking endpoints)  
        • Firebase Auth  
        • Cloud Firestore  
        • Local Storage (SharedPreferences, SQLite)  
        • Third‑party libs (Google Maps, YouTube Player)  
   b. **Relationships & Interactions**  
      - UI Widgets dispatch events → BLoC → invokes Domain UseCase → calls Repository Interface → Data Layer picks Remote or Local DataSource → REST API / Firestore / local DB → returns Entities upstream → BLoC emits new states → UI updates.  
      - Authentication flows: Presentation → AuthBloc → Firebase Auth DataSource → Auth Repository → domain → persists token in SharedPreferences.  
      - Booking: BLoC → use case to fetch time slots (mock or remote) → user selects → commit booking via REST API → ticket saved in Cloud Firestore and/or local DB → displayed in Tickets screen.  
   c. **Architectural patterns**  
      - **Clean Architecture**: strict layer dependency (outer layers depend on inner abstractions)  
      - **BLoC**: one BLoC per feature/screen to manage state transitions  
      - **Repository Pattern**: abstracts data sources, choose remote vs mock/local  
      - **Service Locator (GetIt)**: resolves dependencies at startup  
      - **Code Generation**: JSON Serializable, Freezed, Retrofit generator for DTOs  
   d. **Key technologies**  
      - Flutter UI (Widgets), BLoC (flutter_bloc, hydrated_bloc), GoRouter  
      - Networking: Dio + Retrofit  
      - Auth & DB: Firebase Auth, Cloud Firestore, SharedPreferences, Sqflite  
      - DI: GetIt  
      - JSON & immutability: json_serializable, freezed, equatable  

5. Guidelines for tailoring the diagram  
   - **Full‑stack client**: emphasize layered separation within the client app and highlight only external backends (REST API, Firebase).  
   - Emphasize feature modules (home, booking, movie_detail, tickets) as clustered sub‑components under Presentation.  
   - Show the ERD separately or as inset to cover Cinema, Movie, User, Booking, Seat, ShowTime relations.

6. Diagram elements to include  
   - **Shapes/Colors**:  
     • Rectangles for layers (Presentation, Domain, Data, Core) colored distinctively  
     • Cylinders for databases (SQLite, Firestore)  
     • Clouds for external services (REST API, Firebase Auth)  
     • Rounded boxes for feature modules (Login, Home, Booking, Tickets)  
   - **Labels**: clear names (e.g., “BookingSeatSlotBloc”, “MovieInfoService”)  
   - **Arrows**:  
     • Downward arrows for “depends on / calls”  
     • Upward arrows for “data flow response”  
   - **Legend**: icon or color key for Flutter layers vs external services vs local storage.

7. Detail level  
   - Capture each layer’s major sub‑components (e.g., under Data: models, repository_impl, remote_service)  
   - Group similar features (all booking-related BLoCs under one “Booking” container).  
   - Don’t overcrowd: collapse low‑level widgets into “UI Widgets” cluster but list critical ones (e.g., GoRouter, ServiceLocator).

By following these steps and conventions, you’ll produce a clear, accurate, and detailed system design diagram that reflects the Cinema Booking app’s Clean Architecture, feature modules, and external integrations.  
</explanation>

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        UI["UI Widgets"]:::presentation
        Router["GoRouter"]:::presentation
        subgraph "Feature Modules"
            direction TB
            HomeBloc["HomeBloc"]:::presentation
            MovieDetailBloc["MovieDetailBloc"]:::presentation
            BookingBloc["BookingBloc"]:::presentation
            TicketsBloc["TicketsBloc"]:::presentation
            AllMoviesBloc["AllMoviesBloc"]:::presentation
            AuthBloc["AuthBloc"]:::presentation
            AboutBloc["AboutBloc"]:::presentation
        end
        UI -->|dispatch events| AuthBloc
        UI -->|dispatch events| HomeBloc
        UI -->|dispatch events| MovieDetailBloc
        UI -->|dispatch events| BookingBloc
        UI -->|dispatch events| TicketsBloc
        UI -->|dispatch events| AllMoviesBloc
        UI -->|dispatch events| AboutBloc
        Router --> UI
        click Router "https://github.com/chunhthanhde/cinema-booking/blob/main/lib/presentation/router.dart"
        click UI "https://github.com/chunhthanhde/cinema-booking/tree/main/lib/presentation"
    end

    %% Domain Layer
    subgraph "Domain Layer" 
        direction TB
        Entities["Entities"]:::domain
        RepoInterface["Repository Interfaces"]:::domain
        UseCases["Use Cases"]:::domain
    end
    HomeBloc -->|invokes| UseCases
    MovieDetailBloc -->|invokes| UseCases
    BookingBloc -->|invokes| UseCases
    TicketsBloc -->|invokes| UseCases
    AllMoviesBloc -->|invokes| UseCases
    AuthBloc -->|invokes| UseCases
    AboutBloc -->|invokes| UseCases
    UseCases -->|depend on| RepoInterface
    RepoInterface -->|define contracts for| Entities

    click Entities "https://github.com/chunhthanhde/cinema-booking/tree/main/lib/domain/entities"
    click RepoInterface "https://github.com/chunhthanhde/cinema-booking/tree/main/lib/domain/repository"
    click UseCases "https://github.com/chunhthanhde/cinema-booking/tree/main/lib/domain/usecase"

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Models["Models (DTOs)"]:::data
        RepoImpl["Repository Implementations"]:::data
        DataSources["Data Sources"]:::data
    end
    RepoInterface -->|implemented by| RepoImpl
    RepoImpl -->|uses| DataSources
    DataSources -->|map to| Models
    Models -->|convert to| Entities

    click Models "https://github.com/chunhthanhde/cinema-booking/tree/main/lib/data/models"
    click RepoImpl "https://github.com/chunhthanhde/cinema-booking/tree/main/lib/data/repository"
    click DataSources "https://github.com/chunhthanhde/cinema-booking/tree/main/lib/data/sources"

    %% Core Layer
    subgraph "Core Layer"
        direction TB
        ApiClient["DioProvider & RestClient"]:::core
        LocalStorage["SharedPreferences & SQLite"]:::core
        ServiceLocator["Service Locator (GetIt)"]:::core
        Configs["App Configurations"]:::core
    end
    DataSources -->|calls| ApiClient
    DataSources -->|access| LocalStorage
    UseCases -->|use| ServiceLocator
    UI -->|initialized by| ServiceLocator
    Configs -->|provide| ApiClient

    click ApiClient "https://github.com/chunhthanhde/cinema-booking/blob/main/lib/core/api/dio_provider.dart"
    click ApiClient "https://github.com/chunhthanhde/cinema-booking/blob/main/lib/core/api/rest_client.dart"
    click LocalStorage "https://github.com/chunhthanhde/cinema-booking/blob/main/lib/core/local/pref.dart"
    click LocalStorage "https://github.com/chunhthanhde/cinema-booking/blob/main/lib/core/local/db_helper.dart"
    click ServiceLocator "https://github.com/chunhthanhde/cinema-booking/blob/main/lib/service_locator.dart"
    click Configs "https://github.com/chunhthanhde/cinema-booking/tree/main/lib/core/configs"

    %% Common Layer
    subgraph "Common Layer"
        direction TB
        SharedWidgets["Shared Widgets"]:::common
        ThemeBloc["ThemeCubit"]:::common
        AuthStateBloc["AuthenticationBloc"]:::common
    end
    UI --> SharedWidgets
    UI --> ThemeBloc
    UI --> AuthStateBloc

    click SharedWidgets "https://github.com/chunhthanhde/cinema-booking/tree/main/lib/common"
    click ThemeBloc "https://github.com/chunhthanhde/cinema-booking/blob/main/lib/common/bloc/theme/theme_cubit.dart"
    click AuthStateBloc "https://github.com/chunhthanhde/cinema-booking/blob/main/lib/common/bloc/authentication/authentication_bloc.dart"

    %% External Services
    RESTAPI["REST API"]:::external
    FirebaseAuth["Firebase Auth"]:::external
    Firestore[(Cloud Firestore)]:::external
    ThirdParty["Third‑Party Libs (Maps, YouTube)"]:::external

    ApiClient -->|HTTP| RESTAPI
    AuthBloc -->|authenticate via| FirebaseAuth
    AuthBloc -->|store session in| Firestore
    BookingBloc -->|commit booking to| RESTAPI
    BookingBloc -->|save ticket to| Firestore
    DataSources -->|fallback/mock| ThirdParty

    %% Local DB
    SQLite[(SQLite)]:::core
    LocalStorage --> SQLite

    %% Application Entry
    Main["main.dart"]:::presentation
    Main --> ServiceLocator
    Main --> Router
    Main --> UI
    click Main "https://github.com/chunhthanhde/cinema-booking/blob/main/lib/main.dart"

    %% Styles
    classDef presentation fill:#CEF,stroke:#036,stroke-width:1px
    classDef domain fill:#EFC,stroke:#630,stroke-width:1px
    classDef data fill:#FCE,stroke:#C30,stroke-width:1px
    classDef core fill:#CFE,stroke:#063,stroke-width:1px
    classDef common fill:#CFF,stroke:#036,stroke-width:1px
    classDef external fill:#FCC,stroke:#900,stroke-width:1px
```
