# pablosazycz/comercio architecture

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

- Interactive diagram: https://gitdiagram.com/pablosazycz/comercio
- Repository: https://github.com/pablosazycz/comercio

## Overview

Comercio is an Express/MongoDB commerce application. Its main customer workflow is browsing products, adding them to a cart, checking out, and creating and viewing orders. Separate branches cover account access, product and category administration, REST APIs, and real-time chat/operator support. The sampled files show the app mounting routes, several controllers calling models, and payment processing creating an order; unsampled route wiring and other controller behavior are represented only where the README or source index supports them.

Main entry points: [`routes`](https://github.com/pablosazycz/comercio/tree/main/routes) (Web routes), [`app.js`](https://github.com/pablosazycz/comercio/blob/main/app.js) (Express app), [`config/socket.js`](https://github.com/pablosazycz/comercio/blob/main/config/socket.js) (Socket service), [`controllers/pedidoController.js`](https://github.com/pablosazycz/comercio/blob/main/controllers/pedidoController.js) (Order processing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Web entry"]
  node_express["Express app<br/>[app.js]"]
  node_web_routes["Web routes"]
  node_api_routes["API routes"]
end

subgraph group_commerce["Commerce workflow"]
  node_cart["Cart operations<br/>[carroController.js]"]
  node_cart_store[("Carts<br/>[Carro.js]")]
  node_checkout["Order processing"]
  node_order_store[("Orders<br/>[Pedido.js]")]
end

subgraph group_catalog["Catalog management"]
  node_products["Product catalog"]
  node_categories["Category management"]
  node_product_store[("Products<br/>[Producto.js]")]
  node_category_store[("Categories<br/>[Categoria.js]")]
end

subgraph group_identity["Identity and APIs"]
  node_auth["Account access<br/>[authController.js]"]
  node_user_store[("Users<br/>[Usuario.js]")]
  node_auth_middleware["Role checks<br/>[auth.js]"]
  node_product_api["Product API"]
  node_category_api["Category API"]
end

subgraph group_support["Chat support"]
  node_chat_routes["Chat routes<br/>[chat.js]"]
  node_chat_config["Chat service<br/>[chatbot.js]"]
  node_socket["Socket service<br/>[socket.js]"]
  node_chat_client["Chat client<br/>[chat.js]"]
  node_operator_client["Operator client<br/>[operator.js]"]
end

node_customer(("Customer"))
node_operator(("Operator"))

node_customer -->|"sends requests"| node_express
node_express -->|"mounts"| node_web_routes
node_express -->|"mounts"| node_api_routes
node_web_routes -->|"routes to"| node_auth
node_auth -->|"reads and writes"| node_user_store
node_web_routes -->|"protects routes"| node_auth_middleware
node_web_routes -->|"routes to"| node_products
node_products -->|"reads and writes"| node_product_store
node_products -->|"reads"| node_category_store
node_web_routes -->|"routes to"| node_categories
node_categories -->|"reads and writes"| node_category_store
node_categories -->|"reads"| node_product_store
node_api_routes -->|"routes to"| node_product_api
node_product_api -->|"reads and writes"| node_product_store
node_api_routes -->|"routes to"| node_category_api
node_category_api -->|"reads and writes"| node_category_store
node_web_routes -->|"routes to"| node_cart
node_cart -->|"reads and writes"| node_cart_store
node_web_routes -->|"routes to"| node_checkout
node_checkout -->|"reads and updates"| node_cart_store
node_checkout -->|"creates"| node_order_store
node_web_routes -->|"mounts"| node_chat_routes
node_chat_routes -->|"uses"| node_chat_config
node_express -->|"configures"| node_socket
node_socket -->|"uses"| node_chat_config
node_customer -.->|"uses"| node_chat_client
node_operator -.->|"uses"| node_operator_client
node_chat_client -.->|"exchanges messages"| node_socket
node_operator_client -.->|"exchanges messages"| node_socket

click node_express "https://github.com/pablosazycz/comercio/blob/main/app.js"
click node_web_routes "https://github.com/pablosazycz/comercio/tree/main/routes"
click node_api_routes "https://github.com/pablosazycz/comercio/tree/main/routes"
click node_auth "https://github.com/pablosazycz/comercio/blob/main/controllers/authController.js"
click node_user_store "https://github.com/pablosazycz/comercio/blob/main/models/Usuario.js"
click node_auth_middleware "https://github.com/pablosazycz/comercio/blob/main/middlewares/auth.js"
click node_products "https://github.com/pablosazycz/comercio/blob/main/controllers/productoController.js"
click node_categories "https://github.com/pablosazycz/comercio/blob/main/controllers/categoriaController.js"
click node_product_api "https://github.com/pablosazycz/comercio/blob/main/controllers/apiProductoController.js"
click node_category_api "https://github.com/pablosazycz/comercio/blob/main/controllers/apiCategoriaController.js"
click node_product_store "https://github.com/pablosazycz/comercio/blob/main/models/Producto.js"
click node_category_store "https://github.com/pablosazycz/comercio/blob/main/models/Categoria.js"
click node_cart "https://github.com/pablosazycz/comercio/blob/main/controllers/carroController.js"
click node_cart_store "https://github.com/pablosazycz/comercio/blob/main/models/Carro.js"
click node_checkout "https://github.com/pablosazycz/comercio/blob/main/controllers/pedidoController.js"
click node_order_store "https://github.com/pablosazycz/comercio/blob/main/models/Pedido.js"
click node_chat_routes "https://github.com/pablosazycz/comercio/blob/main/routes/chat.js"
click node_chat_config "https://github.com/pablosazycz/comercio/blob/main/config/chatbot.js"
click node_socket "https://github.com/pablosazycz/comercio/blob/main/config/socket.js"
click node_chat_client "https://github.com/pablosazycz/comercio/blob/main/public/js/chat.js"
click node_operator_client "https://github.com/pablosazycz/comercio/blob/main/public/js/operator.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_express,node_web_routes,node_api_routes toneBlue
class node_cart,node_cart_store,node_checkout,node_order_store toneAmber
class node_products,node_categories,node_product_store,node_category_store toneMint
class node_auth,node_user_store,node_auth_middleware,node_product_api,node_category_api toneRose
class node_chat_routes,node_chat_config,node_socket,node_chat_client,node_operator_client,node_customer,node_operator toneIndigo
```

## Components

### Web entry

- [Express app](https://github.com/pablosazycz/comercio/blob/main/app.js): `app.js`
- [Web routes](https://github.com/pablosazycz/comercio/tree/main/routes): `routes`
- [API routes](https://github.com/pablosazycz/comercio/tree/main/routes): `routes`

### Commerce workflow

- [Cart operations](https://github.com/pablosazycz/comercio/blob/main/controllers/carroController.js): `controllers/carroController.js`
- [Carts](https://github.com/pablosazycz/comercio/blob/main/models/Carro.js): `models/Carro.js`
- [Order processing](https://github.com/pablosazycz/comercio/blob/main/controllers/pedidoController.js): `controllers/pedidoController.js`
- [Orders](https://github.com/pablosazycz/comercio/blob/main/models/Pedido.js): `models/Pedido.js`

### Catalog management

- [Product catalog](https://github.com/pablosazycz/comercio/blob/main/controllers/productoController.js): `controllers/productoController.js`
- [Category management](https://github.com/pablosazycz/comercio/blob/main/controllers/categoriaController.js): `controllers/categoriaController.js`
- [Products](https://github.com/pablosazycz/comercio/blob/main/models/Producto.js): `models/Producto.js`
- [Categories](https://github.com/pablosazycz/comercio/blob/main/models/Categoria.js): `models/Categoria.js`

### Identity and APIs

- [Account access](https://github.com/pablosazycz/comercio/blob/main/controllers/authController.js): `controllers/authController.js`
- [Users](https://github.com/pablosazycz/comercio/blob/main/models/Usuario.js): `models/Usuario.js`
- [Role checks](https://github.com/pablosazycz/comercio/blob/main/middlewares/auth.js): `middlewares/auth.js`
- [Product API](https://github.com/pablosazycz/comercio/blob/main/controllers/apiProductoController.js): `controllers/apiProductoController.js`
- [Category API](https://github.com/pablosazycz/comercio/blob/main/controllers/apiCategoriaController.js): `controllers/apiCategoriaController.js`

### Chat support

- [Chat routes](https://github.com/pablosazycz/comercio/blob/main/routes/chat.js): `routes/chat.js`
- [Chat service](https://github.com/pablosazycz/comercio/blob/main/config/chatbot.js): `config/chatbot.js`
- [Socket service](https://github.com/pablosazycz/comercio/blob/main/config/socket.js): `config/socket.js`
- [Chat client](https://github.com/pablosazycz/comercio/blob/main/public/js/chat.js): `public/js/chat.js`
- [Operator client](https://github.com/pablosazycz/comercio/blob/main/public/js/operator.js): `public/js/operator.js`

### Other components

- **Customer**
- **Operator**

## Connections

- Customer → Express app: sends requests (evidence: `app.js`)
- Express app → Web routes: mounts (evidence: `app.js`)
- Express app → API routes: mounts (evidence: `app.js`)
- Web routes → Account access: routes to (evidence: `routes/auth.js`)
- Account access → Users: reads and writes (evidence: `controllers/authController.js`)
- Web routes → Role checks: protects routes (evidence: `routes/carro.js`)
- Web routes → Product catalog: routes to (evidence: `routes/producto.js`)
- Product catalog → Products: reads and writes (evidence: `controllers/productoController.js`)
- Product catalog → Categories: reads (evidence: `controllers/productoController.js`)
- Web routes → Category management: routes to (evidence: `routes/categoria.js`)
- Category management → Categories: reads and writes (evidence: `controllers/categoriaController.js`)
- Category management → Products: reads (evidence: `controllers/categoriaController.js`)
- API routes → Product API: routes to (evidence: `routes/apiProducto.js`)
- Product API → Products: reads and writes (evidence: `controllers/apiProductoController.js`)
- API routes → Category API: routes to (evidence: `routes/apiCategoria.js`)
- Category API → Categories: reads and writes (evidence: `controllers/apiCategoriaController.js`)
- Web routes → Cart operations: routes to (evidence: `routes/carro.js`)
- Cart operations → Carts: reads and writes (evidence: `controllers/carroController.js`)
- Web routes → Order processing: routes to (evidence: `routes/pedido.js`)
- Order processing → Carts: reads and updates (evidence: `controllers/pedidoController.js`)
- Order processing → Orders: creates (evidence: `controllers/pedidoController.js`)
- Web routes → Chat routes: mounts (evidence: `app.js`)
- Chat routes → Chat service: uses (evidence: `routes/chat.js`)
- Express app → Socket service: configures (evidence: `app.js`)
- Socket service → Chat service: uses (evidence: `config/socket.js`)
- Customer → Chat client: uses
- Operator → Operator client: uses
- Chat client → Socket service: exchanges messages
- Operator client → Socket service: exchanges messages
