# johan-cor/rest-serve-nodejs architecture

> Architecture diagram of the GitHub repository johan-cor/rest-serve-nodejs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/johan-cor/rest-serve-nodejs
- Repository: https://github.com/johan-cor/rest-serve-nodejs

## Overview

This is a Node.js/Express REST server for user management. Clients call the `/api/usuarios` endpoints; route handlers apply request validation and dispatch to controller functions, which query or update user records. The API supports paginated active-user listing, creation with password hashing, updates, soft deletion, and a sample PATCH endpoint. Startup configures middleware, routes, and MongoDB connectivity. The README documents these capabilities; source excerpts show the main wiring and data operations, but not every runtime detail.

Main entry points: [`models/server.js`](https://github.com/johan-cor/rest-serve-nodejs/blob/main/models/server.js) (Express server), [`routes/usuarios.route.js`](https://github.com/johan-cor/rest-serve-nodejs/blob/main/routes/usuarios.route.js) (User routes), [`helpers/db-validators.js`](https://github.com/johan-cor/rest-serve-nodejs/blob/main/helpers/db-validators.js) (Database validators), [`DB/confg.db.js`](https://github.com/johan-cor/rest-serve-nodejs/blob/main/DB/confg.db.js) (MongoDB connection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_server["Express server<br/>[server.js]"]
  node_entry["Application entry<br/>[app.js]"]
  node_static["Static assets<br/>[index.html]"]
  node_mongo_config["MongoDB connection<br/>[confg.db.js]"]
end

subgraph group_api["User API"]
  node_user_routes["User routes<br/>[usuarios.route.js]"]
  node_user_controller["User controller"]
end

subgraph group_validation["Validation"]
  node_field_validation["Field validation<br/>[validar-campos.js]"]
  node_db_validators["Database validators<br/>[db-validators.js]"]
end

subgraph group_data["Data models"]
  node_user_model["User model<br/>[usuario.js]"]
  node_role_model["Role model<br/>[role.js]"]
  node_email_model["Email model<br/>[correo.js]"]
end

node_client(("API client"))
node_mongodb[("MongoDB")]

node_entry -->|"creates"| node_server
node_server -->|"connects"| node_mongo_config
node_mongo_config -->|"connects"| node_mongodb
node_server -->|"mounts routes"| node_user_routes
node_server -->|"serves static"| node_static
node_client -->|"sends requests"| node_server
node_user_routes -->|"dispatches"| node_user_controller
node_user_routes -->|"validates fields"| node_field_validation
node_user_routes -->|"checks records"| node_db_validators
node_user_controller -->|"queries and updates"| node_user_model
node_db_validators -->|"checks user"| node_user_model
node_db_validators -->|"checks role"| node_role_model
node_db_validators -->|"checks email"| node_email_model

click node_server "https://github.com/johan-cor/rest-serve-nodejs/blob/main/models/server.js"
click node_entry "https://github.com/johan-cor/rest-serve-nodejs/blob/main/app.js"
click node_static "https://github.com/johan-cor/rest-serve-nodejs/blob/main/public/index.html"
click node_mongo_config "https://github.com/johan-cor/rest-serve-nodejs/blob/main/DB/confg.db.js"
click node_user_routes "https://github.com/johan-cor/rest-serve-nodejs/blob/main/routes/usuarios.route.js"
click node_user_controller "https://github.com/johan-cor/rest-serve-nodejs/blob/main/controllers/usuarios.controller.js"
click node_field_validation "https://github.com/johan-cor/rest-serve-nodejs/blob/main/middleware/validar-campos.js"
click node_db_validators "https://github.com/johan-cor/rest-serve-nodejs/blob/main/helpers/db-validators.js"
click node_user_model "https://github.com/johan-cor/rest-serve-nodejs/blob/main/models/usuario.js"
click node_role_model "https://github.com/johan-cor/rest-serve-nodejs/blob/main/models/role.js"
click node_email_model "https://github.com/johan-cor/rest-serve-nodejs/blob/main/models/correo.js"

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_server,node_entry,node_static,node_mongo_config,node_client toneBlue
class node_user_routes,node_user_controller,node_mongodb toneAmber
class node_field_validation,node_db_validators toneMint
class node_user_model,node_role_model,node_email_model toneRose
```

## Components

### Server runtime

- [Express server](https://github.com/johan-cor/rest-serve-nodejs/blob/main/models/server.js): `models/server.js`
- [Application entry](https://github.com/johan-cor/rest-serve-nodejs/blob/main/app.js): `app.js`
- [Static assets](https://github.com/johan-cor/rest-serve-nodejs/blob/main/public/index.html): `public/index.html`
- [MongoDB connection](https://github.com/johan-cor/rest-serve-nodejs/blob/main/DB/confg.db.js): `DB/confg.db.js`

### User API

- [User routes](https://github.com/johan-cor/rest-serve-nodejs/blob/main/routes/usuarios.route.js): `routes/usuarios.route.js`
- [User controller](https://github.com/johan-cor/rest-serve-nodejs/blob/main/controllers/usuarios.controller.js): `controllers/usuarios.controller.js`

### Validation

- [Field validation](https://github.com/johan-cor/rest-serve-nodejs/blob/main/middleware/validar-campos.js): `middleware/validar-campos.js`
- [Database validators](https://github.com/johan-cor/rest-serve-nodejs/blob/main/helpers/db-validators.js): `helpers/db-validators.js`

### Data models

- [User model](https://github.com/johan-cor/rest-serve-nodejs/blob/main/models/usuario.js): `models/usuario.js`
- [Role model](https://github.com/johan-cor/rest-serve-nodejs/blob/main/models/role.js): `models/role.js`
- [Email model](https://github.com/johan-cor/rest-serve-nodejs/blob/main/models/correo.js): `models/correo.js`

### Other components

- **API client**
- **MongoDB**

## Connections

- Application entry → Express server: creates (evidence: `app.js`)
- Express server → MongoDB connection: connects (evidence: `models/server.js`)
- MongoDB connection → MongoDB: connects (evidence: `DB/confg.db.js`)
- Express server → User routes: mounts routes (evidence: `models/server.js`)
- Express server → Static assets: serves static (evidence: `models/server.js`)
- API client → Express server: sends requests (evidence: `README.md`)
- User routes → User controller: dispatches (evidence: `routes/usuarios.route.js`)
- User routes → Field validation: validates fields (evidence: `routes/usuarios.route.js`)
- User routes → Database validators: checks records (evidence: `routes/usuarios.route.js`)
- User controller → User model: queries and updates (evidence: `controllers/usuarios.controller.js`)
- Database validators → User model: checks user (evidence: `helpers/db-validators.js`)
- Database validators → Role model: checks role (evidence: `helpers/db-validators.js`)
- Database validators → Email model: checks email (evidence: `helpers/db-validators.js`)
