# tkuimwd/finaltermproject architecture

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

- Interactive diagram: https://gitdiagram.com/tkuimwd/finaltermproject
- Repository: https://github.com/tkuimwd/finaltermproject

## Overview

##### Main System Components
- Frontend Client:
- “Frontend” module as the client-side component.
- That it is a React application (with Vite as the build tool, TypeScript for static typing, and various components such as NavBar, LoginModal, ReservationFilter, etc.).
- Role: handling user interactions, rendering views (pages like Landing, AddReservation, Reservations, etc.), and making API calls.
- API Gateway/Communication:
- A label for “API Endpoints” that correlate with the routes defined in the Backend (AuthRoute, AdminRoute, UserRoute, CommonRoute, pageRoute).
- Backend Server:
▸ Routers – which map HTTP endpoints to their corresponding Controllers.
▸ Controllers – that manage incoming requests, validate data (possibly using common middlewares such as the logging middleware), and delegate business logic to Services.
▸ Services – dedicated modules (e.g., AuthService, UserService, PageService, etc.) that encapsulate business logic.
▸ Utility Modules – including token management, data validation (e.g., deepValid), response formatting, and MongoDB connection (in the utils folder).
- You may also note that the Backend follows an architectural pattern that separates abstract classes (base Controller, Route, Service) from concrete implementations.
- Database:
- MongoDB database as a separate component.
- Collections to be created and used (admins, dish_washers, reservations, users) which are configured via MongoDB schemas.
- Connection from the Backend to MongoDB (using the MongoDB utility and the ORM schemas under the “orm/schemas” folder).

##### Relationships & Data Flow
- From the Frontend → API (HTTP/REST calls).
- From the API to the Backend’s Controller → Service layers.
- Finally, from the Backend to the MongoDB database (and vice versa for responses).
- That the Frontend consumes APIs defined in the Backend’s API documentation (API.md) and that any authentication or session management is managed via the token utils.

##### Architectural Patterns & Design Principles
- MVC-like design pattern implemented in the Backend (Controllers manage routes, while Services encapsulate business logic).
- Component-based architecture on the Frontend (utilizing React components and context hooks for state management).
- Mention the use of environment configurations (via .env files in both Frontend and Backend) which allow the system to adapt to different environments.
- Separation of concerns: UI rendering is cleanly separated from server-side data processing, and further, server-side business logic is separated into distinct service modules.

##### Relevant Technologies & Frameworks
- Frontend: React, Vite, TypeScript, and CSS (for style management).
- Backend: Node.js, TypeScript, Express-style routing, and industry-standard middlewares.
- Database: MongoDB (including its collections and JSON-based configuration).
- Utilities and Build tools: Webpack and custom scripts for development, along with configuration files like tsconfig.json.

##### Implementation
- The main UI components and context providers (e.g., DishWashersContext, ReservationsContext, UserContext).
- The routing module (ProtectedRoute, router configuration).
- Routers – mapping URLs to controllers.
- Controllers – for handling different domain functions (Auth, Admin, User, Page, etc.).
- Services – encapsulating business logic.
- Utilities & ORMs – showing the connection modules to MongoDB and utility functions.
- Optional:

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        FClient["Frontend Client\n(React, Vite, TS)"]:::frontend
        FUI["UI Components\n(NavBar, LoginModal, ReservationFilter)"]:::frontend
        FRouting["Routing Module\n(ProtectedRoute, router)"]:::frontend
        FContext["Context Providers\n(DishWashers, Reservations, User)"]:::frontend
        FClient --> FUI
        FClient --> FRouting
        FClient --> FContext
    end

    %% API Endpoints (Communication Layer)
    API["API Endpoints\n(HTTP/REST)"]:::api
    FClient -->|"API_Call"| API

    %% API Documentation Reference
    APIDoc["API Documentation"]:::api
    API -->|"definedIn"| APIDoc

    %% Backend Layer
    subgraph "Backend"
        BApp["Backend App\n(Node.js Server)"]:::backend
        Routers["Routers\n(AdminRoute, AuthRoute, CommonRoute, UserRoute, pageRoute)"]:::backend
        Controllers["Controllers\n(AdminController, AuthController, CommonController, UserController, pageController)"]:::backend
        Services["Services\n(AdminService, AuthService, CommonService, PageService, UserService)"]:::backend
        Middleware["Logging Middleware"]:::backend
        Abstract["Abstract Classes\n(Controller, Route, Service)"]:::backend
        Utilities["Other Utilities\n(token, deepValid, resp)"]:::backend
        MongoConn["MongoDB Connection Utility"]:::backend
        ORMSchemas["ORM Schemas\n(adminsSchemas, dishwashersSchemas, reservationsSchemas, usersSchemas)"]:::backend
        EnvB["Backend Env Config\n(.env.example)"]:::backend

        BApp --> Routers
        Routers --> Controllers
        Controllers --> Services
        Services --> Utilities
        Services --> Middleware
        Utilities --> MongoConn
        MongoConn --> ORMSchemas
        BApp --> Abstract
        BApp --> EnvB
    end

    %% Connect API Documentation to Backend Routers ("mapsTo")
    APIDoc -->|"mapsTo"| Routers

    %% Database Layer
    subgraph "Database"
        DB["MongoDB\n(admins, dish_washers, reservations, users)"]:::database
        EnvF["Frontend Env Config\n(.env.example)"]:::frontend
    end

    %% Backend to Database Connections
    ORMSchemas -->|"Stores/Fetched"| DB
    MongoConn --> DB
    Utilities -->|"Uses_DB"| DB

    %% Connect Frontend Env config to Frontend Client (for completeness)
    FClient --- EnvF

    %% Click Events
    click FClient "https://github.com/tkuimwd/finaltermproject/tree/main/Frontend/src"
    click FUI "https://github.com/tkuimwd/finaltermproject/tree/main/Frontend/src/component"
    click FRouting "https://github.com/tkuimwd/finaltermproject/tree/main/Frontend/src/router"
    click FContext "https://github.com/tkuimwd/finaltermproject/tree/main/Frontend/src/context"
    click APIDoc "https://github.com/tkuimwd/finaltermproject/blob/main/API.md"
    click BApp "https://github.com/tkuimwd/finaltermproject/blob/main/Backend/src/app.ts"
    click Routers "https://github.com/tkuimwd/finaltermproject/tree/main/Backend/src/routers"
    click Controllers "https://github.com/tkuimwd/finaltermproject/tree/main/Backend/src/controller"
    click Services "https://github.com/tkuimwd/finaltermproject/tree/main/Backend/src/Service"
    click Middleware "https://github.com/tkuimwd/finaltermproject/blob/main/Backend/src/middlewares/log.ts"
    click Abstract "https://github.com/tkuimwd/finaltermproject/tree/main/Backend/src/abstract"
    click ORMSchemas "https://github.com/tkuimwd/finaltermproject/tree/main/Backend/src/orm/schemas"
    click MongoConn "https://github.com/tkuimwd/finaltermproject/blob/main/Backend/src/utils/MongoDB.ts"
    click Utilities "https://github.com/tkuimwd/finaltermproject/tree/main/Backend/src/utils"
    click EnvB "https://github.com/tkuimwd/finaltermproject/blob/main/Backend/.env.example"
    click EnvF "https://github.com/tkuimwd/finaltermproject/blob/main/Frontend/.env.example"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFCCCB,stroke:#000,stroke-width:2px;
    classDef database fill:#C3FDB8,stroke:#000,stroke-width:2px;
    classDef api fill:#F9E79F,stroke:#000,stroke-width:2px;
```
