# rodobriones/vino_costero architecture

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

- Interactive diagram: https://gitdiagram.com/rodobriones/vino_costero
- Repository: https://github.com/rodobriones/vino_costero

## Overview

##### Project Type & Purpose
- This is a full-stack web application (MVP) for vineyard management: Node.js/Express backend, React frontend (Vite), MySQL database.
- The frontend serves user interfaces for managing “catas,” “parcelas,” “lotes,” etc., and the backend exposes a REST API that interacts with MySQL.

##### High-Level Components
a. Web Browser & Frontend (web/)
- React SPA (Vite): pages under src/pages (Catas.jsx, Dashboard.jsx, etc.)
- Context/Auth layer (src/context/auth.jsx)
- HTTP client module (src/api/http.js) for making AJAX calls
b. Backend API (server/)
- Express app (app.js)
- Route handlers (server/routes/*.routes.js) for each entity (auth, catas, enfermedades, etc.)
- Auth middleware (server/middleware/auth.js)
- Database connector (server/db.js)
c. Database
- MySQL 8 schema and seed files (sql/schema.sql, sql/seeds.sql per README)
d. Development & Deployment
- .env for configuration
- NPM scripts (npm run dev)
- Vite config (web/vite.config.js)

##### Interactions & Data Flow
1) User in Browser
→ loads React app (served by Vite dev server on localhost:5173)
2) React App
→ uses http.js to send REST requests (GET/POST/PUT/DELETE) to backend at localhost:4000
3) Express API
→ auth middleware checks JWT/session
→ routes/*.routes.js handle business logic and call db.js
4) db.js
→ executes SQL queries against MySQL database
5) MySQL
→ persists data, returns results back up the chain to the client

##### Architectural Patterns & Principles
- Separation of Concerns: Frontend (UI/UX) vs. Backend (API & business logic) vs. Database
- RESTful APIs: one route file per resource (e.g., catas.routes.js handles all /catas endpoints)
- Middleware layering: authentication is applied centrally via auth.js
- Component modularity in React: page components + context + API layer

##### Final Checklist
- Arrowheads indicating request/response direction
- Notes on ports, environment variables, and key configuration files

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Browser
    Browser["Web Browser"]:::external

    %% Frontend Layer
    subgraph "React Frontend" 
        direction TB
        HTML["HTML Template"]:::frontend
        Main["Entry Point"]:::frontend
        AppComp["Root Component"]:::frontend
        Pages["Pages (Catas, Parcelas, Lotes, etc.)"]:::frontend
        Context["Context/Auth Layer"]:::frontend
        HTTPClient["HTTP Client Module"]:::frontend
    end

    %% Backend Layer
    subgraph "Express API"
        direction TB
        AppServer["Application Bootstrap"]:::backend
        Middleware["Auth Middleware"]:::backend
        Routes["Route Handlers"]:::backend
        DBConn["Database Connector"]:::backend
        Config["Config & Dependencies"]:::backend
    end

    %% Database
    MySQL["MySQL Database"]:::database
    SQLFiles["Schema & Seeds"]:::database

    %% Data Flow
    Browser -->|"loads app"| HTML
    HTML --> Main
    Main --> AppComp
    AppComp --> Pages
    AppComp --> Context
    Pages --> HTTPClient
    Context --> HTTPClient
    HTTPClient -->|"REST API calls / JSON"| AppServer
    AppServer --> Middleware
    Middleware --> Routes
    Routes --> DBConn
    DBConn -->|"SQL queries"| MySQL
    SQLFiles --> MySQL

    MySQL -->|"query results"| DBConn
    DBConn --> Routes
    Routes --> Middleware
    Middleware --> AppServer
    AppServer -->|"JSON responses"| HTTPClient
    HTTPClient --> Pages

    %% Click Events - Frontend
    click HTML "https://github.com/rodobriones/vino_costero/blob/main/web/index.html"
    click Main "https://github.com/rodobriones/vino_costero/blob/main/web/src/main.jsx"
    click AppComp "https://github.com/rodobriones/vino_costero/blob/main/web/src/App.jsx"
    click Pages "https://github.com/rodobriones/vino_costero/tree/main/web/src/pages/"
    click Context "https://github.com/rodobriones/vino_costero/blob/main/web/src/context/auth.jsx"
    click HTTPClient "https://github.com/rodobriones/vino_costero/blob/main/web/src/api/http.js"
    click Config "https://github.com/rodobriones/vino_costero/blob/main/web/vite.config.js"

    %% Click Events - Backend
    click AppServer "https://github.com/rodobriones/vino_costero/blob/main/server/app.js"
    click Middleware "https://github.com/rodobriones/vino_costero/blob/main/server/middleware/auth.js"
    click Routes "https://github.com/rodobriones/vino_costero/blob/main/server/routes/auth.routes.js"
    click Routes "https://github.com/rodobriones/vino_costero/blob/main/server/routes/catas.routes.js"
    click Routes "https://github.com/rodobriones/vino_costero/blob/main/server/routes/enfermedades.routes.js"
    click Routes "https://github.com/rodobriones/vino_costero/blob/main/server/routes/lotes.routes.js"
    click Routes "https://github.com/rodobriones/vino_costero/blob/main/server/routes/parcelas.routes.js"
    click Routes "https://github.com/rodobriones/vino_costero/blob/main/server/routes/reportes.routes.js"
    click Routes "https://github.com/rodobriones/vino_costero/blob/main/server/routes/siembras.routes.js"
    click Routes "https://github.com/rodobriones/vino_costero/blob/main/server/routes/tiposUva.routes.js"
    click DBConn "https://github.com/rodobriones/vino_costero/blob/main/server/db.js"
    click Config "https://github.com/rodobriones/vino_costero/blob/main/server/package.json"
    click Config "https://github.com/rodobriones/vino_costero/blob/main/server/README.md"
    click SQLFiles "https://github.com/rodobriones/vino_costero/blob/main/sql/schema.sql"
    click SQLFiles "https://github.com/rodobriones/vino_costero/blob/main/sql/seeds.sql"
    click README "https://github.com/rodobriones/vino_costero/blob/main/README.md"
    click README "https://github.com/rodobriones/vino_costero/blob/main/web/README.md"

    %% Styles
    classDef frontend fill:#e0f7e9,stroke:#2b7a4b,stroke-width:1px
    classDef backend fill:#e0f1f7,stroke:#1f5e8a,stroke-width:1px
    classDef database fill:#fde9d9,stroke:#d2691e,stroke-width:1px
    classDef external fill:#eeeeee,stroke:#999999,stroke-width:1px
```
