# anhell0s/lab_ueb architecture

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

- Interactive diagram: https://gitdiagram.com/anhell0s/lab_ueb
- Repository: https://github.com/anhell0s/lab_ueb

## Overview

##### Main Components
- Frontend (Client):
- Built with React and managed by Vite.
- Contains a robust folder structure for pages, layouts (private/public), components (inputs, buttons, banners, forms, etc.), context providers (for authentication, theming, network status) and hooks.
- A dedicated public folder for static assets and a configuration setup to point API endpoints (via the environment variable VITE_API_BASE_URL).

- Backend (Server):
- Developed using Node.js and Express to serve the API endpoints.
- Organized into controllers, routes, middlewares, models, and helpers – which clearly hints at the separation of concerns (e.g., controllers handling business logic, routes handling HTTP endpoints, models interfacing with the database).
- Uses important middlewares like rate limiting, CORS configuration, error handling, authentication verification (JWT and role-based) and logging (Morgan, Chalk).
- Integrates with a PostgreSQL database (as indicated by PERN) and uses additional services – such as Nodemailer for email notifications and PDF generation libraries.
- Has separate seeders and configurations for bootstrapping the database.

- Database:
- Although the file tree does not explicitly provide a database folder, the architecture assumes a PostgreSQL connection managed via server/config/db.config.js.
- The database serves as the persistent storage for the application’s data.

- External Services & Tools:
- Deployment and Docker configuration are present for both client and server, indicated by Dockerfiles.
- Redis configuration and Mailer setup are included for caching and email services.
- Environment variables (in .env files for both client and server) suggest integration with email SMTP servers and API routing.

##### Relationships & Interactions
- The Client (React application) sends HTTP requests (using Axios) to the Backend API endpoints.
- The Server (Express application) processes incoming HTTP requests, applies middleware (authentication, error handling, rate limiting), and interacts with the PostgreSQL database for CRUD operations.
- Additional interactions include sending emails via Nodemailer and possibly caching or queueing operations via Redis and P-Queue.
- The use of Dockerfiles on both sides indicates containerized deployment and potential orchestration.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clear division between the frontend (UI/UX and state management) and backend (API, business logic, data management).
- Modular Structure: Both client and server codebases follow a modular organization (features, components, services) which can be individually maintained and scaled.
- Middleware Usage: The backend employs multiple middlewares (for logging, error handling, security, and request throttling) to enhance maintainability and reliability.
- RESTful API Design: The server routes indicate RESTful endpoints with controllers performing specific tasks.
- Containerization: Docker configurations help in creating consistent environments across development, staging, and production.

##### Relevant Technologies & Frameworks
- Frontend: React, Vite, React Router, Tailwind CSS, Framer Motion, Axios, React Hook Form, Zod.
- Backend: Node.js, Express, body-parser, Helmet, Morgan, Express-rate-limit, Nodemailer.
- Database: PostgreSQL (implied by PERN).
- Other: Redis (for caching or session management), Docker (deployment).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (Client)"
      direction TB
      FE["Frontend (Client)"]:::frontend
      click FE "https://github.com/anhell0s/lab_ueb/tree/main/client/src"

      subgraph "UI Layer"
        direction TB
        FE1["React UI Components"]:::frontend
        click FE1 "https://github.com/anhell0s/lab_ueb/tree/main/client/src/components"
        FE2["Feature Modules"]:::frontend
        click FE2 "https://github.com/anhell0s/lab_ueb/tree/main/client/src/features"
      end

      subgraph "Layouts"
        direction TB
        L1["Private Layout"]:::frontend
        click L1 "https://github.com/anhell0s/lab_ueb/tree/main/client/src/layouts/Private"
        L2["Public Layout"]:::frontend
        click L2 "https://github.com/anhell0s/lab_ueb/tree/main/client/src/layouts/Public"
      end

      subgraph "Context Providers"
        direction TB
        CP1["AuthContext"]:::frontend
        click CP1 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/context/AuthContext.jsx"
        CP2["ThemeContext"]:::frontend
        click CP2 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/context/ThemeContext.jsx"
        CP3["NetworkStatusContext"]:::frontend
        click CP3 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/context/NetworkStatusContext.jsx"
      end

      subgraph "Routing"
        direction TB
        R1["config.routes.jsx"]:::frontend
        click R1 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/routes/config.routes.jsx"
        R2["protected.routes.jsx"]:::frontend
        click R2 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/routes/protected.routes.jsx"
        R3["routes.js"]:::frontend
        click R3 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/routes/routes.js"
      end

      subgraph "HTTP API Services"
        direction TB
        HS1["auth.api.js"]:::frontend
        click HS1 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/services/api/auth.api.js"
        HS2["lab.api.js"]:::frontend
        click HS2 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/services/api/lab.api.js"
        HS3["reactive.api.js"]:::frontend
        click HS3 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/services/api/reactive.api.js"
        HS4["role.api.js"]:::frontend
        click HS4 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/services/api/role.api.js"
        HS5["sample.api.js"]:::frontend
        click HS5 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/services/api/sample.api.js"
        HS6["user.api.js"]:::frontend
        click HS6 "https://github.com/anhell0s/lab_ueb/blob/main/client/src/services/api/user.api.js"
      end

      FEClientHTTP["HTTP Client (Axios)"]:::frontend
      FEClientDocker["Docker (Client)"]:::external
      click FEClientDocker "https://github.com/anhell0s/lab_ueb/tree/main/client/Dockerfile"
    end

    subgraph "Backend (Server)"
      direction TB
      BE["Backend (Server)"]:::backend
      click BE "https://github.com/anhell0s/lab_ueb/tree/main/server/"

      subgraph "API Layer"
        direction TB
        BE1["Express Routes"]:::backend
        click BE1 "https://github.com/anhell0s/lab_ueb/tree/main/server/routes"
        BE2["Middlewares"]:::backend
        click BE2 "https://github.com/anhell0s/lab_ueb/tree/main/server/middlewares"
        BE3["Controllers"]:::backend
        click BE3 "https://github.com/anhell0s/lab_ueb/tree/main/server/controllers"
      end

      subgraph "Data & Services"
        direction TB
        DS1["Database (PostgreSQL)"]:::backend
        click DS1 "https://github.com/anhell0s/lab_ueb/blob/main/server/config/db.config.js"
        DS2["Mailer Service"]:::backend
        click DS2 "https://github.com/anhell0s/lab_ueb/blob/main/server/config/mailer.config.js"
        DS3["Mailer Lib"]:::backend
        click DS3 "https://github.com/anhell0s/lab_ueb/blob/main/server/libs/mailer.lib.js"
        DS4["Redis Cache"]:::backend
        click DS4 "https://github.com/anhell0s/lab_ueb/blob/main/server/config/redis.config.js"
        DS5["Seeders"]:::backend
        click DS5 "https://github.com/anhell0s/lab_ueb/tree/main/server/seeders"
        DS6["Docker (Server)"]:::external
        click DS6 "https://github.com/anhell0s/lab_ueb/tree/main/server/Dockerfile"
      end
    end

    %% Relationships
    FEClientHTTP -->|"HTTP_Request"| BE1
    BE1 -->|"uses"| BE2
    BE2 -->|"validates"| BE3
    BE3 -->|"CRUD"| DS1
    BE3 -->|"sendsEmail"| DS2
    BE3 -->|"sendsEmail"| DS3
    BE3 -->|"caches"| DS4

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef external fill:#FFFFCC,stroke:#000,stroke-width:2px,stroke-dasharray: 5,5;
```
