# xxvnte/website-chaleco_inteligente architecture

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

- Interactive diagram: https://gitdiagram.com/xxvnte/website-chaleco_inteligente
- Repository: https://github.com/xxvnte/website-chaleco_inteligente

## Overview

##### Project type and purpose
- This is a full-stack monitoring application for a “smart vest” that collects sensor data.
- Frontend: React + Vite + Tailwind CSS (SPA for registration, login, dashboard, user profile).
- Backend: Node.js + Express (REST API with authentication middleware)
- Database: PostgreSQL (stores users, sensor readings).

##### File structure
- Root: monorepo containing two sub-projects.
- chaleco-inteligente/ → Express server, entry point app.js/index.js, middlewares/auth.js, routes/main.js & user.js.
- chaleco-inteligente-ui/ → React app (src/components, context/AuthContext, assets, config files for Vite/Tailwind).
- Config files:
- Frontend: package.json, vite.config.js, tailwind.config.js, postcss.config.js
- Backend: package.json, .gitignore, Express setup files

##### README for insights
- Confirms architecture: React frontend on port 5173, Express backend on port 3000, local PostgreSQL.
- Use cases: user registration/login, viewing live sensor data, editing profile.

##### Main components and interactions
a. Components
1. External Actor: Smart Vest Device (IoT sensor source)
2. Frontend Client (React SPA)
3. Backend API Server (Node.js + Express)
4. Authentication Middleware (JWT/session)
5. Routes/Controllers (main.js, user.js)
6. PostgreSQL Database
b. Relationships / Data Flow
- Smart Vest → HTTP/WebSocket → Backend API → persists to DB
- Browser ←→ React SPA (UI components)
- React SPA → REST calls → Express routes → auth middleware → DB queries
- Backend → Responses (JSON) → React displays sensor readings and user data
c. Architectural patterns & principles
- Separation of concerns: UI layer vs API layer vs Data layer
- Middleware chain in Express for authentication/authorization
- Context provider in React for global auth state
- Component-based UI (DatosSensores, UserForm, UserCard)
d. Key technologies
- Frontend: React, Vite, Tailwind CSS, Context API
- Backend: Node.js, Express, PostgreSQL driver (e.g., node-pg)
- Dev tools: ESLint, PostCSS, Vite

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External device
    SmartVest["Smart Vest Device"]:::external

    %% Frontend client
    subgraph "Frontend Client (React SPA)"
        direction TB
        FrontendClient["React SPA"]:::frontend
        Entry["main.jsx"]:::frontend
        AuthContext["AuthContext.jsx"]:::frontend
        DatosSensores["DatosSensores.jsx"]:::frontend
        UserForm["UserForm.jsx"]:::frontend
        UserCard["UserCard.jsx"]:::frontend
        Navbar["Navbar.jsx"]:::frontend
        Secciones["Secciones.jsx"]:::frontend
    end

    %% Backend API server
    subgraph "Backend API Server (Express)" 
        direction TB
        APIServer["Express App"]:::server
        AppInit["app.js"]:::server
        Startup["index.js"]:::server
        AuthMiddleware["auth.js"]:::server
        subgraph "Controllers"
            MainRoutes["main.js"]:::server
            UserRoutes["user.js"]:::server
        end
    end

    %% Database
    Postgres["PostgreSQL Database"]:::db

    %% Connections
    SmartVest -->|"HTTP/WebSocket"| APIServer
    FrontendClient -->|"HTTP REST calls"| APIServer
    APIServer -->|"SQL Queries"| Postgres
    Postgres -->|"Query Results"| APIServer
    APIServer -->|"JSON Responses"| FrontendClient

    %% Click Events
    click FrontendClient "https://github.com/xxvnte/website-chaleco_inteligente/tree/main/chaleco-inteligente-ui/"
    click Entry "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente-ui/src/main.jsx"
    click AuthContext "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente-ui/src/context/AuthContext.jsx"
    click DatosSensores "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente-ui/src/components/DatosSensores.jsx"
    click UserForm "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente-ui/src/components/UserForm.jsx"
    click UserCard "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente-ui/src/components/UserCard.jsx"
    click Navbar "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente-ui/src/components/Navbar.jsx"
    click Secciones "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente-ui/src/components/Secciones.jsx"
    click APIServer "https://github.com/xxvnte/website-chaleco_inteligente/tree/main/chaleco-inteligente/"
    click AppInit "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente/app.js"
    click Startup "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente/index.js"
    click AuthMiddleware "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente/middlewares/auth.js"
    click MainRoutes "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente/routes/main.js"
    click UserRoutes "https://github.com/xxvnte/website-chaleco_inteligente/blob/main/chaleco-inteligente/routes/user.js"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064;
    classDef server fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef db fill:#FFF3E0,stroke:#E65100,color:#E65100;
    classDef external fill:#ECEFF1,stroke:#546E7A,color:#546E7A;
```
