# tinitamo08-2007/proyecto-3-tercer-trimestre architecture

> Architecture diagram of the GitHub repository tinitamo08-2007/proyecto-3-tercer-trimestre, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tinitamo08-2007/proyecto-3-tercer-trimestre
- Repository: https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre

## Overview

1. **High-level shape**
   - This repository is a multi-module student project for managing a livestock farm, centered on a **shared MySQL database**.
   - There are two independent application fronts:
     - a **Java console application** for operational management
     - a **Node.js web application** for viewing/querying the same data
   - A third subsystem provides **database schema/documentation**, and a fourth provides **Docker-based local database deployment**.

2. **Core boundary: the database is the system-of-record**
   - Both the Java app and the web app read from and write to the same MySQL schema.
   - That shared database is the main integration point and the architectural boundary between presentation logic and persistence.
   - The repository also includes SQL scripts for schema creation, sample data, and documented queries, plus ER/relational/normalization artifacts.

3. **Java console application subsystem**
   - Located under `granja-digital-github/app`.
   - Uses a classic **MVC + DAO** structure:
     - `controlador` contains the entry point and orchestration
     - `vista` contains console interaction
     - `modelo` contains domain entities and enums
     - `dao` contains JDBC persistence access
     - `util` contains logging, validation, backup, export helpers
     - `excepciones` contains domain-specific error types
   - The Java app is the more complete “transactional” layer for CRUD and operational workflows.

4. **Java data flow**
   - User input enters through the console view.
   - The controller validates and routes actions.
   - Domain objects such as `Animal`, `Empleado`, and `Actividad` are passed to DAOs.
   - DAOs use `ConexionBD` and JDBC to execute SQL against MySQL.
   - Utilities support cross-cutting concerns: logging, validation, backup, and export to Excel/PDF.

5. **Java domain model**
   - The model is centered on three main business entities:
     - `Animal`
     - `Empleado`
     - `Actividad`
   - `EstadoAnimal` and `TipoActividad` are enums that constrain business states/types.
   - This suggests the domain logic is mostly centered around livestock registry, staff management, and daily activity tracking.

6. **Web application subsystem**
   - Located under `granja-web`.
   - Built with **Node.js + Express** and a static frontend in `public/`.
   - The frontend is composed of `index.html`, `style.css`, and `main.js`, with browser-side interaction through fetch-based calls to the backend API.
   - The web app is not a separate data store; it is a live query layer on top of MySQL.

7. **Web data flow and API boundary**
   - `server.js` exposes a small REST API:
     - `GET /api/animales`
     - `GET /api/empleados`
     - `GET /api/actividades`
     - `GET /api/stats`
     - `POST /api/consulta`
   - The browser loads the static UI, then JavaScript requests data from Express.
   - Express then queries MySQL using `mysql2`, including joins through the database view for activity listings.
   - The README indicates a fallback to demo data if MySQL is unavailable, which makes the web layer resilient for presentation/demo use.

8. **Database subsystem**
   - The `database/` folder holds the relational design, SQL scripts, and documentation.
   - Main tables are:
     - `empleado`
     - `animal`
     - `actividad`
     - `actividad_animal` for the many-to-many relationship
     - `vista_actividades` as a denormalized query view
   - The design is documented as normalized to 3NF, with an explicit relational schema and ER diagrams.
   - This module is not runtime code; it is the schema and reference layer for both apps.

9. **Deployment/infrastructure subsystem**
   - `docker_db/` packages MySQL into a Dockerized environment.
   - `docker-compose.yml` defines the database service, persistence, and networking.
   - The intent is to make the database reproducible across machines without installing MySQL locally.
   - The repository supports both local Docker deployment and an external/cloud option (Aiven), which affects how the apps are configured.

10. **Configuration and secret boundaries**
    - The Java app uses `config.properties.example` as a credential template.
    - The Docker setup uses `.env` for database credentials.
    - The web server also expects database credentials, with the README warning not to hardcode secrets in source control.
    - This creates a clear separation between code and environment-specific deployment settings.

