How tinitamo08-2007/proyecto-3-tercer-trimestre works
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: ControladorGranja.java Controller · server.js Express server · dao DAOs · scripts SQL scripts
Components 15
Java console app
MVC + DAO operational client
- Controller · Main orchestration and action routing
granja-digital-github/app/src/granja/controlador/ControladorGranja.java - Console UI · Terminal interaction layer
granja-digital-github/app/src/granja/vista/VistaConsola.java - Domain model · Animal, Empleado, Actividad and enums
granja-digital-github/app/src/granja/modelo - DAOs · Animal, Empleado, Actividad data access
granja-digital-github/app/src/granja/dao - Utilities · Logging, validation, backup, export
granja-digital-github/app/src/granja/util - Exceptions · Domain-specific validation and lookup errors
granja-digital-github/app/src/granja/excepciones - Main class · Application bootstrap
granja-digital-github/app/src/granja/controlador/Principal.java
Web app
Express API plus browser UI
- Express server · REST endpoints and MySQL queries
granja-web/server.js - Browser UI · HTML, CSS, and client-side fetch calls
granja-web/public/index.html - Client JS · Fetches API data and renders results
granja-web/public/js/main.js
Database layer
Schema, scripts, and documentation
- MySQL DB · Shared MySQL schema used by both applications
- SQL scripts · Creation, sample data, and queries
database/scripts - DB docs · ER, normalization, and database memory
database/docs
Deployment
Dockerized MySQL environment
- Docker MySQL · Dockerized local database deployment
docker_db/docker-compose.yml - Docker assets · Image build, seed copy, and env template
docker_db
Connections 18
- 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