How erikaemi-uni/deporteextrem works
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: index.js routes · AppRouter.jsx AppRouter · authService.js API services · authController.js Auth
Components 25
BACKEND
Express API, domain logic, persistence, and batch tooling.
- server.js · Backend runtime entry point and app bootstrap.
BACKEND/server.js - routes · Main routing layer that exposes the API endpoints.
BACKEND/routes/index.js - Auth · Authentication, JWT login, and identity management.
BACKEND/controllers/authController.js - Users · User, role, and permission management.
BACKEND/controllers/userController.js - Activities · Activity and category management.
BACKEND/controllers/actividadController.js - Reservations · Reservations, dates, and booking flow.
BACKEND/controllers/reservaController.js - Itineraries · Itinerary and step management.
BACKEND/controllers/itinerarioController.js - Medical · Medical record handling for tourists and reservations.
BACKEND/controllers/fichamedicaController.js - Geo Risk · Geospatial boundaries, polygons, and risk mapping.
BACKEND/controllers/geoController.js - Reports · Reports, logs, notifications, and activity reporting.
BACKEND/controllers/reporteController.js - authorize.js · Route protection and role/permission checks.
BACKEND/middlewares/authorize.js - db.js · MongoDB connection and backend persistence setup.
BACKEND/config/db.js - email · Outbound email transport and templates.
BACKEND/config/email.js - scripts · Seeds, imports, migrations, and analytics jobs.
BACKEND/scripts/importGADM.js
FRONTEND
React/Vite SPA with role-based user experiences.
- main.jsx · Frontend bootstrap and app mounting.
FRONTEND/src/main.jsx - AppRouter · Client-side route composition and page selection.
FRONTEND/src/router/AppRouter.jsx - Auth UI · Authentication state, login, and protected routing.
FRONTEND/src/features/auth/AuthContext.jsx - Public UI · Landing, map exploration, details, and reservations.
FRONTEND/src/features/section1/Section1.jsx - Turista · Tourist self-service panels for bookings and medical data.
FRONTEND/src/Components/Turista/PanelTurista.jsx - Operaciones · Operational workflows for validation and pre/post activity control.
FRONTEND/src/Components/Operaciones/PanelOperaciones.jsx - Administrador · Administrative management for users, reports, media, and settings.
FRONTEND/src/features/admin/AdminPage.jsx - API services · Frontend service layer used to call backend endpoints.
FRONTEND/src/services/authService.js
Storage & Data
Databases, uploaded assets, and imported geographic datasets.
- MongoDB · System of record for users, activities, reservations, itineraries, reports, and geo entities.
- uploads · Local binary asset storage for medical PDFs, 3D models, and multimedia.
BACKEND/uploads - GADM data · Imported geographic boundary datasets used by geo processing.
BACKEND/data/gadm/gadm41_BOL_0.json
Connections 36
- 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.