# key-runnnnnnn/flights-and-search-service architecture

> Architecture diagram of the GitHub repository key-runnnnnnn/flights-and-search-service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/key-runnnnnnn/flights-and-search-service
- Repository: https://github.com/key-runnnnnnn/flights-and-search-service

## Overview

##### Project type and purpose
- This is a Node.js-based, RESTful “Flight Service” API.
- It exposes CRUD and search endpoints around flights, airplanes, airports, and cities.
- It uses Express.js for routing, Sequelize (ORM) for MySQL interactions, plus migrations/seeders for database lifecycle.

##### File structure
- Top-level:
- package.json / package-lock.json – Node dependencies and scripts
- src/index.js – app entry point (loads config, starts Express)
- src/config – environment & DB configuration (db.js, serverConfig.js, config.json stub)
- src/routes & src/routes/v1 – HTTP route definitions (versioned API)
- src/controllers – handle incoming requests, call services
- src/services – business logic, orchestrates calls to repositories
- src/repository – data-access layer, wraps Sequelize models
- src/models – Sequelize model definitions
- src/migrations & src/seeders – DB schema and initial data scripts
- src/middlewares – request/response processing (validation, error handling)
- src/utils – shared helpers and error codes

##### README for additional insights
- Describes environment setup (.env, PORT=3000, src/config/config.json)
- DB domain model:
- City 1-to-many Airport
- Airport 1-to-many Flight
- Airplane 1-to-many Flight

