# yap2203/tracechain architecture

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

- Interactive diagram: https://gitdiagram.com/yap2203/tracechain
- Repository: https://github.com/yap2203/tracechain

## Overview

TraceChain is a supply-chain traceability platform for company onboarding, ingredient and product provenance, evidence exchange, custody transfers, and order logistics. Users enter through a wallet-authenticated web application and role-specific workspaces; the API coordinates authorization, workflow services, blockchain reads, and SSI credentials. The README also documents paginated order views, product history, and multi-provider RPC resilience. Some subsystem wiring is unsampled, so uncertain links are omitted rather than inferred; dashed links mark unverified web-to-API integration.

Main entry points: [`apps/api/src/app.ts`](https://github.com/yap2203/tracechain/blob/main/apps/api/src/app.ts) (HTTP API), [`apps/web/src/App.tsx`](https://github.com/yap2203/tracechain/blob/main/apps/web/src/App.tsx) (Web routes), [`apps/api/src/modules/auth/auth.service.ts`](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/auth/auth.service.ts) (Session authorization), [`apps/api/src/modules/blockchain/blockchain-gateway.service.ts`](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/blockchain/blockchain-gateway.service.ts) (Blockchain gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_webapp["Web routes<br/>[App.tsx]"]
  node_wallet["Wallet login"]
  node_workspaces["Role workspaces<br/>[WorkspaceApp.tsx]"]
  node_trace_ui["Traceability views"]
  node_orders_ui["Orders workspace<br/>[OrdersPage.tsx]"]
end

subgraph group_workflow["Supply-chain workflows"]
  node_orders["Orders and logistics<br/>[orders.service.ts]"]
  node_production["Evidence workflows"]
  node_ingredients["Ingredient batches"]
  node_custody["Custody transfers"]
  node_extraction["Document extraction"]
end

subgraph group_identity["Identity and evidence"]
  node_auth["Session authorization<br/>[auth.service.ts]"]
  node_directory["Stakeholder directory"]
  node_messaging["DIDComm evidence exchange<br/>[didcomm.service.ts]"]
  node_ssi["SSI credentials"]
end

subgraph group_chain["Blockchain access"]
  node_chain_gateway["Blockchain gateway"]
  node_rpc["RPC provider routing<br/>[rpc-provider.ts]"]
  node_contracts["TraceChain contracts<br/>[TraceChain.ts]"]
end

subgraph group_platform["API platform"]
  node_api["HTTP API<br/>[app.ts]"]
end

node_user(("Company user"))
node_rpc_services(("RPC providers"))
node_wallet_provider(("Browser wallet"))

node_user -->|"uses"| node_webapp
node_webapp -->|"routes login"| node_wallet
node_webapp -->|"routes workspace"| node_workspaces
node_webapp -->|"routes traceability"| node_trace_ui
node_wallet -.->|"requests signature"| node_wallet_provider
node_wallet -->|"verifies session"| node_auth
node_api -->|"configures"| node_auth
node_auth -->|"resolves stakeholder"| node_directory
node_auth -->|"checks authorization"| node_chain_gateway
node_api -->|"constructs gateway"| node_chain_gateway
node_api -->|"constructs service"| node_orders
node_orders -->|"uses evidence workflows"| node_production
node_orders_ui -.->|"requests order data"| node_api
node_trace_ui -.->|"requests trace data"| node_api
node_api -.->|"exposes batch workflows"| node_ingredients
node_api -.->|"exposes transfer workflows"| node_custody
node_api -.->|"exposes extraction"| node_extraction
node_production -->|"verifies credentials"| node_ssi
node_ingredients -->|"issues credentials"| node_ssi
node_production -->|"checks certification files"| node_ingredients
node_api -.->|"configures DIDComm"| node_messaging
node_chain_gateway -->|"uses provider"| node_rpc
node_rpc -->|"fails over reads"| node_rpc_services
node_chain_gateway -.->|"reads contract state"| node_contracts

click node_webapp "https://github.com/yap2203/tracechain/blob/main/apps/web/src/App.tsx"
click node_wallet "https://github.com/yap2203/tracechain/blob/main/apps/web/src/features/auth/useWalletAuthentication.ts"
click node_workspaces "https://github.com/yap2203/tracechain/blob/main/apps/web/src/features/workspaces/WorkspaceApp.tsx"
click node_trace_ui "https://github.com/yap2203/tracechain/blob/main/apps/web/src/features/product-traceability/ProductTraceabilityPage.tsx"
click node_orders_ui "https://github.com/yap2203/tracechain/blob/main/apps/web/src/features/orders/OrdersPage.tsx"
click node_api "https://github.com/yap2203/tracechain/blob/main/apps/api/src/app.ts"
click node_auth "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/auth/auth.service.ts"
click node_directory "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/stakeholder-directory/stakeholder-directory.service.ts"
click node_orders "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/orders/orders.service.ts"
click node_production "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/production-flow/production-flow.service.ts"
click node_ingredients "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/ingredient-batches/ingredient-batch.service.ts"
click node_custody "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/custody-transfers/custody-transfer.service.ts"
click node_extraction "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/document-extraction/document-extraction.service.ts"
click node_messaging "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/didcomm/didcomm.service.ts"
click node_ssi "https://github.com/yap2203/tracechain/blob/main/packages/ssi/src/agent/tracechain-agent.ts"
click node_chain_gateway "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/blockchain/blockchain-gateway.service.ts"
click node_rpc "https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/blockchain/rpc-provider.ts"
click node_contracts "https://github.com/yap2203/tracechain/blob/main/packages/contracts/ignition/modules/TraceChain.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_webapp,node_wallet,node_workspaces,node_trace_ui,node_orders_ui,node_user,node_wallet_provider toneBlue
class node_orders,node_production,node_ingredients,node_custody,node_extraction toneAmber
class node_auth,node_directory,node_messaging,node_ssi toneMint
class node_chain_gateway,node_rpc,node_contracts toneRose
class node_api,node_rpc_services toneIndigo
```

## Components

### Web application

- [Web routes](https://github.com/yap2203/tracechain/blob/main/apps/web/src/App.tsx): `apps/web/src/App.tsx`
- [Wallet login](https://github.com/yap2203/tracechain/blob/main/apps/web/src/features/auth/useWalletAuthentication.ts): `apps/web/src/features/auth/useWalletAuthentication.ts`
- [Role workspaces](https://github.com/yap2203/tracechain/blob/main/apps/web/src/features/workspaces/WorkspaceApp.tsx): `apps/web/src/features/workspaces/WorkspaceApp.tsx`
- [Traceability views](https://github.com/yap2203/tracechain/blob/main/apps/web/src/features/product-traceability/ProductTraceabilityPage.tsx): `apps/web/src/features/product-traceability/ProductTraceabilityPage.tsx`
- [Orders workspace](https://github.com/yap2203/tracechain/blob/main/apps/web/src/features/orders/OrdersPage.tsx): `apps/web/src/features/orders/OrdersPage.tsx`

### Supply-chain workflows

- [Orders and logistics](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/orders/orders.service.ts): `apps/api/src/modules/orders/orders.service.ts`
- [Evidence workflows](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/production-flow/production-flow.service.ts): `apps/api/src/modules/production-flow/production-flow.service.ts`
- [Ingredient batches](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/ingredient-batches/ingredient-batch.service.ts): `apps/api/src/modules/ingredient-batches/ingredient-batch.service.ts`
- [Custody transfers](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/custody-transfers/custody-transfer.service.ts): `apps/api/src/modules/custody-transfers/custody-transfer.service.ts`
- [Document extraction](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/document-extraction/document-extraction.service.ts): `apps/api/src/modules/document-extraction/document-extraction.service.ts`

### Identity and evidence

- [Session authorization](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/auth/auth.service.ts): `apps/api/src/modules/auth/auth.service.ts`
- [Stakeholder directory](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/stakeholder-directory/stakeholder-directory.service.ts): `apps/api/src/modules/stakeholder-directory/stakeholder-directory.service.ts`
- [DIDComm evidence exchange](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/didcomm/didcomm.service.ts): `apps/api/src/modules/didcomm/didcomm.service.ts`
- [SSI credentials](https://github.com/yap2203/tracechain/blob/main/packages/ssi/src/agent/tracechain-agent.ts): `packages/ssi/src/agent/tracechain-agent.ts`

### Blockchain access

- [Blockchain gateway](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/blockchain/blockchain-gateway.service.ts): `apps/api/src/modules/blockchain/blockchain-gateway.service.ts`
- [RPC provider routing](https://github.com/yap2203/tracechain/blob/main/apps/api/src/modules/blockchain/rpc-provider.ts): `apps/api/src/modules/blockchain/rpc-provider.ts`
- [TraceChain contracts](https://github.com/yap2203/tracechain/blob/main/packages/contracts/ignition/modules/TraceChain.ts): `packages/contracts/ignition/modules/TraceChain.ts`

### API platform

- [HTTP API](https://github.com/yap2203/tracechain/blob/main/apps/api/src/app.ts): `apps/api/src/app.ts`

### Other components

- **Company user**
- **RPC providers**
- **Browser wallet**

## Connections

- Company user → Web routes: uses (evidence: `apps/web/src/App.tsx`)
- Web routes → Wallet login: routes login (evidence: `apps/web/src/App.tsx`)
- Web routes → Role workspaces: routes workspace (evidence: `apps/web/src/App.tsx`)
- Web routes → Traceability views: routes traceability (evidence: `apps/web/src/App.tsx`)
- Wallet login → Browser wallet: requests signature
- Wallet login → Session authorization: verifies session (evidence: `apps/web/src/features/auth/useWalletAuthentication.ts`)
- HTTP API → Session authorization: configures (evidence: `apps/api/src/app.ts`)
- Session authorization → Stakeholder directory: resolves stakeholder (evidence: `apps/api/src/modules/auth/auth.service.ts`)
- Session authorization → Blockchain gateway: checks authorization (evidence: `apps/api/src/modules/auth/auth.service.ts`)
- HTTP API → Blockchain gateway: constructs gateway (evidence: `apps/api/src/app.ts`)
- HTTP API → Orders and logistics: constructs service (evidence: `apps/api/src/app.ts`)
- Orders and logistics → Evidence workflows: uses evidence workflows (evidence: `apps/api/src/modules/orders/orders.routes.ts`)
- Orders workspace → HTTP API: requests order data
- Traceability views → HTTP API: requests trace data
- HTTP API → Ingredient batches: exposes batch workflows (evidence: `apps/api/src/app.ts`)
- HTTP API → Custody transfers: exposes transfer workflows (evidence: `apps/api/src/app.ts`)
- HTTP API → Document extraction: exposes extraction (evidence: `apps/api/src/app.ts`)
- Evidence workflows → SSI credentials: verifies credentials (evidence: `apps/api/src/modules/production-flow/production-flow.service.ts`)
- Ingredient batches → SSI credentials: issues credentials (evidence: `apps/api/src/modules/ingredient-batches/ingredient-batch.service.ts`)
- Evidence workflows → Ingredient batches: checks certification files (evidence: `apps/api/src/modules/production-flow/production-flow.service.ts`)
- HTTP API → DIDComm evidence exchange: configures DIDComm (evidence: `apps/api/src/app.ts`)
- Blockchain gateway → RPC provider routing: uses provider (evidence: `apps/api/src/modules/blockchain/blockchain-gateway.service.ts`)
- RPC provider routing → RPC providers: fails over reads
- Blockchain gateway → TraceChain contracts: reads contract state
