# dluong1210/qairline architecture

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

- Interactive diagram: https://gitdiagram.com/dluong1210/qairline
- Repository: https://github.com/dluong1210/qairline

## Overview

Based on our analysis of the file tree and README, QAirline is a full‐stack application designed for airline management/booking. It features a React-based frontend (located under src/FE) and a Node/Express backend (under src/server) that manages business logic, user authentication, and database interactions (with the database schema provided in QAirline_database.zip and server/database files).

##### Main Components
- Frontend Application: Represent the client-side UI built with React. Indicate that this layer includes:
- Components for user interactions (e.g., Home, SearchFlight, Profile, Notification, and specialized admin pages under src/FE/src/components/admin).
- Utility modules such as contexts (e.g., AuthContext), hooks (e.g., useLogin, useRegister), services (api.js for REST calls), and assets (CSS and images).
- A clear separation of concerns (e.g., pages, general components, admin interfaces) which suggests a modular design.
- Backend Server: Represent the Node/Express server responsible for:
- Handling API endpoints (grouped under routes such as auth, flight, airplane, airport, booking, and user).
- Processing requests via controllers (located in src/server/controllers) which follow the MVC-like pattern.
- Managing database operations via models (in src/server/models) and interacting with the database (set up by the provided SQL scripts and database.js).
- Applying middleware (e.g., auth.middleware.js) for authentication or authorization.
- Database: Represent the persistent storage (hinted at with QAirline_database.zip and the SQL creation scripts) that the backend communicates with.

##### Relationships and Interactions
- The User (or Browser) interacts with the Frontend UI.
- The Frontend makes RESTful API calls via its “services/api.js” to the Node/Express backend.
- The Backend processes the incoming API requests, routes them to appropriate controllers, applies middleware where necessary, and performs CRUD operations against the Database.
- There is an administrative interface on the frontend as well, showing additional interactions for admin users.

##### Architectural Patterns/Design Principles
- Full-stack Separation: A distinct separation between frontend and backend processes, sometimes even running concurrently. This is indicated by separate npm scripts for “FE” and “server”.
- MVC-like Pattern on the Backend: With clear divisions among models, views (in this case, controllers and routes), and middleware.
- Component-Based UI on the Frontend: The React application is organized into various reusable components for different pages and functionalities.
- Modular Design: Both the frontend and backend are broken down into folders/modules (e.g., components, hooks, routes, controllers) that logically group related functionalities.

##### Relevant Technologies & Frameworks
- Frontend: React (components, hooks, contexts), CSS styling, and possibly other libraries (as inferred by the extensive component structure).
- Backend: Node.js and Express.js for handling routes, controllers, and middleware.
- Database: A relational database managed via provided SQL scripts (details can be extracted from QAirline_database.zip).
- Additional: Scripts for concurrent running and package management (npm scripts, package.json files).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global User
    U["User/Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend (React Client)"
        direction TB
        %% UI Components
        subgraph "UI Components"
            A["Main React App"]:::fe
            H["Home Page"]:::fe
            S["SearchFlight Page"]:::fe
            P["Profile Page"]:::fe
            N["Notification Page"]:::fe
        end
        %% Utility Modules
        subgraph "Utility Modules"
            AC["Auth Context"]:::fe
            UL["useLogin"]:::fe
            UR["useRegister"]:::fe
            AP["API Service"]:::fe
        end
        %% Admin Interface
        subgraph "Admin Interface"
            ADM["Admin Components"]:::fe
        end
        %% Public Assets
        subgraph "Public Assets"
            AS["Assets"]:::fe
        end
    end

    %% Backend Layer
    subgraph "Backend (Express Server)"
        direction TB
        %% API Routes
        subgraph "API Routes"
            R["Routes"]:::be
        end
        %% Controllers
        subgraph "Controllers"
            C["Controllers"]:::be
        end
        %% Middleware
        subgraph "Middleware"
            M["Auth Middleware"]:::be
        end
        %% Database Operations
        subgraph "Database Operations"
            MD["Models & DB Logic"]:::be
            DC["DB Connection"]:::be
            SQL["SQL Schema"]:::be
        end
    end

    %% Database Component
    D["Database"]:::db

    %% Connections
    U -->|"interacts"| A
    AP -->|"calls"| R
    R -->|"uses"| M
    R -->|"routesTo"| C
    C -->|"performsOps"| MD
    MD -->|"connectsVia"| DC
    DC -->|"queries"| D
    SQL -->|"defines"| D

    %% Click Events for Frontend
    click A "https://github.com/dluong1210/qairline/blob/main/src/FE/src/App.js"
    click H "https://github.com/dluong1210/qairline/blob/main/src/FE/src/components/pages/Home.js"
    click S "https://github.com/dluong1210/qairline/blob/main/src/FE/src/components/SearchFlight/SearchFlight.js"
    click P "https://github.com/dluong1210/qairline/blob/main/src/FE/src/components/Profile/Profile.js"
    click N "https://github.com/dluong1210/qairline/blob/main/src/FE/src/components/Notification/Notification.js"
    click ADM "https://github.com/dluong1210/qairline/tree/main/src/FE/src/components/admin"
    click AC "https://github.com/dluong1210/qairline/blob/main/src/FE/src/contexts/AuthContext.js"
    click UL "https://github.com/dluong1210/qairline/blob/main/src/FE/src/hooks/auth/useLogin.js"
    click UR "https://github.com/dluong1210/qairline/blob/main/src/FE/src/hooks/auth/useRegister.js"
    click AP "https://github.com/dluong1210/qairline/blob/main/src/FE/src/services/api.js"
    click AS "https://github.com/dluong1210/qairline/tree/main/src/FE/src/assets"

    %% Click Events for Backend
    click R "https://github.com/dluong1210/qairline/blob/main/src/server/routes/auth.js"
    click C "https://github.com/dluong1210/qairline/blob/main/src/server/controllers/auth.js"
    click M "https://github.com/dluong1210/qairline/blob/main/src/server/middleware/auth.middleware.js"
    click MD "https://github.com/dluong1210/qairline/tree/main/src/server/models"
    click DC "https://github.com/dluong1210/qairline/blob/main/src/server/database/database.js"
    click SQL "https://github.com/dluong1210/qairline/blob/main/src/server/database/create_database.sql"

    %% Style Definitions
    classDef fe fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef be fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef db fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px,stroke-dasharray: 5 5;
```
