# andresdelossantos99/apirest-libros architecture

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

- Interactive diagram: https://gitdiagram.com/andresdelossantos99/apirest-libros
- Repository: https://github.com/andresdelossantos99/apirest-libros

## Overview

ApiRest-Libros is an Express REST API for managing authors and their book posts. Clients send requests through the server and mounted API routes; route middleware validates input before controllers delegate CRUD and author-post lookups to services, which query PostgreSQL. The API also provides health status, filtering and pagination for posts, and centralized error responses. The README describes an earlier in-memory mock alongside the current PostgreSQL-backed behavior; the mock is shown as a separate, unverified option because the sampled runtime does not wire it in.

Main entry points: [`app.js`](https://github.com/andresdelossantos99/apirest-libros/blob/main/app.js) (Express app), [`source/dbConfig/db.js`](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/dbConfig/db.js) (PostgreSQL access), [`source/routes/indexRoutes.js`](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/routes/indexRoutes.js) (API route index), [`source/routes/authorRoutes.js`](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/routes/authorRoutes.js) (Author routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["API runtime"]
  node_server["Server startup<br/>[server.js]"]
  node_app["Express app<br/>[app.js]"]
  node_api_routes["API route index<br/>[indexRoutes.js]"]
end

subgraph group_author["Author resources"]
  node_author_routes["Author routes<br/>[authorRoutes.js]"]
  node_author_validation["Request validation<br/>[validators.js]"]
  node_author_controller["Author controller"]
  node_author_service["Author service<br/>[authorService.js]"]
end

subgraph group_posts["Post resources"]
  node_post_routes["Post routes<br/>[postRoutes.js]"]
  node_post_controller["Post controller<br/>[postController.js]"]
  node_post_service["Post service<br/>[postService.js]"]
end

subgraph group_persistence["Persistence and errors"]
  node_error_handler["Error handler<br/>[errorHandler.js]"]
  node_db_access["PostgreSQL access<br/>[db.js]"]
  node_postgres[("PostgreSQL")]
  node_mock_store[("In-memory mock<br/>[dbMock.js]")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_app
node_server -->|"starts"| node_app
node_server -->|"tests connection"| node_db_access
node_app -->|"mounts API"| node_api_routes
node_app -->|"registers errors"| node_error_handler
node_api_routes -->|"mounts authors"| node_author_routes
node_api_routes -->|"mounts posts"| node_post_routes
node_author_routes -->|"validates requests"| node_author_validation
node_author_routes -->|"dispatches"| node_author_controller
node_author_controller -->|"calls"| node_author_service
node_author_controller -->|"gets author posts"| node_post_service
node_post_routes -->|"validates requests"| node_author_validation
node_post_routes -->|"dispatches"| node_post_controller
node_post_controller -->|"calls"| node_post_service
node_author_service -->|"queries"| node_db_access
node_post_service -->|"queries"| node_db_access
node_db_access -->|"executes SQL"| node_postgres
node_mock_store -.->|"optional alternative"| node_author_service

click node_server "https://github.com/andresdelossantos99/apirest-libros/blob/main/server.js"
click node_app "https://github.com/andresdelossantos99/apirest-libros/blob/main/app.js"
click node_api_routes "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/routes/indexRoutes.js"
click node_author_routes "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/routes/authorRoutes.js"
click node_author_validation "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/middlewares/validators.js"
click node_author_controller "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/controllers/authorController.js"
click node_author_service "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/services/authorService.js"
click node_post_routes "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/routes/postRoutes.js"
click node_post_controller "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/controllers/postController.js"
click node_post_service "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/services/postService.js"
click node_error_handler "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/middlewares/errorHandler.js"
click node_db_access "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/dbConfig/db.js"
click node_mock_store "https://github.com/andresdelossantos99/apirest-libros/blob/main/source/services/dbMock.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_app,node_api_routes,node_client toneBlue
class node_author_routes,node_author_validation,node_author_controller,node_author_service toneAmber
class node_post_routes,node_post_controller,node_post_service toneMint
class node_error_handler,node_db_access,node_postgres,node_mock_store toneRose
```

## Components

### API runtime

- [Server startup](https://github.com/andresdelossantos99/apirest-libros/blob/main/server.js): `server.js`
- [Express app](https://github.com/andresdelossantos99/apirest-libros/blob/main/app.js): `app.js`
- [API route index](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/routes/indexRoutes.js): `source/routes/indexRoutes.js`

### Author resources

- [Author routes](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/routes/authorRoutes.js): `source/routes/authorRoutes.js`
- [Request validation](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/middlewares/validators.js): `source/middlewares/validators.js`
- [Author controller](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/controllers/authorController.js): `source/controllers/authorController.js`
- [Author service](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/services/authorService.js): `source/services/authorService.js`

### Post resources

- [Post routes](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/routes/postRoutes.js): `source/routes/postRoutes.js`
- [Post controller](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/controllers/postController.js): `source/controllers/postController.js`
- [Post service](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/services/postService.js): `source/services/postService.js`

### Persistence and errors

- [Error handler](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/middlewares/errorHandler.js): `source/middlewares/errorHandler.js`
- [PostgreSQL access](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/dbConfig/db.js): `source/dbConfig/db.js`
- **PostgreSQL**
- [In-memory mock](https://github.com/andresdelossantos99/apirest-libros/blob/main/source/services/dbMock.js): `source/services/dbMock.js`

### Other components

- **API client**

## Connections

- API client → Express app: sends requests (evidence: `README.md`)
- Server startup → Express app: starts (evidence: `server.js`)
- Server startup → PostgreSQL access: tests connection (evidence: `server.js`)
- Express app → API route index: mounts API (evidence: `app.js`)
- Express app → Error handler: registers errors (evidence: `app.js`)
- API route index → Author routes: mounts authors (evidence: `source/routes/indexRoutes.js`)
- API route index → Post routes: mounts posts (evidence: `source/routes/indexRoutes.js`)
- Author routes → Request validation: validates requests (evidence: `source/routes/authorRoutes.js`)
- Author routes → Author controller: dispatches (evidence: `source/routes/authorRoutes.js`)
- Author controller → Author service: calls (evidence: `source/controllers/authorController.js`)
- Author controller → Post service: gets author posts (evidence: `source/controllers/authorController.js`)
- Post routes → Request validation: validates requests (evidence: `source/routes/postRoutes.js`)
- Post routes → Post controller: dispatches (evidence: `source/routes/postRoutes.js`)
- Post controller → Post service: calls (evidence: `source/controllers/postController.js`)
- Author service → PostgreSQL access: queries (evidence: `source/services/authorService.js`)
- Post service → PostgreSQL access: queries (evidence: `source/services/postService.js`)
- PostgreSQL access → PostgreSQL: executes SQL (evidence: `source/dbConfig/db.js`)
- In-memory mock → Author service: optional alternative
