# paul-developer-stack/tarea-4-backend architecture

> Architecture diagram of the GitHub repository paul-developer-stack/tarea-4-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/paul-developer-stack/tarea-4-backend
- Repository: https://github.com/paul-developer-stack/tarea-4-backend

## Overview

This is an Express/MySQL inventory backend. Customers register or log in, then authenticated customers can submit purchases that validate stock and record purchase details transactionally; administrators can manage the product catalog, while product listing is public. The graph separates HTTP routing, authorization, domain controllers, and persistence. The README documents the endpoint and role boundaries; source excerpts show route dispatch and controller database operations. The SQL schema is represented as the store, but its definitions were not sampled.

Main entry points: [`index.js`](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/index.js) (Express app), [`src/config/db.js`](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/config/db.js) (MySQL pool), [`src/routes/productosRoutes.js`](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/routes/productosRoutes.js) (Product routes), [`src/routes/comprasRoutes.js`](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/routes/comprasRoutes.js) (Purchase routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP API"]
  node_express_app["Express app<br/>[index.js]"]
  node_auth_routes["Auth routes<br/>[authRoutes.js]"]
  node_product_routes["Product routes<br/>[productosRoutes.js]"]
  node_purchase_routes["Purchase routes<br/>[comprasRoutes.js]"]
end

subgraph group_identity["Identity &amp; Access"]
  node_auth_controller["Registration &amp; login<br/>[authController.js]"]
  node_token_auth["Token &amp; role checks<br/>[authMiddleware.js]"]
  node_jwt_config["JWT secret<br/>[auth.js]"]
end

subgraph group_inventory["Inventory Operations"]
  node_product_controller["Product catalog"]
  node_purchase_controller["Purchase processing"]
end

subgraph group_persistence["Persistence"]
  node_mysql_pool["MySQL pool<br/>[db.js]"]
  node_inventory_db[("Inventory database<br/>[database.sql]")]
end

node_customer(("Customer"))
node_administrator(("Administrator"))

node_customer -->|"calls API"| node_express_app
node_administrator -->|"calls API"| node_express_app
node_express_app -->|"routes /api/auth"| node_auth_routes
node_express_app -->|"routes /api/productos"| node_product_routes
node_express_app -->|"routes /api/compras"| node_purchase_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_product_routes -->|"dispatches"| node_product_controller
node_purchase_routes -->|"dispatches"| node_purchase_controller
node_product_routes -->|"checks admin role"| node_token_auth
node_purchase_routes -->|"checks customer role"| node_token_auth
node_auth_controller -->|"signs tokens"| node_jwt_config
node_token_auth -->|"verifies tokens"| node_jwt_config
node_auth_controller -->|"queries users"| node_mysql_pool
node_product_controller -->|"queries products"| node_mysql_pool
node_purchase_controller -->|"records purchases"| node_mysql_pool
node_mysql_pool -.->|"reads and writes"| node_inventory_db

click node_express_app "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/index.js"
click node_auth_routes "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/routes/authRoutes.js"
click node_product_routes "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/routes/productosRoutes.js"
click node_purchase_routes "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/routes/comprasRoutes.js"
click node_auth_controller "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/controllers/authController.js"
click node_token_auth "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/middlewares/authMiddleware.js"
click node_jwt_config "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/config/auth.js"
click node_product_controller "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/controllers/productosController.js"
click node_purchase_controller "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/controllers/comprasController.js"
click node_mysql_pool "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/config/db.js"
click node_inventory_db "https://github.com/paul-developer-stack/tarea-4-backend/blob/main/database.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_express_app,node_auth_routes,node_product_routes,node_purchase_routes toneBlue
class node_auth_controller,node_token_auth,node_jwt_config toneAmber
class node_product_controller,node_purchase_controller toneMint
class node_mysql_pool,node_inventory_db toneRose
class node_customer,node_administrator toneIndigo
```

## Components

### HTTP API

- [Express app](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/index.js): `index.js`
- [Auth routes](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/routes/authRoutes.js): `src/routes/authRoutes.js`
- [Product routes](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/routes/productosRoutes.js): `src/routes/productosRoutes.js`
- [Purchase routes](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/routes/comprasRoutes.js): `src/routes/comprasRoutes.js`

### Identity & Access

- [Registration & login](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/controllers/authController.js): `src/controllers/authController.js`
- [Token & role checks](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/middlewares/authMiddleware.js): `src/middlewares/authMiddleware.js`
- [JWT secret](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/config/auth.js): `src/config/auth.js`

### Inventory Operations

- [Product catalog](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/controllers/productosController.js): `src/controllers/productosController.js`
- [Purchase processing](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/controllers/comprasController.js): `src/controllers/comprasController.js`

### Persistence

- [MySQL pool](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/src/config/db.js): `src/config/db.js`
- [Inventory database](https://github.com/paul-developer-stack/tarea-4-backend/blob/main/database.sql): `database.sql`

### Other components

- **Customer**
- **Administrator**

## Connections

- Customer → Express app: calls API (evidence: `README.md`)
- Administrator → Express app: calls API (evidence: `README.md`)
- Express app → Auth routes: routes /api/auth (evidence: `index.js`)
- Express app → Product routes: routes /api/productos (evidence: `index.js`)
- Express app → Purchase routes: routes /api/compras (evidence: `index.js`)
- Auth routes → Registration & login: dispatches (evidence: `src/routes/authRoutes.js`)
- Product routes → Product catalog: dispatches (evidence: `src/routes/productosRoutes.js`)
- Purchase routes → Purchase processing: dispatches (evidence: `src/routes/comprasRoutes.js`)
- Product routes → Token & role checks: checks admin role (evidence: `src/routes/productosRoutes.js`)
- Purchase routes → Token & role checks: checks customer role (evidence: `src/routes/comprasRoutes.js`)
- Registration & login → JWT secret: signs tokens (evidence: `src/controllers/authController.js`)
- Token & role checks → JWT secret: verifies tokens (evidence: `src/middlewares/authMiddleware.js`)
- Registration & login → MySQL pool: queries users (evidence: `src/controllers/authController.js`)
- Product catalog → MySQL pool: queries products (evidence: `src/controllers/productosController.js`)
- Purchase processing → MySQL pool: records purchases (evidence: `src/controllers/comprasController.js`)
- MySQL pool → Inventory database: reads and writes
