# teo-information/entregable architecture

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

- Interactive diagram: https://gitdiagram.com/teo-information/entregable
- Repository: https://github.com/teo-information/entregable

## Overview

##### Project Type and Purpose
- This is a full-stack CRUD web application (“Sistema de Gestión de Vendedores”) built with Node.js, Express and MySQL.
- It follows the classic MVC pattern to let users Create, Read, Update and Delete “vendedores” and their “contactos.”

##### File Structure Analysis
- Top-level:
- Dockerfile & GitHub Actions workflow (CI/CD)
- package.json / package-lock.json (Node dependencies, scripts)
- ventas.sql & crud-vendedores/database/*.sql (DB schema & stored procedures)
- `crud-vendedores/`: Main Express app
- app.js (entry point, middleware setup)
- config/db.js (MySQL connection)
- routes/ (Express routes)
- controllers/ (business logic)
- models/ (data models mapping to DB)
- public/ (static assets: HTML/CSS/JS)
- views/ (EJS templates)

##### README Insights
- Confirms Node v14+, MySQL 5.7+, and use of express, mysql2, ejs, body-parser.
- Describes DB initialization (ventas.sql import) and env-specific DB credentials in config/db.js.
- Shows project start scripts (`npm start`, `npm run dev`).

##### Main Components
a. Client Layer (Browser)
- Static UI (HTML/CSS/JS in public/) served by Express
- EJS templates (views/) rendered server-side
b. Application Layer (Express Server inside Docker container)
- Routes (contacto.routes.js, vendedores.js)
- Controllers (contacto.controller.js, vendedor.controller.js)
- Models (contacto.model.js, vendedor.model.js)
- Config (db.js establishing MySQL connection)
c. Data Layer (MySQL Database)
- Schema & tables defined in tables.sql
- Stored procedures in procedures.sql
d. Infrastructure / DevOps
- Docker container hosting the Node.js app
- GitHub Actions workflow for deployment
- Environment variables for DB credentials

##### Relationships and Data Flow
- Browser → HTTP Request → Express Route
- Route → Controller → Model (constructs SQL queries)
- Model → MySQL Server (executes SQL) → returns data
- Controller → selects view template or JSON → Response to Browser
- Static assets served directly from public/ folder
- Docker networking between App container and MySQL (could be in another container or managed service)
- CI/CD pipeline triggers Docker build & deploy via .github/workflows/deploy.yml

##### Architectural Patterns & Design Principles
- MVC separation:
- Models isolate data access
- Controllers encapsulate business logic, coordinate Models + Views
- Views (EJS) handle presentation logic
- Layered architecture: Presentation → Application → Data
- 12-factor app principles: config in environment, portability via Docker
- Use of stored procedures centralizes complex DB logic

##### Essential Elements
- Component names and brief descriptions (e.g., “vendedor.controller.js – business logic”)
- Methods of communication (HTTP, SQL queries)
- External services or tools (Docker, GitHub Actions, environment variables)
- Database schema overview: tables for vendedores/contactos, stored procedures

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer (Browser)"
        direction TB
        StaticAssets["Static Assets"]:::client
        IndexHTML["index.html"]:::client
        ScriptJS["script.js"]:::client
        ContactoJS["contacto.js"]:::client
        subgraph "EJS Templates"
            direction TB
            TemplatesDir["Templates Directory"]:::client
            ListarVendedores["index.ejs"]:::client
            NuevoVendedor["nuevo.ejs"]:::client
            EditarVendedor["editar.ejs"]:::client
        end
    end

    %% Application Layer
    subgraph "Application Layer (Express Server)" 
        direction TB
        AppEntry["app.js\n(Express + Node.js)"]:::server
        ConfigDB["db.js\n(MySQL Connection)"]:::server
        subgraph "Routes"
            direction TB
            RoutesVendedores["vendedores.js"]:::server
            RoutesContacto["contacto.routes.js"]:::server
        end
        subgraph "Controllers"
            direction TB
            ControllerVendedor["vendedor.controller.js"]:::server
            ControllerContacto["contacto.controller.js"]:::server
        end
        subgraph "Models"
            direction TB
            ModelVendedor["vendedor.model.js"]:::server
            ModelContacto["contacto.model.js"]:::server
        end
    end

    %% Data Layer
    subgraph "Data Layer (MySQL Database)"
        direction TB
        DB["MySQL Database"]:::db
        TablesSQL["tables.sql"]:::db
        ProcsSQL["procedures.sql"]:::db
        OneOffSQL["ventas.sql"]:::db
    end

    %% Infrastructure / DevOps
    subgraph "Infrastructure / DevOps"
        direction TB
        Dockerfile["Dockerfile"]:::infra
        CICD["GitHub Actions Workflow"]:::infra
        PackageJSON["package.json / package-lock.json"]:::infra
        Readme["README.md"]:::infra
    end

    %% Data Flows
    Browser["Browser"]:::client
    Browser -->|HTTP Request| IndexHTML
    IndexHTML -->|loads| StaticAssets
    IndexHTML -->|renders| ListarVendedores
    IndexHTML -->|renders| NuevoVendedor
    IndexHTML -->|renders| EditarVendedor
    ScriptJS -->|AJAX| AppEntry
    ContactoJS -->|AJAX| AppEntry
    Browser -->|HTTP Request| AppEntry

    AppEntry -->|uses| ConfigDB
    AppEntry -->|routes to| RoutesVendedores
    AppEntry -->|routes to| RoutesContacto
    RoutesVendedores -->|calls| ControllerVendedor
    RoutesContacto -->|calls| ControllerContacto
    ControllerVendedor -->|queries| ModelVendedor
    ControllerContacto -->|queries| ModelContacto
    ModelVendedor -->|executes SQL| DB
    ModelContacto -->|executes SQL| DB
    DB -->|schema| TablesSQL
    DB -->|procedures| ProcsSQL

    CICD -->|triggers| Dockerfile
    Dockerfile -->|builds| AppEntry
    Dockerfile -->|pulls| DB
    Readme -->|documents| AppEntry
    PackageJSON -->|defines| AppEntry

    %% Click Events
    click StaticAssets "https://github.com/teo-information/entregable/tree/main/crud-vendedores/public/"
    click IndexHTML "https://github.com/teo-information/entregable/blob/main/crud-vendedores/public/index.html"
    click ScriptJS "https://github.com/teo-information/entregable/blob/main/crud-vendedores/public/js/script.js"
    click ContactoJS "https://github.com/teo-information/entregable/blob/main/crud-vendedores/public/js/contacto.js"
    click TemplatesDir "https://github.com/teo-information/entregable/tree/main/crud-vendedores/views/"
    click ListarVendedores "https://github.com/teo-information/entregable/blob/main/crud-vendedores/views/index.ejs"
    click NuevoVendedor "https://github.com/teo-information/entregable/blob/main/crud-vendedores/views/nuevo.ejs"
    click EditarVendedor "https://github.com/teo-information/entregable/blob/main/crud-vendedores/views/editar.ejs"
    click AppEntry "https://github.com/teo-information/entregable/blob/main/crud-vendedores/app.js"
    click ConfigDB "https://github.com/teo-information/entregable/blob/main/crud-vendedores/config/db.js"
    click RoutesVendedores "https://github.com/teo-information/entregable/blob/main/crud-vendedores/routes/vendedores.js"
    click RoutesContacto "https://github.com/teo-information/entregable/blob/main/crud-vendedores/routes/contacto.routes.js"
    click ControllerVendedor "https://github.com/teo-information/entregable/blob/main/crud-vendedores/controllers/vendedor.controller.js"
    click ControllerContacto "https://github.com/teo-information/entregable/blob/main/crud-vendedores/controllers/contacto.controller.js"
    click ModelVendedor "https://github.com/teo-information/entregable/blob/main/crud-vendedores/models/vendedor.model.js"
    click ModelContacto "https://github.com/teo-information/entregable/blob/main/crud-vendedores/models/contacto.model.js"
    click TablesSQL "https://github.com/teo-information/entregable/blob/main/crud-vendedores/database/tables.sql"
    click ProcsSQL "https://github.com/teo-information/entregable/blob/main/crud-vendedores/database/procedures.sql"
    click OneOffSQL "https://github.com/teo-information/entregable/blob/main/ventas.sql"
    click Dockerfile "https://github.com/teo-information/entregable/tree/main/Dockerfile"
    click CICD "https://github.com/teo-information/entregable/blob/main/.github/workflows/deploy.yml"
    click PackageJSON "https://github.com/teo-information/entregable/blob/main/package.json"
    click Readme "https://github.com/teo-information/entregable/blob/main/README.md"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef server fill:#90EE90,stroke:#333,stroke-width:1px
    classDef db fill:#FFA500,stroke:#333,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px
```
