# bagpotato/brain-agent architecture

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

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

## Overview

brain-agent is a small, single-file local agent: users submit one or more topics, the script requests structured Markdown from Ollama, classifies the note, and saves it in the matching Obsidian vault folder. The graph separates CLI entry, generation, backend access, and note persistence. README capabilities such as configurable model/vault, interactive input, and note-type folders are represented; the implementation is entirely in the one indexed source file.

Main entry points: [`Brain-agent.py`](https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py) (Generate note)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["User interface"]
  node_entry["CLI configuration<br/>[Brain-agent.py]"]
  node_interactive["Interactive loop<br/>[Brain-agent.py]"]
end

subgraph group_generation["Note generation"]
  node_generate["Generate note<br/>[Brain-agent.py]"]
  node_prompt["Structured prompt<br/>[Brain-agent.py]"]
  node_ollama["Ollama backend"]
end

subgraph group_storage["Vault storage"]
  node_classify["Folder detection<br/>[Brain-agent.py]"]
  node_title["Title extraction<br/>[Brain-agent.py]"]
  node_save["Note persistence<br/>[Brain-agent.py]"]
end

node_user(("User"))
node_vault[("Obsidian vault")]

node_user -->|"runs"| node_entry
node_entry -->|"dispatches"| node_interactive
node_entry -->|"dispatches"| node_generate
node_interactive -->|"submits topic"| node_generate
node_generate -->|"builds request"| node_prompt
node_generate -->|"requests generation"| node_ollama
node_ollama -->|"returns Markdown"| node_generate
node_generate -->|"saves content"| node_save
node_save -->|"detects folder"| node_classify
node_save -->|"extracts filename"| node_title
node_save -->|"writes note"| node_vault

click node_entry "https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py"
click node_interactive "https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py"
click node_generate "https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py"
click node_prompt "https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py"
click node_classify "https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py"
click node_title "https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py"
click node_save "https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.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_entry,node_interactive,node_user toneBlue
class node_generate,node_prompt,node_ollama,node_vault toneAmber
class node_classify,node_title,node_save toneMint
```

## Components

### User interface

- [CLI configuration](https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py): `Brain-agent.py`
- [Interactive loop](https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py): `Brain-agent.py`

### Note generation

- [Generate note](https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py): `Brain-agent.py`
- [Structured prompt](https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py): `Brain-agent.py`
- **Ollama backend**

### Vault storage

- [Folder detection](https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py): `Brain-agent.py`
- [Title extraction](https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py): `Brain-agent.py`
- [Note persistence](https://github.com/bagpotato/brain-agent/blob/main/Brain-agent.py): `Brain-agent.py`

### Other components

- **User**
- **Obsidian vault**

## Connections

- User → CLI configuration: runs (evidence: `Brain-agent.py`)
- CLI configuration → Interactive loop: dispatches (evidence: `Brain-agent.py`)
- CLI configuration → Generate note: dispatches (evidence: `Brain-agent.py`)
- Interactive loop → Generate note: submits topic (evidence: `Brain-agent.py`)
- Generate note → Structured prompt: builds request (evidence: `Brain-agent.py`)
- Generate note → Ollama backend: requests generation (evidence: `Brain-agent.py`)
- Ollama backend → Generate note: returns Markdown (evidence: `Brain-agent.py`)
- Generate note → Note persistence: saves content (evidence: `Brain-agent.py`)
- Note persistence → Folder detection: detects folder (evidence: `Brain-agent.py`)
- Note persistence → Title extraction: extracts filename (evidence: `Brain-agent.py`)
- Note persistence → Obsidian vault: writes note (evidence: `Brain-agent.py`)
