How lecoeurdelest/shb-digital works
Purpose and entry points
Digital Expert Guild is a Vietnamese banking advisory and controlled-action system: customer or bank staff chat with a multi-agent team for credit, legal, product, and operations work; sensitive actions such as disbursement are enforced server-side. Runtime entry points are FastAPI in backend/app/main.py and the React SPA in frontend/src/main.tsx; Docker Compose provisions the deployed stack via docker-compose.prod.yml.
Client/API boundary
The React/Vite client provides customer workspace, 3D agent lobby, cards/canvas, and an admin Control Tower. It calls REST and consumes per-conversation SSE; full conversation state is the reconnect boundary.
• frontend/src/App.tsx
• frontend/src/Workspace.tsx
• frontend/src/hooks/useConversationSSE.ts
• backend/app/api/conversations.py
• backend/app/api/sse.py
Identity, personas, and authorization
Authentication supports credentials and Google OAuth, issuing HTTP-only JWT cookies. Request dependencies establish customer versus bank/admin identity; data visibility is enforced through role/owner read scope, including tool-layer protection.
• backend/app/auth/router.py
• backend/app/auth/google.py
• backend/app/auth/deps.py
• backend/app/mount/read_scope.py
Persistent banking and operational state
PostgreSQL 15 is the shared system of record for banking data, conversations, task/render state, approvals, audit records, retrieval data, and LLM usage. SQLAlchemy/Alembic define and evolve schema; seeds supply demo business data and policy corpus.
• backend/app/db/models.py
• backend/app/db/migrations/
• backend/app/db/seed_from_lab.py
• deploy/seed/shb-132.db
Agent orchestration lifecycle
A chat request starts a durable MAIN session that plans and synthesizes. Dispatch schedules independent role SUB agents; their completion/events can wake MAIN to continue or resume after restart. The orchestration shell owns idempotent dispatch and state transitions, while role-specific reasoning remains in prompts/skills.
• backend/app/orch/main_session.py
• backend/app/orch/dispatch.py
• backend/app/orch/sub_runner.py
• backend/app/orch/registry.py
Extensible role tools and retrieval
Role packages are mounted dynamically: each domain supplies a SKILL.md and Python business tools, while mount adapters provide schema, Postgres access, and read scope. Shared retrieval handles policy wiki/document lineage, local vector notes, and related-entity exposure checks. Policy source material is local under the deployment seed.
• roles/credit/functions.py
• roles/legal/functions.py
• roles/_retrieval/functions.py
• backend/app/mount/pg_adapter.py
• deploy/seed/wiki/
Controlled actions, audit, and presentation
SUB tools emit structured cards and trace events for the frontend. Audit is append-only around tool calls. Disbursement is a hard control boundary: approval records keyed by normalized payload hash are atomically claimed and executed in the same database transaction, with owner checks and auto/manual authority verdicts.
• backend/app/orch/gated.py
• backend/app/orch/disburse_guard.py
• backend/app/orch/audit_emit.py
• backend/app/orch/common_tools.py
• backend/app/sse/redact.py
Runtime integrations and operations
Python 3.11/FastAPI runs the backend; React 19/Vite serves the UI behind nginx. LLM providers are registry-configured and selected per conversation/turn, supporting Claude SDK, GLM, GPT gateway, and local Ollama. Optional Gmail email notifications and SSE support operational workflows; cloudflared is part of deployment infrastructure.
• configs/providers.yaml
• backend/app/orch/providers.py
• backend/app/notify/email.py
• frontend/nginx.conf
• backend/Dockerfile
Main entry points: sub_runner.py Role SUB runners · main.py FastAPI application · main_session.py Durable MAIN session · models.py PostgreSQL system of record
Components 18
Client
- React workspace & Control Tower · Customer and bank-staff workspace, agent lobby, cards, and admin views.
frontend/src/App.tsx - Conversation SSE client · Reconnects using full conversation state.
frontend/src/hooks/useConversationSSE.ts
Backend
- FastAPI application · Backend entry point and REST boundary.
backend/app/main.py - Conversations API
backend/app/api/conversations.py - SSE endpoint · Streams per-conversation updates.
backend/app/api/sse.py - Authentication & identity · Credential and Google OAuth login issue HTTP-only JWT cookies.
backend/app/auth/router.py - Role/owner read scope · Enforces customer versus bank/admin visibility, including tools.
backend/app/mount/read_scope.py
Agent Runtime
- Durable MAIN session · Plans, synthesizes, and resumes conversations.
backend/app/orch/main_session.py - Agent dispatch · Idempotently schedules role sub-agents and transitions state.
backend/app/orch/dispatch.py - Role SUB runners · Execute independent domain reasoning and emit completion events.
backend/app/orch/sub_runner.py - LLM provider selection · Selects configured Claude, GLM, GPT gateway, or Ollama providers per turn.
backend/app/orch/providers.py - Disbursement control gate · Atomically claims approval by normalized payload hash and executes with owner and authority checks.
backend/app/orch/disburse_guard.py - Audit, cards & redaction · Emits append-only tool audit and structured cards while redacting SSE output.
backend/app/orch/audit_emit.py
Roles & Retrieval
- Credit & legal role tools · Dynamically mounted domain skills and Python business tools.
roles/credit/functions.py - Policy retrieval · Provides policy, vector-note, lineage, and related-entity access checks.
roles/_retrieval/functions.py - Postgres mount adapter · Supplies tool schemas and PostgreSQL access.
backend/app/mount/pg_adapter.py
Data & Deployment
- PostgreSQL system of record · Stores banking, conversation, task, approval, audit, retrieval, and usage state.
backend/app/db/models.py - Production deployment · Deploys backend, UI/nginx, database, and supporting infrastructure.
docker-compose.prod.yml
Connections 25
- React workspace & Control Tower → FastAPI application: REST requests
- React workspace & Control Tower → Conversation SSE client: uses
- Conversation SSE client → SSE endpoint: SSE
- FastAPI application → Conversations API: routes
- FastAPI application → SSE endpoint: routes
- FastAPI application → Authentication & identity: authenticates
- Authentication & identity → Role/owner read scope: establishes identity
- Conversations API → Durable MAIN session: starts or resumes
- Durable MAIN session → Agent dispatch: delegates
- Agent dispatch → Role SUB runners: schedules
- Role SUB runners → Durable MAIN session: completion wakes
- Role SUB runners → Credit & legal role tools: invokes
- Role SUB runners → Policy retrieval: retrieves policy/context
- Role SUB runners → LLM provider selection: uses model
- Credit & legal role tools → Postgres mount adapter: accesses data through
- Postgres mount adapter → Role/owner read scope: applies scope
- Postgres mount adapter → PostgreSQL system of record: queries
- Durable MAIN session → Disbursement control gate: requests controlled action
- Disbursement control gate → PostgreSQL system of record: atomic approval and execution
- Role SUB runners → Audit, cards & redaction: emits traces and cards
- Audit, cards & redaction → PostgreSQL system of record: appends audit
- Audit, cards & redaction → SSE endpoint: publishes redacted events
- Production deployment → FastAPI application: runs backend
- Production deployment → React workspace & Control Tower: serves via nginx
- Production deployment → PostgreSQL system of record: provisions