# cristhianmorales19/sistema-gestion-agricola architecture

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

- Interactive diagram: https://gitdiagram.com/cristhianmorales19/sistema-gestion-agricola
- Repository: https://github.com/cristhianmorales19/sistema-gestion-agricola

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“Sistema de Gestión Agrícola”) that provides an integrated platform for managing personnel, attendance, payroll, productivity, and reports in the agricultural sector.
- Frontend: React + TypeScript
- Backend: Node.js (Express) + TypeScript
- Database: MySQL

##### File Structure Analysis
- Top‐level folders:
- frontend/ – React app
- backend/ – Express API
- database/ – SQL schemas, migrations, seeds
- Each of frontend/src and backend/src uses “caracteristicas” subfolders, reflecting the Screaming Architecture (feature-first, domain-driven).
- Configuration and shared code are likely under infraestructura/ and compartido/ (per README—even if not shown in the snippet).
- A .env.example and package.json in backend; package.json in frontend.

##### README Insights
- Confirms Screaming Architecture: domains (“personal”, “asistencia”, “nomina”, “productividad”, “reportes”, “auth”) are first-class folders.
- Tech stack: React, Express, MySQL, JWT, Bcrypt, Winston, Axios, React Router, Material-UI/Tailwind, Jest, ESLint/Prettier, Nodemon.
- API endpoints are grouped by feature (e.g., /api/auth, /api/personal, /api/asistencia, /api/nomina).

a. Main Components
- Client Browser / Mobile App – hosts the React SPA
- Frontend (React) – UI layers divided by feature modules
- API Gateway (Express) – single HTTP entrypoint (/api)
- Backend Feature Modules – Auth, Personal, Asistencia, Nómina, Productividad, Reportes
- Database (MySQL) – data persistence, migrations, seeds
- External Services / Libraries – JWT service, Bcrypt encryption, Winston logging
b. Relationships & Data Flow
1. User → React UI (via React Router & Material-UI)
2. React UI → Axios HTTP calls → Express API (/api/*)
3. Express routes delegate to feature controllers → services → repositories
4. Backend → MySQL (via an ORM or query layer)
5. Auth flows: login/register endpoints generate JWT → returned to client → client stores token → included in Authorization header on subsequent requests
6. Logging: Winston captures request/response and errors → log files or external store
c. Architectural Patterns & Principles
- Screaming Architecture / Feature-First: directories named by business domain
- Layered / Clean Architecture: controllers → services → repositories → database
- Single Monolithic API with clear feature modules, not microservices
- JWT-based stateless authentication
- Migration/seed versioning for database schema
d. Technologies & Frameworks
- Frontend: React, React Router, Axios, TypeScript, Material-UI/Tailwind
- Backend: Node.js, Express.js, TypeScript, JWT, Bcrypt, Winston
- Database: MySQL (8.0+), migration scripts

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User (Browser/Mobile)"]:::user

    %% Frontend Layer
    subgraph "Frontend (React SPA)" 
        direction TB
        SPA["React SPA"]:::frontend
        AutenticacionUI["Auth Module"]:::frontend
        GestionPersonalUI["Personnel Module"]:::frontend
        ControlAsistenciaUI["Attendance Module"]:::frontend
        GestionNominaUI["Payroll Module"]:::frontend
        ControlProductividadUI["Productivity Module"]:::frontend
        GestionReportesUI["Reports Module"]:::frontend
    end

    User -->|"interacts with"| SPA
    SPA -->|"navigates to"| AutenticacionUI
    SPA -->|"navigates to"| GestionPersonalUI
    SPA -->|"navigates to"| ControlAsistenciaUI
    SPA -->|"navigates to"| GestionNominaUI
    SPA -->|"navigates to"| ControlProductividadUI
    SPA -->|"navigates to"| GestionReportesUI
    SPA -->|"via Axios HTTP"| APIGateway

    %% Backend Layer
    subgraph "Backend (Express API)" 
        direction TB
        APIGateway["API Gateway (/api)"]:::backend
        AuthFeature["Auth Feature"]:::backend
        PersonalFeature["Personal Feature"]:::backend
        AsistenciaFeature["Attendance Feature"]:::backend
        NominaFeature["Payroll Feature"]:::backend
        ProductividadFeature["Productivity Feature"]:::backend
        ReportesFeature["Reports Feature"]:::backend
    end

    SPA -->|"HTTP requests"| APIGateway
    APIGateway -->|"routes to"| AuthFeature
    APIGateway -->|"routes to"| PersonalFeature
    APIGateway -->|"routes to"| AsistenciaFeature
    APIGateway -->|"routes to"| NominaFeature
    APIGateway -->|"routes to"| ProductividadFeature
    APIGateway -->|"routes to"| ReportesFeature

    %% Database
    MySQL["MySQL Database"]:::db
    AuthFeature -->|"queries"| MySQL
    PersonalFeature -->|"queries"| MySQL
    AsistenciaFeature -->|"queries"| MySQL
    NominaFeature -->|"queries"| MySQL
    ProductividadFeature -->|"queries"| MySQL
    ReportesFeature -->|"queries"| MySQL

    %% External Libraries/Services
    JWT["JWT Service"]:::external
    BCRYPT["Bcrypt Encryption"]:::external
    WINSTON["Winston Logging"]:::external

    AuthFeature -->|"uses"| JWT
    AuthFeature -->|"uses"| BCRYPT
    APIGateway -->|"logs to"| WINSTON

    %% Migrations and Seeds
    Migrations["DB Migrations & Seeds"]:::external
    Migrations -.->|"executes"| MySQL

    %% Click Events
    click SPA "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/frontend/"
    click AutenticacionUI "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/frontend/src/caracteristicas/autenticacion/"
    click GestionPersonalUI "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/frontend/src/caracteristicas/gestion-personal/"
    click ControlAsistenciaUI "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/frontend/src/caracteristicas/control-asistencia/"
    click GestionNominaUI "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/frontend/src/caracteristicas/gestion-nomina/"
    click ControlProductividadUI "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/frontend/src/caracteristicas/control-productividad/"
    click GestionReportesUI "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/frontend/src/caracteristicas/gestion-reportes/"

    click APIGateway "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/backend/src/"
    click AuthFeature "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/backend/src/caracteristicas/auth/"
    click PersonalFeature "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/backend/src/caracteristicas/personal/"
    click AsistenciaFeature "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/backend/src/caracteristicas/asistencia/"
    click NominaFeature "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/backend/src/caracteristicas/nomina/"
    click ProductividadFeature "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/backend/src/caracteristicas/productividad/"
    click ReportesFeature "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/backend/src/caracteristicas/reportes/"

    click Migrations "https://github.com/cristhianmorales19/sistema-gestion-agricola/tree/main/database/"
    click EnvConfig "https://github.com/cristhianmorales19/sistema-gestion-agricola/blob/main/backend/.env.example"
    click backendPkg "https://github.com/cristhianmorales19/sistema-gestion-agricola/blob/main/backend/package.json"
    click frontendPkg "https://github.com/cristhianmorales19/sistema-gestion-agricola/blob/main/frontend/package.json"

    %% Styling
    classDef frontend fill:#cce5ff,stroke:#4da3ff,color:#000
    classDef backend fill:#d4edda,stroke:#28a745,color:#000
    classDef db fill:#ffe5b4,stroke:#ff8c00,color:#000
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#000
    classDef user fill:#f8d7da,stroke:#dc3545,color:#000
```
