# 99sparsh/dbs-project architecture

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

- Interactive diagram: https://gitdiagram.com/99sparsh/dbs-project
- Repository: https://github.com/99sparsh/dbs-project

## Overview

##### Project type and purpose
- This is a full-stack Node.js/Express web application called “Airport Management System.”
- It uses MySQL for persistent storage, Redis (dump.rdb) for session/cache, EJS templates for server-rendered views, and static assets under public/.

##### File structure
- app.js: main Express entry point
- config/: database (conn.js), authentication (passport.js), Redis setup (redis.js)
- routes/: Express route modules (auth, frontend, airlineadmin, airportadmin, system, etc.)
- schemas/: request/data validation schemas per route
- utils/: async helper (to.js), response formatting, input validation
- views/: EJS templates for each page (login, home, add-entity, schedule, etc.)
- public/: Bootstrap CSS/JS, custom CSS, fonts, client-side JS (add.js, booking.js, airline.js, crew.js, …)
- Airport.sql: schema definition for MySQL

##### Key architecture notes from README
- Requires Node.js + npm, MySQL, Redis
- Environment configured via .env (template in envexp)
- Run via nodemon

##### Main components
a. Client browser (User Interface)
- EJS-rendered views + static assets (HTML/CSS/JS in public/)
b. Web Server (Node.js/Express)
- app.js
- Route layer (routes/*.js)
- Validation layer (schemas/*.js + utils/validator.js)
- Business logic (utils/response.js, utils/to.js)
- Authentication (config/passport.js)
c. Data Stores
- MySQL (Airport.sql)
- Redis (session/cache store via config/redis.js)
d. External/Infrastructure
- .env configuration
- nodemon (dev tool)

##### Relationships and data flows
1. User → HTTP request (click “Add Booking”) → Express router
2. Router → validate input via schemas → call controller logic
3. Controller → interacts with MySQL (via config/conn.js using mysql driver/ORM)
4. Controller → possibly read/write session from Redis
5. Controller → builds response object (utils/response.js) → selects EJS view or JSON
6. Response → client browser: EJS HTML + static JS/CSS
7. Client side JS (public/js/*.js) → may call additional API endpoints (e.g., fetch crew list)

##### Architectural patterns & principles
- Layered architecture: Presentation (views + public) → Routing → Validation → Business logic → Data access
- Separation of concerns: config, routes, schemas, utils
- MVC‐style: Views (EJS), Controllers (routes + utils), Models (MySQL tables defined via Airport.sql + data access in schemas/config)
- Session management via Redis
- Modularization: each entity (airline, airport, booking, crew, pilot, security, staff) has its own route/schema pair

##### Elements
- Notes on critical config: .env variables for DB/Redis, Passport strategies

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Airport Management System"
        subgraph "Frontend Layer"
            Browser["Client Browser UI<br/>(EJS Templates)"]:::frontend
            Static["Static Assets<br/>(public/)"]:::frontend
        end

        subgraph "Backend Layer"
            Express["Express Server<br/>(app.js)"]:::backend
            subgraph "Route Layer"
                AuthRoute["auth.js"]:::backend
                FrontRoute["frontend.js"]:::backend
                AirlineRoute["airlineadmin.js"]:::backend
                AirportRoute["airportadmin.js"]:::backend
                SystemRoute["system.js"]:::backend
                IndexRoute["index.js"]:::backend
            end
            subgraph "Validation Layer"
                Schemas["Request/Data Schemas<br/>(schemas/)"]:::backend
                Validator["validator.js"]:::backend
            end
            subgraph "Business Logic Helpers"
                Response["response.js"]:::backend
                Async["to.js"]:::backend
            end
            AuthConfig["Passport & Sessions<br/>(config/passport.js)"]:::backend
            MySQLConn["MySQL Connection<br/>(config/conn.js)"]:::backend
            RedisConfig["Redis Setup<br/>(config/redis.js)"]:::backend
        end

        subgraph "Data Layer"
            MySQL["MySQL<br/>(Airport.sql)"]:::data
            Redis["Redis<br/>(dump.rdb)"]:::data
        end

        subgraph "Infrastructure"
            Env[".env Template<br/>(envexp)"]:::infra
            Nodemon["nodemon config<br/>(package.json)"]:::infra
        end
    end

    %% Flows
    Browser -->|HTTP GET/POST| Express
    Static -->|serves assets| Browser
    Express -->|routes| AuthRoute
    Express -->|routes| FrontRoute
    Express -->|routes| AirlineRoute
    Express -->|routes| AirportRoute
    Express -->|routes| SystemRoute
    Express -->|routes| IndexRoute
    AuthRoute -->|validate input| Schemas
    FrontRoute -->|validate input| Schemas
    AirlineRoute -->|validate input| Schemas
    AirportRoute -->|validate input| Schemas
    SystemRoute -->|validate input| Schemas
    IndexRoute -->|validate input| Schemas
    Schemas -->|use| Validator
    Express -->|use| AuthConfig
    Express -->|connect| MySQLConn
    Express -->|sessionOps| RedisConfig
    Express -->|format response| Response
    Express -->|async handling| Async
    MySQLConn -->|queries| MySQL
    RedisConfig -->|read/write| Redis
    Response -->|HTML/JSON| Browser

    %% Click Events
    click Browser "https://github.com/99sparsh/dbs-project/tree/master/views/"
    click Static "https://github.com/99sparsh/dbs-project/tree/master/public/"
    click Express "https://github.com/99sparsh/dbs-project/blob/master/app.js"
    click AuthRoute "https://github.com/99sparsh/dbs-project/blob/master/routes/auth.js"
    click FrontRoute "https://github.com/99sparsh/dbs-project/blob/master/routes/frontend.js"
    click AirlineRoute "https://github.com/99sparsh/dbs-project/blob/master/routes/airlineadmin.js"
    click AirportRoute "https://github.com/99sparsh/dbs-project/blob/master/routes/airportadmin.js"
    click SystemRoute "https://github.com/99sparsh/dbs-project/blob/master/routes/system.js"
    click IndexRoute "https://github.com/99sparsh/dbs-project/blob/master/routes/index.js"
    click Schemas "https://github.com/99sparsh/dbs-project/tree/master/schemas/"
    click Validator "https://github.com/99sparsh/dbs-project/blob/master/utils/validator.js"
    click Response "https://github.com/99sparsh/dbs-project/blob/master/utils/response.js"
    click Async "https://github.com/99sparsh/dbs-project/blob/master/utils/to.js"
    click AuthConfig "https://github.com/99sparsh/dbs-project/blob/master/config/passport.js"
    click MySQLConn "https://github.com/99sparsh/dbs-project/blob/master/config/conn.js"
    click RedisConfig "https://github.com/99sparsh/dbs-project/blob/master/config/redis.js"
    click MySQL "https://github.com/99sparsh/dbs-project/blob/master/Airport.sql"
    click Redis "https://github.com/99sparsh/dbs-project/blob/master/dump.rdb"
    click Env "https://github.com/99sparsh/dbs-project/tree/master/envexp"
    click Nodemon "https://github.com/99sparsh/dbs-project/blob/master/package.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef backend fill:#DFFFE0,stroke:#28A745,color:#28A745;
    classDef data fill:#FFF4D6,stroke:#D69E00,color:#D69E00;
    classDef infra fill:#F0F0F0,stroke:#999999,color:#333333;
```
