# amit-ashok-swain/restaurant-management-system architecture

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

- Interactive diagram: https://gitdiagram.com/amit-ashok-swain/restaurant-management-system
- Repository: https://github.com/amit-ashok-swain/restaurant-management-system

## Overview

##### Project type and purpose
- This is a Spring Boot–based backend service providing RESTful CRUD operations for a restaurant management system. It exposes endpoints for three user roles (Admin, User, Visitor) and integrates with a MySQL database plus external JavaMail email service.

##### File structure
- Top‑level modules:
- Restaurant‑Management‑Service‑API – the main Spring Boot application (Controller, Service, Repository layers).
- (Other folders appear to be older or alternative implementations; focus on the Service‑API module.)
- Layered organization under src/main/java/com/geekster/.../RestaurantManagementServiceAPI:
- Controller – HTTP endpoints
- DTO – request/response payloads
- Model – JPA @Entity classes
- Repository – Spring Data JPA interfaces
- Service – business logic
- Resources: application.properties (DB, mail, security), Swagger (SpringDoc) configuration.

##### Key architectural insights from the README
- Layered (MVC‑style) monolith: Controllers → Services → Repositories → MySQL
- Role‑based access control via Spring Security
- JavaMail API for outgoing emails
- Swagger UI for API documentation

##### Main components
a. Clients & entry points
- Admin client (e.g., Postman or UI)
- User client
- Visitor client
- Swagger UI documentation
b. API Layer
- Controllers (FoodController, OrderController, UserController, VisitorController, AdminController)
c. Business Logic Layer
- Service classes (FoodService, OrderService, UserService, VisitorService, AdminService, AuthenticationService)
d. Data Access Layer
- Spring Data Repositories (IFoodRepo, IOrderRepo, IUserRepo, IVisitorRepo, IAdminRepo, IAuthenticationRepo)
e. Persistence
- MySQL Database
- Tables: User, FoodItem, Order, AuthenticationToken
f. External services
- JavaMail SMTP server (EmailHandler)
g. Supporting services
- Spring Security component enforcing JWT/session authentication
- SpringDoc OpenAPI (Swagger)

##### Relationships and data flows
- Clients → HTTP request → Controllers
- Controllers → invoke Service methods (business rules, validation)
- Services → call Repositories → persist/fetch Entities from MySQL
- AuthenticationService ↔ IAuthenticationRepo ↔ AuthenticationToken table
- UserService ↔ IUserRepo ↔ User table
- OrderService ↔ IOrderRepo ↔ Order table
- FoodService ↔ IFoodRepo ↔ FoodItem table
- AdminService ↔ IAdminRepo & IFoodRepo
- Services send emails via JavaMail API
- Swagger UI → introspects Controllers for interactive API docs

##### Architectural patterns & design principles
- Layered architecture (Controller → Service → Repository)
- Separation of concerns: Controllers handle HTTP and DTOs, Services encapsulate business logic, Repositories abstract persistence
- Role‑based access control via Spring Security annotations
- DTO patterns to decouple API payloads from Entity classes
- Externalized configuration via application.properties

## Diagram (Mermaid)

