# raulperezs/sistema-inventario architecture

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

- Interactive diagram: https://gitdiagram.com/raulperezs/sistema-inventario
- Repository: https://github.com/raulperezs/sistema-inventario

## Overview

Sistema web de inventario multiempresa y multisucursal: usuarios u otros sistemas operan mediante el panel o la API, gestionan catálogo y órdenes, registran movimientos y consultan stock y reportes. La API aplica autenticación, permisos y alcance de empresa/sucursal en sus rutas; los flujos de inventario y órdenes usan servicios transaccionales y persisten en PostgreSQL. Se muestran también seguridad, administración, auditoría y webhooks documentados. Las relaciones no visibles en los extractos se omiten; las capacidades documentadas sin ruta muestreada usan directorios exactos del árbol.

Main entry points: [`frontend/src/lib/api.ts`](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/lib/api.ts) (Cliente API), [`backend/src/lib/webhooks.ts`](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/lib/webhooks.ts) (Despacho de webhooks), [`backend/src/modules/products/products.routes.ts`](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/products/products.routes.ts) (Productos y catálogo), [`backend/src/modules/inventory/inventory.routes.ts`](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/inventory/inventory.routes.ts) (Stock y kardex)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Panel web"]
  node_web["Panel de gestión<br/>[App.tsx]"]
  node_webapi["Cliente API<br/>[api.ts]"]
  node_login["Acceso y sesión<br/>[LoginPage.tsx]"]
  node_catalogui["Catálogo y productos<br/>[ProductsPage.tsx]"]
  node_ordersui["Órdenes y movimientos<br/>[OrdersPage.tsx]"]
  node_reportsui["Panel e informes<br/>[ReportsPage.tsx]"]
  node_webhookui["Gestión webhooks<br/>[WebhooksPage.tsx]"]
end

subgraph group_api["API y seguridad"]
  node_entry["Aplicación HTTP<br/>[app.ts]"]
  node_routes["Registro de rutas<br/>[routes.ts]"]
  node_auth["Autenticación y roles<br/>[auth.ts]"]
  node_router["Validación y despacho<br/>[router.ts]"]
  node_authsvc["Servicio de sesión<br/>[auth.service.ts]"]
  node_scope["Alcance multiempresa<br/>[tenant.ts]"]
end

subgraph group_master["Maestros y administración"]
  node_companies["Empresas y sucursales"]
  node_branches["Sucursales<br/>[branches.routes.ts]"]
  node_products["Productos y catálogo<br/>[products.routes.ts]"]
  node_masters["Maestros comerciales"]
  node_users["Usuarios y API keys<br/>[users.routes.ts]"]
end

subgraph group_operations["Inventario y órdenes"]
  node_inventory["Stock y kardex"]
  node_stockservice["Motor de stock"]
  node_purchase["Órdenes de compra"]
  node_sales["Órdenes de venta"]
  node_orderlogic["Reglas compartidas<br/>[orders.ts]"]
  node_db[("PostgreSQL")]
end

subgraph group_insight["Reportes e integraciones"]
  node_reports["Informes y KPIs<br/>[reports.routes.ts]"]
  node_hooks["Despacho de webhooks<br/>[webhooks.ts]"]
  node_webhookadmin["Configuración webhooks<br/>[webhooks.routes.ts]"]
  node_audit["Bitácora de auditoría<br/>[audit.ts]"]
end

node_operator(("Usuario / sistema"))
node_external(("Sistemas integrados"))

node_operator -->|"usa panel"| node_web
node_operator -.->|"consume API"| node_webapi
node_web -.->|"solicita datos"| node_webapi
node_webapi -.->|"envía HTTP"| node_entry
node_entry -.->|"registra rutas"| node_routes
node_routes -->|"despacha"| node_router
node_router -->|"aplica guards"| node_auth
node_router -.->|"invoca sesión"| node_authsvc
node_auth -.->|"define alcance"| node_scope
node_webapi -.->|"inicia sesión"| node_authsvc
node_catalogui -.->|"consulta catálogo"| node_webapi
node_ordersui -.->|"opera órdenes"| node_webapi
node_reportsui -.->|"consulta informes"| node_webapi
node_webhookui -->|"administra hooks"| node_webapi
node_products -->|"filtra empresa"| node_scope
node_products -.->|"lee y escribe"| node_db
node_masters -.->|"gestiona maestros"| node_db
node_companies -.->|"persiste empresas"| node_db
node_branches -.->|"persiste sucursales"| node_db
node_users -.->|"persiste usuarios"| node_db
node_inventory -->|"aplica cambios"| node_stockservice
node_stockservice -.->|"actualiza stock"| node_db
node_purchase -->|"usa transacción"| node_stockservice
node_purchase -->|"valida órdenes"| node_orderlogic
node_purchase -.->|"lee y persiste"| node_db
node_sales -->|"reserva stock"| node_stockservice
node_sales -->|"valida estados"| node_orderlogic
node_sales -.->|"lee y persiste"| node_db
node_inventory -.->|"lee movimientos"| node_db
node_reports -->|"limita consultas"| node_scope
node_reports -.->|"consulta indicadores"| node_db
node_inventory -->|"emite eventos"| node_hooks
node_products -->|"emite cambios"| node_hooks
node_purchase -->|"emite estados"| node_hooks
node_sales -->|"emite estados"| node_hooks
node_webhookadmin -->|"gestiona entregas"| node_hooks
node_hooks -.->|"envía notificaciones"| node_external
node_inventory -->|"registra actividad"| node_audit
node_products -->|"registra actividad"| node_audit
node_audit -->|"guarda bitácora"| node_db

