# rffrench/portafolioweb architecture

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

- Interactive diagram: https://gitdiagram.com/rffrench/portafolioweb
- Repository: https://github.com/rffrench/portafolioweb

## Overview

##### Project Type and Overall Purpose
- The project is one of several components in a microservices architecture for a restaurant management website. This particular repository implements the NodeJS frontend, which uses EJS as a template engine together with plain HTML, CSS, and client-side JavaScript.
- It serves as the user interface to interact with the backend orchestrator as well as with services handling authentication, restaurant operations (orders/reservations), finance, and warehouse management.

##### Analyzing the File Structure
- Top-level files/folders:
– app.js: The entry point running the Express server.
– controllers: Contains logic for different routes (admin, auth, finance, restaurant, warehouse, error handling).
– middleware: Example – authMiddleware.js for validating user credentials/JWT tokens before processing requests.
– models: Defines data models (e.g., InventoryOrder, productModel, reservationsModel, userModel) used by Sequelize ORM for communicating with the single MySQL database.
– routes: Divided into different endpoint groups (admin, auth, finance, restaurant, warehouse) that map URLs to corresponding controller actions.
– public: Hosts static assets including CSS, JavaScript, and media used in the frontend.
– views: EJS templates organized by feature (admin, auth, finance, restaurant, warehouse) and layout files (includes folder) responsible for rendering the HTML sent to the client.
- Utility and configuration modules in the util folder support the overall backend processing (error handling, configuration constants).

##### Key Information from the README
- The README spells out how the entire system is broken up into several microservices (“Auth Microservice”, “Restaurant Microservice”, “Admin Microservice”) besides the main orchestrator and the NodeJS frontend (this repository).
- Authentication relies on JWT tokens (stored in cookies) that are validated by the backend microservices through the orchestrator, and the communication is strictly via RESTful HTTP requests.
- Additional applications (desktop admin app, totem waiter app, etc.) and their integration with the orchestrator are part of the overall ecosystem.
- The project uses a “microservices architecture” pattern with orchestration—not choreography—so central request routing and security validation (JWT checks) are managed by the orchestrator service.

a. Main Components of the System
- Browser/Client: Represents the end-user’s device accessing the website.
- NodeJS Frontend Service (this repository):
– Controllers (adminController, authController, financeController, restaurantController, warehouseController, errorController, messenger)
– Routes (adminRoutes, authRoutes, financeRoutes, restaurantRoutes, warehouseRoutes)
– Middleware (authMiddleware responsible for JWT validation)
– Models (data models interacting with the MySQL database via Sequelize)
– Views (EJS templates assembling HTML, organized by functional areas).
- External Orchestrator Microservice: Acts as a gateway by forwarding RESTful HTTP requests after checking JWT tokens.
- Backend Microservices:
▪ Auth Microservice (handles signup/login, JWT creation, password management, and email notifications).
▪ Restaurant Microservice (handles orders, reservations, menu image processing and compression, customer operations).
▪ Admin Microservice (handles administration tasks including operations for finance, warehouse, waiters, etc.).
- MySQL Database: A singular database shared among the microservices for data persistence.

b. Relationships and Interactions
- The NodeJS Frontend communicates with the Orchestrator service using RESTful HTTP, including JWT authorization tokens.
- The Orchestrator then routes the requests to the appropriate microservices (Auth, Restaurant, and Admin).
- Each microservice also communicates with the common MySQL database to perform CRUD operations.
- Additionally, socket-based connections (as mentioned in the README for real-time updates) and static file serving (CSS/JS in the public folder) should be illustrated where applicable.

c. Highlighting Architectural Patterns and Design Principles
- Microservices-based architecture along with the orchestration pattern used (i.e., a central orchestrator service that validates and forwards requests).
- Separation of concerns:
– The frontend (presentation layer) is distinctly separated from the business logic (handled by controllers and routed appropriately).
– Data persistence is abstracted via Sequelize models.

d. Relevant Technologies, Frameworks, and Libraries
- Node.js with Express for server handling.
- EJS for template rendering.
- Sequelize ORM for database operations with MySQL.
- Socket.io for real-time communications (if implemented in the app.js or elsewhere).
- JWT for authentication and authorization.

– Browser/Client
– Orchestrator Microservice
– Auth, Restaurant, and Admin Microservices
– MySQL Database
– Data flow from the client to the frontend, then to the orchestrator, and finally to the appropriate microservice.
– Internal flows, such as middleware checking JWT before routing to controllers.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Global Entities
    Browser["Browser/Client"]:::frontend
    
    %% NodeJS Frontend Service Subgraph
    subgraph "NodeJS Frontend Service"
        APP["app.js (Entry Point)"]:::component
        CTRL["Controllers<br/>(admin, auth, finance, restaurant, warehouse, error, messenger)"]:::component
        ROUTES["Routes<br/>(admin, auth, finance, restaurant, warehouse)"]:::component
        MW["Middleware<br/>(authMiddleware - JWT)"]:::component
        MODELS["Models<br/>(InventoryOrder, product, reservations, user)"]:::component
        VIEWS["Views<br/>(EJS Templates)"]:::component
        STATIC["Static Assets<br/>(CSS/JS/Media)"]:::component
        UTIL["Utility Modules<br/>(config, errorFunctions, helperFunctions)"]:::component
    end

    %% External Services and Microservices
    ORCH["External Orchestrator Microservice"]:::external
    AUTH["Auth Microservice"]:::microservice
    REST["Restaurant Microservice"]:::microservice
    ADMIN["Admin Microservice"]:::microservice
    MYSQL["MySQL Database"]:::database

    %% Relationships
    Browser -->|"HTTP request"| APP
    APP -->|"Loads"| ROUTES
    ROUTES -->|"Uses"| MW
    MW -->|"Invokes"| CTRL
    CTRL -->|"Accesses"| MODELS
    CTRL -->|"Renders"| VIEWS
    APP -->|"Serves"| STATIC
    APP -->|"Utilizes"| UTIL

    APP -->|"Sends HTTP request with JWT"| ORCH
    ORCH -->|"Routes to"| AUTH
    ORCH -->|"Routes to"| REST
    ORCH -->|"Routes to"| ADMIN

    AUTH -->|"CRUD Operations"| MYSQL
    REST -->|"CRUD Operations"| MYSQL
    ADMIN -->|"CRUD Operations"| MYSQL

    %% Optional Real-Time Communication
    Browser ---|"Socket.io"| APP

    %% Click Events for Component Mapping
    click APP "https://github.com/rffrench/portafolioweb/blob/master/app.js"
    click CTRL "https://github.com/rffrench/portafolioweb/tree/master/controllers"
    click ROUTES "https://github.com/rffrench/portafolioweb/tree/master/routes"
    click MW "https://github.com/rffrench/portafolioweb/blob/master/middleware/authMiddleware.js"
    click MODELS "https://github.com/rffrench/portafolioweb/tree/master/models"
    click VIEWS "https://github.com/rffrench/portafolioweb/tree/master/views"
    click STATIC "https://github.com/rffrench/portafolioweb/tree/master/public"
    click UTIL "https://github.com/rffrench/portafolioweb/tree/master/util"

    %% Styles
    classDef frontend fill:#f2f2f2,stroke:#333,stroke-width:2px;
    classDef component fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef external fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef microservice fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#333,stroke-width:2px;
```
