# rey1332/etn architecture

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

- Interactive diagram: https://gitdiagram.com/rey1332/etn
- Repository: https://github.com/rey1332/etn

## Overview

Etna is a browser-based ERP with a Next.js API and a PostgreSQL-backed server. Its principal workflow is users working in ERP modules, with workflow editing and execution exposed through workflow APIs and a server-side runtime. Other substantial capabilities include accounting and analytics, ontology search, workspace and role management, authentication, documents, currency, backup, and sync. The tree and source index establish these domains; only sampled excerpts and indexed references are used for edges, so unsampled UI-to-API relationships are not asserted.

Main entry points: [`src/server/db/execute.ts`](https://github.com/rey1332/etn/blob/main/src/server/db/execute.ts) (Query Execution), [`src/server/db/route-client.ts`](https://github.com/rey1332/etn/blob/main/src/server/db/route-client.ts) (Route Client), [`src/app/api/erp/workflows/route.ts`](https://github.com/rey1332/etn/blob/main/src/app/api/erp/workflows/route.ts) (Workflow Routes), [`src/server/db/executor.ts`](https://github.com/rey1332/etn/blob/main/src/server/db/executor.ts) (PostgreSQL Executor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_erp["ERP Workspace"]
  node_erp_ui["ERP Modules"]
  node_workspace_ui["Workspace Settings<br/>[WorkspacePanel.tsx]"]
end

subgraph group_workflows["Workflow Automation"]
  node_workflow_ui["Workflow Editor<br/>[page.tsx]"]
  node_workflow_client["Workflow API Client<br/>[storage.ts]"]
  node_workflow_api["Workflow Routes<br/>[route.ts]"]
  node_workflow_runtime["Workflow Runtime<br/>[runtime.ts]"]
  node_workflow_executor["Workflow Executor<br/>[executor.ts]"]
end

subgraph group_domain["Business Domains"]
  node_analytics["Analytics"]
  node_ontology["Ontology Search<br/>[service.ts]"]
  node_business_rules["ERP Rules<br/>[erpRules.ts]"]
  node_documents["Documents<br/>[service.ts]"]
  node_currency["Currency<br/>[service.ts]"]
end

subgraph group_server["Server Services"]
  node_workspace_api["Workspace API<br/>[route.ts]"]
  node_auth_api["Authentication API<br/>[route.ts]"]
  node_auth_service["Authentication Service<br/>[service.ts]"]
  node_backup["Backup<br/>[backup.ts]"]
  node_sync["Data Sync<br/>[syncService.ts]"]
end

subgraph group_platform["Data Platform"]
  node_route_client["Route Client<br/>[route-client.ts]"]
  node_db_api["Data API<br/>[route.ts]"]
  node_db_execution["Query Execution<br/>[execute.ts]"]
  node_db_executor["PostgreSQL Executor<br/>[executor.ts]"]
end

node_user(("ERP User"))
node_postgres[("PostgreSQL")]

node_workflow_client -->|"calls workflow endpoints"| node_workflow_api
node_workflow_api -.->|"runs workflows"| node_workflow_runtime
node_workflow_api -.->|"uses route client"| node_route_client
node_workflow_runtime -.->|"delegates execution"| node_workflow_executor
node_workspace_api -->|"creates client"| node_route_client
node_workspace_api -->|"checks roles"| node_business_rules
node_auth_api -->|"handles auth actions"| node_auth_service
node_auth_service -->|"runs transactions"| node_db_executor
node_route_client -->|"executes requests"| node_db_execution
node_db_execution -->|"queries transactions"| node_db_executor
node_db_executor -->|"connects to"| node_postgres
node_db_api -->|"executes data requests"| node_db_execution
node_documents -->|"queries records"| node_db_execution
node_documents -.->|"stores document files"| node_postgres
node_analytics -->|"uses ERP definitions"| node_business_rules
node_analytics -->|"queries through client"| node_route_client
node_ontology -->|"uses ERP definitions"| node_business_rules
node_ontology -->|"executes queries"| node_db_execution
node_currency -->|"queries records"| node_db_execution
node_currency -.->|"fetches exchange rates"| node_postgres
node_user -.->|"uses modules"| node_erp_ui
node_user -.->|"edits workflows"| node_workflow_ui

click node_erp_ui "https://github.com/rey1332/etn/tree/main/src/app/erp"
click node_workspace_ui "https://github.com/rey1332/etn/blob/main/src/app/erp/components/WorkspacePanel.tsx"
click node_workflow_ui "https://github.com/rey1332/etn/blob/main/src/app/erp/workflows/page.tsx"
click node_workflow_client "https://github.com/rey1332/etn/blob/main/src/lib/workflow/storage.ts"
click node_workflow_api "https://github.com/rey1332/etn/blob/main/src/app/api/erp/workflows/route.ts"
click node_workflow_runtime "https://github.com/rey1332/etn/blob/main/src/lib/workflow/runtime.ts"
click node_workflow_executor "https://github.com/rey1332/etn/blob/main/src/lib/workflow/executor.ts"
click node_analytics "https://github.com/rey1332/etn/tree/main/src/lib/analytics"
click node_ontology "https://github.com/rey1332/etn/blob/main/src/server/ontology/service.ts"
click node_business_rules "https://github.com/rey1332/etn/blob/main/src/app/erp/lib/erpRules.ts"
click node_documents "https://github.com/rey1332/etn/blob/main/src/server/documents/service.ts"
click node_currency "https://github.com/rey1332/etn/blob/main/src/server/currency/service.ts"
click node_workspace_api "https://github.com/rey1332/etn/blob/main/src/app/api/erp/workspace/route.ts"
click node_auth_api "https://github.com/rey1332/etn/blob/main/src/app/api/auth/%5Baction%5D/route.ts"
click node_auth_service "https://github.com/rey1332/etn/blob/main/src/server/auth/service.ts"
click node_backup "https://github.com/rey1332/etn/blob/main/src/server/backup.ts"
click node_sync "https://github.com/rey1332/etn/blob/main/src/app/erp/lib/syncService.ts"
click node_route_client "https://github.com/rey1332/etn/blob/main/src/server/db/route-client.ts"
click node_db_api "https://github.com/rey1332/etn/blob/main/src/app/api/data/route.ts"
click node_db_execution "https://github.com/rey1332/etn/blob/main/src/server/db/execute.ts"
click node_db_executor "https://github.com/rey1332/etn/blob/main/src/server/db/executor.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_erp_ui,node_workspace_ui,node_user toneBlue
class node_workflow_ui,node_workflow_client,node_workflow_api,node_workflow_runtime,node_workflow_executor,node_postgres toneAmber
class node_analytics,node_ontology,node_business_rules,node_documents,node_currency toneMint
class node_workspace_api,node_auth_api,node_auth_service,node_backup,node_sync toneRose
class node_route_client,node_db_api,node_db_execution,node_db_executor toneIndigo
```

## Components

### ERP Workspace

- [ERP Modules](https://github.com/rey1332/etn/tree/main/src/app/erp): `src/app/erp`
- [Workspace Settings](https://github.com/rey1332/etn/blob/main/src/app/erp/components/WorkspacePanel.tsx): `src/app/erp/components/WorkspacePanel.tsx`

### Workflow Automation

- [Workflow Editor](https://github.com/rey1332/etn/blob/main/src/app/erp/workflows/page.tsx): `src/app/erp/workflows/page.tsx`
- [Workflow API Client](https://github.com/rey1332/etn/blob/main/src/lib/workflow/storage.ts): `src/lib/workflow/storage.ts`
- [Workflow Routes](https://github.com/rey1332/etn/blob/main/src/app/api/erp/workflows/route.ts): `src/app/api/erp/workflows/route.ts`
- [Workflow Runtime](https://github.com/rey1332/etn/blob/main/src/lib/workflow/runtime.ts): `src/lib/workflow/runtime.ts`
- [Workflow Executor](https://github.com/rey1332/etn/blob/main/src/lib/workflow/executor.ts): `src/lib/workflow/executor.ts`

### Business Domains

- [Analytics](https://github.com/rey1332/etn/tree/main/src/lib/analytics): `src/lib/analytics`
- [Ontology Search](https://github.com/rey1332/etn/blob/main/src/server/ontology/service.ts): `src/server/ontology/service.ts`
- [ERP Rules](https://github.com/rey1332/etn/blob/main/src/app/erp/lib/erpRules.ts): `src/app/erp/lib/erpRules.ts`
- [Documents](https://github.com/rey1332/etn/blob/main/src/server/documents/service.ts): `src/server/documents/service.ts`
- [Currency](https://github.com/rey1332/etn/blob/main/src/server/currency/service.ts): `src/server/currency/service.ts`

### Server Services

- [Workspace API](https://github.com/rey1332/etn/blob/main/src/app/api/erp/workspace/route.ts): `src/app/api/erp/workspace/route.ts`
- [Authentication API](https://github.com/rey1332/etn/blob/main/src/app/api/auth/%5Baction%5D/route.ts): `src/app/api/auth/[action]/route.ts`
- [Authentication Service](https://github.com/rey1332/etn/blob/main/src/server/auth/service.ts): `src/server/auth/service.ts`
- [Backup](https://github.com/rey1332/etn/blob/main/src/server/backup.ts): `src/server/backup.ts`
- [Data Sync](https://github.com/rey1332/etn/blob/main/src/app/erp/lib/syncService.ts): `src/app/erp/lib/syncService.ts`

### Data Platform

- [Route Client](https://github.com/rey1332/etn/blob/main/src/server/db/route-client.ts): `src/server/db/route-client.ts`
- [Data API](https://github.com/rey1332/etn/blob/main/src/app/api/data/route.ts): `src/app/api/data/route.ts`
- [Query Execution](https://github.com/rey1332/etn/blob/main/src/server/db/execute.ts): `src/server/db/execute.ts`
- [PostgreSQL Executor](https://github.com/rey1332/etn/blob/main/src/server/db/executor.ts): `src/server/db/executor.ts`

### Other components

- **ERP User**
- **PostgreSQL**

## Connections

- Workflow API Client → Workflow Routes: calls workflow endpoints (evidence: `src/lib/workflow/storage.ts`)
- Workflow Routes → Workflow Runtime: runs workflows
- Workflow Routes → Route Client: uses route client
- Workflow Runtime → Workflow Executor: delegates execution
- Workspace API → Route Client: creates client (evidence: `src/app/api/erp/workspace/route.ts`)
- Workspace API → ERP Rules: checks roles (evidence: `src/app/api/erp/workspace/route.ts`)
- Authentication API → Authentication Service: handles auth actions (evidence: `src/app/api/auth/[action]/route.ts`)
- Authentication Service → PostgreSQL Executor: runs transactions (evidence: `src/server/auth/service.ts`)
- Route Client → Query Execution: executes requests (evidence: `src/server/db/route-client.ts`)
- Query Execution → PostgreSQL Executor: queries transactions (evidence: `src/server/db/execute.ts`)
- PostgreSQL Executor → PostgreSQL: connects to (evidence: `src/server/db/executor.ts`)
- Data API → Query Execution: executes data requests (evidence: `src/app/api/data/route.ts`)
- Documents → Query Execution: queries records (evidence: `src/server/documents/service.ts`)
- Documents → PostgreSQL: stores document files
- Analytics → ERP Rules: uses ERP definitions (evidence: `src/lib/analytics/catalog.ts`)
- Analytics → Route Client: queries through client (evidence: `src/lib/analytics/server.ts`)
- Ontology Search → ERP Rules: uses ERP definitions (evidence: `src/server/ontology/service.ts`)
- Ontology Search → Query Execution: executes queries (evidence: `src/server/ontology/service.ts`)
- Currency → Query Execution: queries records (evidence: `src/server/currency/service.ts`)
- Currency → PostgreSQL: fetches exchange rates
- ERP User → ERP Modules: uses modules
- ERP User → Workflow Editor: edits workflows
