# erikaemi-uni/deporteextrem architecture

> Architecture diagram of the GitHub repository erikaemi-uni/deporteextrem, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/erikaemi-uni/deporteextrem
- Repository: https://github.com/erikaemi-uni/deporteextrem

## Overview

1. **Top-level shape**
   - The repository is a two-tier application: a **Node.js/Express backend** in `BACKEND/` and a **React/Vite frontend** in `FRONTEND/`.
   - The backend exposes the API and owns persistence, file storage, auth, and geospatial processing.
   - The frontend is a role-aware UI for tourists, operators, and administrators.

2. **Backend entry and API boundary**
   - `BACKEND/server.js` is the runtime entry point; `routes/index.js` and the route files under `routes/` define the HTTP surface.
   - Controllers implement the request/response logic, while models encapsulate MongoDB collections via Mongoose.
   - This is a classic layered API boundary: **route → controller → model/database**.

3. **Core domain subsystems**
   - The main business areas are split by controller/model pairs:
     - **Users / auth / roles / permissions**: `authController`, `userController`, `roleController`, `permissionController`
     - **Activities and categories**: `actividadController`, `categoriaController`, plus `models/Actividad.js` and `Categoria.js`
     - **Reservations and schedules**: `reservaController`, `fechaController`
     - **Itineraries**: `itinerarioController`, `pasoItinerarioController`
     - **Medical records**: `fichamedicaController`
     - **Geo/risk mapping**: `geoController`, `poligonoController`, `GeoBoundary`, `PoligonoRiesgo`
     - **Reports, logs, and notifications**: `reporteController`, `reporteActividadController`, `historialController`, `notificationController`

4. **Security and authorization**
   - Authentication appears to be **JWT-based** with password hashing via bcrypt, managed through the auth controllers and `middlewares/authorize.js`.
   - Authorization is role/permission driven, not just simple login state; the `Role` and `Permission` models suggest route-level access control.
   - The backend therefore has a distinct **identity/security subsystem** that gates admin and operator operations.

5. **File and media handling**
   - The backend stores uploaded content under `uploads/`, including:
     - medical PDFs in `uploads/fichas_medicas`
     - 3D models in `uploads/modelos3d`
     - multimedia in `uploads/multimedia`
   - This indicates the API handles both metadata in MongoDB and binary assets on disk, with controllers likely persisting file references in documents.
   - `multer`-style upload handling is a key architectural boundary between API requests and persistent media storage.

6. **Geospatial and map data flow**
   - Geo features are a first-class part of the system: Turf.js is mentioned in the README, and the repo includes GADM boundary datasets in `data/gadm/`.
   - `geoController`, `poligonoController`, and models like `GeoBoundary` and `PoligonoRiesgo` support map-based risk areas and region boundaries.
   - The backend also includes scripts like `importGADM.js` and `actualizarCoordenadas.js`, showing a data pipeline for ingesting and maintaining geographic datasets.

7. **Operational data and batch tooling**
   - The `scripts/` folder contains seeds, migrations, and maintenance jobs such as:
     - creating users and activities
     - seeding categories and permissions
     - importing geographic boundaries
     - Mongo MapReduce for reservation/risk analysis
   - These scripts are separate from the runtime API and exist as offline operational tooling for initialization, migration, and analytics preparation.

8. **Email and notification subsystem**
   - `config/email.js` and `emailTemplates.js` show a dedicated outbound email capability, likely for account, reservation, or status notifications.
   - `Notification` model and `notificationController` suggest in-app notifications are also persisted.
   - This creates a secondary communication path beyond the main API response cycle: backend event/action → email/notification.

9. **Frontend application structure**
   - The frontend is a React SPA with routing, auth context, and protected routes.
   - The codebase has both older top-level `Components/` folders and a more structured `features/` layout; the latter is where the more domain-oriented UI lives.
   - Entry and routing are split across `src/main.jsx`, `src/app/App.jsx`, and router modules, with context providers handling authentication state.

