# rey1332/etna-iap architecture

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

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

## Overview

ETNA is an enterprise data and intelligence platform with a unified PostgreSQL foundation and a domain application layer historically housed under `src/app/erp`. The principal workflow is a signed-in user’s request passing through a Next.js API route, session and workspace checks, and a server-side database transaction; consumers include ERP modules, analytics, workflows, and ontology search. The README documents the major capabilities and request path. Sampled source confirms selected auth and database-layer calls; links for unsampled subsystems rely on README statements.

Main entry points: [`src/app/api`](https://github.com/rey1332/etna-iap/tree/main/src/app/api) (API routes), [`src/app/admin`](https://github.com/rey1332/etna-iap/tree/main/src/app/admin) (Platform admin), [`src/app/erp`](https://github.com/rey1332/etna-iap/tree/main/src/app/erp) (ERP modules), [`src/lib/ontology/query.ts`](https://github.com/rey1332/etna-iap/blob/main/src/lib/ontology/query.ts) (Ontology search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Access and administration"]
  node_admin_ui["Platform admin"]
  node_auth_routes["Auth routes<br/>[route.ts]"]
  node_auth_request["Session identity<br/>[request.ts]"]
  node_auth_service["Authentication service<br/>[service.ts]"]
  node_workspace_rules["Workspace rules<br/>[erpRules.ts]"]
  node_admin_service["Admin services<br/>[service.ts]"]
end

subgraph group_foundation["Data foundation"]
  node_api["API routes"]
  node_route_client["Request database client<br/>[route-client.ts]"]
  node_db_execute["Request executor<br/>[execute.ts]"]
  node_db_pool["PostgreSQL executor<br/>[executor.ts]"]
  node_postgres[("PostgreSQL")]
end

subgraph group_domain["Domain applications"]
  node_erp_ui["ERP modules"]
  node_documents["Document storage<br/>[service.ts]"]
end

subgraph group_intelligence["Intelligence and automation"]
  node_ontology_search["Ontology search<br/>[query.ts]"]
  node_ontology_registry["Ontology registry<br/>[registry.ts]"]
  node_analytics["Analytics catalog<br/>[catalog.ts]"]
  node_workflows["Visual workflows<br/>[runtime.ts]"]
  node_workflow_api["Workflow API"]
end

subgraph group_integration["Data integration"]
  node_sync["Workspace sync<br/>[syncService.ts]"]
  node_transfer["Encrypted data transfer<br/>[transfer.mjs]"]
end

node_user(("Signed-in user"))
node_external_sources(("External enterprise systems"))

node_user -->|"uses"| node_erp_ui
node_user -->|"manages"| node_admin_ui
node_erp_ui -->|"requests"| node_api
node_admin_ui -->|"requests"| node_api
node_api -->|"resolves session"| node_auth_request
node_auth_request -->|"resolves session"| node_auth_service
node_auth_routes -->|"handles authentication"| node_auth_service
node_api -->|"opens data access"| node_route_client
node_route_client -->|"executes requests"| node_db_execute
node_db_execute -->|"runs transaction"| node_db_pool
node_db_pool -->|"queries"| node_postgres
node_api -->|"checks roles"| node_workspace_rules
node_admin_ui -->|"administers platform"| node_admin_service
node_erp_ui -->|"reads and writes"| node_postgres
node_postgres -->|"stores mapped entities"| node_ontology_registry
node_ontology_search -->|"uses registry"| node_ontology_registry
node_ontology_search -->|"searches records"| node_api
node_analytics -->|"analyzes data"| node_postgres
node_workflows -->|"uses catalog"| node_analytics
node_workflow_api -->|"runs workflows"| node_workflows
node_documents -->|"stores metadata"| node_postgres
node_sync -->|"synchronizes workspace data"| node_postgres
node_transfer -->|"imports and exports"| node_postgres
node_external_sources -.->|"planned connectors"| node_api

click node_erp_ui "https://github.com/rey1332/etna-iap/tree/main/src/app/erp"
click node_admin_ui "https://github.com/rey1332/etna-iap/tree/main/src/app/admin"
click node_api "https://github.com/rey1332/etna-iap/tree/main/src/app/api"
click node_auth_routes "https://github.com/rey1332/etna-iap/blob/main/src/app/api/auth/%5Baction%5D/route.ts"
click node_auth_request "https://github.com/rey1332/etna-iap/blob/main/src/server/auth/request.ts"
click node_auth_service "https://github.com/rey1332/etna-iap/blob/main/src/server/auth/service.ts"
click node_workspace_rules "https://github.com/rey1332/etna-iap/blob/main/src/app/erp/lib/erpRules.ts"
click node_admin_service "https://github.com/rey1332/etna-iap/blob/main/src/server/admin/service.ts"
click node_route_client "https://github.com/rey1332/etna-iap/blob/main/src/server/db/route-client.ts"
click node_db_execute "https://github.com/rey1332/etna-iap/blob/main/src/server/db/execute.ts"
click node_db_pool "https://github.com/rey1332/etna-iap/blob/main/src/server/db/executor.ts"
click node_ontology_search "https://github.com/rey1332/etna-iap/blob/main/src/lib/ontology/query.ts"
click node_ontology_registry "https://github.com/rey1332/etna-iap/blob/main/src/lib/ontology/registry.ts"
click node_analytics "https://github.com/rey1332/etna-iap/blob/main/src/lib/analytics/catalog.ts"
click node_workflows "https://github.com/rey1332/etna-iap/blob/main/src/lib/workflow/runtime.ts"
click node_workflow_api "https://github.com/rey1332/etna-iap/tree/main/src/app/api/erp/workflows"
click node_documents "https://github.com/rey1332/etna-iap/blob/main/src/server/documents/service.ts"
click node_sync "https://github.com/rey1332/etna-iap/blob/main/src/app/erp/lib/syncService.ts"
click node_transfer "https://github.com/rey1332/etna-iap/blob/main/scripts/db/transfer.mjs"

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_admin_ui,node_auth_routes,node_auth_request,node_auth_service,node_workspace_rules,node_admin_service,node_user toneBlue
class node_api,node_route_client,node_db_execute,node_db_pool,node_postgres toneAmber
class node_erp_ui,node_documents toneMint
class node_ontology_search,node_ontology_registry,node_analytics,node_workflows,node_workflow_api toneRose
class node_sync,node_transfer,node_external_sources toneIndigo
```

## Components

### Access and administration

- [Platform admin](https://github.com/rey1332/etna-iap/tree/main/src/app/admin): `src/app/admin`
- [Auth routes](https://github.com/rey1332/etna-iap/blob/main/src/app/api/auth/%5Baction%5D/route.ts): `src/app/api/auth/[action]/route.ts`
- [Session identity](https://github.com/rey1332/etna-iap/blob/main/src/server/auth/request.ts): `src/server/auth/request.ts`
- [Authentication service](https://github.com/rey1332/etna-iap/blob/main/src/server/auth/service.ts): `src/server/auth/service.ts`
- [Workspace rules](https://github.com/rey1332/etna-iap/blob/main/src/app/erp/lib/erpRules.ts): `src/app/erp/lib/erpRules.ts`
- [Admin services](https://github.com/rey1332/etna-iap/blob/main/src/server/admin/service.ts): `src/server/admin/service.ts`

### Data foundation

- [API routes](https://github.com/rey1332/etna-iap/tree/main/src/app/api): `src/app/api`
- [Request database client](https://github.com/rey1332/etna-iap/blob/main/src/server/db/route-client.ts): `src/server/db/route-client.ts`
- [Request executor](https://github.com/rey1332/etna-iap/blob/main/src/server/db/execute.ts): `src/server/db/execute.ts`
- [PostgreSQL executor](https://github.com/rey1332/etna-iap/blob/main/src/server/db/executor.ts): `src/server/db/executor.ts`
- **PostgreSQL**

### Domain applications

- [ERP modules](https://github.com/rey1332/etna-iap/tree/main/src/app/erp): `src/app/erp`
- [Document storage](https://github.com/rey1332/etna-iap/blob/main/src/server/documents/service.ts): `src/server/documents/service.ts`

### Intelligence and automation

- [Ontology search](https://github.com/rey1332/etna-iap/blob/main/src/lib/ontology/query.ts): `src/lib/ontology/query.ts`
- [Ontology registry](https://github.com/rey1332/etna-iap/blob/main/src/lib/ontology/registry.ts): `src/lib/ontology/registry.ts`
- [Analytics catalog](https://github.com/rey1332/etna-iap/blob/main/src/lib/analytics/catalog.ts): `src/lib/analytics/catalog.ts`
- [Visual workflows](https://github.com/rey1332/etna-iap/blob/main/src/lib/workflow/runtime.ts): `src/lib/workflow/runtime.ts`
- [Workflow API](https://github.com/rey1332/etna-iap/tree/main/src/app/api/erp/workflows): `src/app/api/erp/workflows`

### Data integration

- [Workspace sync](https://github.com/rey1332/etna-iap/blob/main/src/app/erp/lib/syncService.ts): `src/app/erp/lib/syncService.ts`
- [Encrypted data transfer](https://github.com/rey1332/etna-iap/blob/main/scripts/db/transfer.mjs): `scripts/db/transfer.mjs`

### Other components

- **Signed-in user**
- **External enterprise systems**

## Connections

- Signed-in user → ERP modules: uses
- Signed-in user → Platform admin: manages
- ERP modules → API routes: requests (evidence: `src/app/api/erp/workspace/route.ts`)
- Platform admin → API routes: requests
- API routes → Session identity: resolves session (evidence: `src/app/api/auth/[action]/route.ts`)
- Session identity → Authentication service: resolves session (evidence: `src/server/auth/request.ts`)
- Auth routes → Authentication service: handles authentication (evidence: `src/app/api/auth/[action]/route.ts`)
- API routes → Request database client: opens data access (evidence: `src/app/api/erp/workspace/route.ts`)
- Request database client → Request executor: executes requests (evidence: `src/server/db/route-client.ts`)
- Request executor → PostgreSQL executor: runs transaction (evidence: `src/server/db/execute.ts`)
- PostgreSQL executor → PostgreSQL: queries (evidence: `src/server/db/executor.ts`)
- API routes → Workspace rules: checks roles (evidence: `src/app/api/erp/workspace/route.ts`)
- Platform admin → Admin services: administers platform
- ERP modules → PostgreSQL: reads and writes
- PostgreSQL → Ontology registry: stores mapped entities
- Ontology search → Ontology registry: uses registry (evidence: `src/lib/ontology/query.ts`)
- Ontology search → API routes: searches records
- Analytics catalog → PostgreSQL: analyzes data
- Visual workflows → Analytics catalog: uses catalog (evidence: `src/lib/workflow/storage.ts`)
- Workflow API → Visual workflows: runs workflows (evidence: `src/app/api/erp/workflows/route.ts`)
- Document storage → PostgreSQL: stores metadata (evidence: `src/server/documents/service.ts`)
- Workspace sync → PostgreSQL: synchronizes workspace data
- Encrypted data transfer → PostgreSQL: imports and exports
- External enterprise systems → API routes: planned connectors
