# olasunkanmi-se/restaurant architecture

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

- Interactive diagram: https://gitdiagram.com/olasunkanmi-se/restaurant
- Repository: https://github.com/olasunkanmi-se/restaurant

## Overview

##### Main components
- Frontend: Built with React (located in the frontend directory). It includes pages, components, contexts, reducers, and APIs which interact with the backend.
- Backend: Developed using NestJS (found under the backend directory). It follows a modular structure, splitting responsibilities into distinct modules such as addon, category, cart, item, location, menu, order, order_manager, order_notes, order_processing_queue, order_statuses, restaurant, singleclient, etc.
- Authentication & Authorization: Managed by the AuthModule alongside JWT-based authentication components (strategies, guards, decorators).
- Data Persistence: Interfaces with a MongoDB database through the DocumentDatabaseModule in the backend infrastructure, and there are numerous repository patterns and schemas to manage data access.
- API Gateway/Endpoints: Exposed endpoints such as /api/restaurants, /api/menus, /api/items, /api/orders, /api/singleclients to handle CRUD operations and communications between the frontend and backend.
- External Services & Utilities: Includes middlewares, context management, logging utilities, and validation pipes to enforce data integrity and proper error handling.

##### Relationships and interactions
- The AuthModule and its supporting infrastructure (guards, strategies, decorators) act as cross-cutting concerns enforcing security and user identity checks.
- The infrastructure layer ties in the database and repository components, depicting how the backend modules rely on repositories (e.g., addon.repository, cart-item.repository, etc.) to interact with MongoDB.
- A separation of concerns is evident by the division between application logic (domain, services), infrastructure (data access, authentication, logging), and presentation (controllers).

##### Important architectural patterns and design principles
- Modular design: The backend is partitioned into numerous feature-specific modules ensuring separation of concerns.
- MVC/Mediator pattern: Controllers handle HTTP requests, services implement business logic, and repositories manage data persistence.
- Domain-Driven Design (DDD): The project includes domain, entity, and value object layers, which encapsulate business rules and entities.
- Repository Pattern: Used extensively for data access abstraction in the infrastructure layer.
- JWT Authentication and Role Based Access Control: Security is enforced using JWT-based strategies and custom middleware/guards.
- Client-side state management: The frontend leverages Context APIs and reducers for shopping cart and session management.

- Frontend:
- Pages and Components (Authentication, Menu, Cart, Order screens)
- API layer (Axios calls, API gateways)
- Backend:
- Controllers (e.g., restaurant.controller, menu.controller, order.controller)
- Services and Modules (AuthModule, OrderModule, etc.)
- Domain Layer (Entities, Value Objects, Mappers)
- Infrastructure (JWT strategies, guards, data access repositories, DocumentDatabaseModule)
- Database and External Services:
- MongoDB along with repository models and schemas
- External API endpoints if any (as suggested by the Postman collection)

