# shubh-debug/restaurant-pos-system architecture

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

- Interactive diagram: https://gitdiagram.com/shubh-debug/restaurant-pos-system
- Repository: https://github.com/shubh-debug/restaurant-pos-system

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) Point-of-Sale (POS) system for restaurants.
- The README describes features such as real-time analytics, table management, order processing, billing/invoicing, KOT generation and Razorpay integration.
- The entire stack is containerized via Docker Compose, with separate frontend and backend services.

##### File structure
- Top-level directories:
- backend/ – Node.js + Express REST API
- frontend/ – React single-page application, Redux Toolkit, TanStack Query
- docker-compose.yml – orchestrates frontend, backend, database containers
- backend/ substructure:
- config/ – database and environment configuration
- controllers/ – MVC controllers for orders, payments, tables, users
- models/ – Mongoose schemas for orders, payments, tables, users, KOTs, counters
- routes/ – Express routes wired to controllers
- middlewares/ – global error handler, JWT verification
- server.js – entry point
- frontend/ substructure:
- public/ + index.html – host container for app
- src/ – React components organized by feature (auth, dashboard, home, menu, kitchen, etc.), pages, hooks, https layer, Redux slices, store
- nginx.conf – to serve built assets via NGINX in production
- vite.config.js – build config
- docker-compose.yml:
- Defines services for frontend, backend, MongoDB, possibly NGINX as reverse proxy
- Networks and volumes for data persistence

##### Additional insights from README
- Architecture highlights: RESTful API, JWT auth, containerized services, real-time state via React + TanStack Query, Redux for global state, Framer Motion, Tailwind CSS.
- Emphasis on production readiness and DevOps best practices (Docker, Docker Compose).

##### Main components & interactions
a. Frontend (React SPA)
- State management: Redux Toolkit + TanStack Query
- HTTP client: axios wrapper toward backend API
- Pages and feature components rendering UI, collecting user input
b. Backend API (Node.js + Express)
- Authentication middleware (JWT)
- Controllers implementing business logic for orders, payments, tables, users
- Models (Mongoose) interacting with MongoDB
- Global error handler
c. Database (MongoDB)
- Stores collections: users, tables, orders, payments, KOTs, counters
d. External Service: Razorpay
- Online payment processing via backend integration
e. KOT Printer or Kitchen subsystem
- Backend triggers KOT creation which can be sent to a printer service/subsystem
f. DevOps containers
- Docker Compose orchestrating frontend container (Node + NGINX), backend container (Node), MongoDB container

##### Architectural patterns & design principles
- Backend follows MVC: routes → controllers → models
- Frontend follows component-driven architecture with feature folders and centralized state management
- Separation of concerns: UI layer, API layer, data persistence
- Secure stateless auth with JWT
- Containerized micro-services pattern: each major service in its own Docker container

