# thetechieakash/booking architecture

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

- Interactive diagram: https://gitdiagram.com/thetechieakash/booking
- Repository: https://github.com/thetechieakash/booking

## Overview

##### Project type and purpose
- This is a full-stack web application called “Booking” built on PHP using the CodeIgniter 4 MVC framework.
- Purpose: A hotel and trip booking platform with separate admin and user interfaces, backed by a MySQL database, and a rich front-end using Bootstrap and custom JavaScript.

##### File structure
- Top-level:
- app/ – the CodeIgniter application folder (Controllers, Models, Views, Config, Helpers, Filters, Libraries, Database migrations & seeds).
- public/ – the web-root serving index.php, .htaccess, assets (CSS, JS, images, vendors).
- writable/ – runtime directories (cache, logs, uploads, session).
- spark – CLI tool for migrations and other CodeIgniter utilities.
- tests/ – automated tests (unit, integration, database).
- Patterns:
- MVC layers in app/: Models for data access, Controllers segmented into Admin vs User, Views under app/Views/fronts and app/Views/errors.
- Config folder centralizes environment-specific settings (database, routes, services, security, etc.).
- Database migrations and seeds illustrate schema evolution and initial data loads.
- ThirdParty & Libraries host custom or external PHP code (authentication, hashing).

##### README for additional insights
- Tech stack: PHP/CodeIgniter 4, MySQL, Bootstrap, JavaScript.
- Deployment: Uses Composer for PHP dependencies, spark CLI for migrations and seeds, .env for environment variables.
- Workflow: Clone, composer install, env setup, migrate, seed, serve with spark.

