# pablocizq/laboratorioingweb architecture

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

- Interactive diagram: https://gitdiagram.com/pablocizq/laboratorioingweb
- Repository: https://github.com/pablocizq/laboratorioingweb

## Overview

1. **Overall shape**
This repository is a two-process backend: a **gateway** service at the edge and an **app-server** that owns the core business logic. The code is organized around a layered architecture on the app-server side, with a thin API/auth layer in the gateway and an internal **message/RPC-based integration** between them.

2. **Gateway as the public entrypoint**
`backend/gateway` exposes the external HTTP API. Its responsibilities are routing, request validation, authentication, and translating HTTP calls into internal RPC requests. It does not appear to own business rules or persistence; instead it forwards work to the app-server.

3. **App-server as the domain owner**
`backend/app-server` contains the core booking system. It implements use cases such as creating reservations, consulting reservations, login, listing spaces, and modifying spaces. This service also owns database access and the server-side message consumer that answers RPC calls from the gateway.

4. **Layered internal structure in app-server**
The app-server is split into:
- **application**: use-case modules like `crear-reserva`, `cancelar-reserva`, `iniciar-sesion`, `obtener-espacios`
- **domain**: entities, value objects, policies, domain services, and domain errors
- **infrastructure**: SQL repositories, database bootstrapping/seeders, and messaging plumbing  
This indicates a classic dependency direction: use cases depend on domain abstractions, while infrastructure provides concrete implementations.

5. **Domain model and business boundaries**
The domain centers on three main entities: **Usuario**, **Espacio**, and **Reserva**. Supporting types include `CategoriaEspacio` and `IntervaloReserva`, plus a conflict detector (`DetectorConflictosHorario`) and a permissions policy (`PoliticaPermisosReserva`). Those pieces suggest the main business constraints are reservation eligibility, time-window validation, and conflict checking.

6. **Persistence boundary**
App-server defines repository interfaces in `domain/repositories` and SQL implementations in `infrastructure/repositories`. Concrete classes like `RepositorioEspaciosSQL`, `RepositorioReservasSQL`, and `RepositorioUsuariosSQL` imply the system persists to a relational database. The `infrastructure/database` folder and seeders show the DB can be initialized with sample spaces, users, and past reservations.

7. **Messaging boundary and internal RPC**
Both services include a `messaging` folder with broker connection code, and the app-server has `rpc-server.js` while the gateway has `rpc-client.js`. That means the gateway likely sends RPC-style requests over a broker (commonly RabbitMQ, though the repo name alone doesn’t confirm the broker type), and the app-server acts as the responder. This is the key integration boundary between HTTP ingress and domain execution.

8. **HTTP/API surface in the gateway**
The gateway is organized by feature area with `auth`, `espacios`, and `reservas` controllers and routes. The routes are guarded by middleware such as `autenticar` and `validar-payload`, so authentication and request-shape validation happen before the request is translated into internal service calls.

9. **Authentication and token flow**
`gateway/src/services/token.service.js` and `config/jwt.config.js` indicate JWT-based auth. The `auth.controller.js` and `iniciar-sesion` use case together suggest the login flow is handled through the gateway API, with token issuance/verification at the edge before protected reservation endpoints are allowed through.

10. **Data flow for a typical request**
A client request enters the gateway via HTTP, passes middleware validation/authentication, is mapped by a controller to an RPC call, and is sent through the broker to the app-server. The app-server’s RPC server invokes the relevant application use case, which enforces domain rules and calls a repository. The result returns back through RPC to the gateway and then to the client.

11. **Reservation-specific business flow**
Reservation creation likely follows a stricter path than simple reads: validate payload in gateway, execute `crear-reserva` in app-server, check policy and schedule conflicts through domain services, then persist the reservation via the SQL repository. The presence of “consultar reservas vivas”, “mis reservas”, and “cancelar reserva” suggests separate read/write use cases rather than a generic CRUD model.

12. **Deployment and runtime**
Both services have their own `package.json` and `Dockerfile`, and there is a top-level `backend/docker-compose.yml`. That points to containerized deployment with at least the gateway, app-server, and a message broker/database stack coordinated by Compose. The main runtime is Node.js.

13. **What to show in an architecture diagram**
A good diagram should emphasize these boundaries:
- external clients calling the **gateway**
- the gateway handling **JWT auth, validation, and routing**
- the **broker/RPC channel** between gateway and app-server
- the app-server’s split into **application/domain/infrastructure**
- the **SQL database** behind repository implementations
- the **seeders** as initialization data, not runtime logic

14. **Notable design characteristic**
This is not a monolithic Express app. It’s a deliberately separated backend where the gateway is a thin edge layer and the app-server is the system of record for business rules and persistence. The strongest architectural signal is the combination of **DDD-style layering** inside app-server and **messaging-based service boundary** between gateway and core logic.

