How carlosdb25/bookgym works
1. Top-level shape
- The repository is a two-tier application: a Node.js/Express backend and a React/Vite frontend.
- All business rules live in the backend; the frontend is a thin consumer of REST endpoints.
- Persistence is centralized in PostgreSQL via Prisma.
2. Backend runtime boundary
- backend/src/server.js is the process entrypoint.
- backend/src/app.js assembles the Express app, mounts routes, middleware, and Swagger docs.
- Shared infrastructure lives under backend/src/shared, including config, Prisma client, and request guards.
3. Data layer and schema management
- Prisma is the sole data access layer (backend/prisma/schema.prisma, migrations, seed script).
- The database is not just storage for bookings; it also holds operational rules in the configuracion table.
- This makes reservation behavior configurable without changing the frontend.
4. Auth and access control
- The backend has a dedicated auth module for login and token issuance.
- auth.middleware.js enforces authenticated access, and roles.middleware.js separates student vs. admin capabilities.
- Role checks are a hard boundary: admin-only endpoints are not just hidden in the UI, they are enforced server-side.
5. Core booking domain
- franjas exposes the gym’s schedule/capacity view.
- reservas is the transaction-critical module that creates, cancels, and lists reservations.
- The key architectural point is that reservation creation must be atomic to prevent overbooking.
6. Business rules as backend configuration
- Reservation constraints are read from runtime configuration keys such as:
- limite_reservas_activas
- max_reservas_por_dia
- anticipacion_reserva_min
- anticipacion_cancelacion_min
- These rules are part of the backend’s decision flow, not client-side validation.
- The UI can display them, but the backend is the source of truth.
7. Admin analytics and operational views
- metricas provides aggregated weekly summaries for administrators.
- These metrics are derived from reservation and schedule data, with cancelled or non-active slots excluded as described in the README.
- configuracion likely acts as the admin-facing surface for inspecting or adjusting rule parameters.
8. Background processing
- backend/src/scheduler/noshow.scheduler.js indicates a periodic background job inside the API service.
- This scheduler is the non-request path in the architecture, used for time-based state changes such as no-show handling or closing past reservations.
- It is part of the backend process rather than a separate worker service.
9. Frontend structure
- The frontend is a single-page app built with React + Vite.
- Pages are split by user intent: Login, Disponibilidad, MisReservas, and AdminDashboard.
- Shared UI components (FranjaCard, ReservaItem, SaturacionBadge, ActionModal, Toast) encapsulate booking and feedback interactions.
10. Frontend data access pattern
- API calls are centralized in frontend/src/api/client.js.
- Feature hooks (useAuth, useFranjas, useReservas, useMetricas, useReglasReserva) isolate server interaction from components.
- TanStack Query is used for fetching/cache synchronization, so the UI is reactive to backend state rather than maintaining its own source of truth.
11. End-to-end student flow
- Student logs in through /api/auth/login.
- Frontend fetches weekly availability from /api/franjas/semana.
- User confirms a reservation in a modal; backend checks active limits, daily limits, time windows, suspension status, and available capacity.
- If valid, the reservation is committed atomically and then appears in “Mis reservas”.
12. End-to-end admin flow
- Admin logs in through the same auth path but receives admin-scoped access.
- The dashboard reads weekly metrics and schedule saturation from backend endpoints.
- Admin views are read-oriented: they observe occupancy and summary data, while the backend still enforces all operational rules.
13. API documentation and operational endpoints
- Swagger/OpenAPI is integrated directly into the backend, not as a separate service.
- The docs are mounted from backend/src/docs/swagger.js and exposed under /api/docs and /api/docs.json.
- A /health endpoint exists for basic service monitoring.
14. Deployment boundaries
- The repo is structured for separate deployment of backend and frontend, each with its own environment variables.
- Backend needs DATABASE_URL, JWT_SECRET, and PORT; frontend needs VITE_API_URL.
- Railway deployment is supported as two services: one API service rooted at backend/, and one web service rooted at frontend/.
Main entry points: app.js App · prisma/client.js Prisma · api/client.js API client · reservas.service.js Reservas
Components 21
Backend
Node/Express API, business rules, and persistence
- Server · Boots the API process
backend/src/server.js - App · Assembles middleware, routes, and docs
backend/src/app.js - Config · Loads runtime settings and environment variables
backend/src/shared/config/index.js - Prisma · Shared Prisma client used by backend modules
backend/src/shared/prisma/client.js - Auth · Login and token issuance
backend/src/modules/auth/auth.service.js - Auth guard · Enforces authenticated access
backend/src/shared/middlewares/auth.middleware.js - Roles guard · Separates student and admin access
backend/src/shared/middlewares/roles.middleware.js - Franjas · Weekly schedule and capacity view
backend/src/modules/franjas/franjas.service.js - Reservas · Create, cancel, and list bookings atomically
backend/src/modules/reservas/reservas.service.js - Configuración · Operational booking rules and admin-facing settings
backend/src/modules/configuracion/configuracion.service.js - Métricas · Weekly admin summaries and occupancy aggregates
backend/src/modules/metricas/metricas.service.js - No-show job · Periodic time-based reservation handling
backend/src/scheduler/noshow.scheduler.js - Swagger · OpenAPI docs mounted in the API
backend/src/docs/swagger.js
Frontend
React/Vite SPA consuming the API
- SPA · Vite entry and application shell
frontend/src/main.jsx - API client · Centralized backend request layer
frontend/src/api/client.js - Hooks · Query hooks for auth, franjas, reservas, métricas, and rules
frontend/src/hooks/useReservas.js - Pages · Login, availability, reservations, and admin dashboard screens
frontend/src/pages/Login.jsx - Components · Shared booking and feedback widgets
frontend/src/components/ActionModal.jsx
Data
Prisma schema, migrations, and seed data
- Schema · Database models and relations
backend/prisma/schema.prisma - Migrations · Applied database change history
backend/prisma/migrations/20260325043000_init/migration.sql - Seed · Initial data population script
backend/prisma/seed.js
Connections 30
- Server → App: starts · Process entrypoint boots the Express app
- App → Auth guard: uses · Request authentication is applied in the app
- App → Roles guard: uses · Role checks protect admin and student paths
- App → Auth: mounts · Auth routes are attached to the API
- App → Franjas: mounts · Schedule and capacity endpoints
- App → Reservas: mounts · Reservation endpoints
- App → Configuración: mounts · Operational rule endpoints
- App → Métricas: mounts · Admin metrics endpoints
- App → Swagger: exposes · API documentation and spec
- App → No-show job: starts · Background job runs inside the API process
- Auth → Prisma: reads/writes · User lookup and token-related persistence
- Franjas → Prisma: reads · Builds availability from booking data
- Reservas → Prisma: transactions · Atomic reservation create/cancel/list operations
- Reservas → Config: enforces · Uses runtime booking constraints from config
- Configuración → Prisma: reads/writes · Persists operational rule parameters
- Métricas → Prisma: aggregates · Derives weekly summaries from reservation data
- No-show job → Prisma: updates · Time-based state changes and no-show handling
- Prisma → Schema: generated from · Client is based on the Prisma schema
- Schema → Migrations: evolves via · Schema changes are applied through migrations
- Seed → Prisma: initializes · Seeds baseline database data
- SPA → API client: calls · UI reads and mutates state through a central client
- SPA → Hooks: uses · Hooks isolate server interaction from components
- SPA → Pages: renders · Page-level views compose the experience
- Pages → Components: composes · Screens reuse booking and feedback widgets
- Hooks → API client: wraps · Hooks are built on the shared client layer
- API client → Auth: authenticates with · Login and token issuance flow
- API client → Franjas: fetches · Weekly availability and saturation data
- API client → Reservas: fetches/mutates · Student booking lifecycle
- API client → Métricas: fetches · Admin weekly summaries
- API client → Configuración: fetches · Reservation rules exposed to the UI