# hoc081098/movie-ticket-booking architecture

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

- Interactive diagram: https://gitdiagram.com/hoc081098/movie-ticket-booking
- Repository: https://github.com/hoc081098/movie-ticket-booking

## Overview

##### Main Components
- Frontend Mobile Apps:
- User Mobile App (located in MobileApp/datn)
- Admin Mobile App (located in MobileApp/movie_admin)
- Backend:
- NestJS-based API server (located in Backend/main) with many sub-modules (auth, movies, theatres, seats, reservations, socket communication, etc.)
- Real-time communication via socket (socket gateway)
- Databases and External Services:
- MongoDB for primary data storage
- Neo4j for recommendation and graph-based queries (with modules for movie transfers and search via Cypher)
- External APIs such as Stripe, MovieDB API, Firebase authentication and notifications, and Google Places API (for mobile apps)
- Supporting Layers:
- Configuration and environment file management (.env and config module)
- Utility modules (common utilities, decorators, DTOs, etc.)
- Testing and documentation components (Docs folder and test directories)

##### Relationships and Interactions
- Both mobile apps (User and Admin) communicate with the NestJS backend via RESTful APIs and socket connections.
- The backend further interacts with MongoDB (for standard CRUD operations) and with Neo4j (for advanced recommendation queries and graph queries).
- External services (Stripe for payments, Firebase for real-time notifications, third‑party API keys for movie data) are integrated at the configuration level in the backend.
- The mobile apps implement state management using Flutter BLoC and other libraries, and they use network clients to communicate with the backend.
- Additionally, there is separation in backend modules following a modular pattern (each feature such as movies, comments, promotions, reservations is separated into its own module) and custom guards, decorators, and middleware that manage authentication and authorization.

##### Architectural Patterns and Design Principles
- The backend uses the modular design pattern of NestJS (each domain feature is encapsulated in its controller, service, and module).
- MVC-like flows: controllers handle requests, services process business logic, and schema/DTOs support data validation.
- Micro-frontends in the mobile apps: although both mobile apps are built in Flutter, they remain separated by purpose (user versus admin) to provide different interfaces and functionalities.
- Real-time communication with socket.io integrated in the backend.
- Use of dependency injection and separation of concerns in both backend and Flutter application code.
- Environment-based configuration through .env files and external service keys.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UM("User Mobile App (Flutter)"):::mobile
        AM("Admin Mobile App (Flutter)"):::mobile
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE("NestJS API Server"):::backend

        subgraph "Feature Modules"
            Auth("Authentication Module"):::backend
            Movies("Movies Module"):::backend
            Theatres("Theatres Module"):::backend
            ShowTimes("Show Times Module"):::backend
            Seats("Seats Module"):::backend
            Comments("Comments Module"):::backend
            Notifications("Notifications Module"):::backend
            Reservations("Reservations Module"):::backend
            Socket("Socket Module"):::backend
        end

        Config("Config & Environment Management"):::backend
        Utilities("Utility Components"):::backend

        subgraph "API Integrations"
            Stripe("Stripe API"):::external
            MovieDB("MovieDB API"):::external
            Firebase("Firebase"):::external
            GooglePlaces("Google Places API"):::external
        end
    end

    %% Data Layer & External Services
    subgraph "Data Layer & External Services"
        DB("MongoDB"):::db
        Neo4j("Neo4j Database"):::db
        Docs("Documentation"):::external
        Testing("Testing"):::external
    end

    %% Interconnections between layers
    UM ---|"RESTful API"| BE
    AM ---|"RESTful API"| BE

    BE -->|"CRUD Operations"| DB
    Movies -->|"CRUD"| DB
    Theatres -->|"CRUD"| DB
    Reservations -->|"CRUD"| DB

    BE -->|"GraphQueries"| Neo4j

    Socket ---|"RealTimeComm"| UM
    Socket ---|"RealTimeComm"| AM

    Auth ---|"Uses"| Config
    Movies ---|"Uses"| Utilities

    BE -->|"Calls"| Stripe
    BE -->|"Calls"| MovieDB
    BE -->|"Calls"| Firebase
    BE -->|"Calls"| GooglePlaces

    BE ---|"Docs/Test"| Docs
    BE ---|"Docs/Test"| Testing

    %% Click Events
    click UM "https://github.com/hoc081098/movie-ticket-booking/tree/master/MobileApp/datn"
    click AM "https://github.com/hoc081098/movie-ticket-booking/tree/master/MobileApp/movie_admin"
    click BE "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main"
    click Auth "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/auth"
    click Movies "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/movies"
    click Theatres "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/theatres"
    click ShowTimes "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/show-times"
    click Seats "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/seats"
    click Comments "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/comments"
    click Notifications "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/notifications"
    click Reservations "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/reservations"
    click Socket "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/socket"
    click Neo4j "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/neo4j"
    click Config "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/config"
    click Utilities "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/src/common"
    click Docs "https://github.com/hoc081098/movie-ticket-booking/tree/master/Docs"
    click Testing "https://github.com/hoc081098/movie-ticket-booking/tree/master/Backend/main/test"

    %% Styles
    classDef mobile fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFE4B5,stroke:#000,stroke-width:2px;
    classDef db fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef external fill:#DDA0DD,stroke:#000,stroke-width:2px;
```
