# smixs/agent-second-brain architecture

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

- Interactive diagram: https://gitdiagram.com/smixs/agent-second-brain
- Repository: https://github.com/smixs/agent-second-brain

## Overview

Agent Second Brain accepts Telegram messages and media, preserves incoming material in an Obsidian vault, and routes conversation through a persistent interactive Claude Code session. Separate scheduled-job and nightly-processing paths extend the core workflow; watchdog and doctor services support uptime. The README documents autograph’s graph-memory capabilities, but its implementation is supplied as a vault skill and was not sampled. Some subsystem links below rely on README statements or SOURCE INDEX references rather than inspected implementation details.

Main entry points: [`src/d_brain/services/runtime.py`](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/runtime.py) (Session runtime), [`src/d_brain/bot/main.py`](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/main.py) (Bot runtime), [`src/d_brain/bot/handlers/chat.py`](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/chat.py) (Chat and media), [`src/d_brain/bot/handlers/commands.py`](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/commands.py) (Commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_telegram["Telegram interface"]
  node_bot["Bot runtime<br/>[main.py]"]
  node_chat["Chat and media<br/>[chat.py]"]
  node_commands["Commands<br/>[commands.py]"]
  node_buttons["Keyboard buttons<br/>[buttons.py]"]
  node_formatters["Telegram formatting<br/>[formatters.py]"]
  node_transcription["Voice transcription<br/>[transcription.py]"]
  node_process_handler["Manual processing<br/>[process.py]"]
end

subgraph group_sessions["Claude sessions"]
  node_chat_manager["Chat session manager<br/>[chat_session.py]"]
  node_runtime["Session runtime<br/>[runtime.py]"]
  node_claude["Interactive Claude session<br/>[claude_session.py]"]
  node_tmux_parse["Pane state parsing<br/>[tmux_parse.py]"]
end

subgraph group_knowledge["Vault and knowledge"]
  node_vault_storage[("Daily notes and attachments<br/>[storage.py]")]
  node_session_store[("Interaction history<br/>[session.py]")]
  node_vault[("Obsidian vault")]
  node_autograph["Autograph memory engine<br/>[autograph]"]
  node_git["Vault Git sync<br/>[git.py]"]
end

subgraph group_operations["Automation and health"]
  node_settings["Configuration<br/>[config.py]"]
  node_processor["Daily processor<br/>[processor.py]"]
  node_pipeline["Nightly pipeline<br/>[pipeline.py]"]
  node_cron_runner["Scheduled job runner<br/>[cron_runner.py]"]
  node_cron_store[("Cron job store<br/>[cron_store.py]")]
  node_doctor["Daily health doctor<br/>[doctor.py]"]
  node_watchdog["Session watchdog<br/>[watchdog.py]"]
  node_tmux_notify["Service notifications<br/>[systemd_notify.py]"]
end

node_user(("Telegram user"))
node_telegram(("Telegram"))
node_deepgram(("Deepgram"))

node_user -->|"sends messages"| node_telegram
node_telegram -->|"delivers updates"| node_bot
node_bot -->|"routes chat"| node_chat
node_bot -->|"registers commands"| node_commands
node_bot -->|"registers buttons"| node_buttons
node_chat -->|"transcribes voice"| node_transcription
node_transcription -.->|"sends audio"| node_deepgram
node_chat -->|"saves entries"| node_vault_storage
node_chat -->|"records history"| node_session_store
node_chat -->|"routes prompts"| node_chat_manager
node_chat -->|"formats replies"| node_formatters
node_commands -->|"reads daily notes"| node_vault_storage
node_commands -->|"reads history"| node_session_store
node_commands -->|"controls session"| node_chat_manager
node_buttons -->|"calls status/help"| node_commands
node_buttons -->|"calls processing"| node_process_handler
node_chat_manager -->|"gets session"| node_runtime
node_runtime -->|"builds session"| node_claude
node_claude -->|"classifies pane"| node_tmux_parse
node_runtime -->|"builds processor"| node_processor
node_processor -->|"uses session"| node_claude
node_claude -->|"reads and writes"| node_vault
node_vault -->|"uses memory skill"| node_autograph
node_bot -->|"uses settings"| node_settings
node_process_handler -->|"gets processor"| node_runtime
node_process_handler -->|"commits changes"| node_git
node_process_handler -->|"formats report"| node_formatters
node_pipeline -->|"gets runtime"| node_runtime
node_pipeline -.->|"processes daily entries"| node_vault
node_bot -->|"starts ticker"| node_cron_runner
node_cron_runner -->|"loads jobs"| node_cron_store
node_cron_runner -->|"gets session"| node_runtime
node_cron_runner -->|"formats notices"| node_formatters
node_bot -->|"sends readiness"| node_tmux_notify
node_watchdog -->|"checks session"| node_runtime
node_watchdog -->|"checks pane state"| node_tmux_parse
node_watchdog -->|"signals service"| node_tmux_notify
node_doctor -->|"checks health"| node_watchdog
node_doctor -->|"checks runtime"| node_runtime

click node_bot "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/main.py"
click node_chat "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/chat.py"
click node_commands "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/commands.py"
click node_buttons "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/buttons.py"
click node_formatters "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/formatters.py"
click node_settings "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/config.py"
click node_chat_manager "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/chat_session.py"
click node_runtime "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/runtime.py"
click node_claude "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/claude_session.py"
click node_tmux_parse "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/tmux_parse.py"
click node_transcription "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/transcription.py"
click node_vault_storage "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/storage.py"
click node_session_store "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/session.py"
click node_vault "https://github.com/smixs/agent-second-brain/tree/main/vault"
click node_autograph "https://github.com/smixs/agent-second-brain/tree/main/vault/.claude/skills/autograph"
click node_process_handler "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/process.py"
click node_processor "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/processor.py"
click node_pipeline "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/pipeline.py"
click node_git "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/git.py"
click node_cron_runner "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/cron_runner.py"
click node_cron_store "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/cron_store.py"
click node_doctor "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/doctor.py"
click node_watchdog "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/watchdog.py"
click node_tmux_notify "https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/systemd_notify.py"

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_bot,node_chat,node_commands,node_buttons,node_formatters,node_transcription,node_process_handler,node_user toneBlue
class node_chat_manager,node_runtime,node_claude,node_tmux_parse toneAmber
class node_vault_storage,node_session_store,node_vault,node_autograph,node_git toneMint
class node_settings,node_processor,node_pipeline,node_cron_runner,node_cron_store,node_doctor,node_watchdog,node_tmux_notify toneRose
class node_telegram,node_deepgram toneIndigo
```

## Components

### Telegram interface

- [Bot runtime](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/main.py): `src/d_brain/bot/main.py`
- [Chat and media](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/chat.py): `src/d_brain/bot/handlers/chat.py`
- [Commands](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/commands.py): `src/d_brain/bot/handlers/commands.py`
- [Keyboard buttons](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/buttons.py): `src/d_brain/bot/handlers/buttons.py`
- [Telegram formatting](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/formatters.py): `src/d_brain/bot/formatters.py`
- [Voice transcription](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/transcription.py): `src/d_brain/services/transcription.py`
- [Manual processing](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/bot/handlers/process.py): `src/d_brain/bot/handlers/process.py`

### Claude sessions

- [Chat session manager](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/chat_session.py): `src/d_brain/services/chat_session.py`
- [Session runtime](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/runtime.py): `src/d_brain/services/runtime.py`
- [Interactive Claude session](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/claude_session.py): `src/d_brain/services/claude_session.py`
- [Pane state parsing](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/tmux_parse.py): `src/d_brain/services/tmux_parse.py`

### Vault and knowledge

- [Daily notes and attachments](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/storage.py): `src/d_brain/services/storage.py`
- [Interaction history](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/session.py): `src/d_brain/services/session.py`
- [Obsidian vault](https://github.com/smixs/agent-second-brain/tree/main/vault): `vault`
- [Autograph memory engine](https://github.com/smixs/agent-second-brain/tree/main/vault/.claude/skills/autograph): `vault/.claude/skills/autograph`
- [Vault Git sync](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/git.py): `src/d_brain/services/git.py`

### Automation and health

- [Configuration](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/config.py): `src/d_brain/config.py`
- [Daily processor](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/processor.py): `src/d_brain/services/processor.py`
- [Nightly pipeline](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/pipeline.py): `src/d_brain/pipeline.py`
- [Scheduled job runner](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/cron_runner.py): `src/d_brain/services/cron_runner.py`
- [Cron job store](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/cron_store.py): `src/d_brain/services/cron_store.py`
- [Daily health doctor](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/doctor.py): `src/d_brain/services/doctor.py`
- [Session watchdog](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/watchdog.py): `src/d_brain/services/watchdog.py`
- [Service notifications](https://github.com/smixs/agent-second-brain/blob/main/src/d_brain/services/systemd_notify.py): `src/d_brain/services/systemd_notify.py`

### Other components

- **Telegram user**
- **Telegram**
- **Deepgram**

## Connections

- Telegram user → Telegram: sends messages (evidence: `README.md`)
- Telegram → Bot runtime: delivers updates (evidence: `README.md`)
- Bot runtime → Chat and media: routes chat (evidence: `src/d_brain/bot/main.py`)
- Bot runtime → Commands: registers commands (evidence: `src/d_brain/bot/main.py`)
- Bot runtime → Keyboard buttons: registers buttons (evidence: `src/d_brain/bot/main.py`)
- Chat and media → Voice transcription: transcribes voice (evidence: `src/d_brain/bot/handlers/chat.py`)
- Voice transcription → Deepgram: sends audio (evidence: `README.md`)
- Chat and media → Daily notes and attachments: saves entries (evidence: `src/d_brain/bot/handlers/chat.py`)
- Chat and media → Interaction history: records history (evidence: `src/d_brain/bot/handlers/chat.py`)
- Chat and media → Chat session manager: routes prompts (evidence: `src/d_brain/bot/handlers/chat.py`)
- Chat and media → Telegram formatting: formats replies (evidence: `src/d_brain/bot/handlers/chat.py`)
- Commands → Daily notes and attachments: reads daily notes (evidence: `src/d_brain/bot/handlers/commands.py`)
- Commands → Interaction history: reads history (evidence: `src/d_brain/bot/handlers/commands.py`)
- Commands → Chat session manager: controls session (evidence: `src/d_brain/bot/handlers/commands.py`)
- Keyboard buttons → Commands: calls status/help (evidence: `src/d_brain/bot/handlers/buttons.py`)
- Keyboard buttons → Manual processing: calls processing (evidence: `src/d_brain/bot/handlers/buttons.py`)
- Chat session manager → Session runtime: gets session (evidence: `src/d_brain/services/chat_session.py`)
- Session runtime → Interactive Claude session: builds session (evidence: `src/d_brain/services/runtime.py`)
- Interactive Claude session → Pane state parsing: classifies pane (evidence: `src/d_brain/services/claude_session.py`)
- Session runtime → Daily processor: builds processor (evidence: `src/d_brain/services/runtime.py`)
- Daily processor → Interactive Claude session: uses session (evidence: `src/d_brain/services/processor.py`)
- Interactive Claude session → Obsidian vault: reads and writes (evidence: `README.md`)
- Obsidian vault → Autograph memory engine: uses memory skill (evidence: `README.md`)
- Bot runtime → Configuration: uses settings (evidence: `src/d_brain/bot/main.py`)
- Manual processing → Session runtime: gets processor (evidence: `src/d_brain/bot/handlers/process.py`)
- Manual processing → Vault Git sync: commits changes (evidence: `src/d_brain/bot/handlers/process.py`)
- Manual processing → Telegram formatting: formats report (evidence: `src/d_brain/bot/handlers/process.py`)
- Nightly pipeline → Session runtime: gets runtime (evidence: `src/d_brain/pipeline.py`)
- Nightly pipeline → Obsidian vault: processes daily entries (evidence: `README.md`)
- Bot runtime → Scheduled job runner: starts ticker (evidence: `src/d_brain/bot/main.py`)
- Scheduled job runner → Cron job store: loads jobs (evidence: `src/d_brain/services/cron_runner.py`)
- Scheduled job runner → Session runtime: gets session (evidence: `src/d_brain/services/cron_runner.py`)
- Scheduled job runner → Telegram formatting: formats notices (evidence: `src/d_brain/services/cron_runner.py`)
- Bot runtime → Service notifications: sends readiness (evidence: `src/d_brain/bot/main.py`)
- Session watchdog → Session runtime: checks session (evidence: `src/d_brain/services/watchdog.py`)
- Session watchdog → Pane state parsing: checks pane state (evidence: `src/d_brain/services/watchdog.py`)
- Session watchdog → Service notifications: signals service (evidence: `src/d_brain/services/watchdog.py`)
- Daily health doctor → Session watchdog: checks health (evidence: `src/d_brain/services/doctor.py`)
- Daily health doctor → Session runtime: checks runtime (evidence: `src/d_brain/services/doctor.py`)
