# juaenmc/erpsagas architecture

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

- Interactive diagram: https://gitdiagram.com/juaenmc/erpsagas
- Repository: https://github.com/juaenmc/erpsagas

## Overview

SAGAS ERP combines an Express/Prisma commerce API with a React omnichannel administration panel. The principal workflow is an administrator managing catalog and stock through the panel and API; orders are created, stock is reserved, and payment confirmation or cancellation updates that reservation. The panel also exposes analytics, channel publishing, logistics, tracking, automation, integrations, and combo management. Some screen-to-service details and unsampled route internals are not shown, so those relationships are omitted rather than inferred.

Main entry points: [`src/App.tsx`](https://github.com/juaenmc/erpsagas/blob/main/src/App.tsx) (Admin app), [`server/index.ts`](https://github.com/juaenmc/erpsagas/blob/main/server/index.ts) (REST API), [`server/db.ts`](https://github.com/juaenmc/erpsagas/blob/main/server/db.ts) (Neon PostgreSQL), [`server/routes/products.ts`](https://github.com/juaenmc/erpsagas/blob/main/server/routes/products.ts) (Products)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_panel["Admin panel"]
  node_app["Admin app<br/>[App.tsx]"]
  node_products_hook["Product data hook<br/>[useProducts.ts]"]
  node_api_client["API client<br/>[apiClient.ts]"]
  node_dashboard["Dashboard<br/>[DashboardView.tsx]"]
  node_analytics["BI analytics"]
end

subgraph group_commerce["Commerce API"]
  node_api["REST API<br/>[index.ts]"]
  node_products_route["Products<br/>[products.ts]"]
  node_orders_route["Orders and checkout<br/>[orders.ts]"]
  node_stock_route["Stock<br/>[stock.ts]"]
  node_accounts_routes["Accounts and admin<br/>[auth.ts]"]
  node_customer_routes["Cart and addresses<br/>[cart.ts]"]
  node_other_routes["Commerce extensions<br/>[agent-api.ts]"]
end

subgraph group_operations["Omnichannel operations"]
  node_publisher["Product publishing"]
  node_logistics["Logistics hub<br/>[LogisticsHub.tsx]"]
  node_tracking["Tracking hub<br/>[TrackingHub.tsx]"]
  node_integrations["Integrations hub"]
  node_smart_data["Smart data<br/>[SmartDataHub.tsx]"]
  node_automation["Automation engine"]
  node_purchases["Purchases and fashion"]
  node_combos_ui["Combo manager<br/>[CombosManager.tsx]"]
  node_combo_engine["Combo engine<br/>[combo-engine.ts]"]
  node_profit_service["Profit calculator"]
end

subgraph group_data["Persistence and contracts"]
  node_database[("Neon PostgreSQL<br/>[db.ts]")]
  node_product_dto["Product DTO<br/>[product.dto.ts]"]
end

node_admin(("Administrator"))

node_admin -->|"uses"| node_app
node_app -->|"loads products"| node_products_hook
node_app -->|"shows"| node_dashboard
node_app -->|"shows"| node_analytics
node_app -->|"shows"| node_publisher
node_app -->|"shows"| node_logistics
node_app -->|"shows"| node_tracking
node_app -->|"shows"| node_integrations
node_app -->|"shows"| node_smart_data
node_app -->|"shows"| node_automation
node_app -->|"shows"| node_purchases
node_app -->|"shows"| node_combos_ui
node_combos_ui -->|"evaluates rules"| node_combo_engine
node_products_hook -->|"requests products"| node_api_client
node_api_client -->|"sends HTTP requests"| node_api
node_api -->|"registers"| node_products_route
node_api -->|"registers"| node_orders_route
node_api -->|"registers"| node_stock_route
node_api -->|"registers"| node_accounts_routes
node_api -->|"registers"| node_customer_routes
node_api -->|"registers"| node_other_routes
node_products_route -->|"formats responses"| node_product_dto
node_products_route -->|"reads and writes"| node_database
node_stock_route -.->|"reads and writes"| node_database
node_orders_route -.->|"reserves and updates stock"| node_database
node_accounts_routes -->|"accesses records"| node_database
node_customer_routes -->|"accesses records"| node_database
node_other_routes -.->|"accesses records"| node_database

click node_app "https://github.com/juaenmc/erpsagas/blob/main/src/App.tsx"
click node_products_hook "https://github.com/juaenmc/erpsagas/blob/main/src/hooks/useProducts.ts"
click node_api_client "https://github.com/juaenmc/erpsagas/blob/main/src/services/apiClient.ts"
click node_dashboard "https://github.com/juaenmc/erpsagas/blob/main/src/components/DashboardView.tsx"
click node_analytics "https://github.com/juaenmc/erpsagas/blob/main/src/components/BiAnalyticsDashboard.tsx"
click node_publisher "https://github.com/juaenmc/erpsagas/blob/main/src/components/ProductPublisher.tsx"
click node_logistics "https://github.com/juaenmc/erpsagas/blob/main/src/components/LogisticsHub.tsx"
click node_tracking "https://github.com/juaenmc/erpsagas/blob/main/src/components/TrackingHub.tsx"
click node_integrations "https://github.com/juaenmc/erpsagas/blob/main/src/components/IntegrationsHub.tsx"
click node_smart_data "https://github.com/juaenmc/erpsagas/blob/main/src/components/SmartDataHub.tsx"
click node_automation "https://github.com/juaenmc/erpsagas/blob/main/src/components/AutomationEngineView.tsx"
click node_purchases "https://github.com/juaenmc/erpsagas/blob/main/src/components/PurchasesAndFashionView.tsx"
click node_combos_ui "https://github.com/juaenmc/erpsagas/blob/main/src/components/CombosManager.tsx"
click node_combo_engine "https://github.com/juaenmc/erpsagas/blob/main/src/logic/combo-engine.ts"
click node_profit_service "https://github.com/juaenmc/erpsagas/blob/main/src/services/ProfitCalculatorService.ts"
click node_api "https://github.com/juaenmc/erpsagas/blob/main/server/index.ts"
click node_products_route "https://github.com/juaenmc/erpsagas/blob/main/server/routes/products.ts"
click node_orders_route "https://github.com/juaenmc/erpsagas/blob/main/server/routes/orders.ts"
click node_stock_route "https://github.com/juaenmc/erpsagas/blob/main/server/routes/stock.ts"
click node_accounts_routes "https://github.com/juaenmc/erpsagas/blob/main/server/routes/auth.ts"
click node_customer_routes "https://github.com/juaenmc/erpsagas/blob/main/server/routes/cart.ts"
click node_other_routes "https://github.com/juaenmc/erpsagas/blob/main/server/routes/agent-api.ts"
click node_database "https://github.com/juaenmc/erpsagas/blob/main/server/db.ts"
click node_product_dto "https://github.com/juaenmc/erpsagas/blob/main/server/dto/product.dto.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_app,node_products_hook,node_api_client,node_dashboard,node_analytics toneBlue
class node_api,node_products_route,node_orders_route,node_stock_route,node_accounts_routes,node_customer_routes,node_other_routes toneAmber
class node_publisher,node_logistics,node_tracking,node_integrations,node_smart_data,node_automation,node_purchases,node_combos_ui,node_combo_engine,node_profit_service toneMint
class node_database,node_product_dto toneRose
class node_admin toneIndigo
```

## Components

### Admin panel

- [Admin app](https://github.com/juaenmc/erpsagas/blob/main/src/App.tsx): `src/App.tsx`
- [Product data hook](https://github.com/juaenmc/erpsagas/blob/main/src/hooks/useProducts.ts): `src/hooks/useProducts.ts`
- [API client](https://github.com/juaenmc/erpsagas/blob/main/src/services/apiClient.ts): `src/services/apiClient.ts`
- [Dashboard](https://github.com/juaenmc/erpsagas/blob/main/src/components/DashboardView.tsx): `src/components/DashboardView.tsx`
- [BI analytics](https://github.com/juaenmc/erpsagas/blob/main/src/components/BiAnalyticsDashboard.tsx): `src/components/BiAnalyticsDashboard.tsx`

### Commerce API

- [REST API](https://github.com/juaenmc/erpsagas/blob/main/server/index.ts): `server/index.ts`
- [Products](https://github.com/juaenmc/erpsagas/blob/main/server/routes/products.ts): `server/routes/products.ts`
- [Orders and checkout](https://github.com/juaenmc/erpsagas/blob/main/server/routes/orders.ts): `server/routes/orders.ts`
- [Stock](https://github.com/juaenmc/erpsagas/blob/main/server/routes/stock.ts): `server/routes/stock.ts`
- [Accounts and admin](https://github.com/juaenmc/erpsagas/blob/main/server/routes/auth.ts): `server/routes/auth.ts`
- [Cart and addresses](https://github.com/juaenmc/erpsagas/blob/main/server/routes/cart.ts): `server/routes/cart.ts`
- [Commerce extensions](https://github.com/juaenmc/erpsagas/blob/main/server/routes/agent-api.ts): `server/routes/agent-api.ts`

### Omnichannel operations

- [Product publishing](https://github.com/juaenmc/erpsagas/blob/main/src/components/ProductPublisher.tsx): `src/components/ProductPublisher.tsx`
- [Logistics hub](https://github.com/juaenmc/erpsagas/blob/main/src/components/LogisticsHub.tsx): `src/components/LogisticsHub.tsx`
- [Tracking hub](https://github.com/juaenmc/erpsagas/blob/main/src/components/TrackingHub.tsx): `src/components/TrackingHub.tsx`
- [Integrations hub](https://github.com/juaenmc/erpsagas/blob/main/src/components/IntegrationsHub.tsx): `src/components/IntegrationsHub.tsx`
- [Smart data](https://github.com/juaenmc/erpsagas/blob/main/src/components/SmartDataHub.tsx): `src/components/SmartDataHub.tsx`
- [Automation engine](https://github.com/juaenmc/erpsagas/blob/main/src/components/AutomationEngineView.tsx): `src/components/AutomationEngineView.tsx`
- [Purchases and fashion](https://github.com/juaenmc/erpsagas/blob/main/src/components/PurchasesAndFashionView.tsx): `src/components/PurchasesAndFashionView.tsx`
- [Combo manager](https://github.com/juaenmc/erpsagas/blob/main/src/components/CombosManager.tsx): `src/components/CombosManager.tsx`
- [Combo engine](https://github.com/juaenmc/erpsagas/blob/main/src/logic/combo-engine.ts): `src/logic/combo-engine.ts`
- [Profit calculator](https://github.com/juaenmc/erpsagas/blob/main/src/services/ProfitCalculatorService.ts): `src/services/ProfitCalculatorService.ts`

### Persistence and contracts

- [Neon PostgreSQL](https://github.com/juaenmc/erpsagas/blob/main/server/db.ts): `server/db.ts`
- [Product DTO](https://github.com/juaenmc/erpsagas/blob/main/server/dto/product.dto.ts): `server/dto/product.dto.ts`

### Other components

- **Administrator**

## Connections

- Administrator → Admin app: uses (evidence: `src/App.tsx`)
- Admin app → Product data hook: loads products (evidence: `src/App.tsx`)
- Admin app → Dashboard: shows (evidence: `src/App.tsx`)
- Admin app → BI analytics: shows (evidence: `src/App.tsx`)
- Admin app → Product publishing: shows (evidence: `src/App.tsx`)
- Admin app → Logistics hub: shows (evidence: `src/App.tsx`)
- Admin app → Tracking hub: shows (evidence: `src/App.tsx`)
- Admin app → Integrations hub: shows (evidence: `src/App.tsx`)
- Admin app → Smart data: shows (evidence: `src/App.tsx`)
- Admin app → Automation engine: shows (evidence: `src/App.tsx`)
- Admin app → Purchases and fashion: shows (evidence: `src/App.tsx`)
- Admin app → Combo manager: shows (evidence: `src/App.tsx`)
- Combo manager → Combo engine: evaluates rules (evidence: `src/components/CombosManager.tsx`)
- Product data hook → API client: requests products (evidence: `src/hooks/useProducts.ts`)
- API client → REST API: sends HTTP requests (evidence: `src/services/apiClient.ts`)
- REST API → Products: registers (evidence: `server/index.ts`)
- REST API → Orders and checkout: registers (evidence: `server/index.ts`)
- REST API → Stock: registers (evidence: `server/index.ts`)
- REST API → Accounts and admin: registers (evidence: `server/index.ts`)
- REST API → Cart and addresses: registers (evidence: `server/index.ts`)
- REST API → Commerce extensions: registers (evidence: `server/index.ts`)
- Products → Product DTO: formats responses (evidence: `server/routes/products.ts`)
- Products → Neon PostgreSQL: reads and writes (evidence: `server/routes/products.ts`)
- Stock → Neon PostgreSQL: reads and writes
- Orders and checkout → Neon PostgreSQL: reserves and updates stock (evidence: `README.md`)
- Accounts and admin → Neon PostgreSQL: accesses records (evidence: `server/routes/auth.ts`)
- Cart and addresses → Neon PostgreSQL: accesses records (evidence: `server/routes/cart.ts`)
- Commerce extensions → Neon PostgreSQL: accesses records
