# spachecor/protectora architecture

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

- Interactive diagram: https://gitdiagram.com/spachecor/protectora
- Repository: https://github.com/spachecor/protectora

## Overview

##### Main Components
- Presentation Layer: This includes the GUI built with JavaFX. The FXML files (such as main-screen.fxml, nuevoAnimal.fxml, nuevoUsuario.fxml, panel.fxml, card.fxml) indicate the structure of the UI. The MainScreen.java and various controller classes (MainController, NuevoAnimalController, NuevoUsuarioController, PanelController) serve as the bridge between the UI and the logic.
- Business Logic/Controller Layer: The controllers, behavior interfaces (Crudable, Ordenable, Paginable), and properties files define the logic and rules for the application. They also coordinate user actions from the GUI.
- Domain/Model Layer: This includes the models (under models/animals, models/adopcion, models/personas, etc.) which describe the entities such as Animal, Gato, Perro, Usuario, Direccion, and SolicitudAdopcion.
- Services Layer: Contains several subcomponents:
- Database Service (ConexionBBDD.java) for database connectivity.
- File Generation (FileObjectGenerator.java) and XML generation (XmlGenerator and its specific implementations) that assist in creating files or exporting data.
- Customized List Services (such as AnimalLista, UsuarioLista, etc.) which might be used for tailored data presentation.
- Logging Service: With several logger classes (ProtectoraLogger, ProtectoraHandler, ProtectoraFormatter, and ProtectoraFilter) and log files in resources.
- Configuration and Resources: Maven configuration (pom.xml, mvnw scripts), properties, and resource files (e.g., protectora.sql for database setup, images, log files, UML and XML files) which support the application’s runtime and build process.

##### Relationships and Interactions
- Controllers invoke methods on the Business Logic components (which implement interfaces like Crudable, Ordenable, etc.) and manipulate Model objects.
- The Service layer is called upon by the Controllers and Business Logic to perform tasks such as accessing the database (through ConexionBBDD), generating files (via FileObjectGenerator), and handling logging or XML data conversion.
- Data flows from these services back to the Controllers which then update the UI. External dependencies, such as persistence via SQL or file-based logs/XML, must be represented.

##### Architectural Patterns
- The project follows a Model-View-Controller (MVC) approach, where UI (View), Controllers (handling events and user interactions), and Models (representing core data) are kept distinct.
- Additional abstraction is visible with behavioral interfaces (e.g., Crudable, Ordenable) that likely allow for flexible handling of various collections or domain objects.
- Separation of concerns: Each package/namespace clearly represents a distinct area (models, controllers, services, properties), encapsulating specific functionalities.

##### Relevant Technologies, Frameworks, and Libraries
- Java (with modules) and Maven for project management.
- JavaFX for the graphical user interface (FXML files).
- Custom logging mechanisms instead of standard frameworks.
- XML processing for exporting or importing data.
- Database connectivity, likely for CRUD operations, as indicated by the ConexionBBDD class.