```mermaid
flowchart LR
    %% Clients
    subgraph "Clients" 
        direction TB
        AdminClient["Admin Client"]:::external
        UserClient["User Client"]:::external
        VisitorClient["Visitor Client"]:::external
    end

    %% Application Layers
    subgraph "Spring Boot Application"
        direction TB
        subgraph "API Layer" 
            direction TB
            FoodController["FoodController"]:::api
            OrderController["OrderController"]:::api
            UserController["UserController"]:::api
            VisitorController["VisitorController"]:::api
            AdminController["AdminController"]:::api
            SwaggerUI["Swagger UI"]:::swagger
        end
        subgraph "Business Layer"
            direction TB
            AuthenticationService["AuthenticationService"]:::service
            UserService["UserService"]:::service
            OrderService["OrderService"]:::service
            FoodService["FoodService"]:::service
            VisitorService["VisitorService"]:::service
            AdminService["AdminService"]:::service
        end
        subgraph "Data Access Layer"
            direction TB
            IAuthenticationRepo["IAuthenticationRepo"]:::repo
            IUserRepo["IUserRepo"]:::repo
            IOrderRepo["IOrderRepo"]:::repo
            IFoodRepo["IFoodRepo"]:::repo
            IVisitorRepo["IVisitorRepo"]:::repo
            IAdminRepo["IAdminRepo"]:::repo
        end
    end

    %% External Systems
    JavaMail["SMTP Email Service"]:::external
    MySQLDB["MySQL Database"]:::database

    %% Connections
    AdminClient -->|HTTP Request| AdminController
    UserClient -->|HTTP Request| UserController
    VisitorClient -->|HTTP Request| VisitorController
    SwaggerUI -->|Introspects| FoodController
    SwaggerUI -->|Introspects| OrderController
    SwaggerUI -->|Introspects| UserController
    SwaggerUI -->|Introspects| VisitorController
    SwaggerUI -->|Introspects| AdminController

    FoodController -->|"calls"| FoodService
    OrderController -->|"calls"| OrderService
    UserController -->|"calls"| UserService
    VisitorController -->|"calls"| VisitorService
    AdminController -->|"calls"| AdminService
    UserController -->|"auth via"| AuthenticationService

    AuthenticationService -->|"reads/writes"| IAuthenticationRepo
    UserService -->|"reads/writes"| IUserRepo
    OrderService -->|"reads/writes"| IOrderRepo
    FoodService -->|"reads/writes"| IFoodRepo
    VisitorService -->|"reads/writes"| IVisitorRepo
    AdminService -->|"reads/writes"| IAdminRepo
    AdminService -->|"reads/writes"| IFoodRepo

    IAuthenticationRepo -->|"stores tokens in"| MySQLDB
    IUserRepo -->|"stores users in"| MySQLDB
    IOrderRepo -->|"stores orders in"| MySQLDB
    IFoodRepo -->|"stores food items in"| MySQLDB
    IVisitorRepo -->|"stores visitors in"| MySQLDB
    IAdminRepo -->|"stores admins in"| MySQLDB

    FoodService -->|Sends Email via| JavaMail
    OrderService -->|Sends Email via| JavaMail
    UserService -->|Sends Email via| JavaMail
    VisitorService -->|Sends Email via| JavaMail
    AdminService -->|Sends Email via| JavaMail

    %% Click Events
    click FoodController "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Controller/FoodController.java"
    click OrderController "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Controller/OrderController.java"
    click UserController "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Controller/UserController.java"
    click VisitorController "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Controller/VisitorController.java"
    click AdminController "https://github.com/amit-ashok-swain/restaurant-management-system/tree/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Controller"
    click FoodService "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Service/FoodService.java"
    click OrderService "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Service/OrderService.java"
    click UserService "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Service/UserService.java"
    click VisitorService "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Service/VisitorService.java"
    click AdminService "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Service/AdminService.java"
    click IFoodRepo "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Repository/IFoodRepo.java"
    click IOrderRepo "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Repository/IOrderRepo.java"
    click IUserRepo "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Repository/IUserRepo.java"
    click IVisitorRepo "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Repository/IVisitorRepo.java"
    click IAdminRepo "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Repository/IAdminRepo.java"
    click IAuthenticationRepo "https://github.com/amit-ashok-swain/restaurant-management-system/blob/main/Restaurant-Management-Service-API/src/main/java/com/geekster/project/RestaurantManagementServiceAPI/Repository/IAuthenticationRepo.java"

    %% Styles
    classDef api fill:#cce5ff,stroke:#0366d6,color:#0366d6;
    classDef service fill:#d4edda,stroke:#28a745,color:#155724;
    classDef repo fill:#fff3cd,stroke:#ffc107,color:#856404;
    classDef database fill:#e2e3e5,stroke:#6c757d,color:#343a40,stroke-dasharray: 5 5;
    classDef external fill:#f8d7da,stroke:#dc3545,color:#721c24;
    classDef swagger fill:#e7f3ff,stroke:#0366d6,color:#0366d6,stroke-dasharray: 2 2;
```
