# emanuelleramirez28-rgb/proyecto-final-grupo architecture

> Architecture diagram of the GitHub repository emanuelleramirez28-rgb/proyecto-final-grupo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/emanuelleramirez28-rgb/proyecto-final-grupo
- Repository: https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo

## Overview

1. **Type of application**
   - AutoElite is a **Java Swing desktop application** for managing a used-car dealership.
   - It is not web-based; the user interface runs locally on the desktop and talks directly to a local H2 database.

2. **High-level architecture**
   - The repository follows a **classic MVC structure**:
     - **Model**: domain entities under `src/model`
     - **View**: Swing screens/dialogs under `src/view`
     - **Controller**: interaction and orchestration logic under `src/controller`
   - Data persistence is handled separately through **DAO classes** under `src/dao`.

3. **Application entry and startup flow**
   - `src/Main.java` is the entry point.
   - The app starts by loading the login screen, initializes the UI flow, and connects to the database.
   - The database is prepared using `resources/init.sql`, which seeds or creates the schema on startup.

4. **User interface boundary**
   - The UI is split into discrete Swing views:
     - `LoginView`
     - `MainView`
     - `InventarioView`
     - `DashboardView`
     - `SucursalView`
     - `GaleriaView`
     - `AgregarVehiculoDialog`
   - `MainView` acts as the shell/container after authentication, while the other views represent functional modules inside the app.

5. **Controller responsibilities**
   - Controllers mediate between views and persistence:
     - `LoginController` handles authentication and session entry.
     - `MainController` coordinates navigation in the main shell.
     - `InventarioController` manages vehicle listing, filters, and CRUD actions.
     - `DashboardController` prepares dashboard metrics.
     - `SucursalController` manages branch operations.
     - `GaleriaController` manages vehicle images and gallery actions.
   - Controllers are the main coordination layer between UI events and DAOs.

6. **Domain model**
   - The core business entities live in `src/model`:
     - `Vehiculo` is the abstract base class.
     - `Auto`, `Motocicleta`, and `Camion` extend it and provide polymorphic behavior.
     - `Sucursal` represents dealership branches.
     - `Usuario` represents authenticated users and roles.
     - `Imagen` represents stored vehicle media.
   - The model layer also encodes business logic like vehicle type behavior and price validation.

7. **Persistence layer**
   - DAO classes encapsulate all database access:
     - `ConexionDB` centralizes the H2 connection.
     - `UsuarioDAO`, `VehiculoDAO`, `SucursalDAO`, and `ImagenDAO` isolate SQL and CRUD operations.
   - The application uses **H2 Database Engine** via `lib/h2-2.4.240.jar`.
   - The database is configured as **in-memory** (`jdbc:h2:mem:autoelite`), so state is temporary unless exported elsewhere.

8. **Data flow through the system**
   - A typical flow is: **user action in Swing view → controller → DAO → H2 database → controller updates view**.
   - This pattern is repeated across login, inventory, branches, dashboard metrics, and gallery management.
   - The UI does not access the database directly; all persistence goes through the DAO boundary.

9. **Key functional subsystems**
   - **Authentication and session management**: login against the user table with role-based access.
   - **Inventory management**: vehicle CRUD, search, filtering by branch/type/price, and logical deletion.
   - **Branch management**: CRUD for dealership branches.
   - **Gallery management**: vehicle image browsing, upload, primary image selection, and deletion.
   - **Dashboard analytics**: inventory KPIs and vehicle-type distribution summaries.

10. **Role-based access control**
   - The app distinguishes at least two roles: **ADMIN** and **VENDEDOR**.
   - ADMIN users can perform full CRUD operations.
   - VENDEDOR users are restricted mainly to viewing inventory and dashboard-style access, depending on module rules.

11. **File and media handling**
   - Images are copied into `resources/images/` and referenced from the database by path.
   - Gallery behavior is therefore split between **file system storage** and **database metadata**.
   - Inventory export uses CSV generation through standard file writers, making reporting an external file output path.

12. **Error and validation boundary**
   - The project defines custom exceptions for expected failure modes:
     - `AuthFailedException`
     - `InvalidPriceException`
     - `DatabaseException`
   - These indicate clear separation between authentication, domain validation, and persistence failures.

13. **Build and runtime packaging**
   - `compile.sh` / `compile.bat` build the app into `bin/`.
   - `run.sh` / `run.bat` launch the compiled desktop application.
   - The included `MANIFEST.MF` suggests the project can also be packaged as a runnable Java application.

