# adrils16/mercadawfinal architecture

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

- Interactive diagram: https://gitdiagram.com/adrils16/mercadawfinal
- Repository: https://github.com/adrils16/mercadawfinal

## Overview

##### Project Type and Purpose
- This is a final-year web application project – “Trabajo final de Desarrollo de Aplicaciones Web”.
- The README emphasizes scripts for DB setup and data loading, as well as instructions for executing several utility scripts (backup, label printing, payroll, etc.).
- The project uses Java as the primary language (the “src/main/java/…” package structure) and leverages JavaFX (the .fxml files under resources) for view components.
- The application interacts with a MariaDB database (see the SQL folder and docker-compose file) and reads/writes data using CSV and JSON formats, indicating full-stack behavior with a clear separation of view, controller, and model (MVC) responsibilities.

##### Analyzing the File Structure
- Top-level folders include:
- documentation (with comprehensive HTML and Markdown documentation along with javadocs)
- src (which contains the core Java source code, divided in packages by functionality such as controller, model, DAO, entity, utilities, reader, writer, and view)
- sql (for database setup)
- ficherosDarAlta (for initial data files in CSV/JSON)
- Scripts (various .sh files for backup, printing labels, payroll, etc.)
- The presence of docker-compose.yml indicates containerized deployment; the application expects the MariaDB instance to be available when the container is running.
- The project also includes tests (src/test) that mirror the main functionality, emphasizing software robustness.

##### Key Components and their Relationships
a. Presentation Layer:
- JavaFX Views: FXML files and their corresponding controllers (e.g., DarAltaEmpeadoViewController, PrincipalViewController, etc.) located in src/main/resources and src/main/java/.../view.
- These manage the UI interactions and pass requests to the business logic.
b. Business Logic / Controller Layer:
- Controllers (e.g., MercadawController, various other view controllers) that coordinate user actions.
- Exception handling (custom exceptions like FicheroException, FormatoException, etc.)
c. Data Access / Model Layer:
- Model Entities: Employee, Client, Product (found in the model/entity subfolders).
- DAO layer: Concrete implementations (e.g., MercaDawMariaDBDAOImp and MercaDawMockDAOImp) that manage database operations, selecting the right DAO via a DAO factory.
- The model also defines interfaces (Gestionable, Imprimible) to ensure consistency across entity operations.
d. Utility and Integration Components:
- Reader and Writer utilities (e.g., LectorCSV, LectorJSON, ExportarCSV, PDFUtil) that enable data import/export functions.
- Scripts and Docker: External scripts and docker-compose are used to manage execution and database initialization.
e. Database and Infrastructure:
- A MariaDB database is configured with initialization scripts (located in the sql folder).
- Docker and the accompanying docker-compose.yml file underline an infrastructure component.

##### Architectural Patterns and Principles
- MVC/MVP is used: A clear separation between the view (JavaFX UI defined in FXML and accompanying controllers), the controller (business logic controllers and coordinators), and the model/DAO (entities and data access components).
- Factory pattern for DAO creation (e.g., MercaDawDAOFactory) to support different implementations (MariaDB vs. mock).
- Utility classes encapsulate cross-cutting concerns (file reading, CSV export, PDF generation, etc.).

- Presentation (UI / JavaFX Views)
- Business Logic (Controllers: MercadawController and various view controllers)
- Data Access (Model, DAO, Factory, Entities)
- Infrastructure/Support (Scripts, Docker container handling, Database)
- Inside each layer, list the key packages or components (refer to the package names in src/main/java).
- Showing external integrations and how the system is set up for testing (as indicated by the src/test structure).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer (UI)"
        PV["JavaFX Views (FXML files)"]
        VC["View Controllers"]
    end

    subgraph "Business Logic / Controller Layer"
        BL["MercadawController"]
    end

    subgraph "Data Access / Model Layer"
        DE["Model & Entities"]
        DAO["DAO & Implementations"]
        DF["DAO Factory"]
    end

    subgraph "Utility & Integration Components"
        DR["Data Readers"]
        DW["Data Writers & Export Utilities"]
        CSVE["CSV Export Utility"]
    end

    subgraph "Database & Infrastructure"
        DB["Database (MariaDB)"]
        DS["Database Init Scripts"]
        DC["Docker Deployment (docker-compose)"]
        US["Utility Scripts"]
        IDF["Initial Data Files"]
    end

    %% Connections between layers
    PV -->|"triggers"| BL
    VC -->|"handlesUIEvents"| BL
    BL -->|"callsDAO"| DAO
    DAO -->|"managesEntities"| DE
    BL -->|"usesReader"| DR
    BL -->|"usesWriter"| DW
    BL -->|"usesCSVExport"| CSVE
    DAO -->|"CRUDOperations"| DB
    DF -->|"instantiatesDAO"| DAO
    DR -->|"readsFrom"| IDF
    DW -->|"writesTo"| IDF
    CSVE -->|"exportsCSV"| IDF
    DC -->|"initializesDBScripts"| DS
    US -->|"maintains"| DB

    %% Click Events
    click PV "https://github.com/adrils16/mercadawfinal/tree/main/src/main/resources/es/tiernoparla/daw/mercadaw/view/"
    click VC "https://github.com/adrils16/mercadawfinal/tree/main/src/main/java/es/tiernoparla/daw/mercadaw/view/"
    click BL "https://github.com/adrils16/mercadawfinal/blob/main/src/main/java/es/tiernoparla/daw/mercadaw/controller/MercadawController.java"
    click DE "https://github.com/adrils16/mercadawfinal/tree/main/src/main/java/es/tiernoparla/daw/mercadaw/model/"
    click DAO "https://github.com/adrils16/mercadawfinal/tree/main/src/main/java/es/tiernoparla/daw/mercadaw/model/dao/"
    click DF "https://github.com/adrils16/mercadawfinal/blob/main/src/main/java/es/tiernoparla/daw/mercadaw/model/dao/MercaDawDAOFactory.java"
    click DR "https://github.com/adrils16/mercadawfinal/tree/main/src/main/java/es/tiernoparla/daw/mercadaw/utils/reader/"
    click DW "https://github.com/adrils16/mercadawfinal/tree/main/src/main/java/es/tiernoparla/daw/mercadaw/utils/writer/"
    click CSVE "https://github.com/adrils16/mercadawfinal/blob/main/src/main/java/es/tiernoparla/daw/mercadaw/utils/export/ExportarCSV.java"
    click DS "https://github.com/adrils16/mercadawfinal/tree/main/sql/"
    click DC "https://github.com/adrils16/mercadawfinal/blob/main/docker-compose.yml"
    click US "https://github.com/adrils16/mercadawfinal/tree/main/Scripts"
    click IDF "https://github.com/adrils16/mercadawfinal/tree/main/ficherosDarAlta/"

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef business fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef data fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef utility fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef infra fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;

    class PV,VC presentation;
    class BL business;
    class DE,DAO,DF data;
    class DR,DW,CSVE utility;
    class DB,DS,DC,US,IDF infra;
```
