# ballerine-io/ballerine architecture

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

- Interactive diagram: https://gitdiagram.com/ballerine-io/ballerine
- Repository: https://github.com/ballerine-io/ballerine

## Overview

Ballerine is risk and identity-management infrastructure. Its documented user-to-result flow collects KYB/KYC information and documents, uses workflow steps and risk rules, then presents a case for manual assignment and approve/reject/resubmission; resubmission returns to collection. The repository also includes workflow administration, file storage, browser-state persistence, plugins, and reporting. Edges reflect explicit README workflow descriptions or shown/indexed references; where runtime wiring is not evidenced, the graph omits the link rather than assuming it.

Main entry points: [`apps/kyb-app/src/hooks/useFlowContextQuery/useFlowContextQuery.ts`](https://github.com/ballerine-io/ballerine/blob/dev/apps/kyb-app/src/hooks/useFlowContextQuery/useFlowContextQuery.ts) (KYB collection UI), [`apps/backoffice-v2/src/pages/Entity/hooks/useCurrentCaseQuery/useCurrentCaseQuery.tsx`](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/pages/Entity/hooks/useCurrentCaseQuery/useCurrentCaseQuery.tsx) (Case management), [`apps/backoffice-v2/src/domains/auth/query-keys.ts`](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/auth/query-keys.ts) (Auth query keys), [`services/workflows-service/src/storage/storage.controller.external.ts`](https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/storage/storage.controller.external.ts) (Storage API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_collection["Collection experience"]
  node_collection_ui["KYB collection UI"]
  node_end_user_query["End-user query<br/>[useEndUserQuery.ts]"]
  node_customer_query["Customer query"]
  node_document_query["Document query"]
  node_web_ui_sdk["Collection UI SDK<br/>[Routes.svelte]"]
end

subgraph group_review["Case review"]
  node_backoffice["Case management"]
  node_auth["Authentication"]
  node_auth_fetchers["Auth fetchers<br/>[fetchers.ts]"]
  node_auth_keys["Auth query keys<br/>[query-keys.ts]"]
  node_case_documents["Case documents"]
  node_individuals["Individual queries"]
  node_reports["Business reports"]
end

subgraph group_workflow["Workflow platform"]
  node_dashboard["Workflow dashboard"]
  node_workflow_definition["Workflow definitions"]
  node_workflow_service["Workflow worker"]
  node_worker_entry["Worker entry<br/>[main.worker.ts]"]
  node_workflow_state["Workflow state plugin<br/>[state-plugin.ts]"]
  node_local_persist["Local state persistence"]
end

subgraph group_services["Service capabilities"]
  node_rule_engine["Rules engine<br/>[rule-engine.ts]"]
  node_form_rules["Form rule hook<br/>[useRuleEngine.ts]"]
  node_storage_api["Storage API"]
  node_storage_service["Storage service<br/>[storage.service.ts]"]
  node_file_manager["File provider manager"]
end

subgraph group_shared["Shared infrastructure"]
  node_storage_keys["Storage query keys<br/>[query-keys.ts]"]
  node_storage_file_query["Storage file queries"]
  node_query_client["Backoffice query client<br/>[query-client.ts]"]
  node_environment["Environment config<br/>[env.ts]"]
  node_websocket["Websocket service<br/>[app.controller.ts]"]
end

node_applicant(("Applicant"))
node_reviewer(("Reviewer"))

node_applicant -->|"submits information"| node_collection_ui
node_collection_ui -->|"loads end user"| node_end_user_query
node_collection_ui -->|"loads customer"| node_customer_query
node_collection_ui -.->|"loads documents"| node_document_query
node_collection_ui -.->|"renders collection flow"| node_web_ui_sdk
node_collection_ui -.->|"updates review case"| node_backoffice
node_reviewer -->|"reviews and decides"| node_backoffice
node_backoffice -.->|"requests resubmission"| node_collection_ui
node_backoffice -.->|"checks access"| node_auth
node_auth -->|"queries authentication"| node_auth_keys
node_auth_keys -->|"references fetchers"| node_auth_fetchers
node_backoffice -.->|"shows case documents"| node_case_documents
node_backoffice -.->|"loads individual details"| node_individuals
node_backoffice -.->|"shows business metrics"| node_reports
node_dashboard -.->|"configures workflows"| node_workflow_definition
node_workflow_service -->|"bootstrapped by"| node_worker_entry
node_workflow_state -->|"extended by"| node_local_persist
node_form_rules -.->|"evaluates risk rules"| node_rule_engine
node_storage_api -->|"reads and writes file links"| node_storage_service
node_storage_api -->|"uploads and downloads"| node_file_manager
node_storage_file_query -->|"uses query keys"| node_storage_keys
node_query_client -->|"clears auth state"| node_auth_keys

click node_collection_ui "https://github.com/ballerine-io/ballerine/blob/dev/apps/kyb-app/src/hooks/useFlowContextQuery/useFlowContextQuery.ts"
click node_end_user_query "https://github.com/ballerine-io/ballerine/blob/dev/apps/kyb-app/src/hooks/useEndUserQuery/useEndUserQuery.ts"
click node_customer_query "https://github.com/ballerine-io/ballerine/blob/dev/apps/kyb-app/src/hooks/useCustomerQuery/useCustomerQuery.ts"
click node_document_query "https://github.com/ballerine-io/ballerine/blob/dev/apps/kyb-app/src/hooks/useDocumentsQuery/useDocumentsQuery.ts"
click node_web_ui_sdk "https://github.com/ballerine-io/ballerine/blob/dev/sdks/web-ui-sdk/src/Routes.svelte"
click node_backoffice "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/pages/Entity/hooks/useCurrentCaseQuery/useCurrentCaseQuery.tsx"
click node_auth "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/auth/context/AuthProvider/hooks/useIsAuthenticated/useIsAuthenticated.tsx"
click node_auth_fetchers "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/auth/fetchers.ts"
click node_auth_keys "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/auth/query-keys.ts"
click node_case_documents "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/documents/hooks/queries/useDocumentsTrackerItemsQuery.ts"
click node_individuals "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/individuals/queries/useEndUserByIdQuery/useEndUserByIdQuery.tsx"
click node_reports "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery.tsx"
click node_dashboard "https://github.com/ballerine-io/ballerine/blob/dev/apps/workflows-dashboard/src/pages/Workflows/hooks/useWorkflowsQuery/useWorkflowsQuery.ts"
click node_workflow_definition "https://github.com/ballerine-io/ballerine/blob/dev/apps/workflows-dashboard/src/common/hooks/useWorkflowDefinitionQuery/useWorkflowDefinitionQuery.ts"
click node_workflow_service "https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/app.worker.module.ts"
click node_worker_entry "https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/main.worker.ts"
click node_workflow_state "https://github.com/ballerine-io/ballerine/blob/dev/sdks/workflow-browser-sdk/src/lib/plugins/state-plugin.ts"
click node_local_persist "https://github.com/ballerine-io/ballerine/blob/dev/sdks/workflow-browser-sdk/src/lib/plugins/local-storage-persist-plugin.ts"
click node_rule_engine "https://github.com/ballerine-io/ballerine/blob/dev/packages/rules-engine/src/lib/rule-engine.ts"
click node_form_rules "https://github.com/ballerine-io/ballerine/blob/dev/packages/ui/src/components/organisms/Form/hooks/useRuleEngine/useRuleEngine.ts"
click node_storage_api "https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/storage/storage.controller.external.ts"
click node_storage_service "https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/storage/storage.service.ts"
click node_file_manager "https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/storage/get-file-storage-manager.ts"
click node_storage_keys "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/storage/query-keys.ts"
click node_storage_file_query "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/storage/hooks/queries/useStorageFileByIdQuery/useStorageFileByIdQuery.tsx"
click node_query_client "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/lib/react-query/query-client.ts"
click node_environment "https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/common/env/env.ts"
click node_websocket "https://github.com/ballerine-io/ballerine/blob/dev/services/websocket-service/src/app.controller.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_collection_ui,node_end_user_query,node_customer_query,node_document_query,node_web_ui_sdk,node_reviewer toneBlue
class node_backoffice,node_auth,node_auth_fetchers,node_auth_keys,node_case_documents,node_individuals,node_reports toneAmber
class node_dashboard,node_workflow_definition,node_workflow_service,node_worker_entry,node_workflow_state,node_local_persist toneMint
class node_rule_engine,node_form_rules,node_storage_api,node_storage_service,node_file_manager toneRose
class node_storage_keys,node_storage_file_query,node_query_client,node_environment,node_websocket,node_applicant toneIndigo
```

## Components

### Collection experience

- [KYB collection UI](https://github.com/ballerine-io/ballerine/blob/dev/apps/kyb-app/src/hooks/useFlowContextQuery/useFlowContextQuery.ts): `apps/kyb-app/src/hooks/useFlowContextQuery/useFlowContextQuery.ts`
- [End-user query](https://github.com/ballerine-io/ballerine/blob/dev/apps/kyb-app/src/hooks/useEndUserQuery/useEndUserQuery.ts): `apps/kyb-app/src/hooks/useEndUserQuery/useEndUserQuery.ts`
- [Customer query](https://github.com/ballerine-io/ballerine/blob/dev/apps/kyb-app/src/hooks/useCustomerQuery/useCustomerQuery.ts): `apps/kyb-app/src/hooks/useCustomerQuery/useCustomerQuery.ts`
- [Document query](https://github.com/ballerine-io/ballerine/blob/dev/apps/kyb-app/src/hooks/useDocumentsQuery/useDocumentsQuery.ts): `apps/kyb-app/src/hooks/useDocumentsQuery/useDocumentsQuery.ts`
- [Collection UI SDK](https://github.com/ballerine-io/ballerine/blob/dev/sdks/web-ui-sdk/src/Routes.svelte): `sdks/web-ui-sdk/src/Routes.svelte`

### Case review

- [Case management](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/pages/Entity/hooks/useCurrentCaseQuery/useCurrentCaseQuery.tsx): `apps/backoffice-v2/src/pages/Entity/hooks/useCurrentCaseQuery/useCurrentCaseQuery.tsx`
- [Authentication](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/auth/context/AuthProvider/hooks/useIsAuthenticated/useIsAuthenticated.tsx): `apps/backoffice-v2/src/domains/auth/context/AuthProvider/hooks/useIsAuthenticated/useIsAuthenticated.tsx`
- [Auth fetchers](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/auth/fetchers.ts): `apps/backoffice-v2/src/domains/auth/fetchers.ts`
- [Auth query keys](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/auth/query-keys.ts): `apps/backoffice-v2/src/domains/auth/query-keys.ts`
- [Case documents](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/documents/hooks/queries/useDocumentsTrackerItemsQuery.ts): `apps/backoffice-v2/src/domains/documents/hooks/queries/useDocumentsTrackerItemsQuery.ts`
- [Individual queries](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/individuals/queries/useEndUserByIdQuery/useEndUserByIdQuery.tsx): `apps/backoffice-v2/src/domains/individuals/queries/useEndUserByIdQuery/useEndUserByIdQuery.tsx`
- [Business reports](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery.tsx): `apps/backoffice-v2/src/domains/business-reports/hooks/queries/useBusinessReportsQuery/useBusinessReportsQuery.tsx`

### Workflow platform

- [Workflow dashboard](https://github.com/ballerine-io/ballerine/blob/dev/apps/workflows-dashboard/src/pages/Workflows/hooks/useWorkflowsQuery/useWorkflowsQuery.ts): `apps/workflows-dashboard/src/pages/Workflows/hooks/useWorkflowsQuery/useWorkflowsQuery.ts`
- [Workflow definitions](https://github.com/ballerine-io/ballerine/blob/dev/apps/workflows-dashboard/src/common/hooks/useWorkflowDefinitionQuery/useWorkflowDefinitionQuery.ts): `apps/workflows-dashboard/src/common/hooks/useWorkflowDefinitionQuery/useWorkflowDefinitionQuery.ts`
- [Workflow worker](https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/app.worker.module.ts): `services/workflows-service/src/app.worker.module.ts`
- [Worker entry](https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/main.worker.ts): `services/workflows-service/src/main.worker.ts`
- [Workflow state plugin](https://github.com/ballerine-io/ballerine/blob/dev/sdks/workflow-browser-sdk/src/lib/plugins/state-plugin.ts): `sdks/workflow-browser-sdk/src/lib/plugins/state-plugin.ts`
- [Local state persistence](https://github.com/ballerine-io/ballerine/blob/dev/sdks/workflow-browser-sdk/src/lib/plugins/local-storage-persist-plugin.ts): `sdks/workflow-browser-sdk/src/lib/plugins/local-storage-persist-plugin.ts`

### Service capabilities

- [Rules engine](https://github.com/ballerine-io/ballerine/blob/dev/packages/rules-engine/src/lib/rule-engine.ts): `packages/rules-engine/src/lib/rule-engine.ts`
- [Form rule hook](https://github.com/ballerine-io/ballerine/blob/dev/packages/ui/src/components/organisms/Form/hooks/useRuleEngine/useRuleEngine.ts): `packages/ui/src/components/organisms/Form/hooks/useRuleEngine/useRuleEngine.ts`
- [Storage API](https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/storage/storage.controller.external.ts): `services/workflows-service/src/storage/storage.controller.external.ts`
- [Storage service](https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/storage/storage.service.ts): `services/workflows-service/src/storage/storage.service.ts`
- [File provider manager](https://github.com/ballerine-io/ballerine/blob/dev/services/workflows-service/src/storage/get-file-storage-manager.ts): `services/workflows-service/src/storage/get-file-storage-manager.ts`

### Shared infrastructure

- [Storage query keys](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/storage/query-keys.ts): `apps/backoffice-v2/src/domains/storage/query-keys.ts`
- [Storage file queries](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/domains/storage/hooks/queries/useStorageFileByIdQuery/useStorageFileByIdQuery.tsx): `apps/backoffice-v2/src/domains/storage/hooks/queries/useStorageFileByIdQuery/useStorageFileByIdQuery.tsx`
- [Backoffice query client](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/lib/react-query/query-client.ts): `apps/backoffice-v2/src/lib/react-query/query-client.ts`
- [Environment config](https://github.com/ballerine-io/ballerine/blob/dev/apps/backoffice-v2/src/common/env/env.ts): `apps/backoffice-v2/src/common/env/env.ts`
- [Websocket service](https://github.com/ballerine-io/ballerine/blob/dev/services/websocket-service/src/app.controller.ts): `services/websocket-service/src/app.controller.ts`

### Other components

- **Applicant**
- **Reviewer**

## Connections

- Applicant → KYB collection UI: submits information
- KYB collection UI → End-user query: loads end user (evidence: `apps/kyb-app/src/hooks/useFlowContextQuery/useFlowContextQuery.ts`)
- KYB collection UI → Customer query: loads customer (evidence: `apps/kyb-app/src/hooks/useCustomerQuery/useCustomerQuery.ts`)
- KYB collection UI → Document query: loads documents
- KYB collection UI → Collection UI SDK: renders collection flow
- KYB collection UI → Case management: updates review case
- Reviewer → Case management: reviews and decides
- Case management → KYB collection UI: requests resubmission
- Case management → Authentication: checks access
- Authentication → Auth query keys: queries authentication (evidence: `apps/backoffice-v2/src/domains/auth/context/AuthProvider/hooks/useIsAuthenticated/useIsAuthenticated.tsx`)
- Auth query keys → Auth fetchers: references fetchers (evidence: `apps/backoffice-v2/src/domains/auth/query-keys.ts`)
- Case management → Case documents: shows case documents
- Case management → Individual queries: loads individual details
- Case management → Business reports: shows business metrics
- Workflow dashboard → Workflow definitions: configures workflows
- Workflow worker → Worker entry: bootstrapped by (evidence: `services/workflows-service/src/main.worker.ts`)
- Workflow state plugin → Local state persistence: extended by (evidence: `sdks/workflow-browser-sdk/src/lib/plugins/local-storage-persist-plugin.ts`)
- Form rule hook → Rules engine: evaluates risk rules
- Storage API → Storage service: reads and writes file links (evidence: `services/workflows-service/src/storage/storage.controller.external.ts`)
- Storage API → File provider manager: uploads and downloads (evidence: `services/workflows-service/src/storage/storage.controller.external.ts`)
- Storage file queries → Storage query keys: uses query keys (evidence: `apps/backoffice-v2/src/domains/storage/hooks/queries/useStorageFileByIdQuery/useStorageFileByIdQuery.tsx`)
- Backoffice query client → Auth query keys: clears auth state (evidence: `apps/backoffice-v2/src/lib/react-query/query-client.ts`)