a. Main components
- Client browsers (desktop/mobile)
- Front-end layer: HTML/CSS/JS (Bootstrap + custom scripts + third-party vendor JS) served from public/assets
- Routing & Entry point: public/index.php → CodeIgniter Router → Controllers
- Controllers:
– User controllers (app/Controllers/User/*)
– Admin controllers (app/Controllers/Admin/*)
- Models (app/Models/*.php) interacting with MySQL via the Database layer/config
- Views (app/Views/fronts & app/Views/errors) generating HTML responses
- Services & Libraries (app/Config, app/Libraries, app/Helpers) for configuration, authentication, caching, encryption
- Filters: AdminFilter, UserFilter enforcing access control
- Database: MySQL instance with tables for users, admins, hotels, rooms, bookings, amenities, photos (migrations define schema)
- Writable storage: logs, cache, sessions, uploads
- CLI spark tool for migrations/seeds
- External dependencies: Composer-managed PHP packages, vendor JS/CSS packs in public/vendors

b. Relationships and data flow
1. User/browser sends HTTP request → web server (Apache/Nginx) → public/index.php
2. CodeIgniter bootstraps (app/Config/Boot) → routing resolves to a Controller
3. Controller may invoke Filters (authentication/authorization)
4. Controller calls Models to read/write database
5. Models use the Database config and drivers to communicate with MySQL
6. Controller loads Views, passing data for rendering HTML
7. Response (HTML + asset references) returns to client
8. Client may then fetch additional AJAX calls to Controllers returning JSON or partial Views
9. spark CLI (offline) interacts with migrations/seeds in app/Database to evolve schema

c. Architectural patterns & principles
- MVC separation: Clear separation of concerns between data (Models), UI (Views), and request handling/business logic (Controllers).
- Modular Controllers by role (Admin vs User)
- Config-driven environment (development/production/testing)
- Dependency injection and service locators via app/Config/Services
- Filter pipeline for cross-cutting concerns (authentication, CORS, CSRF)
- Use of migrations and seeders for reproducible database state
- Public folder isolation for static assets, securing the app/ source code

d. Key technologies/frameworks/libraries
- PHP 8+, CodeIgniter 4 core
- MySQL (via mysqli driver configured in app/Config/Database.php)
- Bootstrap CSS framework, custom CSS/JS under public/assets
- Rich vendor JS ecosystem in public/vendors (mapbox, dropzone, intl-tel-input, echarts, etc.)
- Composer for PHP dependencies, spark CLI for build tasks

##### Final reminders
- Be granular: split Controllers by admin vs user, show Filters as separate blocks, include migrations & seeds under Database.
- Environment configs (development vs production) as a note on the Config component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Client Browser\n(Desktop/Mobile)"]:::frontend
    end

    %% Front-end Static Assets
    StaticAssets["Static Assets\npublic/assets & public/vendors"]:::frontend
    click StaticAssets "https://github.com/thetechieakash/booking/tree/main/public/assets/"
    click StaticAssets "https://github.com/thetechieakash/booking/tree/main/public/vendors/"

    Browser -->|"HTTP Request"| StaticAssets
    Browser -->|"HTTP Request"| WebServer

    %% Web Server Entry
    WebServer["Web Server\n(.htaccess)"]:::external
    click WebServer "https://github.com/thetechieakash/booking/blob/main/public/.htaccess"

    WebServer -->|"Rewrite to index.php"| EntryPoint

    EntryPoint["Entry Point\npublic/index.php"]:::backend
    click EntryPoint "https://github.com/thetechieakash/booking/blob/main/public/index.php"

    %% CodeIgniter Bootstrap & Routing
    Bootstrap["Bootstrap & Preload\npreload.php"]:::backend
    click Bootstrap "https://github.com/thetechieakash/booking/blob/main/preload.php"
    EntryPoint --> Bootstrap

    ConfigEnv["Environment Config\n.env & app/Config/*.php"]:::backend
    click ConfigEnv "https://github.com/thetechieakash/booking/blob/main/app/Config/Routes.php"
    click ConfigEnv "https://github.com/thetechieakash/booking/blob/main/app/Config/Database.php"
    click ConfigEnv "https://github.com/thetechieakash/booking/blob/main/app/Config/Paths.php"
    click ConfigEnv "https://github.com/thetechieakash/booking/blob/main/app/Config/Autoload.php"
    click ConfigEnv "https://github.com/thetechieakash/booking/blob/main/app/Config/Services.php"
    click ConfigEnv "https://github.com/thetechieakash/booking/blob/main/.env"

    Routes["Router & Routes Definition"]:::backend
    click Routes "https://github.com/thetechieakash/booking/blob/main/app/Config/Routes.php"
    Bootstrap -->|"/route match"| Routes
    Routes --> Controllers

    %% Backend Logic Layer
    subgraph "Backend Logic" 
        direction TB
        Controllers["Controllers\nAdmin & User"]:::backend
        click Controllers "https://github.com/thetechieakash/booking/blob/main/app/Controllers/BaseController.php"
        click Controllers "https://github.com/thetechieakash/booking/blob/main/app/Controllers/RenderAdminViewController.php"
        click Controllers "https://github.com/thetechieakash/booking/blob/main/app/Controllers/RenderUserViewController.php"
        click Controllers "https://github.com/thetechieakash/booking/tree/main/app/Controllers/Admin/"
        click Controllers "https://github.com/thetechieakash/booking/tree/main/app/Controllers/User/"

        Filters["Filters\nAdminFilter, UserFilter"]:::backend
        click Filters "https://github.com/thetechieakash/booking/blob/main/app/Filters/AdminFilter.php"
        click Filters "https://github.com/thetechieakash/booking/blob/main/app/Filters/UserFilter.php"

        Helpers["Helpers"]:::backend
        click Helpers "https://github.com/thetechieakash/booking/tree/main/app/Helpers/"

        Libraries["Libraries & Services"]:::backend
        click Libraries "https://github.com/thetechieakash/booking/tree/main/app/Libraries/"
        click Libraries "https://github.com/thetechieakash/booking/blob/main/app/Config/Services.php"

        Models["Models\nData Access"]:::backend
        click Models "https://github.com/thetechieakash/booking/tree/main/app/Models/"

        Views["Views\nUser & Admin UI"]:::frontend
        click Views "https://github.com/thetechieakash/booking/tree/main/app/Views/fronts/user/"
        click Views "https://github.com/thetechieakash/booking/tree/main/app/Views/fronts/admin/"
        click Views "https://github.com/thetechieakash/booking/tree/main/app/Views/fronts/user-auth/"
        click Views "https://github.com/thetechieakash/booking/tree/main/app/Views/fronts/admin-auth/"
        click Views "https://github.com/thetechieakash/booking/tree/main/app/Views/fronts/templates/"
        click Views "https://github.com/thetechieakash/booking/tree/main/app/Views/fronts/admin/templates/"
        click Views "https://github.com/thetechieakash/booking/tree/main/app/Views/errors/html/"
        click Views "https://github.com/thetechieakash/booking/tree/main/app/Views/errors/cli/"
        click Views "https://github.com/thetechieakash/booking/blob/main/app/Views/fronts/Error_404.php"
    end

    Routes --> Controllers
    Controllers -->|uses| Filters
    Controllers -->|calls| Models
    Controllers -->|renders| Views
    Controllers -->|calls helpers| Helpers
    Controllers -->|uses services| Libraries

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Database["MySQL Database"]:::datastore
        click Database "https://github.com/thetechieakash/booking/blob/main/app/Database/booking_db.sql"

        Migrations["Migrations"]:::datastore
        click Migrations "https://github.com/thetechieakash/booking/tree/main/app/Database/Migrations/"

        Seeders["Seeders"]:::datastore
        click Seeders "https://github.com/thetechieakash/booking/tree/main/app/Database/Seeds/"

        Writable["Writable Storage\nlogs, cache, sessions, uploads"]:::datastore
        click Writable "https://github.com/thetechieakash/booking/tree/main/writable/"
    end

    Models --> Database
    Migrations -.-> Database
    Seeders -.-> Database

    %% AJAX / API
    Controllers -->|"AJAX JSON"| Browser

    %% CLI & Dev Tools
    subgraph "Development Tools"
        direction TB
        Spark["spark CLI Tool"]:::external
        click Spark "https://github.com/thetechieakash/booking/tree/main/spark"

        Composer["Composer Dependencies"]:::external
        click Composer "https://github.com/thetechieakash/booking/blob/main/composer.json"
        click Composer "https://github.com/thetechieakash/booking/blob/main/composer.lock"

        Tests["Automated Tests"]:::external
        click Tests "https://github.com/thetechieakash/booking/tree/main/tests/"
    end

    Spark -.-> Migrations
    Spark -.-> Seeders
    Composer --> Controllers
    Tests --> Controllers
    Tests --> Models
    Tests --> Database

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef backend fill:#E8F5E9,stroke:#1B5E20,color:#2E7D32
    classDef datastore fill:#FFF3E0,stroke:#E65100,color:#BF360C
    classDef external fill:#ECEFF1,stroke:#455A64,color:#263238
```
