# ignaciohernandez/pp3-api-pedidos architecture

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

- Interactive diagram: https://gitdiagram.com/ignaciohernandez/pp3-api-pedidos
- Repository: https://github.com/ignaciohernandez/pp3-api-pedidos

## Overview

Pedidos is an independently deployed HTTP service for authenticated order lifecycle management. Its principal workflow accepts an idempotent purchase request, persists orders and items, then supports authorized listing/detail, confirmation with coordinator-authorized amounts, simulated payment and receipt retrieval, cancellation states, and shipping/delivery transitions. The README also documents stock coordination as Gateway-owned; this service exposes internal order queues but does not itself call Catalog. Routes and DB behavior are only partly sampled, so omitted implementation details are not inferred.

Main entry points: [`src/app.js`](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js) (Order API), [`src/db.js`](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/db.js) (Connection Pool), [`src/migrate.js`](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/migrate.js) (Migration Runner), [`src/server.js`](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/server.js) (HTTP Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_app["Order API<br/>[app.js]"]
  node_auth["Service Token Auth<br/>[auth.js]"]
end

subgraph group_lifecycle["Order Lifecycle"]
  node_create["Idempotent Creation<br/>[app.js]"]
  node_order_queries["Order Queries<br/>[app.js]"]
  node_confirmation["Authorized Confirmation<br/>[app.js]"]
  node_payment_receipt["Payment and Receipt<br/>[app.js]"]
  node_cancellation["Cancellation Flow<br/>[app.js]"]
  node_fulfillment["Shipping and Delivery<br/>[app.js]"]
end

subgraph group_storage["Persistence"]
  node_mysql[("MySQL Database")]
  node_pool["Connection Pool<br/>[db.js]"]
end

subgraph group_operations["Service Operations"]
  node_migrations["Schema Migrations"]
  node_migrator["Migration Runner<br/>[migrate.js]"]
  node_server["HTTP Server<br/>[server.js]"]
end

node_client(("Client"))
node_gateway["Gateway"]
node_admin(("Administrator"))

node_client -->|"sends requests"| node_gateway
node_gateway -->|"forwards identity"| node_app
node_admin -->|"manages orders"| node_app
node_server -->|"creates app"| node_app
node_server -->|"creates pool"| node_pool
node_app -->|"registers middleware"| node_auth
node_app -->|"routes creation"| node_create
node_app -->|"routes queries"| node_order_queries
node_app -.->|"routes confirmation"| node_confirmation
node_app -.->|"routes payment"| node_payment_receipt
node_app -.->|"routes cancellation"| node_cancellation
node_app -.->|"routes fulfillment"| node_fulfillment
node_create -.->|"writes orders"| node_pool
node_order_queries -->|"reads orders"| node_pool
node_confirmation -->|"updates amounts"| node_pool
node_payment_receipt -->|"reads receipts"| node_pool
node_cancellation -.->|"updates status"| node_pool
node_fulfillment -.->|"updates status"| node_pool
node_pool -->|"queries"| node_mysql
node_migrator -->|"creates pool"| node_pool
node_migrator -->|"applies SQL"| node_migrations
node_migrator -->|"records schema"| node_mysql
node_server -->|"warms connection"| node_mysql

click node_app "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js"
click node_auth "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/auth.js"
click node_create "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js"
click node_order_queries "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js"
click node_confirmation "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js"
click node_payment_receipt "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js"
click node_cancellation "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js"
click node_fulfillment "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js"
click node_pool "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/db.js"
click node_migrations "https://github.com/ignaciohernandez/pp3-api-pedidos/tree/main/migrations"
click node_migrator "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/migrate.js"
click node_server "https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/server.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_app,node_auth,node_client toneBlue
class node_create,node_order_queries,node_confirmation,node_payment_receipt,node_cancellation,node_fulfillment toneAmber
class node_mysql,node_pool toneMint
class node_migrations,node_migrator,node_server toneRose
class node_gateway,node_admin toneIndigo
```

## Components

### HTTP API

- [Order API](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js): `src/app.js`
- [Service Token Auth](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/auth.js): `src/auth.js`

### Order Lifecycle

- [Idempotent Creation](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js): `src/app.js`
- [Order Queries](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js): `src/app.js`
- [Authorized Confirmation](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js): `src/app.js`
- [Payment and Receipt](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js): `src/app.js`
- [Cancellation Flow](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js): `src/app.js`
- [Shipping and Delivery](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/app.js): `src/app.js`

### Persistence

- **MySQL Database**
- [Connection Pool](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/db.js): `src/db.js`

### Service Operations

- [Schema Migrations](https://github.com/ignaciohernandez/pp3-api-pedidos/tree/main/migrations): `migrations`
- [Migration Runner](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/migrate.js): `src/migrate.js`
- [HTTP Server](https://github.com/ignaciohernandez/pp3-api-pedidos/blob/main/src/server.js): `src/server.js`

### Other components

- **Client**
- **Gateway**
- **Administrator**

## Connections

- Client → Gateway: sends requests (evidence: `README.md`)
- Gateway → Order API: forwards identity (evidence: `README.md`)
- Administrator → Order API: manages orders (evidence: `README.md`)
- HTTP Server → Order API: creates app (evidence: `src/server.js`)
- HTTP Server → Connection Pool: creates pool (evidence: `src/server.js`)
- Order API → Service Token Auth: registers middleware (evidence: `src/app.js`)
- Order API → Idempotent Creation: routes creation (evidence: `src/app.js`)
- Order API → Order Queries: routes queries (evidence: `src/app.js`)
- Order API → Authorized Confirmation: routes confirmation (evidence: `src/app.js`)
- Order API → Payment and Receipt: routes payment (evidence: `src/app.js`)
- Order API → Cancellation Flow: routes cancellation (evidence: `src/app.js`)
- Order API → Shipping and Delivery: routes fulfillment (evidence: `src/app.js`)
- Idempotent Creation → Connection Pool: writes orders
- Order Queries → Connection Pool: reads orders (evidence: `src/app.js`)
- Authorized Confirmation → Connection Pool: updates amounts (evidence: `src/app.js`)
- Payment and Receipt → Connection Pool: reads receipts (evidence: `src/app.js`)
- Cancellation Flow → Connection Pool: updates status
- Shipping and Delivery → Connection Pool: updates status
- Connection Pool → MySQL Database: queries (evidence: `src/db.js`)
- Migration Runner → Connection Pool: creates pool (evidence: `src/migrate.js`)
- Migration Runner → Schema Migrations: applies SQL (evidence: `src/migrate.js`)
- Migration Runner → MySQL Database: records schema (evidence: `src/migrate.js`)
- HTTP Server → MySQL Database: warms connection (evidence: `src/server.js`)
