# debau123/proyecto_2daw architecture

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

- Interactive diagram: https://gitdiagram.com/debau123/proyecto_2daw
- Repository: https://github.com/debau123/proyecto_2daw

## Overview

##### Project Type & Purpose
- RestoraTech is an integrated management platform for restaurants, clearly segmented by user roles (administrator, chef, waiter, client) and focusing on key operations such as menu management, order tracking, table management, reservations, and more.
- The project is a full-stack application. The frontend is built with Next.js using React (with Context for state management) and styled with TailwindCSS. In contrast, the backend is built with Strapi (a headless CMS) interfacing with a MySQL database, along with other integrated services like JWT authentication, email verification, and optionally realtime updates via Socket.io.

##### Analyzing the File Structure
- Top-Level Directories: The project is divided into two major directories: "frontend" (which contains a robust Next.js structure including pages, API routes, components, and helper libraries) and "backend" (which, although minimal in the provided tree, represents the Strapi project, as noted in the README). There is also an “Analisi_Funcional_RestoraTech.pdf” and a main README.
- Frontend:
- The "front" (or "frontend" as per the README) directory is structured to handle API routes, authentication pages per role, shared components (e.g., NavBar, ReservationForm), and libraries (for authentication, mailing, models, etc).
- Files like "next.config.ts", "tailwind.config.js", "tsconfig.json" indicate a modern Next.js configuration with TypeScript and TailwindCSS.
- Backend:
- Although less detailed in the file tree, the README clarifies that the "backend" contains a Strapi project with defined collections to manage data.
- Additional Files:

##### Main Components
a. Frontend (Client Side):
- Next.js Application: Highlight pages, API endpoints, and role-based authentication views (admin, chef, waiter, client).
- Shared libraries and components for navigation, reservation forms, and authentication management.
- User interaction flows: Registration with email verification, login/logout, viewing menus, placing orders/reservations.
b. Backend (Server Side):
- Strapi CMS: Representing the core backend where CRUD operations for menus, orders, inventory, reservations, and user management occur.
- Database: MySQL database connected to Strapi, storing persistent data.
- Authentication: JWT-based authentication including routes for login, logout, and verification.
- External Services: Integration with Chart.js for generating graphs, Socket.io for real-time order updates (if enabled), and mailing services for sending verification emails or notifications.
c. Communication & Data Flow:
- Authentication Flow: Indicate how user credentials flow from the client to the backend and how token-based responses are used in session management.
- Optional Realtime: If implemented, real-time updates via Socket.io between backend and frontend.

##### Architectural Patterns & Design Principles
- Separation of concerns: clearly differentiating the frontend (presentation layer) from the backend (business logic and data management).
- Use of API Endpoints: Clearly mark the API routes (as seen in the "front/app/api" routes) that handle backend communications.
- Client-Side Routing & State Management: Indicate the use of Next.js’s file-based routing and React Context or similar for state management.
- Modularization: Show components such as authentication, user management, ordering, and reservations as individual but connected modules.
- Scalability: Mark how the architecture allows for future expansion (e.g., additional routes, microservices expansion on the backend).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        F["Next.js Frontend"]:::frontend
        FAuth["Role-Based Authentication Pages"]:::frontend
        FComp["Shared UI Components"]:::frontend
        FLib["Shared Libraries & Models"]:::frontend
        FAPI["Frontend API Endpoints"]:::frontend
        
        subgraph "API Modules"
            ResAPI["Reservations API Module"]:::frontend
            UserAuth["User Authentication API & JWT Handling"]:::frontend
            EmailEndpoint["Test Email Endpoint"]:::frontend
            MailerLib["Mailer Library"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B["Strapi Backend (CMS)"]:::backend
        JWT["JWT Authentication"]:::backend
        DB["MySQL Database"]:::database
        Socket["Socket.io (Realtime Updates)"]:::external
        Chart["Chart.js (Analytics)"]:::external
    end

    %% Connections within Frontend
    F -->|"uses"| FAuth
    F -->|"includes"| FComp
    F -->|"utilizes"| FLib
    F -->|"calls"| FAPI
    FAPI -->|"routes to"| ResAPI
    FAPI -->|"routes to"| UserAuth
    FAPI -->|"triggers"| EmailEndpoint
    FAPI -->|"triggers"| MailerLib

    %% Connections between Frontend and Backend
    FAPI -->|"API-call"| B

    %% Backend internal connections
    B -->|"performs CRUD"| DB
    B -->|"handles auth"| JWT
    B -->|"sends realtime updates"| Socket
    B -->|"generates analytics"| Chart

    %% Click Events for Frontend components
    click F "https://github.com/debau123/proyecto_2daw/tree/main/front/"
    click FAPI "https://github.com/debau123/proyecto_2daw/tree/main/front/app/api"
    click ResAPI "https://github.com/debau123/proyecto_2daw/tree/main/front/app/api/reservations"
    click UserAuth "https://github.com/debau123/proyecto_2daw/tree/main/front/app/api/users"
    click EmailEndpoint "https://github.com/debau123/proyecto_2daw/tree/main/front/app/api/sendTestEmail"
    click MailerLib "https://github.com/debau123/proyecto_2daw/blob/main/front/lib/mailer.js"
    click FAuth "https://github.com/debau123/proyecto_2daw/tree/main/front/app/auth"
    click FComp "https://github.com/debau123/proyecto_2daw/tree/main/front/app/components"
    click FLib "https://github.com/debau123/proyecto_2daw/tree/main/front/lib"

    %% Click Event for Backend component
    click B "https://github.com/debau123/proyecto_2daw/tree/main/back/"

    %% Styles
    classDef frontend fill:#CDEBFF,stroke:#036,stroke-width:2px;
    classDef backend fill:#DFFFD6,stroke:#060,stroke-width:2px;
    classDef database fill:#FFE4B5,stroke:#A65,stroke-width:2px;
    classDef external fill:#FFD2D2,stroke:#933,stroke-width:2px;
```