11. **Cross-cutting utilities**
    - Logging, validation, backup, and export are implemented as shared Java utilities rather than being embedded in the controller.
    - `ExportadorExcel` and `ExportadorPDF` indicate report generation is a first-class feature.
    - `CopiaSeguridadUtil` suggests the Java app can capture the state of the system independently of the Docker/database backup story.

12. **How an engineer should draw the architecture**
    - Draw one central MySQL database box.
    - Connect to it from two separate clients:
      - the Java console application via JDBC/DAO
      - the Node/Express web application via `mysql2`
    - Place the SQL scripts/docs and Docker assets as supporting subsystems around the database.
    - Treat the browser UI as a thin client over the Express API, and treat the Java console as a direct database client with richer local business workflows.

Main entry points: [`granja-digital-github/app/src/granja/controlador/ControladorGranja.java`](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-digital-github/app/src/granja/controlador/ControladorGranja.java) (Controller), [`granja-web/server.js`](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-web/server.js) (Express server), [`granja-digital-github/app/src/granja/dao`](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/granja-digital-github/app/src/granja/dao) (DAOs), [`database/scripts`](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/database/scripts) (SQL scripts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_java_app["Java console app"]
  node_java_controller["Controller<br/>Java MVC"]
  node_java_view["Console UI<br/>Java view<br/>[VistaConsola.java]"]
  node_java_models["Domain model<br/>Java entities"]
  node_java_daos["DAOs<br/>JDBC persistence"]
  node_java_utils["Utilities<br/>Java support"]
  node_java_errors["Exceptions<br/>Java errors"]
  node_java_entry(("Main class<br/>Java entrypoint<br/>[Principal.java]"))
end

subgraph group_web_app["Web app"]
  node_web_server["Express server<br/>Node API<br/>[server.js]"]
  node_web_ui["Browser UI<br/>static frontend<br/>[index.html]"]
  node_web_client_js["Client JS<br/>browser script<br/>[main.js]"]
end

subgraph group_database["Database layer"]
  node_central_db[("MySQL DB<br/>system-of-record")]
  node_schema_scripts["SQL scripts<br/>schema scripts"]
  node_db_docs["DB docs<br/>relational docs"]
end

subgraph group_deployment["Deployment"]
  node_docker_mysql[("Docker MySQL<br/>container stack<br/>[docker-compose.yml]")]
  node_docker_assets["Docker assets<br/>db packaging"]
end

node_java_entry -->|"starts"| node_java_controller
node_java_controller -->|"drives"| node_java_view
node_java_controller -->|"uses"| node_java_models
node_java_controller -->|"delegates"| node_java_daos
node_java_controller -->|"cross-cutting"| node_java_utils
node_java_controller -->|"raises"| node_java_errors
node_java_daos -->|"JDBC"| node_central_db
node_java_utils -.->|"backup/export"| node_central_db
node_web_ui -->|"loads"| node_web_client_js
node_web_client_js -->|"fetches"| node_web_server
node_web_server -->|"mysql2"| node_central_db
node_schema_scripts -->|"defines"| node_central_db
node_db_docs -.->|"documents"| node_central_db
node_docker_mysql -->|"runs"| node_central_db
node_docker_assets -.->|"packages"| node_docker_mysql
node_web_server -.->|"serves"| node_web_ui
node_java_daos -.->|"aligned with"| node_schema_scripts
node_web_server -.->|"aligned with"| node_schema_scripts

click node_java_controller "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-digital-github/app/src/granja/controlador/ControladorGranja.java"
click node_java_view "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-digital-github/app/src/granja/vista/VistaConsola.java"
click node_java_models "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/granja-digital-github/app/src/granja/modelo"
click node_java_daos "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/granja-digital-github/app/src/granja/dao"
click node_java_utils "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/granja-digital-github/app/src/granja/util"
click node_java_errors "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/granja-digital-github/app/src/granja/excepciones"
click node_java_entry "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-digital-github/app/src/granja/controlador/Principal.java"
click node_web_server "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-web/server.js"
click node_web_ui "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-web/public/index.html"
click node_web_client_js "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-web/public/js/main.js"
click node_schema_scripts "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/database/scripts"
click node_db_docs "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/database/docs"
click node_docker_mysql "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/docker_db/docker-compose.yml"
click node_docker_assets "https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/docker_db"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_java_controller,node_java_view,node_java_models,node_java_daos,node_java_utils,node_java_errors,node_java_entry toneBlue
class node_web_server,node_web_ui,node_web_client_js toneAmber
class node_central_db,node_schema_scripts,node_db_docs toneMint
class node_docker_mysql,node_docker_assets toneRose
```

## Components

### Java console app

MVC + DAO operational client

- [Controller](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-digital-github/app/src/granja/controlador/ControladorGranja.java): Java MVC · Main orchestration and action routing · `granja-digital-github/app/src/granja/controlador/ControladorGranja.java`
- [Console UI](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-digital-github/app/src/granja/vista/VistaConsola.java): Java view · Terminal interaction layer · `granja-digital-github/app/src/granja/vista/VistaConsola.java`
- [Domain model](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/granja-digital-github/app/src/granja/modelo): Java entities · Animal, Empleado, Actividad and enums · `granja-digital-github/app/src/granja/modelo`
- [DAOs](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/granja-digital-github/app/src/granja/dao): JDBC persistence · Animal, Empleado, Actividad data access · `granja-digital-github/app/src/granja/dao`
- [Utilities](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/granja-digital-github/app/src/granja/util): Java support · Logging, validation, backup, export · `granja-digital-github/app/src/granja/util`
- [Exceptions](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/granja-digital-github/app/src/granja/excepciones): Java errors · Domain-specific validation and lookup errors · `granja-digital-github/app/src/granja/excepciones`
- [Main class](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-digital-github/app/src/granja/controlador/Principal.java): Java entrypoint · Application bootstrap · `granja-digital-github/app/src/granja/controlador/Principal.java`

### Web app

Express API plus browser UI

- [Express server](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-web/server.js): Node API · REST endpoints and MySQL queries · `granja-web/server.js`
- [Browser UI](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-web/public/index.html): static frontend · HTML, CSS, and client-side fetch calls · `granja-web/public/index.html`
- [Client JS](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/granja-web/public/js/main.js): browser script · Fetches API data and renders results · `granja-web/public/js/main.js`

### Database layer

Schema, scripts, and documentation

- **MySQL DB**: system-of-record · Shared MySQL schema used by both applications
- [SQL scripts](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/database/scripts): schema scripts · Creation, sample data, and queries · `database/scripts`
- [DB docs](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/database/docs): relational docs · ER, normalization, and database memory · `database/docs`

### Deployment

Dockerized MySQL environment

- [Docker MySQL](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/blob/main/docker_db/docker-compose.yml): container stack · Dockerized local database deployment · `docker_db/docker-compose.yml`
- [Docker assets](https://github.com/tinitamo08-2007/proyecto-3-tercer-trimestre/tree/main/docker_db): db packaging · Image build, seed copy, and env template · `docker_db`

## Connections

- Main class → Controller: starts · Bootstraps the console workflow
- Controller → Console UI: drives · Reads user input and prints responses
- Controller → Domain model: uses · Passes domain objects through workflows
- Controller → DAOs: delegates · Routes CRUD operations to persistence
- Controller → Utilities: cross-cutting · Validation, logging, backup, export
- Controller → Exceptions: raises · Domain exceptions surfaced to the UI
- DAOs → MySQL DB: JDBC · Direct MySQL access through ConexionBD
- Utilities → MySQL DB: backup/export · Supports database-related maintenance flows
- Browser UI → Client JS: loads · Static browser shell
- Client JS → Express server: fetches · Client-side API calls
- Express server → MySQL DB: mysql2 · Queries shared schema and views
- SQL scripts → MySQL DB: defines · Creates tables, relations, sample data, and queries
- DB docs → MySQL DB: documents · Relational model, ER design, and normalization
- Docker MySQL → MySQL DB: runs · Provides local MySQL service
- Docker assets → Docker MySQL: packages · Build and configuration inputs
- Express server → Browser UI: serves · Backend for the browser frontend
- DAOs → SQL scripts: aligned with · Persistence layer follows the documented schema
- Express server → SQL scripts: aligned with · Queries and endpoints reflect the same schema
