# 0xh4ku/babel-discord-translator architecture

> Architecture diagram of the GitHub repository 0xh4ku/babel-discord-translator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0xh4ku/babel-discord-translator
- Repository: https://github.com/0xh4ku/babel-discord-translator

## Overview

Babel is a self-hosted Discord translator with Guild and Pocket install profiles. Users invoke text translation or Babel Lens from Discord; the app applies language and profile policy, translates through configured providers, accounts for usage, and returns a private result. Operators configure the service and inspect health, metrics, and usage through the dashboard. The README documents queueing, caching, glossaries, and Lens quotas, but their implementation is not present in the sampled excerpts; those connections are shown only at a documented capability level.

Main entry points: [`src/commands/lens.ts`](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/commands/lens.ts) (Babel Lens), [`src/commands/translate.ts`](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/commands/translate.ts) (Text Translation), [`src/modules/dashboard/dashboard.ts`](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/dashboard/dashboard.ts) (Dashboard Routes), [`src/apps/commands.ts`](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/apps/commands.ts) (Command Routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discord["Discord Apps"]
  node_guild["Guild Profile<br/>[app-profile.ts]"]
  node_pocket["Pocket Profile<br/>[app-profile.ts]"]
  node_bootstrap["App Bootstrap<br/>[bootstrap.ts]"]
  node_commands["Command Routing<br/>[commands.ts]"]
end

subgraph group_translation["Translation Core"]
  node_translate["Text Translation<br/>[translate.ts]"]
  node_lens["Babel Lens<br/>[lens.ts]"]
  node_usage["Usage Accounting<br/>[usage.ts]"]
end

subgraph group_operations["Dashboard Operations"]
  node_dashboard["Dashboard Routes<br/>[dashboard.ts]"]
  node_dashboard_client["Dashboard UI<br/>[app.js]"]
  node_auth["Dashboard Authentication<br/>[dashboard-auth.ts]"]
  node_session_repo["Session Repository"]
  node_health_metrics["Health And Metrics"]
  node_logger["Structured Logging"]
end

subgraph group_state["Configuration And State"]
  node_config["Runtime Configuration"]
  node_store[("Shared Store<br/>[store.ts]")]
  node_sqlite[("SQLite Database<br/>[sqlite-database.ts]")]
end

subgraph group_providers["Provider Integrations"]
  node_provider_orchestrator["Provider Selection"]
  node_vertex["Vertex AI Client"]
  node_openai["OpenAI Client<br/>[openai-client.ts]"]
  node_vision["Cloud Vision OCR"]
end

node_user(("Discord User"))
node_provider_services{{"External AI Services"}}

node_user -->|"invokes commands"| node_commands
node_bootstrap -->|"selects profile"| node_guild
node_bootstrap -->|"selects profile"| node_pocket
node_bootstrap -->|"registers handlers"| node_commands
node_commands -->|"dispatches text"| node_translate
node_commands -->|"dispatches image"| node_lens
node_translate -->|"requests translation"| node_provider_orchestrator
node_lens -->|"requests OCR"| node_vision
node_lens -->|"requests translation"| node_provider_orchestrator
node_provider_orchestrator -->|"selects provider"| node_vertex
node_provider_orchestrator -->|"selects provider"| node_openai
node_vertex -->|"sends request"| node_provider_services
node_openai -->|"sends request"| node_provider_services
node_vision -->|"sends OCR request"| node_provider_services
node_translate -->|"accounts usage"| node_usage
node_lens -->|"accounts usage"| node_usage
node_translate -->|"reads settings"| node_config
node_lens -->|"reads settings"| node_config
node_config -->|"reads and updates"| node_store
node_store -->|"persists state"| node_sqlite
node_dashboard_client -->|"calls API"| node_dashboard
node_dashboard -->|"checks access"| node_auth
node_auth -->|"reads and writes sessions"| node_session_repo
node_dashboard -->|"manages settings"| node_config
node_dashboard -->|"serves operations data"| node_health_metrics
node_usage -->|"persists accounting"| node_store
node_translate -.->|"records events"| node_logger
node_lens -.->|"records events"| node_logger

click node_guild "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/apps/app-profile.ts"
click node_pocket "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/apps/app-profile.ts"
click node_bootstrap "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/apps/bootstrap.ts"
click node_commands "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/apps/commands.ts"
click node_translate "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/commands/translate.ts"
click node_lens "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/commands/lens.ts"
click node_provider_orchestrator "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/infra/provider-orchestrator.ts"
click node_vertex "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/infra/vertex-ai-client.ts"
click node_openai "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/infra/openai-client.ts"
click node_vision "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/infra/cloud-vision-client.ts"
click node_config "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/config/config-repository.ts"
click node_usage "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/usage/usage.ts"
click node_store "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/persistence/store.ts"
click node_sqlite "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/persistence/sqlite-database.ts"
click node_dashboard "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/dashboard/dashboard.ts"
click node_dashboard_client "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/public/js/app.js"
click node_auth "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/dashboard/auth/dashboard-auth.ts"
click node_session_repo "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/dashboard/auth/session-repository.ts"
click node_health_metrics "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/dashboard/health-dashboard.ts"
click node_logger "https://github.com/0xh4ku/babel-discord-translator/blob/main/src/shared/structured-logger.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_guild,node_pocket,node_bootstrap,node_commands,node_user toneBlue
class node_translate,node_lens,node_usage toneAmber
class node_dashboard,node_dashboard_client,node_auth,node_session_repo,node_health_metrics,node_logger toneMint
class node_config,node_store,node_sqlite toneRose
class node_provider_orchestrator,node_vertex,node_openai,node_vision,node_provider_services toneIndigo
```

## Components

### Discord Apps

- [Guild Profile](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/apps/app-profile.ts): `src/apps/app-profile.ts`
- [Pocket Profile](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/apps/app-profile.ts): `src/apps/app-profile.ts`
- [App Bootstrap](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/apps/bootstrap.ts): `src/apps/bootstrap.ts`
- [Command Routing](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/apps/commands.ts): `src/apps/commands.ts`

### Translation Core

- [Text Translation](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/commands/translate.ts): `src/commands/translate.ts`
- [Babel Lens](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/commands/lens.ts): `src/commands/lens.ts`
- [Usage Accounting](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/usage/usage.ts): `src/modules/usage/usage.ts`

### Dashboard Operations

- [Dashboard Routes](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/dashboard/dashboard.ts): `src/modules/dashboard/dashboard.ts`
- [Dashboard UI](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/public/js/app.js): `src/public/js/app.js`
- [Dashboard Authentication](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/dashboard/auth/dashboard-auth.ts): `src/modules/dashboard/auth/dashboard-auth.ts`
- [Session Repository](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/dashboard/auth/session-repository.ts): `src/modules/dashboard/auth/session-repository.ts`
- [Health And Metrics](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/dashboard/health-dashboard.ts): `src/modules/dashboard/health-dashboard.ts`
- [Structured Logging](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/shared/structured-logger.ts): `src/shared/structured-logger.ts`

### Configuration And State

- [Runtime Configuration](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/modules/config/config-repository.ts): `src/modules/config/config-repository.ts`
- [Shared Store](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/persistence/store.ts): `src/persistence/store.ts`
- [SQLite Database](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/persistence/sqlite-database.ts): `src/persistence/sqlite-database.ts`

### Provider Integrations

- [Provider Selection](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/infra/provider-orchestrator.ts): `src/infra/provider-orchestrator.ts`
- [Vertex AI Client](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/infra/vertex-ai-client.ts): `src/infra/vertex-ai-client.ts`
- [OpenAI Client](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/infra/openai-client.ts): `src/infra/openai-client.ts`
- [Cloud Vision OCR](https://github.com/0xh4ku/babel-discord-translator/blob/main/src/infra/cloud-vision-client.ts): `src/infra/cloud-vision-client.ts`

### Other components

- **Discord User**
- **External AI Services**

## Connections

- Discord User → Command Routing: invokes commands
- App Bootstrap → Guild Profile: selects profile
- App Bootstrap → Pocket Profile: selects profile
- App Bootstrap → Command Routing: registers handlers
- Command Routing → Text Translation: dispatches text
- Command Routing → Babel Lens: dispatches image
- Text Translation → Provider Selection: requests translation
- Babel Lens → Cloud Vision OCR: requests OCR
- Babel Lens → Provider Selection: requests translation
- Provider Selection → Vertex AI Client: selects provider
- Provider Selection → OpenAI Client: selects provider
- Vertex AI Client → External AI Services: sends request
- OpenAI Client → External AI Services: sends request
- Cloud Vision OCR → External AI Services: sends OCR request
- Text Translation → Usage Accounting: accounts usage
- Babel Lens → Usage Accounting: accounts usage
- Text Translation → Runtime Configuration: reads settings
- Babel Lens → Runtime Configuration: reads settings
- Runtime Configuration → Shared Store: reads and updates
- Shared Store → SQLite Database: persists state
- Dashboard UI → Dashboard Routes: calls API
- Dashboard Routes → Dashboard Authentication: checks access
- Dashboard Authentication → Session Repository: reads and writes sessions
- Dashboard Routes → Runtime Configuration: manages settings
- Dashboard Routes → Health And Metrics: serves operations data
- Usage Accounting → Shared Store: persists accounting
- Text Translation → Structured Logging: records events
- Babel Lens → Structured Logging: records events
