# amunozsuarez/gestion-restaurante architecture

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

- Interactive diagram: https://gitdiagram.com/amunozsuarez/gestion-restaurante
- Repository: https://github.com/amunozsuarez/gestion-restaurante

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“Sistema de Gestión de Restaurante”) providing three user-facing modules—Mostrador (counter), Delivery and Admin—for order management, product/category management, customer management, cash register and reporting.

##### File Structure Analysis
- Top level:
- backend – Node.js/Express REST API
– src/bdd: MongoDB connection
– src/models: Mongoose schemas (User, Restaurant, Category, Food, Order, Customer, CashRegister)
– src/controllers: business logic per entity
– src/routes: Express routers mapping endpoints (/api/auth, /user, /restaurant, /category, /food, /order, /customer, /cash, /report)
– src/middlewares: auth (JWT), role-based, restaurant filtering
– server.js: API entry point
- frontend – React SPA
– public: index.html, static assets
– src/components: UI components split by module (admin, cart, common, forms, layout, lists, pages for delivery/mostrador/login)
– src/hooks: custom hooks (API access, business logic, state/forms)
– src/services: axios config, React Query client, API wrappers
– src/store: global state (Zustand stores for auth, cart, UI, restaurant)
– src/styles: CSS by component/module

a. Main Components
- Client layer: React SPA with three logical modules (Mostrador, Delivery, Admin)
- API layer: Node.js/Express server
- Data layer: MongoDB database
- Auth subsystem: JWT issuance & validation middleware
- External services: (optional) Email/SMS gateways, third-party payment or delivery partner APIs

b. Relationships & Data Flows
1. User (browser/mobile) interacts with the React SPA
2. SPA calls backend endpoints via Axios/React-Query (using REACT_APP_API_URL)
3. Express middleware validates JWT and user roles, then routes to controllers
4. Controllers perform CRUD via Mongoose models against MongoDB
5. Responses propagate back through middleware to the client
6. For reporting, the server aggregates data and returns analytics

c. Architectural Patterns & Design Principles
- Client-Server separation
- MVC pattern on backend (Models, Controllers, Routes)
- Component-based architecture on frontend with custom hooks for separation of concerns
- Single source of truth for global state (Zustand)
- API layer secured via JWT + role-based access
- Modularization by feature (admin vs. user vs. order management)

d. Key Technologies & Frameworks
- Frontend: React 19, React Router 7, Zustand, React Query, Axios, React Toastify
- Backend: Node.js, Express, Mongoose (MongoDB), JWT, bcrypt, Morgan

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Mostrador["React Mostrador Module"]:::frontend
        Delivery["React Delivery Module"]:::frontend
        Admin["React Admin Module"]:::frontend
    end

    %% Client Utilities
    subgraph "Client Utilities"
        direction TB
        App["App.js & Routing"]:::frontend
        Services["API Services & Config"]:::frontend
        Hooks["Custom Hooks"]:::frontend
        Store["Zustand Global State"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        Server["Express Server"]:::backend
        subgraph "Middlewares"
            direction TB
            Auth["Auth Middleware (JWT)"]:::middleware
            Role["Role-Based Access Middleware"]:::middleware
            AdminMW["Admin-Only Middleware"]:::middleware
            Filter["Restaurant Filter Middleware"]:::middleware
        end
        subgraph "Routes"
            direction TB
            Routes["Express Routes (/api/*)"]:::backend
        end
        subgraph "Controllers"
            direction TB
            Controllers["Controllers (Users, Orders, Food, etc.)"]:::backend
        end
        subgraph "Models"
            direction TB
            Models["Mongoose Models"]:::backend
        end
        DBconn["DB Connection"]:::db
    end

    %% Database
    DB["MongoDB Cluster"]:::database

    %% External Services
    External["External Services (Email/SMS/Payments)"]:::external

    %% Connections
    Mostrador -->|uses| App
    Delivery -->|uses| App
    Admin -->|uses| App
    App -->|calls| Services
    Services -->|HTTP/API| Routes
    Server -->|initializes| Auth
    Auth -->|validates| Role
    Role -->|checks| AdminMW
    AdminMW -->|filters| Filter
    Filter -->|routes to| Routes
    Routes -->|invokes| Controllers
    Controllers -->|CRUD| Models
    Models -->|connects via| DBconn
    DBconn -->|stores data| DB
    Services -.->|optional| External

    %% Click Events
    click Mostrador "https://github.com/amunozsuarez/gestion-restaurante/tree/master/frontend/src/components/pages/mostrador"
    click Delivery "https://github.com/amunozsuarez/gestion-restaurante/tree/master/frontend/src/components/pages/delivery"
    click Admin "https://github.com/amunozsuarez/gestion-restaurante/tree/master/frontend/src/components/admin"
    click Store "https://github.com/amunozsuarez/gestion-restaurante/tree/master/frontend/src/store"
    click Hooks "https://github.com/amunozsuarez/gestion-restaurante/tree/master/frontend/src/hooks"
    click Services "https://github.com/amunozsuarez/gestion-restaurante/tree/master/frontend/src/services"
    click App "https://github.com/amunozsuarez/gestion-restaurante/blob/master/frontend/src/App.js"
    click Server "https://github.com/amunozsuarez/gestion-restaurante/blob/master/backend/src/server.js"
    click DBconn "https://github.com/amunozsuarez/gestion-restaurante/blob/master/backend/src/bdd/conexion.js"
    click Models "https://github.com/amunozsuarez/gestion-restaurante/tree/master/backend/src/models"
    click Controllers "https://github.com/amunozsuarez/gestion-restaurante/tree/master/backend/src/controllers"
    click Routes "https://github.com/amunozsuarez/gestion-restaurante/tree/master/backend/src/routes"
    click Auth "https://github.com/amunozsuarez/gestion-restaurante/blob/master/backend/src/middlewares/authMiddleware.js"
    click Role "https://github.com/amunozsuarez/gestion-restaurante/blob/master/backend/src/middlewares/roleMiddleware.js"
    click AdminMW "https://github.com/amunozsuarez/gestion-restaurante/blob/master/backend/src/middlewares/adminMiddleware.js"
    click Filter "https://github.com/amunozsuarez/gestion-restaurante/blob/master/backend/src/middlewares/filterByRestaurant.js"

    %% Styles
    classDef frontend fill:#d0e1ff,stroke:#0366d6;
    classDef backend fill:#d0ffd8,stroke:#0a0;
    classDef middleware fill:#fff3cd,stroke:#ffb300;
    classDef db fill:#ffe0b3,stroke:#d97706;
    classDef database fill:#ffd1dc,stroke:#d60024,stroke-dasharray: 5 5;
    classDef external fill:#f0f0f0,stroke:#888888,stroke-dasharray: 2 2;
```