14. **Architectural diagram focus**
   - A correct diagram should show:
     - **Desktop user**
     - **Swing views**
     - **Controllers**
     - **DAO/persistence layer**
     - **H2 in-memory database**
     - **File system for images and CSV export**
     - **`init.sql` as startup initialization**
   - The main boundary is between the **presentation/controller layer** and the **DAO/database + file-system side effects**.

Main entry points: [`src/controller/MainController.java`](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/MainController.java) (MainCtrl), [`src/dao/ImagenDAO.java`](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/ImagenDAO.java) (ImagenDAO), [`src/dao/VehiculoDAO.java`](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/VehiculoDAO.java) (VehiculoDAO), [`src/dao/ConexionDB.java`](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/ConexionDB.java) (ConexionDB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_desktop_user(("Desktop user<br/>actor"))
  node_main_java["Main<br/>entrypoint<br/>[Main.java]"]
  node_login_view["Login<br/>swing view<br/>[LoginView.java]"]
  node_main_view["Main shell<br/>swing view<br/>[MainView.java]"]
  node_inventario_view["Inventario<br/>swing view"]
  node_dashboard_view["Dashboard<br/>swing view<br/>[DashboardView.java]"]
  node_sucursal_view["Sucursal<br/>swing view<br/>[SucursalView.java]"]
  node_galeria_view["Galeria<br/>swing view<br/>[GaleriaView.java]"]
  node_vehiculo_dialog["Agregar vehículo<br/>swing dialog"]
  node_login_controller["LoginCtrl<br/>controller"]
  node_main_controller["MainCtrl<br/>controller"]
  node_inventario_controller["InventarioCtrl<br/>controller"]
  node_dashboard_controller["DashboardCtrl<br/>controller"]
  node_sucursal_controller["SucursalCtrl<br/>controller"]
  node_galeria_controller["GaleriaCtrl<br/>controller"]
end

subgraph group_domain["Domain"]
  node_vehiculo_model{{"Vehiculo<br/>abstract model<br/>[Vehiculo.java]"}}
  node_vehicle_types{{"Vehicle types<br/>model family"}}
  node_sucursal_model{{"Sucursal<br/>model<br/>[Sucursal.java]"}}
  node_usuario_model{{"Usuario<br/>model<br/>[Usuario.java]"}}
  node_imagen_model{{"Imagen<br/>model<br/>[Imagen.java]"}}
end

subgraph group_persistence["Persistence"]
  node_conexion_db[("ConexionDB<br/>db connection<br/>[ConexionDB.java]")]
  node_usuario_dao["UsuarioDAO<br/>[UsuarioDAO.java]"]
  node_vehiculo_dao["VehiculoDAO<br/>[VehiculoDAO.java]"]
  node_sucursal_dao["SucursalDAO<br/>[SucursalDAO.java]"]
  node_imagen_dao["ImagenDAO<br/>[ImagenDAO.java]"]
end

subgraph group_external["External"]
  node_h2_db[("H2 DB<br/>in-memory database<br/>[autoelite.mv.db]")]
  node_init_sql["init.sql<br/>startup seed<br/>[init.sql]"]
  node_images_fs["Image files<br/>filesystem"]
  node_csv_export["CSV export<br/>file output"]
end

node_desktop_user -->|"uses"| node_login_view
node_desktop_user -->|"uses"| node_main_view
node_main_java -->|"starts"| node_login_view
node_main_java -->|"initializes"| node_init_sql
node_login_view -->|"events"| node_login_controller
node_login_controller -->|"auth"| node_usuario_dao
node_usuario_dao -->|"uses"| node_conexion_db
node_conexion_db -->|"connects"| node_h2_db
node_main_view -->|"nav"| node_main_controller
node_main_controller -->|"opens"| node_inventario_view
node_main_controller -->|"opens"| node_dashboard_view
node_main_controller -->|"opens"| node_sucursal_view
node_main_controller -->|"opens"| node_galeria_view
node_inventario_view -->|"events"| node_inventario_controller
node_dashboard_view -->|"events"| node_dashboard_controller
node_sucursal_view -->|"events"| node_sucursal_controller
node_galeria_view -->|"events"| node_galeria_controller
node_vehiculo_dialog -->|"edit"| node_inventario_controller
node_inventario_controller -->|"crud"| node_vehiculo_dao
node_inventario_controller -->|"exports"| node_csv_export
node_dashboard_controller -->|"reads"| node_vehiculo_dao
node_sucursal_controller -->|"crud"| node_sucursal_dao
node_galeria_controller -->|"crud"| node_imagen_dao
node_vehiculo_dao -->|"uses"| node_conexion_db
node_sucursal_dao -->|"uses"| node_conexion_db
node_imagen_dao -->|"uses"| node_conexion_db
node_vehiculo_dao -->|"maps"| node_vehiculo_model
node_vehiculo_model -->|"extends"| node_vehicle_types
node_vehiculo_model -->|"relates"| node_sucursal_model
node_vehiculo_model -->|"relates"| node_imagen_model
node_usuario_dao -->|"maps"| node_usuario_model
node_sucursal_dao -->|"maps"| node_sucursal_model
node_imagen_dao -->|"maps"| node_imagen_model
node_imagen_dao -->|"stores"| node_images_fs
node_vehiculo_dao -->|"reads/writes"| node_h2_db
node_sucursal_dao -->|"reads/writes"| node_h2_db
node_imagen_dao -->|"reads/writes"| node_h2_db

click node_main_java "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/Main.java"
click node_login_view "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/LoginView.java"
click node_main_view "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/MainView.java"
click node_inventario_view "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/InventarioView.java"
click node_dashboard_view "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/DashboardView.java"
click node_sucursal_view "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/SucursalView.java"
click node_galeria_view "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/GaleriaView.java"
click node_vehiculo_dialog "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/AgregarVehiculoDialog.java"
click node_login_controller "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/LoginController.java"
click node_main_controller "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/MainController.java"
click node_inventario_controller "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/InventarioController.java"
click node_dashboard_controller "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/DashboardController.java"
click node_sucursal_controller "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/SucursalController.java"
click node_galeria_controller "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/GaleriaController.java"
click node_vehiculo_model "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/model/Vehiculo.java"
click node_sucursal_model "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/model/Sucursal.java"
click node_usuario_model "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/model/Usuario.java"
click node_imagen_model "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/model/Imagen.java"
click node_conexion_db "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/ConexionDB.java"
click node_usuario_dao "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/UsuarioDAO.java"
click node_vehiculo_dao "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/VehiculoDAO.java"
click node_sucursal_dao "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/SucursalDAO.java"
click node_imagen_dao "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/ImagenDAO.java"
click node_h2_db "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/data/autoelite.mv.db"
click node_init_sql "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/resources/init.sql"
click node_images_fs "https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/tree/main/resources/images"

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_desktop_user,node_main_java,node_login_view,node_main_view,node_inventario_view,node_dashboard_view,node_sucursal_view,node_galeria_view,node_vehiculo_dialog,node_login_controller,node_main_controller,node_inventario_controller,node_dashboard_controller,node_sucursal_controller,node_galeria_controller toneBlue
class node_vehiculo_model,node_vehicle_types,node_sucursal_model,node_usuario_model,node_imagen_model toneAmber
class node_conexion_db,node_usuario_dao,node_vehiculo_dao,node_sucursal_dao,node_imagen_dao toneMint
class node_h2_db,node_init_sql,node_images_fs,node_csv_export toneRose
```

## Components

### Presentation

Swing desktop UI and interaction flow

- **Desktop user**: actor · Person using the Swing application
- [Main](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/Main.java): entrypoint · Application startup and bootstrap · `src/Main.java`
- [Login](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/LoginView.java): swing view · Authentication screen · `src/view/LoginView.java`
- [Main shell](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/MainView.java): swing view · Authenticated container and navigation shell · `src/view/MainView.java`
- [Inventario](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/InventarioView.java): swing view · Vehicle listing and actions · `src/view/InventarioView.java`
- [Dashboard](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/DashboardView.java): swing view · Metrics and summary screen · `src/view/DashboardView.java`
- [Sucursal](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/SucursalView.java): swing view · Branch management screen · `src/view/SucursalView.java`
- [Galeria](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/GaleriaView.java): swing view · Vehicle image gallery screen · `src/view/GaleriaView.java`
- [Agregar vehículo](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/view/AgregarVehiculoDialog.java): swing dialog · Vehicle creation/edit dialog · `src/view/AgregarVehiculoDialog.java`
- [LoginCtrl](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/LoginController.java): controller · Handles authentication and session entry · `src/controller/LoginController.java`
- [MainCtrl](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/MainController.java): controller · Coordinates shell navigation · `src/controller/MainController.java`
- [InventarioCtrl](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/InventarioController.java): controller · Manages inventory CRUD, filters, and export · `src/controller/InventarioController.java`
- [DashboardCtrl](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/DashboardController.java): controller · Builds dashboard metrics · `src/controller/DashboardController.java`
- [SucursalCtrl](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/SucursalController.java): controller · Manages branch operations · `src/controller/SucursalController.java`
- [GaleriaCtrl](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/controller/GaleriaController.java): controller · Manages vehicle images and gallery actions · `src/controller/GaleriaController.java`

### Domain

Business entities and rules

- [Vehiculo](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/model/Vehiculo.java): abstract model · Base vehicle entity and shared rules · `src/model/Vehiculo.java`
- **Vehicle types**: model family · Auto, Motocicleta, and Camion specializations
- [Sucursal](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/model/Sucursal.java): model · Dealership branch entity · `src/model/Sucursal.java`
- [Usuario](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/model/Usuario.java): model · Authenticated user and role entity · `src/model/Usuario.java`
- [Imagen](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/model/Imagen.java): model · Vehicle media metadata · `src/model/Imagen.java`

### Persistence

DAO layer and database access

- [ConexionDB](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/ConexionDB.java): db connection · Central H2 connection manager · `src/dao/ConexionDB.java`
- [UsuarioDAO](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/UsuarioDAO.java): dao · User authentication queries · `src/dao/UsuarioDAO.java`
- [VehiculoDAO](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/VehiculoDAO.java): dao · Vehicle CRUD and listing queries · `src/dao/VehiculoDAO.java`
- [SucursalDAO](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/SucursalDAO.java): dao · Branch CRUD queries · `src/dao/SucursalDAO.java`
- [ImagenDAO](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/src/dao/ImagenDAO.java): dao · Image metadata and gallery queries · `src/dao/ImagenDAO.java`

### External

Database, file system, and startup resources

- [H2 DB](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/data/autoelite.mv.db): in-memory database · Temporary local database state · `data/autoelite.mv.db`
- [init.sql](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/blob/main/resources/init.sql): startup seed · Schema creation and seed data · `resources/init.sql`
- [Image files](https://github.com/emanuelleramirez28-rgb/proyecto-final-grupo/tree/main/resources/images): filesystem · Stored vehicle images under resources/images · `resources/images`
- **CSV export**: file output · Inventory reporting output path

## Connections

- Desktop user → Login: uses · User interacts with the login screen
- Desktop user → Main shell: uses · User works in the authenticated shell
- Main → Login: starts · Application bootstraps the login UI
- Main → init.sql: initializes · Startup schema and seed script are applied
- Login → LoginCtrl: events · Login actions are handled by controller
- LoginCtrl → UsuarioDAO: auth · Authenticates against user records
- UsuarioDAO → ConexionDB: uses · DAO obtains the shared connection
- ConexionDB → H2 DB: connects · Central access to the H2 database
- Main shell → MainCtrl: nav · Shell navigation is coordinated by controller
- MainCtrl → Inventario: opens · Shows inventory module
- MainCtrl → Dashboard: opens · Shows dashboard module
- MainCtrl → Sucursal: opens · Shows branch module
- MainCtrl → Galeria: opens · Shows gallery module
- Inventario → InventarioCtrl: events · Inventory UI actions go through controller
- Dashboard → DashboardCtrl: events · Dashboard requests are handled by controller
- Sucursal → SucursalCtrl: events · Branch UI actions go through controller
- Galeria → GaleriaCtrl: events · Gallery UI actions go through controller
- Agregar vehículo → InventarioCtrl: edit · Vehicle add/edit dialog is managed by inventory flow
- InventarioCtrl → VehiculoDAO: crud · Inventory controller reads and mutates vehicles
- InventarioCtrl → CSV export: exports · Inventory data can be written to CSV
- DashboardCtrl → VehiculoDAO: reads · Dashboard derives metrics from vehicle data
- SucursalCtrl → SucursalDAO: crud · Branch controller manages branches
- GaleriaCtrl → ImagenDAO: crud · Gallery controller manages image metadata
- VehiculoDAO → ConexionDB: uses · Vehicle persistence uses shared connection
- SucursalDAO → ConexionDB: uses · Branch persistence uses shared connection
- ImagenDAO → ConexionDB: uses · Image persistence uses shared connection
- VehiculoDAO → Vehiculo: maps · DAO persists the vehicle hierarchy
- Vehiculo → Vehicle types: extends · Auto, Motocicleta, and Camion specialize the base entity
- Vehiculo → Sucursal: relates · Vehicles are associated with branches
- Vehiculo → Imagen: relates · Vehicles are associated with images
- UsuarioDAO → Usuario: maps · DAO loads authenticated users
- SucursalDAO → Sucursal: maps · DAO loads branch entities
- ImagenDAO → Imagen: maps · DAO loads image metadata
- ImagenDAO → Image files: stores · Image files live on disk and are referenced by path
- VehiculoDAO → H2 DB: reads/writes · Vehicle data is persisted in H2
- SucursalDAO → H2 DB: reads/writes · Branch data is persisted in H2
- ImagenDAO → H2 DB: reads/writes · Image metadata is persisted in H2