click node_web "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/App.tsx"
click node_webapi "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/lib/api.ts"
click node_login "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/LoginPage.tsx"
click node_catalogui "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/ProductsPage.tsx"
click node_ordersui "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/OrdersPage.tsx"
click node_reportsui "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/ReportsPage.tsx"
click node_webhookui "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/WebhooksPage.tsx"
click node_entry "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/app.ts"
click node_routes "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/routes.ts"
click node_auth "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/middleware/auth.ts"
click node_router "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/lib/router.ts"
click node_authsvc "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/auth/auth.service.ts"
click node_scope "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/lib/tenant.ts"
click node_companies "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/companies/companies.routes.ts"
click node_branches "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/branches/branches.routes.ts"
click node_products "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/products/products.routes.ts"
click node_masters "https://github.com/raulperezs/sistema-inventario/tree/claude/wizardly-brown-wgusp6/backend/src/modules"
click node_users "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/users/users.routes.ts"
click node_inventory "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/inventory/inventory.routes.ts"
click node_stockservice "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/inventory/inventory.service.ts"
click node_purchase "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/purchase-orders/purchase-orders.routes.ts"
click node_sales "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/sales-orders/sales-orders.routes.ts"
click node_orderlogic "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/_shared/orders.ts"
click node_reports "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/reports/reports.routes.ts"
click node_hooks "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/lib/webhooks.ts"
click node_webhookadmin "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/webhooks/webhooks.routes.ts"
click node_audit "https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/lib/audit.ts"

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_web,node_webapi,node_login,node_catalogui,node_ordersui,node_reportsui,node_webhookui toneBlue
class node_entry,node_routes,node_auth,node_router,node_authsvc,node_scope toneAmber
class node_companies,node_branches,node_products,node_masters,node_users toneMint
class node_inventory,node_stockservice,node_purchase,node_sales,node_orderlogic,node_db toneRose
class node_reports,node_hooks,node_webhookadmin,node_audit,node_operator,node_external toneIndigo
```

## Components

### Panel web

- [Panel de gestión](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Cliente API](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`
- [Acceso y sesión](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/LoginPage.tsx): `frontend/src/pages/LoginPage.tsx`
- [Catálogo y productos](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/ProductsPage.tsx): `frontend/src/pages/ProductsPage.tsx`
- [Órdenes y movimientos](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/OrdersPage.tsx): `frontend/src/pages/OrdersPage.tsx`
- [Panel e informes](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/ReportsPage.tsx): `frontend/src/pages/ReportsPage.tsx`
- [Gestión webhooks](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/frontend/src/pages/WebhooksPage.tsx): `frontend/src/pages/WebhooksPage.tsx`

### API y seguridad

- [Aplicación HTTP](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/app.ts): `backend/src/app.ts`
- [Registro de rutas](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/routes.ts): `backend/src/routes.ts`
- [Autenticación y roles](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/middleware/auth.ts): `backend/src/middleware/auth.ts`
- [Validación y despacho](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/lib/router.ts): `backend/src/lib/router.ts`
- [Servicio de sesión](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/auth/auth.service.ts): `backend/src/modules/auth/auth.service.ts`
- [Alcance multiempresa](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/lib/tenant.ts): `backend/src/lib/tenant.ts`

### Maestros y administración