##### Be detailed but modular
- Do not collapse related but distinct modules (e.g., show separate repositories even if they share a base class)
- Essential elements: config loader, error utils, helper utilities

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["External Client"]:::external

    %% Config Layer
    subgraph "Configuration & Environment"
        DBConfig["db.js"]:::config
        ServerConfig["serverConfig.js"]:::config
    end

    %% HTTP Server
    APIServer["Express HTTP Server\n(src/index.js)"]:::api

    %% Middleware Layer
    subgraph "Middleware Layer"
        MiddlewareIndex["index.js"]:::api
        FlightMiddlewares["flight-middlewares.js"]:::api
    end

    %% Routing Layer
    subgraph "Routing Layer (v1)"
        RoutesIndex["routes/index.js"]:::api
        V1Routes["routes/v1/index.js"]:::api
    end

    %% Controller Layer
    subgraph "Controller Layer"
        CityController["CityController\n(city-controller.js)"]:::api
        AirportController["AirportController\n(airport-controller.js)"]:::api
        FlightController["FlightController\n(flight-controller.js)"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        CityService["CityService\n(city-service.js)"]:::service
        AirportService["AirportService\n(airport-service.js)"]:::service
        FlightService["FlightService\n(flight-service.js)"]:::service
        GenericCrudService["GenericCrudService\n(crud-service.js)"]:::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        CityRepository["CityRepository\n(city-repository.js)"]:::data
        AirportRepository["AirportRepository\n(airport-repository.js)"]:::data
        FlightRepository["FlightRepository\n(flight-repository.js)"]:::data
        AirplaneRepository["AirplaneRepository\n(airplane-repository.js)"]:::data
        GenericCrudRepository["GenericCrudRepository\n(crud-repository.js)"]:::data
    end

    %% ORM & Models
    subgraph "ORM & Models"
        SequelizeInit["Sequelize Init\n(models/index.js)"]:::data
        CityModel["City Model\n(city.js)"]:::data
        AirportModel["Airport Model\n(airport.js)"]:::data
        AirplaneModel["Airplane Model\n(airplane.js)"]:::data
        FlightModel["Flight Model\n(flights.js)"]:::data
    end

    %% Database
    DB["MySQL Database\n(Flights_Search_DB_DEV)"]:::data

    %% Migrations
    subgraph "Migrations"
        CreateCity["20240604051840-create-city.js"]:::offline
        CreateAirport["20240607110922-create-airport.js"]:::offline
        CreateAirplane["20240609091041-create-airplane.js"]:::offline
        CreateFlights["20240609101453-create-flights.js"]:::offline
    end

    %% Seeders
    subgraph "Seeders"
        SeedAirports["20240607113622-add-airports.js"]:::offline
        SeedAirplanes["20240609093007-add-airplanes.js"]:::offline
    end

    %% Utilities
    subgraph "Utilities"
        Helper["helper.js"]:::config
        ErrorCodes["error-codes.js"]:::config
    end

    %% Flows
    Client -->|"REST Requests"| APIServer
    APIServer -->|"load config"| DBConfig
    APIServer --> ServerConfig
    APIServer -->|"register middleware"| MiddlewareIndex
    MiddlewareIndex --> FlightMiddlewares
    FlightMiddlewares --> RoutesIndex
    RoutesIndex --> V1Routes
    V1Routes --> CityController
    V1Routes --> AirportController
    V1Routes --> FlightController
    CityController --> CityService
    AirportController --> AirportService
    FlightController --> FlightService
    CityService --> CityRepository
    AirportService --> AirportRepository
    FlightService --> FlightRepository
    GenericCrudService --> GenericCrudRepository
    CityRepository --> SequelizeInit
    AirportRepository --> SequelizeInit
    FlightRepository --> SequelizeInit
    AirplaneRepository --> SequelizeInit
    GenericCrudRepository --> SequelizeInit
    SequelizeInit --> CityModel
    SequelizeInit --> AirportModel
    SequelizeInit --> AirplaneModel
    SequelizeInit --> FlightModel
    CityModel --> DB
    AirportModel --> DB
    AirplaneModel --> DB
    FlightModel --> DB

    %% Offline processes
    CreateCity -.-> DB
    CreateAirport -.-> DB
    CreateAirplane -.-> DB
    CreateFlights -.-> DB
    SeedAirports -.-> DB
    SeedAirplanes -.-> DB

    %% Click Events
    click APIServer "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/index.js"
    click DBConfig "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/config/db.js"
    click ServerConfig "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/config/serverConfig.js"
    click MiddlewareIndex "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/middlewares/index.js"
    click FlightMiddlewares "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/middlewares/flight-middlewares.js"
    click RoutesIndex "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/routes/index.js"
    click V1Routes "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/routes/v1/index.js"
    click CityController "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/controllers/city-controller.js"
    click AirportController "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/controllers/airport-controller.js"
    click FlightController "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/controllers/flight-controller.js"
    click CityService "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/services/city-service.js"
    click AirportService "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/services/airport-service.js"
    click FlightService "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/services/flight-service.js"
    click GenericCrudService "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/services/crud-service.js"
    click CityRepository "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/repository/city-repository.js"
    click AirportRepository "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/repository/airport-repository.js"
    click FlightRepository "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/repository/flight-repository.js"
    click AirplaneRepository "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/repository/airplane-repository.js"
    click GenericCrudRepository "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/repository/crud-repository.js"
    click SequelizeInit "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/models/index.js"
    click CityModel "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/models/city.js"
    click AirportModel "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/models/airport.js"
    click AirplaneModel "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/models/airplane.js"
    click FlightModel "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/models/flights.js"
    click CreateCity "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/migrations/20240604051840-create-city.js"
    click CreateAirport "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/migrations/20240607110922-create-airport.js"
    click CreateAirplane "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/migrations/20240609091041-create-airplane.js"
    click CreateFlights "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/migrations/20240609101453-create-flights.js"
    click SeedAirports "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/seeders/20240607113622-add-airports.js"
    click SeedAirplanes "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/seeders/20240609093007-add-airplanes.js"
    click Helper "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/utils/helper.js"
    click ErrorCodes "https://github.com/key-runnnnnnn/flights-and-search-service/blob/master/src/utils/error-codes.js"

    %% Styles
    classDef api fill:#D6EFFF,stroke:#0366d6,stroke-width:1px
    classDef service fill:#E0F8E0,stroke:#28a745,stroke-width:1px
    classDef data fill:#FFE4B3,stroke:#e36209,stroke-width:1px
    classDef config fill:#F0F0F0,stroke:#6a737d,stroke-width:1px
    classDef offline fill:#F8F8F8,stroke-dasharray: 5 5,stroke:#6a737d
    classDef external fill:#ffffff,stroke:#0366d6,stroke-width:2px,stroke-dasharray: 2 2
```