##### Specific Elements
- Presentation Layer (JavaFX FXML and MainScreen)
- Controllers (MainController, NuevoAnimalController, etc.)
- Models (Animal, Gato, Perro, Usuario, etc.)
- Services (Database Connection, File Generator, XML Generator, Logger)
- Configuration/Resources (pom.xml, properties, SQL script)
- User actions flowing into the Presentation and Controller layers.
- Calls from Controllers to Services (e.g., logging, data retrieval, XML file generation).
- Data flow between the Model components and the UI.
- If possible, include notes indicating architectural patterns like MVC and list technologies (Java, Maven, JavaFX) alongside the relevant components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        UI["JavaFX UI (FXML)"]:::presentation
        MS["MainScreen Controller"]:::presentation
    end

    subgraph "Controller Layer"
        MC["MainController"]:::controllers
        NAC["NuevoAnimalController"]:::controllers
        NUC["NuevoUsuarioController"]:::controllers
        PC["PanelController"]:::controllers
        Card["Card Component"]:::controllers
    end

    subgraph "Model Layer"
        Entidad["Entidad Model"]:::model
        Animals["Animals Models"]:::model
        Adoption["Adoption Model"]:::model
        Personas["Personas Models"]:::model
        Crudable["Crudable Interface"]:::model
        Ordenable["Ordenable Interface"]:::model
        Paginable["Paginable Interface"]:::model
    end

    subgraph "Services Layer"
        DB["Database Service"]:::services
        FileGen["File Generator Service"]:::services
        ListServ["Custom List Services"]:::services
        Logger["Logging Service"]:::services
        XMLGen["XML Generation Service"]:::services
    end

    subgraph "Configuration & Resources"
        Maven["Maven Build & Config"]:::config
        AppProps["Application Properties"]:::config
        Resources["Resource Files & SQL Script"]:::config
    end

    %% Connections between layers
    UI -->|"triggers"| MS
    MS -->|"delegates"| MC

    %% Controllers to Model and Business Interfaces
    MC -->|"calls"| Crudable
    MC -->|"updates"| Entidad
    NAC -->|"handles"| Animals
    NAC -->|"uses"| Ordenable
    NUC -->|"handles"| Personas
    PC -->|"handles"| Adoption
    PC -->|"uses"| Paginable

    %% Controllers to Services
    MC -->|"calls"| DB
    NAC -->|"calls"| FileGen
    NUC -->|"calls"| Logger
    PC -->|"calls"| XMLGen
    Card -->|"uses"| ListServ

    %% Services to Configuration & Resources
    DB -->|"reads"| Resources
    Logger -->|"logsTo"| Resources
    FileGen -->|"writesTo"| Resources
    XMLGen -->|"readWrite"| Resources
    DB -->|"configures"| AppProps
    FileGen -->|"configures"| AppProps
    AppProps -->|"includedIn"| Maven

    %% Styling Classes
    classDef presentation fill:#f9f,stroke:#333,stroke-width:2px;
    classDef controllers fill:#bbf,stroke:#333,stroke-width:2px;
    classDef model fill:#cfc,stroke:#333,stroke-width:2px;
    classDef services fill:#fc9,stroke:#333,stroke-width:2px;
    classDef config fill:#cff,stroke:#333,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/spachecor/protectora/tree/master/src/main/resources/org/project/protectora/fxml/"
    click MS "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/MainScreen.java"
    click MC "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/controllers/MainController.java"
    click NAC "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/controllers/NuevoAnimalController.java"
    click NUC "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/controllers/NuevoUsuarioController.java"
    click PC "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/controllers/PanelController.java"
    click Card "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/controllers/Card.java"
    click Entidad "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/models/Entidad.java"
    click Animals "https://github.com/spachecor/protectora/tree/master/src/main/java/org/project/protectora/models/animals/"
    click Adoption "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/models/adopcion/SolicitudAdopcion.java"
    click Personas "https://github.com/spachecor/protectora/tree/master/src/main/java/org/project/protectora/models/personas/"
    click Crudable "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/comportamiento/Crudable.java"
    click Ordenable "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/comportamiento/Ordenable.java"
    click Paginable "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/comportamiento/Paginable.java"
    click DB "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/servicios/bbdd/ConexionBBDD.java"
    click FileGen "https://github.com/spachecor/protectora/blob/master/src/main/java/org/project/protectora/servicios/filegenerator/FileObjectGenerator.java"
    click ListServ "https://github.com/spachecor/protectora/tree/master/src/main/java/org/project/protectora/servicios/listapersonalizada/"
    click Logger "https://github.com/spachecor/protectora/tree/master/src/main/java/org/project/protectora/servicios/logger/"
    click XMLGen "https://github.com/spachecor/protectora/tree/master/src/main/java/org/project/protectora/servicios/xml/"
    click Maven "https://github.com/spachecor/protectora/blob/master/pom.xml"
    click AppProps "https://github.com/spachecor/protectora/tree/master/src/main/java/org/project/protectora/properties/"
    click Resources "https://github.com/spachecor/protectora/blob/master/src/main/resources/protectora.sql"
```