- Labels for each service, database, and external system
- Notes on ports or network (e.g., backend: 5000, frontend: 3000, MongoDB: 27017)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and Browser
    User["User Browser"]:::external
    %% Frontend Container
    subgraph "Frontend Container" 
        direction TB
        ReactApp["React SPA"]:::frontend
        Pages["React Pages (UI Routing)"]:::frontend
        Components["Feature Components"]:::frontend
        ReduxStore["Redux Toolkit"]:::frontend
        Slices["Redux Slices"]:::frontend
        TanStack["TanStack Query & Hooks"]:::frontend
        AxiosLayer["Axios HTTP Wrapper"]:::frontend
        StaticAssets["Static Assets & Public Host"]:::frontend
        NginxConf["Production Server Config (NGINX)"]:::frontend
        ViteConfig["Vite Build Config"]:::frontend
        TailwindConfig["Tailwind CSS Config"]:::frontend
    end

    %% Backend Container
    subgraph "Backend Container"
        direction TB
        Server["Express Server"]:::backend
        subgraph "Routing Layer"
            direction TB
            Routes["Express Routes"]:::backend
        end
        subgraph "Business Logic"
            direction TB
            Controllers["Controllers"]:::backend
        end
        subgraph "Data Layer"
            direction TB
            Models["Mongoose Models"]:::backend
        end
        subgraph "Middlewares"
            direction TB
            AuthMiddleware["JWT Verification"]:::backend
            ErrorMiddleware["Global Error Handler"]:::backend
        end
        Configs["Env & DB Config"]:::backend
    end

    %% Database and External
    MongoDB["MongoDB (27017)"]:::datastore
    Razorpay["Razorpay API"]:::external
    KOTPrinter["KOT Printer Service"]:::external

    %% Docker Orchestration
    subgraph "Docker Compose"
        direction TB
        FrontDocker["Frontend Dockerfile"]:::docker
        BackDocker["Backend Dockerfile"]:::docker
        Compose["docker-compose.yml"]:::docker
    end

    %% Connections
    User -->|"HTTP 80"| ReactApp
    ReactApp -->|renders| Pages
    ReactApp -->|uses| Components
    ReactApp -->|dispatches| ReduxStore
    Pages -->|reads state| ReduxStore
    Components -->|queries| TanStack
    TanStack -->|fetches| AxiosLayer
    AxiosLayer -->|REST API calls| Server
    ReactApp -->|serves static| StaticAssets
    StaticAssets -->|served by| NginxConf

    Server -->|uses config| Configs
    Server -->|handles routes| Routes
    Routes -->|invoke| Controllers
    Controllers -->|CRUD ops| Models
    Controllers -->|apply| AuthMiddleware
    Controllers -->|apply| ErrorMiddleware
    Controllers -->|process payment| Razorpay
    Controllers -->|generate KOT| KOTPrinter
    Controllers -->|read/write| MongoDB

    %% Docker links
    FrontDocker -->|builds| ReactApp
    BackDocker -->|builds| Server
    Compose -->|orchestrates| FrontDocker
    Compose -->|orchestrates| BackDocker
    Compose -->|orchestrates| MongoDB

    %% Click Events
    click ReactApp "https://github.com/shubh-debug/restaurant-pos-system/tree/main/frontend/src"
    click Pages "https://github.com/shubh-debug/restaurant-pos-system/tree/main/frontend/src/pages"
    click Components "https://github.com/shubh-debug/restaurant-pos-system/tree/main/frontend/src/components"
    click ReduxStore "https://github.com/shubh-debug/restaurant-pos-system/blob/main/frontend/src/redux/store.js"
    click Slices "https://github.com/shubh-debug/restaurant-pos-system/tree/main/frontend/src/redux/slices"
    click TanStack "https://github.com/shubh-debug/restaurant-pos-system/blob/main/frontend/src/hooks/useLoadData.js"
    click AxiosLayer "https://github.com/shubh-debug/restaurant-pos-system/blob/main/frontend/src/https/axiosWrapper.js"
    click AxiosLayer "https://github.com/shubh-debug/restaurant-pos-system/blob/main/frontend/src/https/index.js"
    click StaticAssets "https://github.com/shubh-debug/restaurant-pos-system/tree/main/frontend/public"
    click StaticAssets "https://github.com/shubh-debug/restaurant-pos-system/blob/main/frontend/index.html"
    click NginxConf "https://github.com/shubh-debug/restaurant-pos-system/blob/main/frontend/nginx.conf"
    click ViteConfig "https://github.com/shubh-debug/restaurant-pos-system/blob/main/frontend/vite.config.js"
    click TailwindConfig "https://github.com/shubh-debug/restaurant-pos-system/blob/main/frontend/tailwind.config.js"
    click Server "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/server.js"
    click Configs "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/config/config.js"
    click Configs "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/config/database.js"
    click Routes "https://github.com/shubh-debug/restaurant-pos-system/tree/main/backend/routes"
    click Controllers "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/controllers/orderController.js"
    click Controllers "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/controllers/paymentController.js"
    click Controllers "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/controllers/tableController.js"
    click Controllers "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/controllers/userController.js"
    click Models "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/models/orderModel.js"
    click Models "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/models/paymentModel.js"
    click Models "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/models/tableModel.js"
    click Models "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/models/userModel.js"
    click Models "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/models/kotModel.js"
    click Models "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/models/counterModel.js"
    click AuthMiddleware "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/middlewares/tokenVerification.js"
    click ErrorMiddleware "https://github.com/shubh-debug/restaurant-pos-system/blob/main/backend/middlewares/globalErrorHandler.js"
    click FrontDocker "https://github.com/shubh-debug/restaurant-pos-system/tree/main/frontend/dockerfile"
    click BackDocker "https://github.com/shubh-debug/restaurant-pos-system/tree/main/backend/dockerfile"
    click Compose "https://github.com/shubh-debug/restaurant-pos-system/blob/main/docker-compose.yml"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef datastore fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef docker fill:#f8f9fa,stroke:#343a40,color:#343a40
```
