# twilight2368/web-ticket-booking-cinema-project architecture

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

- Interactive diagram: https://gitdiagram.com/twilight2368/web-ticket-booking-cinema-project
- Repository: https://github.com/twilight2368/web-ticket-booking-cinema-project

## Overview

##### Project Type and Purpose
- The project is a full-stack web application for managing movie-related activities (booking tickets, showing movie information, managing news, payments, etc.).
- The backend is built with Node.js, employing various submodules (authentication, caching, emailing, logging) and works with a database (using MongoDB as suggested by the connectMongo.js file).
- The frontend appears in multiple flavors: one under “draft-ui/web-booking-fe” (likely an admin dashboard or a styled booking interface) and another under “frontend/client-app” (the client-facing UI).
- The README is minimal (labels this as “Project bai tap lon cho mon lap trinh Web”), indicating it’s a major project from a web programming course.

##### Analyzing the File Structure
- The backend directory is well-structured into configurations, controllers (for movies, news, payment, etc.), models (with separate directories for production data and migration mock data), routes, authentication (using JWT and Passport), caching (with Redis), mailing (using nodemailer), and logging components.
- The existence of a “database” folder (with a JSON file and its own README) suggests some demo or seed data.
- The frontends are further split into “draft-ui/web-booking-fe” and “frontend/client-app”. Both use modern frontend technologies (React, Tailwind CSS, Vite in one, and similar structures in the other). They have components for building UI elements like headers, footers, modals, and pages for booking, movies, news, profiles, etc.
- Configuration files like .env examples, tailwind.config.js, vite.config.js, etc., indicate that both frontends are set-up for local builds and potential production deployment.

a. Main Components:
– Client Frontend(s):
- "draft-ui/web-booking-fe": Likely the complete web front end for booking (or possibly the admin dashboard).
- "frontend/client-app": The client-facing application.
– Backend Server:
- Main Express server (initial entry point: index.js in backend) handling HTTP routing.
- Controllers to process business logic (managing movies, news, bookings, payments, user management).
- Middlewares for authentication (JWT, Passport), error handling, and general request processing.
- Sub-modules for caching (Redis connections), mailing (nodemailer module), and logging.
– Database:
- MongoDB accessed via the connection module (connectMongo.js).
- A file-based demo or seed database in the “database” folder.
– External Services:
- Redis server (for caching).
- Possibly external email services integrated via nodemailer.
- Payment gateways (if integrated into payment.controller.js).

b. Relationships and Interactions:
– Frontend applications communicate with the backend via RESTful APIs (routes for authentication, movie info retrieval, bookings, payments, etc.).
– The backend uses controllers to manage incoming requests, which in turn interact with:
- The database (for persistent storage of movies, bookings, user details, etc.).
- External caching (via Redis) to enhance performance.
- External emailing services for notifications.
– Authentication modules (JWT and Passport) secure sensitive endpoints.
– Logging tools record events across the services.
– Mailer module sends out emails after certain user actions (like booking confirmation).

c. Architectural Patterns or Design Principles:
– Modular design through separation into controllers, middlewares, and services.
– Use of MVC-like separation in the backend (even though it may not be a strict MVC, controllers and models are clearly separated).
– REST API communication between frontends and backend.
– Use of middleware for cross-cutting concerns (authentication, error handling, logging).
– Separation of concerns is also visible in frontends (organized components, layouts, pages, and state management using Redux slices or context).

d. Relevant Technologies & Frameworks:
– Node.js, Express, Passport, JSON Web Tokens (JWT) for backend.
– MongoDB as the main database.
– Redis for caching.
– Nodemailer for emailing.
– On the frontend: React, likely using Vite as a bundler, Tailwind CSS for styling, and possibly Redux for state management (as hints by store and slice files).
– Other utilities and open-source libraries as seen in the helpers, auth, and logging modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        F1("Frontend - Client App"):::frontend
        F2("Frontend - Admin UI"):::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B1("Backend Server (Express)"):::backend
        B2("Entry Point (index.js)"):::backend
        B3("Express App (app.js)"):::backend
        B1 --> B2
        B1 --> B3

        subgraph "Backend Modules"
            BM1("Controllers"):::backend
            BM2("Authentication Module (JWT/Passport)"):::backend
            BM3("Caching Service (Redis)"):::backend
            BM4("Mail Service (Nodemailer)"):::backend
            BM5("Logging Module"):::backend
            BM6("Database Connection"):::backend
        end
        B1 --> BM2
        B1 --> BM1
        B1 --> BM5
        B1 --> BM3
        B1 --> BM4
        B1 --> BM6
    end

    %% External Services
    subgraph "External Services"
        DB1("MongoDB Database"):::external
        DS("Demo/Seed Database"):::external
        RS("Redis Server"):::external
        EE("External Email Service"):::external
        PG("Payment Gateway"):::external
    end

    %% Inter-layer Connections
    F1 -->|"HTTP_Request"| B1
    F2 -->|"HTTP_Request"| B1

    BM1 -->|"CRUD_operations"| BM6
    BM1 -->|"Trigger_Email"| BM4
    BM1 -->|"Process_Payment"| PG
    BM2 -->|"Secures"| BM1

    BM6 -->|"Connects_to"| DB1
    BM6 -->|"Seeds"| DS

    BM3 -->|"Interacts_with"| RS
    BM4 -->|"Sends_via"| EE

    %% Click Events
    click F1 "https://github.com/twilight2368/web-ticket-booking-cinema-project/tree/main/frontend/client-app"
    click F2 "https://github.com/twilight2368/web-ticket-booking-cinema-project/tree/main/draft-ui/web-booking-fe"
    click B2 "https://github.com/twilight2368/web-ticket-booking-cinema-project/blob/main/backend/index.js"
    click B3 "https://github.com/twilight2368/web-ticket-booking-cinema-project/blob/main/backend/src/app.js"
    click BM1 "https://github.com/twilight2368/web-ticket-booking-cinema-project/tree/main/backend/src/controllers"
    click BM2 "https://github.com/twilight2368/web-ticket-booking-cinema-project/tree/main/backend/src/auth"
    click BM3 "https://github.com/twilight2368/web-ticket-booking-cinema-project/blob/main/backend/src/cache/redis/connection.js"
    click BM4 "https://github.com/twilight2368/web-ticket-booking-cinema-project/blob/main/backend/src/mail/nodemailer.js"
    click BM5 "https://github.com/twilight2368/web-ticket-booking-cinema-project/blob/main/backend/src/logging/tools/logger.js"
    click BM6 "https://github.com/twilight2368/web-ticket-booking-cinema-project/blob/main/backend/src/models/connections/connectMongo.js"
    click DS "https://github.com/twilight2368/web-ticket-booking-cinema-project/tree/main/database"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#2a9df4,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef external fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
```