10. **Role-based UI partitions**
    - The UI is segmented into distinct experiences:
      - **Public/home**: landing content, map, activity browsing, details, and reservations
      - **Turista**: booking, medical form, activity status, personal panel
      - **Operaciones**: validation, pre-salida, itinerary control, post-activity reporting
      - **Administrador**: dashboards, users, roles, reports, multimedia, risk polygons, dates, and activity management
    - This mirrors the backend’s authorization model and makes role-based diagramming straightforward.

11. **Frontend data flow to backend**
    - Frontend services in `src/services/` and feature-specific services/hooks call the API over HTTP, likely using Axios as described in the README.
    - `AuthContext` and `ProtectedRoute` enforce client-side access control, while the backend remains the authoritative gate.
    - In the diagram, the frontend should be shown as consuming the backend API rather than owning business state locally.

12. **Stateful UI features and external libraries**
    - The frontend uses map and visualization tooling such as **Leaflet** and **Chart.js**, plus animation support via **Framer Motion**.
    - These libraries materially affect the architecture because they define major UI concerns: map rendering, dashboards, and interactive modals.
    - The public “section1” feature is especially map-centric and tied to geospatial activity exploration.

13. **Data persistence boundaries**
    - MongoDB is the system of record for users, activities, reservations, itineraries, reports, permissions, and geo entities.
    - File system storage is used for uploaded assets, while JSON/seed data exists for import and initialization.
    - So the backend has two persistence planes: **document storage in MongoDB** and **binary/static asset storage on disk**.

14. **What to emphasize in an architecture diagram**
    - Show the frontend as a role-based SPA with public and protected panels.
    - Show the backend as a modular Express API split by domain controllers/routes.
    - Highlight the shared cross-cutting services: auth, authorization, uploads, email, geospatial processing, and batch scripts.
    - Draw separate storage nodes for MongoDB, local uploads, and imported geo datasets, because those are distinct operational dependencies.