- [Empresas y sucursales](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/companies/companies.routes.ts): `backend/src/modules/companies/companies.routes.ts`
- [Sucursales](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/branches/branches.routes.ts): `backend/src/modules/branches/branches.routes.ts`
- [Productos y catálogo](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/products/products.routes.ts): `backend/src/modules/products/products.routes.ts`
- [Maestros comerciales](https://github.com/raulperezs/sistema-inventario/tree/claude/wizardly-brown-wgusp6/backend/src/modules): `backend/src/modules`
- [Usuarios y API keys](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/users/users.routes.ts): `backend/src/modules/users/users.routes.ts`

### Inventario y órdenes

- [Stock y kardex](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/inventory/inventory.routes.ts): `backend/src/modules/inventory/inventory.routes.ts`
- [Motor de stock](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/inventory/inventory.service.ts): `backend/src/modules/inventory/inventory.service.ts`
- [Órdenes de compra](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/purchase-orders/purchase-orders.routes.ts): `backend/src/modules/purchase-orders/purchase-orders.routes.ts`
- [Órdenes de venta](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/sales-orders/sales-orders.routes.ts): `backend/src/modules/sales-orders/sales-orders.routes.ts`
- [Reglas compartidas](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/_shared/orders.ts): `backend/src/modules/_shared/orders.ts`
- **PostgreSQL**

### Reportes e integraciones

- [Informes y KPIs](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/reports/reports.routes.ts): `backend/src/modules/reports/reports.routes.ts`
- [Despacho de webhooks](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/lib/webhooks.ts): `backend/src/lib/webhooks.ts`
- [Configuración webhooks](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/modules/webhooks/webhooks.routes.ts): `backend/src/modules/webhooks/webhooks.routes.ts`
- [Bitácora de auditoría](https://github.com/raulperezs/sistema-inventario/blob/claude/wizardly-brown-wgusp6/backend/src/lib/audit.ts): `backend/src/lib/audit.ts`

### Other components

- **Usuario / sistema**
- **Sistemas integrados**

## Connections

- Usuario / sistema → Panel de gestión: usa panel
- Usuario / sistema → Cliente API: consume API (evidence: `README.md`)
- Panel de gestión → Cliente API: solicita datos (evidence: `README.md`)
- Cliente API → Aplicación HTTP: envía HTTP (evidence: `README.md`)
- Aplicación HTTP → Registro de rutas: registra rutas (evidence: `backend/src/routes.ts`)
- Registro de rutas → Validación y despacho: despacha (evidence: `backend/src/routes.ts`)
- Validación y despacho → Autenticación y roles: aplica guards (evidence: `backend/src/lib/router.ts`)
- Validación y despacho → Servicio de sesión: invoca sesión
- Autenticación y roles → Alcance multiempresa: define alcance
- Cliente API → Servicio de sesión: inicia sesión (evidence: `README.md`)
- Catálogo y productos → Cliente API: consulta catálogo (evidence: `README.md`)
- Órdenes y movimientos → Cliente API: opera órdenes (evidence: `README.md`)
- Panel e informes → Cliente API: consulta informes (evidence: `README.md`)
- Gestión webhooks → Cliente API: administra hooks (evidence: `frontend/src/pages/WebhooksPage.tsx`)
- Productos y catálogo → Alcance multiempresa: filtra empresa (evidence: `backend/src/modules/products/products.routes.ts`)
- Productos y catálogo → PostgreSQL: lee y escribe
- Maestros comerciales → PostgreSQL: gestiona maestros (evidence: `README.md`)
- Empresas y sucursales → PostgreSQL: persiste empresas (evidence: `README.md`)
- Sucursales → PostgreSQL: persiste sucursales (evidence: `README.md`)
- Usuarios y API keys → PostgreSQL: persiste usuarios (evidence: `README.md`)
- Stock y kardex → Motor de stock: aplica cambios (evidence: `backend/src/modules/inventory/inventory.routes.ts`)
- Motor de stock → PostgreSQL: actualiza stock
- Órdenes de compra → Motor de stock: usa transacción (evidence: `backend/src/modules/purchase-orders/purchase-orders.routes.ts`)
- Órdenes de compra → Reglas compartidas: valida órdenes (evidence: `backend/src/modules/purchase-orders/purchase-orders.routes.ts`)
- Órdenes de compra → PostgreSQL: lee y persiste
- Órdenes de venta → Motor de stock: reserva stock (evidence: `backend/src/modules/sales-orders/sales-orders.routes.ts`)
- Órdenes de venta → Reglas compartidas: valida estados (evidence: `backend/src/modules/sales-orders/sales-orders.routes.ts`)
- Órdenes de venta → PostgreSQL: lee y persiste
- Stock y kardex → PostgreSQL: lee movimientos
- Informes y KPIs → Alcance multiempresa: limita consultas (evidence: `backend/src/modules/reports/reports.routes.ts`)
- Informes y KPIs → PostgreSQL: consulta indicadores
- Stock y kardex → Despacho de webhooks: emite eventos (evidence: `backend/src/modules/inventory/inventory.routes.ts`)
- Productos y catálogo → Despacho de webhooks: emite cambios (evidence: `backend/src/modules/products/products.routes.ts`)
- Órdenes de compra → Despacho de webhooks: emite estados (evidence: `backend/src/modules/purchase-orders/purchase-orders.routes.ts`)
- Órdenes de venta → Despacho de webhooks: emite estados (evidence: `backend/src/modules/sales-orders/sales-orders.routes.ts`)
- Configuración webhooks → Despacho de webhooks: gestiona entregas (evidence: `backend/src/modules/webhooks/webhooks.routes.ts`)
- Despacho de webhooks → Sistemas integrados: envía notificaciones (evidence: `README.md`)
- Stock y kardex → Bitácora de auditoría: registra actividad (evidence: `backend/src/modules/inventory/inventory.routes.ts`)
- Productos y catálogo → Bitácora de auditoría: registra actividad (evidence: `backend/src/modules/products/products.routes.ts`)
- Bitácora de auditoría → PostgreSQL: guarda bitácora (evidence: `backend/src/lib/audit.ts`)
