# thornywinner/sistema-erp architecture

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

- Interactive diagram: https://gitdiagram.com/thornywinner/sistema-erp
- Repository: https://github.com/thornywinner/sistema-erp

## Overview

This is a React ERP for an industrial-uniforms business. Staff sign in, work through role-specific inventory, sales, production, finance, and workforce modules, while customers can use public order-tracking and sizing pages. The principal flow is order creation and payment, followed by workshop progress and delivery; the shared data context and Supabase form the internal data layer. README capabilities guide the unsampled branches; their internal calls are not asserted where source evidence was unavailable.

Main entry points: [`src/app/lib/supabase.ts`](https://github.com/thornywinner/sistema-erp/blob/main/src/app/lib/supabase.ts) (Supabase services), [`src/app/routes.tsx`](https://github.com/thornywinner/sistema-erp/blob/main/src/app/routes.tsx) (Route map), [`src/app/components/NuevaOrdenMultiProducto.tsx`](https://github.com/thornywinner/sistema-erp/blob/main/src/app/components/NuevaOrdenMultiProducto.tsx) (Orders and sales), [`src/app/context/ErpDataContext.tsx`](https://github.com/thornywinner/sistema-erp/blob/main/src/app/context/ErpDataContext.tsx) (ERP data context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and navigation"]
  node_router["Route map<br/>[routes.tsx]"]
  node_auth["Authentication<br/>[AuthContext.tsx]"]
  node_permissions["Role permissions<br/>[permissions.ts]"]
  node_layout["ERP workspace<br/>[RootLayout.tsx]"]
  node_dashboard["Role dashboards"]
  node_erpdata["ERP data context<br/>[ErpDataContext.tsx]"]
  node_supabase[("Supabase services<br/>[supabase.ts]")]
end

subgraph group_commerce["Sales and inventory"]
  node_inventory["Materials and products"]
  node_orders["Orders and sales"]
  node_crm["Customer CRM<br/>[clientesCrm.ts]"]
  node_quotes["Quotes and pricing<br/>[Cotizaciones.tsx]"]
  node_collections["Payments and collections<br/>[Cobranza.tsx]"]
  node_returns["Returns<br/>[Devoluciones.tsx]"]
end

subgraph group_operations["Production operations"]
  node_workshops["Workshop Kanban"]
  node_tracking["Production tracking<br/>[AvancePedidos.tsx]"]
  node_publictracking["Public order tracking"]
  node_sizing["Customer sizing<br/>[CapturaTallas.tsx]"]
  node_suppliers["Supplier management<br/>[Proveedores.tsx]"]
end

subgraph group_admin["Finance and workforce"]
  node_invoicing["Invoicing and CFDI"]
  node_reports["Reports and commissions<br/>[Reportes.tsx]"]
  node_workforce["Attendance and leave<br/>[Vacaciones.tsx]"]
  node_fixedassets["Fixed assets<br/>[ActivoFijo.tsx]"]
  node_notifications["Notifications"]
end

node_staff(("Staff user"))
node_customer(("Customer"))

node_staff -->|"opens app"| node_router
node_customer -->|"opens public pages"| node_router
node_router -->|"renders workspace"| node_layout
node_router -->|"routes to"| node_publictracking
node_router -->|"routes to"| node_sizing
node_router -->|"routes to"| node_dashboard
node_auth -->|"authenticates with"| node_supabase
node_layout -.->|"checks access"| node_permissions
node_layout -.->|"hosts pages"| node_dashboard
node_erpdata -->|"loads and writes"| node_supabase
node_orders -->|"reads and updates"| node_erpdata
node_orders -->|"uses customer history"| node_crm
node_orders -.->|"records payments"| node_collections
node_orders -.->|"queues production"| node_workshops
node_inventory -.->|"uses shared data"| node_erpdata
node_workshops -.->|"reports progress"| node_tracking
node_publictracking -.->|"reads public status"| node_supabase
node_sizing -.->|"saves sizing"| node_supabase
node_suppliers -.->|"supports replenishment"| node_inventory
node_returns -.->|"affects balances"| node_collections
node_invoicing -->|"uses backend"| node_supabase
node_workforce -.->|"uses backend"| node_supabase
node_fixedassets -.->|"uses backend"| node_supabase
node_notifications -.->|"uses backend"| node_supabase
node_quotes -.->|"supports order sales"| node_orders
node_reports -.->|"uses business data"| node_erpdata

click node_router "https://github.com/thornywinner/sistema-erp/blob/main/src/app/routes.tsx"
click node_auth "https://github.com/thornywinner/sistema-erp/blob/main/src/app/context/AuthContext.tsx"
click node_permissions "https://github.com/thornywinner/sistema-erp/blob/main/src/app/utils/permissions.ts"
click node_layout "https://github.com/thornywinner/sistema-erp/blob/main/src/app/layouts/RootLayout.tsx"
click node_dashboard "https://github.com/thornywinner/sistema-erp/tree/main/src/app/components/dashboard"
click node_erpdata "https://github.com/thornywinner/sistema-erp/blob/main/src/app/context/ErpDataContext.tsx"
click node_supabase "https://github.com/thornywinner/sistema-erp/blob/main/src/app/lib/supabase.ts"
click node_inventory "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/InventarioMateriales.tsx"
click node_orders "https://github.com/thornywinner/sistema-erp/blob/main/src/app/components/NuevaOrdenMultiProducto.tsx"
click node_crm "https://github.com/thornywinner/sistema-erp/blob/main/src/app/lib/clientesCrm.ts"
click node_quotes "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Cotizaciones.tsx"
click node_collections "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Cobranza.tsx"
click node_returns "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Devoluciones.tsx"
click node_workshops "https://github.com/thornywinner/sistema-erp/tree/main/src/app/pages/talleres"
click node_tracking "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/AvancePedidos.tsx"
click node_publictracking "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/publico/SeguimientoPedido.tsx"
click node_sizing "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/publico/CapturaTallas.tsx"
click node_suppliers "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Proveedores.tsx"
click node_invoicing "https://github.com/thornywinner/sistema-erp/tree/main/src/app/pages/facturacion"
click node_reports "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Reportes.tsx"
click node_workforce "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Vacaciones.tsx"
click node_fixedassets "https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/ActivoFijo.tsx"
click node_notifications "https://github.com/thornywinner/sistema-erp/tree/main/src/app/components/notificaciones"

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_router,node_auth,node_permissions,node_layout,node_dashboard,node_erpdata,node_supabase,node_staff toneBlue
class node_inventory,node_orders,node_crm,node_quotes,node_collections,node_returns toneAmber
class node_workshops,node_tracking,node_publictracking,node_sizing,node_suppliers toneMint
class node_invoicing,node_reports,node_workforce,node_fixedassets,node_notifications toneRose
class node_customer toneIndigo
```

## Components

### Access and navigation

- [Route map](https://github.com/thornywinner/sistema-erp/blob/main/src/app/routes.tsx): `src/app/routes.tsx`
- [Authentication](https://github.com/thornywinner/sistema-erp/blob/main/src/app/context/AuthContext.tsx): `src/app/context/AuthContext.tsx`
- [Role permissions](https://github.com/thornywinner/sistema-erp/blob/main/src/app/utils/permissions.ts): `src/app/utils/permissions.ts`
- [ERP workspace](https://github.com/thornywinner/sistema-erp/blob/main/src/app/layouts/RootLayout.tsx): `src/app/layouts/RootLayout.tsx`
- [Role dashboards](https://github.com/thornywinner/sistema-erp/tree/main/src/app/components/dashboard): `src/app/components/dashboard`
- [ERP data context](https://github.com/thornywinner/sistema-erp/blob/main/src/app/context/ErpDataContext.tsx): `src/app/context/ErpDataContext.tsx`
- [Supabase services](https://github.com/thornywinner/sistema-erp/blob/main/src/app/lib/supabase.ts): `src/app/lib/supabase.ts`

### Sales and inventory

- [Materials and products](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/InventarioMateriales.tsx): `src/app/pages/InventarioMateriales.tsx`
- [Orders and sales](https://github.com/thornywinner/sistema-erp/blob/main/src/app/components/NuevaOrdenMultiProducto.tsx): `src/app/components/NuevaOrdenMultiProducto.tsx`
- [Customer CRM](https://github.com/thornywinner/sistema-erp/blob/main/src/app/lib/clientesCrm.ts): `src/app/lib/clientesCrm.ts`
- [Quotes and pricing](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Cotizaciones.tsx): `src/app/pages/Cotizaciones.tsx`
- [Payments and collections](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Cobranza.tsx): `src/app/pages/Cobranza.tsx`
- [Returns](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Devoluciones.tsx): `src/app/pages/Devoluciones.tsx`

### Production operations

- [Workshop Kanban](https://github.com/thornywinner/sistema-erp/tree/main/src/app/pages/talleres): `src/app/pages/talleres`
- [Production tracking](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/AvancePedidos.tsx): `src/app/pages/AvancePedidos.tsx`
- [Public order tracking](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/publico/SeguimientoPedido.tsx): `src/app/pages/publico/SeguimientoPedido.tsx`
- [Customer sizing](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/publico/CapturaTallas.tsx): `src/app/pages/publico/CapturaTallas.tsx`
- [Supplier management](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Proveedores.tsx): `src/app/pages/Proveedores.tsx`

### Finance and workforce

- [Invoicing and CFDI](https://github.com/thornywinner/sistema-erp/tree/main/src/app/pages/facturacion): `src/app/pages/facturacion`
- [Reports and commissions](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Reportes.tsx): `src/app/pages/Reportes.tsx`
- [Attendance and leave](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/Vacaciones.tsx): `src/app/pages/Vacaciones.tsx`
- [Fixed assets](https://github.com/thornywinner/sistema-erp/blob/main/src/app/pages/ActivoFijo.tsx): `src/app/pages/ActivoFijo.tsx`
- [Notifications](https://github.com/thornywinner/sistema-erp/tree/main/src/app/components/notificaciones): `src/app/components/notificaciones`

### Other components

- **Staff user**
- **Customer**

## Connections

- Staff user → Route map: opens app (evidence: `src/app/routes.tsx`)
- Customer → Route map: opens public pages (evidence: `src/app/routes.tsx`)
- Route map → ERP workspace: renders workspace (evidence: `src/app/routes.tsx`)
- Route map → Public order tracking: routes to (evidence: `src/app/routes.tsx`)
- Route map → Customer sizing: routes to (evidence: `src/app/routes.tsx`)
- Route map → Role dashboards: routes to (evidence: `src/app/routes.tsx`)
- Authentication → Supabase services: authenticates with (evidence: `src/app/context/AuthContext.tsx`)
- ERP workspace → Role permissions: checks access
- ERP workspace → Role dashboards: hosts pages
- ERP data context → Supabase services: loads and writes (evidence: `src/app/context/ErpDataContext.tsx`)
- Orders and sales → ERP data context: reads and updates (evidence: `src/app/components/NuevaOrdenMultiProducto.tsx`)
- Orders and sales → Customer CRM: uses customer history (evidence: `src/app/lib/clientesCrm.ts`)
- Orders and sales → Payments and collections: records payments
- Orders and sales → Workshop Kanban: queues production
- Materials and products → ERP data context: uses shared data
- Workshop Kanban → Production tracking: reports progress
- Public order tracking → Supabase services: reads public status
- Customer sizing → Supabase services: saves sizing
- Supplier management → Materials and products: supports replenishment
- Returns → Payments and collections: affects balances
- Invoicing and CFDI → Supabase services: uses backend (evidence: `src/app/pages/facturacion/FacturaForm.tsx`)
- Attendance and leave → Supabase services: uses backend
- Fixed assets → Supabase services: uses backend
- Notifications → Supabase services: uses backend
- Quotes and pricing → Orders and sales: supports order sales
- Reports and commissions → ERP data context: uses business data