Main entry points: [`backend/gateway/src/routes`](https://github.com/pablocizq/laboratorioingweb/tree/main/backend/gateway/src/routes) (Routes), [`backend/gateway/src/messaging/rpc-client.js`](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/messaging/rpc-client.js) (RPC Client), [`backend/gateway/src/controllers/auth.controller.js`](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/controllers/auth.controller.js) (Auth), [`backend/app-server/src/application`](https://github.com/pablocizq/laboratorioingweb/tree/main/backend/app-server/src/application) (Use Cases)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway"]
  node_gateway_server["Gateway API<br/>http edge<br/>[server.js]"]
  node_gateway_routes["Routes<br/>http routing"]
  node_gateway_auth["Auth<br/>controller<br/>[auth.controller.js]"]
  node_gateway_reservas["Reservas<br/>controller"]
  node_gateway_espacios["Espacios<br/>controller"]
  node_gateway_mw["Middlewares<br/>request guards"]
  node_gateway_token["Tokens<br/>jwt service<br/>[token.service.js]"]
  node_gateway_rpc["RPC Client<br/>broker client<br/>[rpc-client.js]"]
end

subgraph group_app_server["App Server"]
  node_app_main["App Server<br/>service host<br/>[main.js]"]
  node_app_rpc["RPC Server<br/>broker consumer<br/>[rpc-server.js]"]
  node_app_usecases["Use Cases<br/>application layer"]
  node_app_domain["Domain Model<br/>domain layer"]
  node_app_policies["Policies<br/>business rules"]
  node_app_repos["Repositories<br/>persistence ports"]
  node_app_db[("Database<br/>sql storage<br/>[index.js]")]
  node_app_seeders["Seed Data<br/>initial data"]
end

node_external_client(("Client<br/>external actor"))
node_broker["Broker<br/>message bus"]

node_external_client -->|"HTTP requests"| node_gateway_server
node_gateway_server -->|"mounts"| node_gateway_routes
node_gateway_routes -->|"guards"| node_gateway_mw
node_gateway_routes -->|"dispatches"| node_gateway_auth
node_gateway_routes -->|"dispatches"| node_gateway_reservas
node_gateway_routes -->|"dispatches"| node_gateway_espacios
node_gateway_auth -->|"issues/reads"| node_gateway_token
node_gateway_auth -->|"login RPC"| node_gateway_rpc
node_gateway_reservas -->|"reservation RPC"| node_gateway_rpc
node_gateway_espacios -->|"space RPC"| node_gateway_rpc
node_gateway_rpc -->|"publish"| node_broker
node_broker -->|"deliver"| node_app_rpc
node_app_rpc -->|"invoke"| node_app_usecases
node_app_usecases -->|"depends on"| node_app_domain
node_app_domain -->|"uses"| node_app_policies
node_app_usecases -->|"reads/writes"| node_app_repos
node_app_repos -->|"persists"| node_app_db
node_app_db -.->|"initializes"| node_app_seeders
node_app_main -->|"starts"| node_app_rpc

click node_gateway_server "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/server.js"
click node_gateway_routes "https://github.com/pablocizq/laboratorioingweb/tree/main/backend/gateway/src/routes"
click node_gateway_auth "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/controllers/auth.controller.js"
click node_gateway_reservas "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/controllers/reservas.controller.js"
click node_gateway_espacios "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/controllers/espacios.controller.js"
click node_gateway_mw "https://github.com/pablocizq/laboratorioingweb/tree/main/backend/gateway/src/middlewares"
click node_gateway_token "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/services/token.service.js"
click node_gateway_rpc "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/messaging/rpc-client.js"
click node_app_main "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/app-server/src/main.js"
click node_app_rpc "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/app-server/src/messaging/rpc-server.js"
click node_app_usecases "https://github.com/pablocizq/laboratorioingweb/tree/main/backend/app-server/src/application"
click node_app_domain "https://github.com/pablocizq/laboratorioingweb/tree/main/backend/app-server/src/domain"
click node_app_policies "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/app-server/src/domain/policies/PoliticaPermisosReserva.js"
click node_app_repos "https://github.com/pablocizq/laboratorioingweb/tree/main/backend/app-server/src/domain/repositories"
click node_app_db "https://github.com/pablocizq/laboratorioingweb/blob/main/backend/app-server/src/infrastructure/database/index.js"
click node_app_seeders "https://github.com/pablocizq/laboratorioingweb/tree/main/backend/app-server/src/infrastructure/database/seeders"

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_gateway_server,node_gateway_routes,node_gateway_auth,node_gateway_reservas,node_gateway_espacios,node_gateway_mw,node_gateway_token,node_gateway_rpc toneBlue
class node_app_main,node_app_rpc,node_app_usecases,node_app_domain,node_app_policies,node_app_repos,node_app_db,node_app_seeders toneAmber
class node_external_client,node_broker toneNeutral
```

## Components

### Gateway

Public HTTP edge and request translation layer

- [Gateway API](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/server.js): http edge · Public entrypoint that routes requests and mediates auth/validation · `backend/gateway/src/server.js`
- [Routes](https://github.com/pablocizq/laboratorioingweb/tree/main/backend/gateway/src/routes): http routing · Feature routes for auth, espacios, and reservas · `backend/gateway/src/routes`
- [Auth](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/controllers/auth.controller.js): controller · Login and token-facing controller logic · `backend/gateway/src/controllers/auth.controller.js`
- [Reservas](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/controllers/reservas.controller.js): controller · Reservation-facing controller logic · `backend/gateway/src/controllers/reservas.controller.js`
- [Espacios](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/controllers/espacios.controller.js): controller · Space-facing controller logic · `backend/gateway/src/controllers/espacios.controller.js`
- [Middlewares](https://github.com/pablocizq/laboratorioingweb/tree/main/backend/gateway/src/middlewares): request guards · Authentication and payload validation before dispatch · `backend/gateway/src/middlewares`
- [Tokens](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/services/token.service.js): jwt service · Token issuance and verification support · `backend/gateway/src/services/token.service.js`
- [RPC Client](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/gateway/src/messaging/rpc-client.js): broker client · Sends gateway requests to the app server over the message broker · `backend/gateway/src/messaging/rpc-client.js`

### App Server

Core booking service with application, domain, and infrastructure layers

- [App Server](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/app-server/src/main.js): service host · Core booking service runtime · `backend/app-server/src/main.js`
- [RPC Server](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/app-server/src/messaging/rpc-server.js): broker consumer · Receives gateway RPC calls and dispatches use cases · `backend/app-server/src/messaging/rpc-server.js`
- [Use Cases](https://github.com/pablocizq/laboratorioingweb/tree/main/backend/app-server/src/application): application layer · Reservation, login, and space operations · `backend/app-server/src/application`
- [Domain Model](https://github.com/pablocizq/laboratorioingweb/tree/main/backend/app-server/src/domain): domain layer · Entities, value objects, policies, errors, and domain services · `backend/app-server/src/domain`
- [Policies](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/app-server/src/domain/policies/PoliticaPermisosReserva.js): business rules · Reservation permissions and conflict checks · `backend/app-server/src/domain/policies/PoliticaPermisosReserva.js`
- [Repositories](https://github.com/pablocizq/laboratorioingweb/tree/main/backend/app-server/src/domain/repositories): persistence ports · Repository interfaces and SQL implementations · `backend/app-server/src/domain/repositories`
- [Database](https://github.com/pablocizq/laboratorioingweb/blob/main/backend/app-server/src/infrastructure/database/index.js): sql storage · Database bootstrap and relational persistence · `backend/app-server/src/infrastructure/database/index.js`
- [Seed Data](https://github.com/pablocizq/laboratorioingweb/tree/main/backend/app-server/src/infrastructure/database/seeders): initial data · Loads sample users, spaces, and past reservations · `backend/app-server/src/infrastructure/database/seeders`

### Other components

- **Client**: external actor · HTTP consumer of the public API
- **Broker**: message bus · Internal messaging channel used for RPC between services

## Connections

- Client → Gateway API: HTTP requests · Clients call the public API
- Gateway API → Routes: mounts · Server wires feature routes
- Routes → Middlewares: guards · Routes apply authentication and validation
- Routes → Auth: dispatches · Auth routes reach the auth controller
- Routes → Reservas: dispatches · Reservation routes reach the reservations controller
- Routes → Espacios: dispatches · Space routes reach the spaces controller
- Auth → Tokens: issues/reads · Authentication depends on token handling
- Auth → RPC Client: login RPC · Login is forwarded to the core service
- Reservas → RPC Client: reservation RPC · Reservation operations are translated to broker calls
- Espacios → RPC Client: space RPC · Space operations are translated to broker calls
- RPC Client → Broker: publish · Gateway sends RPC messages through the broker
- Broker → RPC Server: deliver · Broker routes RPC messages to the app server consumer
- RPC Server → Use Cases: invoke · RPC server selects the matching use case
- Use Cases → Domain Model: depends on · Use cases enforce domain rules and manipulate entities
- Domain Model → Policies: uses · Domain services and policies validate reservation constraints
- Use Cases → Repositories: reads/writes · Use cases access repository abstractions
- Repositories → Database: persists · SQL repositories store and retrieve data
- Database → Seed Data: initializes · Seeders populate the database with baseline data
- App Server → RPC Server: starts · Main runtime bootstraps the broker consumer