##### Emphasizing details
- Don’t shy away from splitting the backend into its several sub-components if needed – the goal is to capture every aspect of the system.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend (React)"
        FE_Pages["React Pages"]:::frontend
        FE_Components["React Components"]:::frontend
        FE_API["React API Layer"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (NestJS Application)"
        BE_App["NestJS App"]:::backend

        subgraph "Authentication"
            Auth_Module["Auth Module"]:::backend
            JWT_Strategies["JWT Strategies"]:::backend
            JWT_Guards["JWT Guards"]:::backend
            JWT_Decorators["JWT Decorators"]:::backend
        end

        Restaurant_Module["Restaurant Module"]:::backend
        Menu_Module["Menu Module"]:::backend
        Order_Module["Order Module"]:::backend
        Singleclient_Module["Singleclient Module"]:::backend

        subgraph "Operational Modules"
            Addon_Module["Addon Module"]:::backend
            Category_Module["Category Module"]:::backend
            Cart_Module["Cart Module"]:::backend
            Item_Module["Item Module"]:::backend
            Location_Module["Location Module"]:::backend
            Order_Manager_Module["Order Manager Module"]:::backend
            Order_Notes_Module["Order Notes Module"]:::backend
            Order_Processing_Queue_Module["Order Processing Queue Module"]:::backend
            Order_Statuses_Module["Order Statuses Module"]:::backend
        end
    end

    %% Data Persistence Layer
    subgraph "Data Persistence (MongoDB)"
        DocumentDB["DocumentDatabaseModule"]:::database
        Repositories["Repositories & Schemas"]:::database
        MongoDB["MongoDB Database"]:::database
    end

    %% External Services & Utilities
    subgraph "External Services & Utilities"
        Middlewares["Middlewares"]:::external
        Logging["Logging Utilities"]:::external
        Utilities["Utilities & Validation"]:::external
    end

    %% Connections within Frontend
    FE_Pages -->|"uses"| FE_API
    FE_Components -->|"renders"| FE_API

    %% Frontend to Backend communication
    FE_API -->|"REST_API"| BE_App

    %% Backend main routing to modules
    BE_App -->|"routes"| Auth_Module
    BE_App -->|"routes"| Restaurant_Module
    BE_App -->|"routes"| Menu_Module
    BE_App -->|"routes"| Order_Module
    BE_App -->|"routes"| Singleclient_Module
    BE_App -->|"routes"| Addon_Module
    BE_App -->|"routes"| Category_Module
    BE_App -->|"routes"| Cart_Module
    BE_App -->|"routes"| Item_Module
    BE_App -->|"routes"| Location_Module
    BE_App -->|"routes"| Order_Manager_Module
    BE_App -->|"routes"| Order_Notes_Module
    BE_App -->|"routes"| Order_Processing_Queue_Module
    BE_App -->|"routes"| Order_Statuses_Module

    %% Authentication module internal flow
    Auth_Module -->|"implements"| JWT_Strategies
    Auth_Module -->|"implements"| JWT_Guards
    Auth_Module -->|"implements"| JWT_Decorators

    %% Backend modules interacting with Data Persistence
    Auth_Module -->|"data_access"| DocumentDB
    Restaurant_Module -->|"data_access"| DocumentDB
    Menu_Module -->|"data_access"| DocumentDB
    Order_Module -->|"data_access"| DocumentDB
    Singleclient_Module -->|"data_access"| DocumentDB
    Addon_Module -->|"data_access"| DocumentDB
    Category_Module -->|"data_access"| DocumentDB
    Cart_Module -->|"data_access"| DocumentDB
    Item_Module -->|"data_access"| DocumentDB
    Location_Module -->|"data_access"| DocumentDB
    Order_Manager_Module -->|"data_access"| DocumentDB
    Order_Notes_Module -->|"data_access"| DocumentDB
    Order_Processing_Queue_Module -->|"data_access"| DocumentDB
    Order_Statuses_Module -->|"data_access"| DocumentDB

    DocumentDB -->|"uses"| Repositories
    Repositories -->|"persists_to"| MongoDB

    %% Backend using External Services & Utilities
    BE_App -->|"middleware"| Middlewares
    BE_App -->|"logs"| Logging
    BE_App -->|"validates"| Utilities

    %% Class Definitions for Colors
    classDef frontend fill:#e7f5ff,stroke:#1c7ed6,stroke-width:2px;
    classDef backend fill:#e6fcf5,stroke:#3bc9db,stroke-width:2px;
    classDef database fill:#fff3bf,stroke:#fa5252,stroke-width:2px;
    classDef external fill:#fce4ec,stroke:#e91e63,stroke-width:2px;

    %% Click Events
    click FE_Pages "https://github.com/olasunkanmi-se/restaurant/tree/main/frontend/src/pages"
    click FE_Components "https://github.com/olasunkanmi-se/restaurant/tree/main/frontend/src/components"
    click FE_API "https://github.com/olasunkanmi-se/restaurant/tree/main/frontend/src/apis"
    click BE_App "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src"
    click Auth_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/infrastructure/auth"
    click JWT_Strategies "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/infrastructure/auth/strategies"
    click JWT_Guards "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/infrastructure/guards"
    click JWT_Decorators "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/infrastructure/decorators"
    click Restaurant_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/restaurant"
    click Menu_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/menu"
    click Order_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/order"
    click Singleclient_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/singleclient"
    click Addon_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/addon"
    click Category_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/category"
    click Cart_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/cart"
    click Item_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/item"
    click Location_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/location"
    click Order_Manager_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/order_manager"
    click Order_Notes_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/order_notes"
    click Order_Processing_Queue_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/order_processing_queue"
    click Order_Statuses_Module "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/order_statuses"
    click DocumentDB "https://github.com/olasunkanmi-se/restaurant/blob/main/backend/src/infrastructure/database/document-database.module.ts"
    click Repositories "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/infrastructure/data_access/repositories"
    click Middlewares "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/infrastructure/middlewares"
    click Logging "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/infrastructure/logger"
    click Utilities "https://github.com/olasunkanmi-se/restaurant/tree/main/backend/src/infrastructure/utilities"
```
