# sebikea/flybook architecture

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

- Interactive diagram: https://gitdiagram.com/sebikea/flybook
- Repository: https://github.com/sebikea/flybook

## Overview

##### Project Type and Purpose
- This is a deliberately‐vulnerable full-stack flight booking demo.
- It consists of:
- A static front end (HTML/CSS/JS) in `web-app/`
- A PHP-based API layer in `api/`
- A CGI component in C++ under `cgi-bin/`
- A MySQL database schema in `sql/`
- Docker-based deployment (Dockerfile + docker-compose.yml)

##### File Structure
- Top level
- Dockerfile, docker-compose.yml → containerize all services
- README.md → usage instructions
- `sql/flybook.sql` → DB schema and initial data
- API tier
- `api/API.php` → main PHP endpoint routing requests
- `api/database.php` → DB connection logic
- CGI tier
- `cgi-bin/status_check` (compiled from status_check.cpp) → external status‐check service
- Web tier
- `web-app/` with HTML, CSS, JS, images, vendor libraries

##### README for Additional Insights
- Services all run in a single docker-compose stack, exposed on port 8000

##### Main Components & Their Relationships
a. Components
- Client Browser (User Interface)
- Static Web Server (serving `web-app/`)
- PHP API Service (Apache+PHP-FPM container)
- CGI Service (invoked from web server for status checks)
- MySQL Database
- Docker Host / Docker-Compose Network
b. Interactions & Data Flow
1. Browser → HTTP GET/POST → Web Server
2. Web Server
- If request for HTML/CSS/JS → serve static file from `web-app/`
- If API request (e.g., booking operations) → forward to PHP API (`api/API.php`)
- If status-check path → invoke CGI binary (`cgi-bin/status_check`)
3. PHP API → MySQL (through `database.php`)
4. CGI → may run its own internal logic or query system state
c. Architectural Patterns & Principles
- Three-tier architecture: Presentation, Application, Data
- Separation of concerns: static assets vs. dynamic API vs. native CGI
- Containerization: all services isolated but share a Docker network
d. Key Technologies & Frameworks
- Docker & docker-compose
- Apache + PHP (API layer)
- CGI in C++ (legacy/vulnerability demo)
- MySQL (relational DB)
- Plain HTML/CSS/JS (no SPA framework)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External client
    Browser["Client Browser"]:::frontend

    %% Docker boundary
    subgraph "Docker Compose" 
        direction TB
        Docker["Docker Compose\n(Dockerfile & docker-compose.yml)"]:::infra
        
        subgraph "Web Server Container"
            direction TB
            StaticAssets["Static Web Server\nserves web-app/"]:::frontend
            CGI["CGI Service\n(cgi-bin/status_check)"]:::backend
        end

        PHPAPI["PHP API Service\napi/API.php"]:::backend
        MySQL["MySQL Database\nsql/flybook.sql"]:::database
    end

    README["README.md"]:::docs

    %% Data flows
    Browser -->|"HTTP 8000"| StaticAssets
    StaticAssets -->|"API requests (HTTP)"| PHPAPI
    StaticAssets -->|"CGI invocation (HTTP)"| CGI
    PHPAPI -->|"TCP 3306 (MySQL)"| MySQL

    %% Documentation link
    Browser --- README

    %% Click events
    click StaticAssets "https://github.com/sebikea/flybook/tree/main/web-app/"
    click PHPAPI "https://github.com/sebikea/flybook/tree/main/api/"
    click CGI "https://github.com/sebikea/flybook/tree/main/cgi-bin/"
    click MySQL "https://github.com/sebikea/flybook/blob/main/sql/flybook.sql"
    click Docker "https://github.com/sebikea/flybook/blob/main/docker-compose.yml"
    click Docker "https://github.com/sebikea/flybook/tree/main/Dockerfile"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px
    classDef database fill:#FFA500,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef docs fill:#FFFFFF,stroke:#000,stroke-width:1px
```
