# advanced-computer-lab-2024/trip-genie architecture

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

- Interactive diagram: https://gitdiagram.com/advanced-computer-lab-2024/trip-genie
- Repository: https://github.com/advanced-computer-lab-2024/trip-genie

## Overview

##### Main Components

- Frontend (Client Side)
- Built in React (with Vite) and styled using Tailwind CSS.
- Organized into key folders such as “src”, “components”, “pages”, “assets”, and “hooks.”
- Handles user interfaces, routing, authentication, and dynamic interactions (for activities, itineraries, products, etc.).

- Backend (Server Side)
- Built with Node.js and Express.js.
- Contains directories like “controllers”, “models”, “routes”, “middlewares”, “services”, and “utils.”
- Implements role-specific APIs for different endpoints (tourist, tour-guide, advertiser, seller, tourism governor, admin).
- Includes error handling, file uploads, cloud services integration (Cloudinary for images) and uses external APIs (Amadeus for flights, Stripe for payments, Booking.com for hotels).

- Database
- Although not explicitly depicted in the file tree, the README mentions MongoDB as the technology used.
- The data models (in “backend/models”) represent the data structure for users, activities, itineraries, products, currencies, and more.

- External Services
- Payment Service: Stripe for payment processing.
- Flight/Hotel API: Amadeus and Booking.com connected via REST endpoints.
- Image Storage: Cloudinary uploads from various endpoints (e.g., product images & activity images).
- Authentication: Uses JWT stored in cookies with role-based access middleware.

##### Diagramming Relationships and Interactions

- User Flow / Client Interaction:
- Users interact with the Frontend (browser) which sends API requests to the backend.
- Role-based access is clearly enforced. For example, tourists, tour guides, sellers, advertisers, and admins have specific routes and controllers.
- The frontend components (React pages and common UI components) handle the presentation and call appropriate API endpoints based on role.

- Backend API Layer:
- Controllers receive requests through Express routes. Each controller (e.g., authController, activityController, productController) processes the logic for its specific domain.
- Middlewares (authMiddleware) ensure authentication and authorization before reaching the controllers.
- Service layer (e.g., emailService) and utility modules (e.g., cloudinary functions) provide additional support and integration with external services.

- Database Communication:
- Controllers interact with MongoDB through Mongoose models (found in “backend/models”), handling CRUD operations for various entities like activities, itineraries, products, bookings, etc.

- External Systems:
- The backend communicates with external APIs (Amadeus, Stripe, and Booking.com) to fetch flight/hotel information, process payments, or manage booking details.
- Cloudinary is used for uploading and storing images, managed by dedicated functions in “backend/utils”.

##### Important Architectural Patterns/Design Principles
- Modular Structure: Separation between controllers, models, routes, and services enables maintainability and scalability.
- Role-Based Access Control: Different endpoints and authentication logic tailored for each distinct user role.
- Service-Oriented Integrations: External APIs and micro-services (payment, image storage, flight data) integrated with dedicated modules.
- Component-Based Frontend: React components distributed across pages and UI libraries with clear folder separation.

##### Diagramming the Specific Project Architecture

[Browser/Client]
│
▼
[Frontend (React App)]
│   (Authenticated API requests based on user role)
▼
[Backend API Server (Express)]
├── [Authentication & Role Middleware]
├── [Controllers (e.g., Auth, Activity, Itinerary, Product, Booking)]
└── [Services & Utilities (Email, Cloudinary, etc.)]
│
├──→ [Database (MongoDB)]
└──→ [External Services]
- Payment: Stripe
- Flight/Hotel: Amadeus & Booking APIs
- File Storage: Cloudinary

##### Additional Details
- Be sure to include any configuration or deployment elements such as “vercel.json” from the backend for deployment setup.
- Mention that multiple testing strategies exist (e.g., Postman tests, backend test scripts) which validate API endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser/Client"]:::client
    FE["Frontend (React App)"]:::frontend
    BE["Backend API Server (Express)"]:::backend
    Middleware["Auth & Role Middleware"]:::middleware
    Controllers["Controllers (Auth, Activity, Itinerary, Product, etc.)"]:::backend
    Services["Services & Utilities (Email, Cloudinary, etc.)"]:::backend
    DB["Database (MongoDB)"]:::database
    External["External Services\n• Stripe\n• Amadeus API\n• Booking API\n• Cloudinary"]:::external
    Deployment["Deployment Config (vercel.json)"]:::deployment

    %% Client to Frontend
    Browser -->|"API-requests"| FE

    %% Frontend to Backend
    FE -->|"HTTP REST calls"| BE

    %% Backend internal flow
    BE -->|"processes request"| Middleware
    Middleware -->|"routes request"| Controllers
    Controllers -->|"calls services"| Services
    Controllers -->|"data CRUD"| DB
    Services -->|"integrates with"| External

    %% Deployment configuration
    BE ---|"configured by"| Deployment

    %% Click Events
    click FE "https://github.com/advanced-computer-lab-2024/trip-genie/tree/main/frontend/"
    click BE "https://github.com/advanced-computer-lab-2024/trip-genie/tree/main/backend/"
    click Middleware "https://github.com/advanced-computer-lab-2024/trip-genie/blob/main/backend/middlewares/authMiddleware.js"
    click Controllers "https://github.com/advanced-computer-lab-2024/trip-genie/tree/main/backend/controllers/"
    click DB "https://github.com/advanced-computer-lab-2024/trip-genie/tree/main/backend/models/"
    click Services "https://github.com/advanced-computer-lab-2024/trip-genie/blob/main/backend/utils/cloudinary.js"
    click Deployment "https://github.com/advanced-computer-lab-2024/trip-genie/blob/main/backend/vercel.json"

    %% Styles
    classDef client fill:#b3e5fc,stroke:#333,stroke-width:2px
    classDef frontend fill:#66ccff,stroke:#333,stroke-width:2px
    classDef backend fill:#ffcc66,stroke:#333,stroke-width:2px
    classDef middleware fill:#ccffcc,stroke:#333,stroke-width:2px
    classDef database fill:#ff9999,stroke:#333,stroke-width:2px
    classDef external fill:#d1c4e9,stroke:#333,stroke-width:2px
    classDef deployment fill:#ffe0b2,stroke:#333,stroke-width:2px
```
