# ledaithanhlong/dacn_jurni architecture

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

- Interactive diagram: https://gitdiagram.com/ledaithanhlong/dacn_jurni
- Repository: https://github.com/ledaithanhlong/dacn_jurni

## Overview

##### Project Type & Purpose
- This is a full-stack “tour booking and management” web application (“Jurni”) built on the MVC pattern.
- Frontend: React (Vite) with Tailwind CSS, rendering views and consuming REST APIs.
- Backend: Node.js + Express + Sequelize ORM, exposing REST endpoints and implementing business logic.
- Database: MySQL (via Sequelize migrations/models).
- External services: Cloudinary (media uploads), VNPay/MoMo (payments), email/SMS notifications.

##### File Structure Analysis
- Top level: two peers, **frontend/** and **backend/**.
- backend/src:
- config/ (database, cloudinary, env)
- models/ & migrations/ (Sequelize ORM + schema evolution)
- controllers/ (business logic per resource: users, hotels, flights, cars, activities, bookings, favorites, vouchers, notifications)
- routes/ (Express routers mapping HTTP paths to controllers)
- middlewares/auth.js (JWT or session-based auth)
- server.js (app bootstrap & listening)
- frontend/src:
- components/ (shared UI pieces + admin views)
- pages/ (route-level React pages)
- routes/App.jsx (React Router mapping)
- assets: index.html, styles.css, tailwind.config.js

##### Key Architectural Insights from README
- Strict MVC separation on backend, with client-server HTTP API.
- Payment integration (VNPay/MoMo) implies external API calls.
- Cloudinary for media.
- User roles & authorization (admin vs. end-user).
- Uses Sequelize migrations → relational schema (ERD).

a. Main Components
- Web Client (Browser)
- CDN/Static Hosting (serving frontend assets via Vite build)
- API Gateway / Express Backend
- Database (MySQL)
- External Services:
- Cloudinary (image storage)
- Payment Providers (VNPay, MoMo)
- Notification service (email/SMS – can be 3rd-party or in-house microservice)
b. Relationships & Data Flow
1. User → Browser UI → HTTP(S) → Express API
2. Express controllers ↔ Sequelize ORM → MySQL
3. Express → Cloudinary SDK
4. Express ↔ Payment gateways (redirects/callback)
5. Express → Notification service
c. Architectural Patterns
- MVC and layered architecture (routing → controller → service/ORM → database)
- Stateless REST API (JWT or session cookies)
- Externalized configuration (env variables via src/config/env.js)
- Role-based access control via auth middleware
d. Key Technologies
- Frontend: React, Vite, Tailwind CSS, React Router
- Backend: Node.js, Express, Sequelize, JWT/Auth middleware
- Database: MySQL
- External: Cloudinary, VNPay/MoMo, possibly Nodemailer/twilio

##### Detailed Capture of Essential Elements
- Authentication flow: login → JWT token → protected routes.
- File-upload flow: user → Express upload route → cloudinary.config.
- Migration/model layer for schema management.
- Major REST resources: /users, /hotels, /flights, /activities, /bookings, /vouchers, /favorites, /notifications.
- Middlewares (auth) lying between routes and controllers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        ReactSPA["React SPA"]:::frontend
        Main["main.jsx (Entry Point)"]:::frontend
        AppRoute["App.jsx (Routing)"]:::frontend
        Components["Shared UI Components"]:::frontend
        AdminComponents["Admin UI Components"]:::frontend
        Pages["Page-Level Views"]:::frontend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        APIServer["Express API Server"]:::backend
        EnvConfig["env.js (Configuration)"]:::backend
        DBConfig["database.cjs"]:::backend
        CloudConfig["cloudinary.js"]:::backend
        AuthMiddleware["auth.js (Middleware)"]:::backend
        Controllers["Controllers (Users, Hotels, Flights, Cars, Activities, Bookings, Favorites, Vouchers, Notifications)"]:::backend
        Routes["Routes (users, hotels, flights, cars, activities, bookings, favorites, vouchers, notifications, upload)"]:::backend
        Models["Sequelize Models"]:::backend
        Migrations["Sequelize Migrations"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Database["MySQL Database"]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Cloudinary["Cloudinary"]:::external
        Payments["VNPay/MoMo"]:::external
        Notifications["Email/SMS Service"]:::external
    end

    %% Connections
    ReactSPA -->|HTTPS/JSON| APIServer
    Main --> ReactSPA
    AppRoute --> ReactSPA
    Components --> ReactSPA
    AdminComponents --> ReactSPA
    Pages --> ReactSPA

    APIServer -->|uses| EnvConfig
    APIServer -->|uses| DBConfig
    APIServer -->|uses| CloudConfig
    APIServer -->|uses| AuthMiddleware
    APIServer -->|routes to| Routes
    Routes -->|calls| Controllers
    Controllers -->|queries via ORM| Models
    Controllers -->|runs migrations| Migrations
    Models -->|executes SQL| Database

    APIServer -->|Upload API Call| Cloudinary
    APIServer -->|Payment Redirect/Callback| Payments
    APIServer -->|Send Notifications| Notifications

    %% Click Events
    click ReactSPA "https://github.com/ledaithanhlong/dacn_jurni/tree/main/frontend/src"
    click Main "https://github.com/ledaithanhlong/dacn_jurni/blob/main/frontend/src/main.jsx"
    click AppRoute "https://github.com/ledaithanhlong/dacn_jurni/blob/main/frontend/src/routes/App.jsx"
    click Components "https://github.com/ledaithanhlong/dacn_jurni/tree/main/frontend/src/components"
    click AdminComponents "https://github.com/ledaithanhlong/dacn_jurni/tree/main/frontend/src/components/admin"
    click Pages "https://github.com/ledaithanhlong/dacn_jurni/tree/main/frontend/src/pages"
    click APIServer "https://github.com/ledaithanhlong/dacn_jurni/blob/main/backend/src/server.js"
    click EnvConfig "https://github.com/ledaithanhlong/dacn_jurni/blob/main/backend/src/config/env.js"
    click DBConfig "https://github.com/ledaithanhlong/dacn_jurni/blob/main/backend/src/config/database.cjs"
    click CloudConfig "https://github.com/ledaithanhlong/dacn_jurni/blob/main/backend/src/config/cloudinary.js"
    click AuthMiddleware "https://github.com/ledaithanhlong/dacn_jurni/blob/main/backend/src/middlewares/auth.js"
    click Models "https://github.com/ledaithanhlong/dacn_jurni/tree/main/backend/src/models"
    click Migrations "https://github.com/ledaithanhlong/dacn_jurni/tree/main/backend/src/migrations"
    click Controllers "https://github.com/ledaithanhlong/dacn_jurni/blob/main/backend/src/controllers/users.controller.js"
    click Routes "https://github.com/ledaithanhlong/dacn_jurni/blob/main/backend/src/routes/users.routes.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0066CC,color:#000;
    classDef backend fill:#E0F7E0,stroke:#009900,color:#000;
    classDef database fill:#FFF4D0,stroke:#CC9900,color:#000,stroke-width:2px;
    classDef external fill:#FFE8D0,stroke:#CC6600,color:#000;
```
