# hoangm416/hustfood architecture

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

- Interactive diagram: https://gitdiagram.com/hoangm416/hustfood
- Repository: https://github.com/hoangm416/hustfood

## Overview

##### Main Components
- Frontend (Client-Side):
– Built with React using TypeScript and Vite (as indicated by the presence of vite.config.ts, tsconfig, and .tsx files)
– Contains pages (e.g., HomePage, DetailPage, UserProfilePage), auth components (e.g., Auth0ProviderWithNavigate, ProtectedRoute) and common UI components (Header, Footer, and various reusable UI components).
– Includes modules for API interactions where the frontend calls backend endpoints.

- Backend (Server-Side):
– Built in Node.js using TypeScript (noted by .ts files throughout the backend folder)
– Follows an MVC-like structure with clear separation into controllers (e.g., MyRestaurantController.ts, OrderController.ts), models (e.g., order, restaurant, user), middleware layers (authentication and validation), and routing files.
– Offers REST API endpoints that the frontend communicates with (as seen in the routes directory work).

- Database:
– Although not represented directly in the file tree, the README mentions MongoDB, so including it as the persistence layer is key.
– The models directory in the backend reflects the data structure that is likely stored in MongoDB.

- External Services/Integrations:
– Auth0: For user authentication, as evidenced by the frontend/auth directory components and provided account credentials in the README.
– Cloudinary: Likely used for managing media (images, restaurant photos, etc.).
– MoMo Payment Gateway: The README instructions mention downloading the MoMo UAT application, indicating integration for processing payments.

##### Relationships and Interactions
- The backend handles business logic in controllers and interacts with the MongoDB database to store or retrieve entities like orders, restaurants, and users.
- For image uploads or media management, show an interface between the backend or possibly directly the frontend and Cloudinary.
- Payment processing is facilitated through the MoMo payment gateway. Indicate communication from the backend (or directly from a payment module) to the MoMo service.

##### Architectural Patterns & Design Principles
- Classic separation of concerns:
- The frontend is a decoupled, client-side application with its own routing and state management.
- The backend uses an MVC-like pattern: controllers (handling requests), models (data representation), and routes (defining API endpoints), along with middleware for cross-cutting concerns like authentication and validation.
- Component-based design for the frontend (clearly visible through the numerous reusable UI components) and RESTful API design in the backend.
- Importance of external integrations (authentication, storage, payment) as part of the system design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (React SPA)"
        FE["React (Vite, TypeScript)"]:::frontend
        FEAuth["Auth0 Integration"]:::frontendAuth
    end

    subgraph "Backend (Node/Express Server with TypeScript)"
        BE["API Server"]:::backend
        Routes["Routes (API Endpoints)"]:::backendSub
        Middleware["Middleware (Auth & Validation)"]:::backendSub
        Controllers["Controllers (REST API)"]:::backendSub
        Models["Data Models (MongoDB)"]:::backendSub
    end

    subgraph "External Services"
        DB["MongoDB Database"]:::database
        Auth0["Auth0 Service"]:::external
        Cloudinary["Cloudinary Service"]:::external
        MoMo["MoMo Payment Gateway"]:::external
    end

    %% Inter-component relationships
    FE -->|"API_Request"| BE
    FE -->|"AuthFlow"| FEAuth
    FEAuth -->|"Uses"| Auth0

    BE -->|"Handles"| Routes
    Routes -->|"Processes"| Middleware
    Middleware -->|"Validates"| Controllers
    Controllers -->|"CRUD_Operations"| Models
    Models -->|"DB_Access"| DB

    Controllers -->|"Payment"| MoMo
    Controllers -->|"Media_Upload"| Cloudinary
    Middleware -->|"Token_Verify"| Auth0

    %% Click Events
    click FE "https://github.com/hoangm416/hustfood/tree/main/frontend/"
    click FEAuth "https://github.com/hoangm416/hustfood/tree/main/frontend/src/auth/"
    click BE "https://github.com/hoangm416/hustfood/tree/main/backend/src/"
    click Routes "https://github.com/hoangm416/hustfood/tree/main/backend/src/routes/"
    click Middleware "https://github.com/hoangm416/hustfood/tree/main/backend/src/middleware/"
    click Controllers "https://github.com/hoangm416/hustfood/tree/main/backend/src/controllers/"
    click Models "https://github.com/hoangm416/hustfood/tree/main/backend/src/models/"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef frontendAuth fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#FAD7A0,stroke:#B9770E,stroke-width:2px;
    classDef backendSub fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef database fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#943126,stroke-width:2px;
```
