# project-for-huflit/traveloki architecture

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

- Interactive diagram: https://gitdiagram.com/project-for-huflit/traveloki
- Repository: https://github.com/project-for-huflit/traveloki

## Overview

- FE_Traveloki – the client-facing front end (built with React/Vite, Tailwind CSS, etc.) that handles customer interactions, booking flows, ratings, and profiles.
- ADMIN_Traveloki – the admin panel (also React/Vite based) that gives administrators an interface for managing details like vehicles, schedules, and transactions.
- BE_Traveloki – the server-side business logic built in Node (likely Express-based) with an organized structure that includes controllers, services, routes, models, middlewares, and even integrations with Kafka (message-queue system), MongoDB (as seen in the configuration files), Cloudinary, and Google Drive providers.

##### Main Component Breakdown
a. Client Applications:
– Frontend (FE_Traveloki): Represents customer UI components for searching, booking (bus, car, train), cancellations, and ratings. Mark deployment with Netlify (as shown by the README badges).
– Admin Panel (ADMIN_Traveloki): Represents the administrative user interface that manages operations such as vehicle details, scheduling (LichChay), user accounts, and dashboard charts. Also deployed via Netlify.
b. Backend Service (BE_Traveloki):
– API endpoints grouped by functionalities (authentication, booking, details, feedback, history, etc.) managed via routes and controllers.
– Business logic layers handled in services and factories (e.g., booking service, carFactory service, etc.).
– Data persistence via MongoDB (indicated by config.mongodb.js and related init scripts).
– Middleware and security layers for authentication, API key checks (using x-api-key in headers), rate limiting, and error handling.
– Integration Components: Message queue (Kafka-based producers/consumers), Cloudinary and Google Drive providers for media handling.
c. External Services and Tools:
– Deployment & CI/CD: GitHub Workflows (for FE, GitHub packages, etc.) and Netlify dashboard integration.
– Third-party libraries for WebP image support (as explained in the README) along with Docker containerization (Dockerfiles and docker-compose files exist).

##### Relationship and Data Flow
– Both client applications (FE_Traveloki and ADMIN_Traveloki) send HTTP/HTTPS requests to the BE_Traveloki service using a secured API key in headers.
– The back end interacts with the database (MongoDB) to perform CRUD operations, store transaction records, booking details, and vehicle data.
– The BE_Traveloki also communicates with external services:
- Kafka for asynchronous messaging (e.g., notifications or updating booking statuses).
- Cloudinary (and perhaps Google Drive) for handling image uploads or document storage.
– GitHub workflows are integrated for continuous integration and deployment, affecting source code in FE, ADMIN, and BE respectively.

##### Architectural Patterns and Design Principles
– Layered Architecture: Clear separation of front end presentation, back end business logic (controllers, services, models), and data persistence.
– Modular Structure: Both FE and BE are split into modular components that can be independently tested and scaled.
– API-centric communication: Emphasis on RESTful endpoints with proper routing and middleware for validation and error handling.
– Use of a message queue (Kafka) indicates an event-driven or asynchronous processing aspect within the backend.
– Security best practices, as seen in the dedicated middleware and the use of an x-api-key header.

##### Final Recommendations
– Include clear, legible labels for each service or component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Applications
    subgraph "Client Applications"
        FE["Frontend (FE_Traveloki)"]:::frontend
        ADMIN["Admin Panel (ADMIN_Traveloki)"]:::admin
    end

    %% Backend Service
    subgraph "Backend Service"
        BE["Backend API Service (BE_Traveloki)"]:::backend
        subgraph "Business Layers"
            API["API Endpoints (Controllers & Routes)"]:::backend
            SERVICE["Business Logic & Service Layers"]:::backend
            MIDDLE["Middleware & Security Layers"]:::backend
        end
        DB["Database (MongoDB)"]:::database
    end

    %% External Services
    subgraph "External Services"
        KAFKA["Kafka (Message Queue)"]:::external
        CLOUD["Cloudinary"]:::external
        GOOGLE["Google Drive"]:::external
    end

    %% CI/CD & Deployment
    DEPLOY["CI/CD & Deployment"]:::external

    %% Connections from Client Applications to Backend
    FE -->|"HTTP_API_call(x-api-key)"| API
    ADMIN -->|"HTTP_API_call(x-api-key)"| API

    %% Internal Backend Flow
    API -->|"validate"| MIDDLE
    API -->|"calls"| SERVICE
    SERVICE -->|"persist_data"| DB

    %% External Integrations from Business Logic
    SERVICE -->|"async_message"| KAFKA
    SERVICE -->|"media_upload"| CLOUD
    SERVICE -->|"media_upload"| GOOGLE

    %% Deployment integration arrows
    FE ---|"deployed_on"| DEPLOY
    ADMIN ---|"deployed_on"| DEPLOY
    BE ---|"dockerized_CICD"| DEPLOY

    %% Click Events
    click FE "https://github.com/project-for-huflit/traveloki/tree/main/FE_Traveloki"
    click ADMIN "https://github.com/project-for-huflit/traveloki/tree/main/ADMIN_Traveloki"
    click BE "https://github.com/project-for-huflit/traveloki/tree/main/BE_Traveloki"
    click API "https://github.com/project-for-huflit/traveloki/tree/main/BE_Traveloki/src/controllers"
    click SERVICE "https://github.com/project-for-huflit/traveloki/tree/main/BE_Traveloki/src/services"
    click MIDDLE "https://github.com/project-for-huflit/traveloki/tree/main/BE_Traveloki/src/middlewares"
    click DB "https://github.com/project-for-huflit/traveloki/blob/main/BE_Traveloki/src/config/config.mongodb.js"
    click KAFKA "https://github.com/project-for-huflit/traveloki/tree/main/BE_Traveloki/src/utils/message-queue/kafka"
    click CLOUD "https://github.com/project-for-huflit/traveloki/tree/main/BE_Traveloki/src/provider/cloudinary"
    click GOOGLE "https://github.com/project-for-huflit/traveloki/tree/main/BE_Traveloki/src/provider/google-drive"
    click DEPLOY "https://github.com/project-for-huflit/traveloki/tree/main/.github/workflows"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef admin fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef backend fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef database fill:#A9DFBF,stroke:#239B56,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#CB4335,stroke-width:2px;
```
