# hescobarmx/api-miniblog architecture

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

- Interactive diagram: https://gitdiagram.com/hescobarmx/api-miniblog
- Repository: https://github.com/hescobarmx/api-miniblog

## Overview

This is an Express REST API for CRUD operations on authors and posts, with a one-to-many author–post relationship. Clients send requests through the server and resource routes; validation and controllers handle requests, services perform PostgreSQL queries, and JSON responses return to clients. The README documents the endpoints and Swagger UI. The graph follows the sampled wiring and README; SQL schema details and unsampled bootstrap behavior are represented only where documented or indicated by the source index.

Main entry points: [`src/server.js`](https://github.com/hescobarmx/api-miniblog/blob/main/src/server.js) (Express server), [`src/routes/index.js`](https://github.com/hescobarmx/api-miniblog/blob/main/src/routes/index.js) (Route aggregator), [`src/routes/authors.routes.js`](https://github.com/hescobarmx/api-miniblog/blob/main/src/routes/authors.routes.js) (Author routes), [`src/controllers/authors.controller.js`](https://github.com/hescobarmx/api-miniblog/blob/main/src/controllers/authors.controller.js) (Author controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_bootstrap["Startup<br/>[index.js]"]
  node_server["Express server<br/>[server.js]"]
  node_api_routes["Route aggregator<br/>[index.js]"]
  node_openapi["API specification<br/>[openapi.yaml]"]
end

subgraph group_author["Author API"]
  node_authors_routes["Author routes<br/>[authors.routes.js]"]
  node_authors_validation["Author validation"]
  node_authors_controller["Author controller"]
  node_authors_service["Author queries<br/>[authors.service.js]"]
end

subgraph group_post["Post API"]
  node_posts_routes["Post routes<br/>[posts.routes.js]"]
  node_posts_validation["Post validation"]
  node_posts_controller["Post controller"]
  node_posts_service["Post queries<br/>[posts.service.js]"]
end

subgraph group_shared["Shared runtime"]
  node_async_handler["Async wrapper<br/>[asyncHandler.js]"]
  node_error_handler["Error handler<br/>[errorhandler.js]"]
  node_not_found["Not-found handler<br/>[notFoundHandler.js]"]
  node_db_pool["PostgreSQL pool<br/>[db.js]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL<br/>[setup.sql]")]

node_client -->|"sends requests"| node_server
node_bootstrap -->|"starts"| node_server
node_server -->|"mounts routes"| node_api_routes
node_server -->|"loads specification"| node_openapi
node_server -->|"registers fallback"| node_not_found
node_server -->|"registers errors"| node_error_handler
node_api_routes -->|"routes authors"| node_authors_routes
node_api_routes -->|"routes posts"| node_posts_routes
node_authors_routes -->|"validates input"| node_authors_validation
node_authors_routes -->|"dispatches requests"| node_authors_controller
node_authors_controller -->|"calls queries"| node_authors_service
node_authors_controller -->|"wraps handlers"| node_async_handler
node_authors_service -->|"queries through"| node_db_pool
node_posts_routes -->|"validates input"| node_posts_validation
node_posts_routes -->|"dispatches requests"| node_posts_controller
node_posts_controller -->|"calls queries"| node_posts_service
node_posts_controller -->|"wraps handlers"| node_async_handler
node_posts_service -->|"queries through"| node_db_pool
node_db_pool -->|"connects to"| node_postgres

