# xavi-di16/proyectom2_xavierdilorenzo architecture

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

- Interactive diagram: https://gitdiagram.com/xavi-di16/proyectom2_xavierdilorenzo
- Repository: https://github.com/xavi-di16/proyectom2_xavierdilorenzo

## Overview

MiniBlog is a REST API for managing authors, posts, and comments. A client sends requests to the Express server, which dispatches them to resource routes; routes validate input and call domain services, which query PostgreSQL. The server also exposes Swagger UI backed by the OpenAPI file and installs centralized error handling. The route, service, and database connections are supported by the sampled source; the schema setup relationship is documented in the README.

Main entry points: [`server.js`](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/server.js) (Express server), [`db/config.js`](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/db/config.js) (PostgreSQL pool), [`routes/authors.js`](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/routes/authors.js) (Author routes), [`routes/posts.js`](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/routes/posts.js) (Post routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API runtime"]
  node_server["Express server<br/>[server.js]"]
  node_authors_route["Author routes<br/>[authors.js]"]
  node_posts_route["Post routes<br/>[posts.js]"]
  node_comments_route["Comment routes<br/>[comments.js]"]
  node_errors["Error handler<br/>[errorHandler.js]"]
end

subgraph group_domain["Content operations"]
  node_author_service["Author service<br/>[authorService.js]"]
  node_post_service["Post service<br/>[postService.js]"]
  node_comment_service["Comment service<br/>[commentService.js]"]
end

subgraph group_persistence["Persistence"]
  node_pool["PostgreSQL pool<br/>[config.js]"]
  node_schema["Database schema<br/>[setup.sql]"]
end

subgraph group_docs["API documentation"]
  node_swagger["Swagger UI<br/>[server.js]"]
  node_openapi["OpenAPI definition<br/>[openapi.yaml]"]
end

node_client(("API client"))
node_postgres[("PostgreSQL")]

node_client -->|"sends requests"| node_server
node_server -->|"mounts routes"| node_authors_route
node_server -->|"mounts routes"| node_posts_route
node_server -->|"mounts routes"| node_comments_route
node_server -->|"installs handler"| node_errors
node_authors_route -->|"calls"| node_author_service
node_posts_route -->|"calls"| node_post_service
node_comments_route -->|"calls"| node_comment_service
node_author_service -->|"queries"| node_pool
node_post_service -->|"queries"| node_pool
node_comment_service -->|"queries"| node_pool
node_pool -->|"connects"| node_postgres
node_schema -->|"initializes tables"| node_postgres
node_server -->|"serves docs"| node_swagger
node_swagger -->|"loads definition"| node_openapi

click node_server "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/server.js"
click node_authors_route "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/routes/authors.js"
click node_posts_route "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/routes/posts.js"
click node_comments_route "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/routes/comments.js"
click node_errors "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/middlewares/errorHandler.js"
click node_author_service "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/services/authorService.js"
click node_post_service "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/services/postService.js"
click node_comment_service "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/services/commentService.js"
click node_pool "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/db/config.js"
click node_schema "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/db/setup.sql"
click node_swagger "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/server.js"
click node_openapi "https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/openapi.yaml"

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_authors_route,node_posts_route,node_comments_route,node_errors,node_client toneBlue
class node_author_service,node_post_service,node_comment_service,node_postgres toneAmber
class node_pool,node_schema toneMint
class node_swagger,node_openapi toneRose
```

## Components

### API runtime

- [Express server](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/server.js): `server.js`
- [Author routes](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/routes/authors.js): `routes/authors.js`
- [Post routes](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/routes/posts.js): `routes/posts.js`
- [Comment routes](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/routes/comments.js): `routes/comments.js`
- [Error handler](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/middlewares/errorHandler.js): `middlewares/errorHandler.js`

### Content operations

- [Author service](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/services/authorService.js): `services/authorService.js`
- [Post service](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/services/postService.js): `services/postService.js`
- [Comment service](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/services/commentService.js): `services/commentService.js`

### Persistence

- [PostgreSQL pool](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/db/config.js): `db/config.js`
- [Database schema](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/db/setup.sql): `db/setup.sql`

### API documentation

- [Swagger UI](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/server.js): `server.js`
- [OpenAPI definition](https://github.com/xavi-di16/proyectom2_xavierdilorenzo/blob/main/openapi.yaml): `openapi.yaml`

### Other components

- **API client**
- **PostgreSQL**

## Connections

- API client → Express server: sends requests (evidence: `README.MD`)
- Express server → Author routes: mounts routes (evidence: `server.js`)
- Express server → Post routes: mounts routes (evidence: `server.js`)
- Express server → Comment routes: mounts routes (evidence: `server.js`)
- Express server → Error handler: installs handler (evidence: `server.js`)
- Author routes → Author service: calls (evidence: `routes/authors.js`)
- Post routes → Post service: calls (evidence: `routes/posts.js`)
- Comment routes → Comment service: calls (evidence: `routes/comments.js`)
- Author service → PostgreSQL pool: queries (evidence: `services/authorService.js`)
- Post service → PostgreSQL pool: queries (evidence: `services/postService.js`)
- Comment service → PostgreSQL pool: queries (evidence: `services/commentService.js`)
- PostgreSQL pool → PostgreSQL: connects (evidence: `db/config.js`)
- Database schema → PostgreSQL: initializes tables (evidence: `README.MD`)
- Express server → Swagger UI: serves docs (evidence: `server.js`)
- Swagger UI → OpenAPI definition: loads definition (evidence: `server.js`)
