# theyuvan/euthyna architecture

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

- Interactive diagram: https://gitdiagram.com/theyuvan/euthyna
- Repository: https://github.com/theyuvan/euthyna

## Overview

Euthyna is an AI treasury agent for small businesses: owners onboard a vault and bills, then a scheduled agent assesses bills and liquidity, proposes actions, checks policy, and executes permitted payments. Contract-enforced commitments are settled against on-chain records to earn or lose spending capacity; the console exposes decisions, escalations, trust, and replay. The backend also indexes chain activity and accepts invoice intake. Edges follow shown imports/calls or README architecture statements; unsampled implementation details are not inferred.

Main entry points: [`backend/src/agent.ts`](https://github.com/theyuvan/euthyna/blob/main/backend/src/agent.ts) (Agent Orchestrator), [`backend/src/server.ts`](https://github.com/theyuvan/euthyna/blob/main/backend/src/server.ts) (HTTP API), [`backend/src/executor.ts`](https://github.com/theyuvan/euthyna/blob/main/backend/src/executor.ts) (Transaction Executor), [`backend/src/scheduler.ts`](https://github.com/theyuvan/euthyna/blob/main/backend/src/scheduler.ts) (Run Scheduler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_owner["Owner Console"]
  node_console["Console Views"]
  node_onboard["Vault Onboarding<br/>[page.tsx]"]
  node_trust["Trust and Settlement<br/>[page.tsx]"]
  node_replay["Decision Replay<br/>[page.tsx]"]
  node_wallet["Wallet Access<br/>[wallet.ts]"]
  node_webapi["Console API Client<br/>[api.ts]"]
end

subgraph group_agent["Treasury Agent"]
  node_agent["Agent Orchestrator<br/>[agent.ts]"]
  node_snapshot["Vault Snapshot<br/>[snapshot.ts]"]
  node_precompute["Decision Inputs<br/>[precompute.ts]"]
  node_llm["Action Proposal<br/>[llm.ts]"]
  node_policy["Policy Checks<br/>[policy.ts]"]
  node_canonical["Decision Hashing<br/>[canonical.ts]"]
end

subgraph group_operations["Operations and Indexing"]
  node_server["HTTP API<br/>[server.ts]"]
  node_scheduler["Run Scheduler<br/>[scheduler.ts]"]
  node_invoice["Invoice Intake<br/>[invoice.ts]"]
  node_indexer["Chain Indexer<br/>[indexer.ts]"]
  node_settler["Commitment Settler<br/>[settler.ts]"]
end

subgraph group_integrations["Chain and Services"]
  node_executor["Transaction Executor<br/>[executor.ts]"]
  node_db[("Application Database<br/>[db.ts]")]
  node_chain["Arc RPC Client<br/>[chain.ts]"]
  node_vault{{"Euthyna Vault<br/>[abi.ts]"}}
end

node_owner(("Business Owner"))
node_circle["Circle Wallets"]
node_providers["Model Providers"]

node_owner -->|"onboards"| node_onboard
node_onboard -->|"signs with"| node_wallet
node_console -.->|"requests data"| node_webapi
node_webapi -->|"uses auth"| node_wallet
node_webapi -->|"calls API"| node_server
node_owner -->|"reviews trust"| node_trust
node_trust -->|"requests settlement"| node_server
node_owner -->|"replays decisions"| node_replay
node_server -->|"requests run"| node_scheduler
node_server -->|"settles vault"| node_settler
node_scheduler -->|"runs agent"| node_agent
node_scheduler -->|"starts indexing"| node_indexer
node_scheduler -->|"runs settlement"| node_settler
node_agent -->|"takes snapshot"| node_snapshot
node_agent -->|"computes inputs"| node_precompute
node_agent -->|"requests proposal"| node_llm
node_agent -->|"checks actions"| node_policy
node_agent -->|"hashes decision"| node_canonical
node_agent -->|"executes actions"| node_executor
node_llm -->|"requests completion"| node_providers
node_executor -->|"sends transactions"| node_circle
node_snapshot -->|"reads contract"| node_chain
node_executor -->|"simulates calls"| node_chain
node_executor -->|"executes actions"| node_vault
node_settler -->|"reads and writes"| node_chain
node_settler -->|"sends settlement"| node_executor
node_server -->|"queries records"| node_db
node_snapshot -->|"reads context"| node_db
node_indexer -->|"mirrors events"| node_db
node_server -.->|"accepts intake"| node_invoice

click node_console "https://github.com/theyuvan/euthyna/tree/main/frontend/app/console"
click node_onboard "https://github.com/theyuvan/euthyna/blob/main/frontend/app/console/onboard/page.tsx"
click node_trust "https://github.com/theyuvan/euthyna/blob/main/frontend/app/console/trust/page.tsx"
click node_replay "https://github.com/theyuvan/euthyna/blob/main/frontend/app/console/replay/page.tsx"
click node_wallet "https://github.com/theyuvan/euthyna/blob/main/frontend/lib/wallet.ts"
click node_webapi "https://github.com/theyuvan/euthyna/blob/main/frontend/lib/api.ts"
click node_server "https://github.com/theyuvan/euthyna/blob/main/backend/src/server.ts"
click node_scheduler "https://github.com/theyuvan/euthyna/blob/main/backend/src/scheduler.ts"
click node_agent "https://github.com/theyuvan/euthyna/blob/main/backend/src/agent.ts"
click node_snapshot "https://github.com/theyuvan/euthyna/blob/main/backend/src/snapshot.ts"
click node_precompute "https://github.com/theyuvan/euthyna/blob/main/backend/src/precompute.ts"
click node_llm "https://github.com/theyuvan/euthyna/blob/main/backend/src/llm.ts"
click node_policy "https://github.com/theyuvan/euthyna/blob/main/backend/src/policy.ts"
click node_canonical "https://github.com/theyuvan/euthyna/blob/main/backend/src/canonical.ts"
click node_executor "https://github.com/theyuvan/euthyna/blob/main/backend/src/executor.ts"
click node_invoice "https://github.com/theyuvan/euthyna/blob/main/backend/src/invoice.ts"
click node_indexer "https://github.com/theyuvan/euthyna/blob/main/backend/src/indexer.ts"
click node_settler "https://github.com/theyuvan/euthyna/blob/main/backend/src/settler.ts"
click node_db "https://github.com/theyuvan/euthyna/blob/main/backend/src/db.ts"
click node_chain "https://github.com/theyuvan/euthyna/blob/main/backend/src/chain.ts"
click node_vault "https://github.com/theyuvan/euthyna/blob/main/backend/src/abi.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_console,node_onboard,node_trust,node_replay,node_wallet,node_webapi toneBlue
class node_agent,node_snapshot,node_precompute,node_llm,node_policy,node_canonical toneAmber
class node_server,node_scheduler,node_invoice,node_indexer,node_settler toneMint
class node_executor,node_db,node_chain,node_vault toneRose
class node_owner,node_circle,node_providers toneIndigo
```

## Components

### Owner Console

- [Console Views](https://github.com/theyuvan/euthyna/tree/main/frontend/app/console): `frontend/app/console`
- [Vault Onboarding](https://github.com/theyuvan/euthyna/blob/main/frontend/app/console/onboard/page.tsx): `frontend/app/console/onboard/page.tsx`
- [Trust and Settlement](https://github.com/theyuvan/euthyna/blob/main/frontend/app/console/trust/page.tsx): `frontend/app/console/trust/page.tsx`
- [Decision Replay](https://github.com/theyuvan/euthyna/blob/main/frontend/app/console/replay/page.tsx): `frontend/app/console/replay/page.tsx`
- [Wallet Access](https://github.com/theyuvan/euthyna/blob/main/frontend/lib/wallet.ts): `frontend/lib/wallet.ts`
- [Console API Client](https://github.com/theyuvan/euthyna/blob/main/frontend/lib/api.ts): `frontend/lib/api.ts`

### Treasury Agent

- [Agent Orchestrator](https://github.com/theyuvan/euthyna/blob/main/backend/src/agent.ts): `backend/src/agent.ts`
- [Vault Snapshot](https://github.com/theyuvan/euthyna/blob/main/backend/src/snapshot.ts): `backend/src/snapshot.ts`
- [Decision Inputs](https://github.com/theyuvan/euthyna/blob/main/backend/src/precompute.ts): `backend/src/precompute.ts`
- [Action Proposal](https://github.com/theyuvan/euthyna/blob/main/backend/src/llm.ts): `backend/src/llm.ts`
- [Policy Checks](https://github.com/theyuvan/euthyna/blob/main/backend/src/policy.ts): `backend/src/policy.ts`
- [Decision Hashing](https://github.com/theyuvan/euthyna/blob/main/backend/src/canonical.ts): `backend/src/canonical.ts`

### Operations and Indexing

- [HTTP API](https://github.com/theyuvan/euthyna/blob/main/backend/src/server.ts): `backend/src/server.ts`
- [Run Scheduler](https://github.com/theyuvan/euthyna/blob/main/backend/src/scheduler.ts): `backend/src/scheduler.ts`
- [Invoice Intake](https://github.com/theyuvan/euthyna/blob/main/backend/src/invoice.ts): `backend/src/invoice.ts`
- [Chain Indexer](https://github.com/theyuvan/euthyna/blob/main/backend/src/indexer.ts): `backend/src/indexer.ts`
- [Commitment Settler](https://github.com/theyuvan/euthyna/blob/main/backend/src/settler.ts): `backend/src/settler.ts`

### Chain and Services

- [Transaction Executor](https://github.com/theyuvan/euthyna/blob/main/backend/src/executor.ts): `backend/src/executor.ts`
- [Application Database](https://github.com/theyuvan/euthyna/blob/main/backend/src/db.ts): `backend/src/db.ts`
- [Arc RPC Client](https://github.com/theyuvan/euthyna/blob/main/backend/src/chain.ts): `backend/src/chain.ts`
- [Euthyna Vault](https://github.com/theyuvan/euthyna/blob/main/backend/src/abi.ts): `backend/src/abi.ts`

### Other components

- **Business Owner**
- **Circle Wallets**
- **Model Providers**

## Connections

- Business Owner → Vault Onboarding: onboards
- Vault Onboarding → Wallet Access: signs with
- Console Views → Console API Client: requests data
- Console API Client → Wallet Access: uses auth (evidence: `frontend/lib/api.ts`)
- Console API Client → HTTP API: calls API
- Business Owner → Trust and Settlement: reviews trust
- Trust and Settlement → HTTP API: requests settlement
- Business Owner → Decision Replay: replays decisions
- HTTP API → Run Scheduler: requests run (evidence: `backend/src/server.ts`)
- HTTP API → Commitment Settler: settles vault (evidence: `backend/src/server.ts`)
- Run Scheduler → Agent Orchestrator: runs agent (evidence: `backend/src/scheduler.ts`)
- Run Scheduler → Chain Indexer: starts indexing (evidence: `backend/src/scheduler.ts`)
- Run Scheduler → Commitment Settler: runs settlement (evidence: `backend/src/scheduler.ts`)
- Agent Orchestrator → Vault Snapshot: takes snapshot (evidence: `backend/src/agent.ts`)
- Agent Orchestrator → Decision Inputs: computes inputs (evidence: `backend/src/agent.ts`)
- Agent Orchestrator → Action Proposal: requests proposal (evidence: `backend/src/agent.ts`)
- Agent Orchestrator → Policy Checks: checks actions (evidence: `backend/src/agent.ts`)
- Agent Orchestrator → Decision Hashing: hashes decision (evidence: `backend/src/agent.ts`)
- Agent Orchestrator → Transaction Executor: executes actions (evidence: `backend/src/agent.ts`)
- Action Proposal → Model Providers: requests completion (evidence: `backend/src/llm.ts`)
- Transaction Executor → Circle Wallets: sends transactions
- Vault Snapshot → Arc RPC Client: reads contract (evidence: `backend/src/snapshot.ts`)
- Transaction Executor → Arc RPC Client: simulates calls (evidence: `backend/src/executor.ts`)
- Transaction Executor → Euthyna Vault: executes actions (evidence: `backend/src/executor.ts`)
- Commitment Settler → Arc RPC Client: reads and writes (evidence: `backend/src/settler.ts`)
- Commitment Settler → Transaction Executor: sends settlement (evidence: `backend/src/settler.ts`)
- HTTP API → Application Database: queries records (evidence: `backend/src/server.ts`)
- Vault Snapshot → Application Database: reads context (evidence: `backend/src/snapshot.ts`)
- Chain Indexer → Application Database: mirrors events
- HTTP API → Invoice Intake: accepts intake (evidence: `backend/src/server.ts`)