click node_bootstrap "https://github.com/hescobarmx/api-miniblog/blob/main/index.js"
click node_server "https://github.com/hescobarmx/api-miniblog/blob/main/src/server.js"
click node_api_routes "https://github.com/hescobarmx/api-miniblog/blob/main/src/routes/index.js"
click node_openapi "https://github.com/hescobarmx/api-miniblog/blob/main/openapi.yaml"
click node_authors_routes "https://github.com/hescobarmx/api-miniblog/blob/main/src/routes/authors.routes.js"
click node_authors_validation "https://github.com/hescobarmx/api-miniblog/blob/main/src/validations/authors.validation.js"
click node_authors_controller "https://github.com/hescobarmx/api-miniblog/blob/main/src/controllers/authors.controller.js"
click node_authors_service "https://github.com/hescobarmx/api-miniblog/blob/main/src/services/authors.service.js"
click node_posts_routes "https://github.com/hescobarmx/api-miniblog/blob/main/src/routes/posts.routes.js"
click node_posts_validation "https://github.com/hescobarmx/api-miniblog/blob/main/src/validations/posts.validation.js"
click node_posts_controller "https://github.com/hescobarmx/api-miniblog/blob/main/src/controllers/posts.controller.js"
click node_posts_service "https://github.com/hescobarmx/api-miniblog/blob/main/src/services/posts.service.js"
click node_async_handler "https://github.com/hescobarmx/api-miniblog/blob/main/src/middlewares/asyncHandler.js"
click node_error_handler "https://github.com/hescobarmx/api-miniblog/blob/main/src/middlewares/errorhandler.js"
click node_not_found "https://github.com/hescobarmx/api-miniblog/blob/main/src/middlewares/notFoundHandler.js"
click node_db_pool "https://github.com/hescobarmx/api-miniblog/blob/main/src/config/db.js"
click node_postgres "https://github.com/hescobarmx/api-miniblog/blob/main/db/setup.sql"

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_bootstrap,node_server,node_api_routes,node_openapi,node_client toneBlue
class node_authors_routes,node_authors_validation,node_authors_controller,node_authors_service,node_postgres toneAmber
class node_posts_routes,node_posts_validation,node_posts_controller,node_posts_service toneMint
class node_async_handler,node_error_handler,node_not_found,node_db_pool toneRose
```

## Components

### API entry

- [Startup](https://github.com/hescobarmx/api-miniblog/blob/main/index.js): `index.js`
- [Express server](https://github.com/hescobarmx/api-miniblog/blob/main/src/server.js): `src/server.js`
- [Route aggregator](https://github.com/hescobarmx/api-miniblog/blob/main/src/routes/index.js): `src/routes/index.js`
- [API specification](https://github.com/hescobarmx/api-miniblog/blob/main/openapi.yaml): `openapi.yaml`

### Author API

- [Author routes](https://github.com/hescobarmx/api-miniblog/blob/main/src/routes/authors.routes.js): `src/routes/authors.routes.js`
- [Author validation](https://github.com/hescobarmx/api-miniblog/blob/main/src/validations/authors.validation.js): `src/validations/authors.validation.js`
- [Author controller](https://github.com/hescobarmx/api-miniblog/blob/main/src/controllers/authors.controller.js): `src/controllers/authors.controller.js`
- [Author queries](https://github.com/hescobarmx/api-miniblog/blob/main/src/services/authors.service.js): `src/services/authors.service.js`

### Post API

- [Post routes](https://github.com/hescobarmx/api-miniblog/blob/main/src/routes/posts.routes.js): `src/routes/posts.routes.js`
- [Post validation](https://github.com/hescobarmx/api-miniblog/blob/main/src/validations/posts.validation.js): `src/validations/posts.validation.js`
- [Post controller](https://github.com/hescobarmx/api-miniblog/blob/main/src/controllers/posts.controller.js): `src/controllers/posts.controller.js`
- [Post queries](https://github.com/hescobarmx/api-miniblog/blob/main/src/services/posts.service.js): `src/services/posts.service.js`

### Shared runtime

- [Async wrapper](https://github.com/hescobarmx/api-miniblog/blob/main/src/middlewares/asyncHandler.js): `src/middlewares/asyncHandler.js`
- [Error handler](https://github.com/hescobarmx/api-miniblog/blob/main/src/middlewares/errorhandler.js): `src/middlewares/errorhandler.js`
- [Not-found handler](https://github.com/hescobarmx/api-miniblog/blob/main/src/middlewares/notFoundHandler.js): `src/middlewares/notFoundHandler.js`
- [PostgreSQL pool](https://github.com/hescobarmx/api-miniblog/blob/main/src/config/db.js): `src/config/db.js`

### Other components

- **API client**
- [PostgreSQL](https://github.com/hescobarmx/api-miniblog/blob/main/db/setup.sql): `db/setup.sql`

## Connections

- API client → Express server: sends requests (evidence: `README.md`)
- Startup → Express server: starts (evidence: `index.js`)
- Express server → Route aggregator: mounts routes (evidence: `src/server.js`)
- Express server → API specification: loads specification (evidence: `README.md`)
- Express server → Not-found handler: registers fallback (evidence: `src/server.js`)
- Express server → Error handler: registers errors (evidence: `src/server.js`)
- Route aggregator → Author routes: routes authors (evidence: `src/routes/index.js`)
- Route aggregator → Post routes: routes posts (evidence: `src/routes/index.js`)
- Author routes → Author validation: validates input (evidence: `src/routes/authors.routes.js`)
- Author routes → Author controller: dispatches requests (evidence: `src/routes/authors.routes.js`)
- Author controller → Author queries: calls queries (evidence: `src/controllers/authors.controller.js`)
- Author controller → Async wrapper: wraps handlers (evidence: `src/controllers/authors.controller.js`)
- Author queries → PostgreSQL pool: queries through (evidence: `src/services/authors.service.js`)
- Post routes → Post validation: validates input (evidence: `src/routes/posts.routes.js`)
- Post routes → Post controller: dispatches requests (evidence: `src/routes/posts.routes.js`)
- Post controller → Post queries: calls queries (evidence: `src/controllers/posts.controller.js`)
- Post controller → Async wrapper: wraps handlers (evidence: `src/controllers/posts.controller.js`)
- Post queries → PostgreSQL pool: queries through (evidence: `src/services/posts.service.js`)
- PostgreSQL pool → PostgreSQL: connects to (evidence: `README.md`)