Main entry points: [`BACKEND/routes/index.js`](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/routes/index.js) (routes), [`FRONTEND/src/router/AppRouter.jsx`](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/router/AppRouter.jsx) (AppRouter), [`FRONTEND/src/services/authService.js`](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/services/authService.js) (API services), [`BACKEND/controllers/authController.js`](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/authController.js) (Auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["BACKEND"]
  node_backend_server["server.js<br/>api entry<br/>[server.js]"]
  node_backend_routes["routes<br/>http surface<br/>[index.js]"]
  node_backend_auth["Auth<br/>security<br/>[authController.js]"]
  node_backend_users["Users<br/>domain controllers<br/>[userController.js]"]
  node_backend_activity["Activities<br/>domain controllers"]
  node_backend_booking["Reservations<br/>domain controllers"]
  node_backend_itineraries["Itineraries<br/>domain controllers"]
  node_backend_health["Medical<br/>domain controllers"]
  node_backend_geo["Geo Risk<br/>geo controllers<br/>[geoController.js]"]
  node_backend_ops["Reports<br/>ops controllers"]
  node_backend_middleware["authorize.js<br/>middleware<br/>[authorize.js]"]
  node_backend_db[("db.js<br/>database config<br/>[db.js]")]
  node_backend_email["email<br/>messaging config<br/>[email.js]"]
  node_backend_scripts["scripts<br/>batch tooling<br/>[importGADM.js]"]
end

subgraph group_frontend["FRONTEND"]
  node_frontend_main["main.jsx<br/>spa entry<br/>[main.jsx]"]
  node_frontend_router["AppRouter<br/>routing<br/>[AppRouter.jsx]"]
  node_frontend_auth["Auth UI<br/>auth context<br/>[AuthContext.jsx]"]
  node_frontend_public["Public UI<br/>public experience<br/>[Section1.jsx]"]
  node_frontend_turista["Turista<br/>role panel<br/>[PanelTurista.jsx]"]
  node_frontend_ops["Operaciones<br/>role panel"]
  node_frontend_admin["Administrador<br/>role panel<br/>[AdminPage.jsx]"]
  node_frontend_services["API services<br/>http clients<br/>[authService.js]"]
end

subgraph group_storage["Storage & Data"]
  node_storage_mongo[("MongoDB<br/>document store")]
  node_storage_uploads[("uploads<br/>file storage")]
  node_storage_gadm["GADM data<br/>geo dataset<br/>[gadm41_BOL_0.json]"]
end

node_backend_server -->|"mounts"| node_backend_routes
node_backend_routes -->|"dispatches"| node_backend_auth
node_backend_routes -->|"dispatches"| node_backend_users
node_backend_routes -->|"dispatches"| node_backend_activity
node_backend_routes -->|"dispatches"| node_backend_booking
node_backend_routes -->|"dispatches"| node_backend_itineraries
node_backend_routes -->|"dispatches"| node_backend_health
node_backend_routes -->|"dispatches"| node_backend_geo
node_backend_routes -->|"dispatches"| node_backend_ops
node_backend_auth -->|"guards"| node_backend_middleware
node_backend_users -->|"guards"| node_backend_middleware
node_backend_activity -->|"guards"| node_backend_middleware
node_backend_booking -->|"guards"| node_backend_middleware
node_backend_server -->|"connects"| node_backend_db
node_backend_auth -->|"reads/writes"| node_storage_mongo
node_backend_users -->|"reads/writes"| node_storage_mongo
node_backend_activity -->|"reads/writes"| node_storage_mongo
node_backend_booking -->|"reads/writes"| node_storage_mongo
node_backend_itineraries -->|"reads/writes"| node_storage_mongo
node_backend_health -->|"stores files"| node_storage_uploads
node_backend_ops -->|"sends"| node_backend_email
node_backend_geo -->|"imports"| node_storage_gadm
node_backend_scripts -->|"ingests"| node_storage_gadm
node_backend_scripts -->|"migrates"| node_storage_mongo
node_frontend_main -->|"boots"| node_frontend_router
node_frontend_router -->|"wraps"| node_frontend_auth
node_frontend_router -->|"shows"| node_frontend_public
node_frontend_router -->|"shows"| node_frontend_turista
node_frontend_router -->|"shows"| node_frontend_ops
node_frontend_router -->|"shows"| node_frontend_admin
node_frontend_public -->|"fetches"| node_frontend_services
node_frontend_turista -->|"fetches"| node_frontend_services
node_frontend_ops -->|"fetches"| node_frontend_services
node_frontend_admin -->|"fetches"| node_frontend_services
node_frontend_services -->|"calls API"| node_backend_routes
node_frontend_auth -->|"authenticates"| node_backend_auth

click node_backend_server "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/server.js"
click node_backend_routes "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/routes/index.js"
click node_backend_auth "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/authController.js"
click node_backend_users "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/userController.js"
click node_backend_activity "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/actividadController.js"
click node_backend_booking "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/reservaController.js"
click node_backend_itineraries "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/itinerarioController.js"
click node_backend_health "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/fichamedicaController.js"
click node_backend_geo "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/geoController.js"
click node_backend_ops "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/reporteController.js"
click node_backend_middleware "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/middlewares/authorize.js"
click node_backend_db "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/config/db.js"
click node_backend_email "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/config/email.js"
click node_backend_scripts "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/scripts/importGADM.js"
click node_frontend_main "https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/main.jsx"
click node_frontend_router "https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/router/AppRouter.jsx"
click node_frontend_auth "https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/features/auth/AuthContext.jsx"
click node_frontend_public "https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/features/section1/Section1.jsx"
click node_frontend_turista "https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/Components/Turista/PanelTurista.jsx"
click node_frontend_ops "https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/Components/Operaciones/PanelOperaciones.jsx"
click node_frontend_admin "https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/features/admin/AdminPage.jsx"
click node_frontend_services "https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/services/authService.js"
click node_storage_uploads "https://github.com/erikaemi-uni/deporteextrem/tree/main/BACKEND/uploads"
click node_storage_gadm "https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/data/gadm/gadm41_BOL_0.json"

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_backend_server,node_backend_routes,node_backend_auth,node_backend_users,node_backend_activity,node_backend_booking,node_backend_itineraries,node_backend_health,node_backend_geo,node_backend_ops,node_backend_middleware,node_backend_db,node_backend_email,node_backend_scripts toneBlue
class node_frontend_main,node_frontend_router,node_frontend_auth,node_frontend_public,node_frontend_turista,node_frontend_ops,node_frontend_admin,node_frontend_services toneAmber
class node_storage_mongo,node_storage_uploads,node_storage_gadm toneMint
```

## Components

### BACKEND

Express API, domain logic, persistence, and batch tooling.

- [server.js](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/server.js): api entry · Backend runtime entry point and app bootstrap. · `BACKEND/server.js`
- [routes](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/routes/index.js): http surface · Main routing layer that exposes the API endpoints. · `BACKEND/routes/index.js`
- [Auth](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/authController.js): security · Authentication, JWT login, and identity management. · `BACKEND/controllers/authController.js`
- [Users](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/userController.js): domain controllers · User, role, and permission management. · `BACKEND/controllers/userController.js`
- [Activities](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/actividadController.js): domain controllers · Activity and category management. · `BACKEND/controllers/actividadController.js`
- [Reservations](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/reservaController.js): domain controllers · Reservations, dates, and booking flow. · `BACKEND/controllers/reservaController.js`
- [Itineraries](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/itinerarioController.js): domain controllers · Itinerary and step management. · `BACKEND/controllers/itinerarioController.js`
- [Medical](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/fichamedicaController.js): domain controllers · Medical record handling for tourists and reservations. · `BACKEND/controllers/fichamedicaController.js`
- [Geo Risk](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/geoController.js): geo controllers · Geospatial boundaries, polygons, and risk mapping. · `BACKEND/controllers/geoController.js`
- [Reports](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/controllers/reporteController.js): ops controllers · Reports, logs, notifications, and activity reporting. · `BACKEND/controllers/reporteController.js`
- [authorize.js](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/middlewares/authorize.js): middleware · Route protection and role/permission checks. · `BACKEND/middlewares/authorize.js`
- [db.js](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/config/db.js): database config · MongoDB connection and backend persistence setup. · `BACKEND/config/db.js`
- [email](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/config/email.js): messaging config · Outbound email transport and templates. · `BACKEND/config/email.js`
- [scripts](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/scripts/importGADM.js): batch tooling · Seeds, imports, migrations, and analytics jobs. · `BACKEND/scripts/importGADM.js`

### FRONTEND

React/Vite SPA with role-based user experiences.

- [main.jsx](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/main.jsx): spa entry · Frontend bootstrap and app mounting. · `FRONTEND/src/main.jsx`
- [AppRouter](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/router/AppRouter.jsx): routing · Client-side route composition and page selection. · `FRONTEND/src/router/AppRouter.jsx`
- [Auth UI](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/features/auth/AuthContext.jsx): auth context · Authentication state, login, and protected routing. · `FRONTEND/src/features/auth/AuthContext.jsx`
- [Public UI](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/features/section1/Section1.jsx): public experience · Landing, map exploration, details, and reservations. · `FRONTEND/src/features/section1/Section1.jsx`
- [Turista](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/Components/Turista/PanelTurista.jsx): role panel · Tourist self-service panels for bookings and medical data. · `FRONTEND/src/Components/Turista/PanelTurista.jsx`
- [Operaciones](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/Components/Operaciones/PanelOperaciones.jsx): role panel · Operational workflows for validation and pre/post activity control. · `FRONTEND/src/Components/Operaciones/PanelOperaciones.jsx`
- [Administrador](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/features/admin/AdminPage.jsx): role panel · Administrative management for users, reports, media, and settings. · `FRONTEND/src/features/admin/AdminPage.jsx`
- [API services](https://github.com/erikaemi-uni/deporteextrem/blob/main/FRONTEND/src/services/authService.js): http clients · Frontend service layer used to call backend endpoints. · `FRONTEND/src/services/authService.js`

### Storage & Data

Databases, uploaded assets, and imported geographic datasets.

- **MongoDB**: document store · System of record for users, activities, reservations, itineraries, reports, and geo entities.
- [uploads](https://github.com/erikaemi-uni/deporteextrem/tree/main/BACKEND/uploads): file storage · Local binary asset storage for medical PDFs, 3D models, and multimedia. · `BACKEND/uploads`
- [GADM data](https://github.com/erikaemi-uni/deporteextrem/blob/main/BACKEND/data/gadm/gadm41_BOL_0.json): geo dataset · Imported geographic boundary datasets used by geo processing. · `BACKEND/data/gadm/gadm41_BOL_0.json`

## Connections

- server.js → routes: mounts · Bootstraps and registers the HTTP routes.
- routes → Auth: dispatches · Routes auth requests to the auth controller.
- routes → Users: dispatches · Routes user, role, and permission requests.
- routes → Activities: dispatches · Routes activity and category requests.
- routes → Reservations: dispatches · Routes reservation and date requests.
- routes → Itineraries: dispatches · Routes itinerary requests.
- routes → Medical: dispatches · Routes medical form and record requests.
- routes → Geo Risk: dispatches · Routes geo and polygon requests.
- routes → Reports: dispatches · Routes reports, logs, and notifications.
- Auth → authorize.js: guards · Authentication and authorization are enforced by middleware.
- Users → authorize.js: guards · Role and permission operations are protected.
- Activities → authorize.js: guards · Admin/operator mutations are permissioned.
- Reservations → authorize.js: guards · Booking and control endpoints are access-controlled.
- server.js → db.js: connects · Initializes MongoDB connectivity.
- Auth → MongoDB: reads/writes · Persists users and auth state in MongoDB.
- Users → MongoDB: reads/writes · Persists roles, permissions, and users.
- Activities → MongoDB: reads/writes · Persists activities and categories.
- Reservations → MongoDB: reads/writes · Persists reservations and dates.
- Itineraries → MongoDB: reads/writes · Persists itineraries and steps.
- Medical → uploads: stores files · Stores generated or uploaded medical PDFs on disk.
- Reports → email: sends · Triggers outbound email and notification content.
- Geo Risk → GADM data: imports · Uses imported geographic boundary datasets.
- scripts → GADM data: ingests · Batch jobs import and update geographic data.
- scripts → MongoDB: migrates · Seeds and maintenance scripts update MongoDB collections.
- main.jsx → AppRouter: boots · App entry hands off to routing.
- AppRouter → Auth UI: wraps · Routing is coordinated with auth state and protected routes.
- AppRouter → Public UI: shows · Public browsing and map exploration experience.
- AppRouter → Turista: shows · Tourist role panel.
- AppRouter → Operaciones: shows · Operations role panel.
- AppRouter → Administrador: shows · Administrator role panel.
- Public UI → API services: fetches · Public UI loads data from the API via services.
- Turista → API services: fetches · Tourist workflows use the shared API client layer.
- Operaciones → API services: fetches · Operations workflows use backend services.
- Administrador → API services: fetches · Admin screens call backend endpoints through services.
- API services → routes: calls API · Frontend talks to the backend HTTP surface.
- Auth UI → Auth: authenticates · Client auth flows rely on backend login and session handling.
