How neural-maze/substack-brain-course works
The Substack Brain turns allowlisted newsletter feeds into a searchable, citation-bearing knowledge base. Its main workflow discovers articles, durably ingests and versions their passages, then retrieves and synthesizes answers; users can also search, manage backfills and syncs, and access the system through MCP. Postgres stores content, jobs, and answer snapshots. The README describes later graph extraction, evaluations, and agent/digest capabilities, but those implementations are not present in the supplied tree. Edges reflect shown imports, calls, or README statements; unsampled internals are not inferred.
Main entry points: ingest.py Article ingestion · ask.py Answer and citations · inngest_client.py Durable orchestration · queries.py Database queries
Components 28
API and MCP
- HTTP API
kb/main.py - MCP server
kb/mcp/server.py - MCP tools
kb/mcp/tools.py - Health checks
kb/health.py
Durable workflows
- Feed discovery
kb/functions/discovery.py - Publication backfill
kb/functions/backfill.py - Freshness polling
kb/functions/freshness.py - Article ingestion
kb/functions/ingest.py - Durable orchestration
kb/inngest_client.py - Event contracts
kb/schemas/events.py
Content ingestion
- Publication allowlist
kb/sources/allowlist.py - RSS handling
kb/sources/rss.py - Fetch parse chunk
kb/sources - Embeddings
kb/sources/embedder.py - Canonical identifiers
kb/schemas/ids.py
Retrieval and answers
- Hybrid retrieval
kb/retrieval/hybrid.py - Answer and citations
kb/functions/ask.py - Retrieval snapshots
kb/retrieval/snapshot.py - Later course capabilities
Persistence
- Database queries
kb/db/queries.py - Database models
kb/db/models.py - Database sessions
kb/db/session.py
Other components
- Engineer / AI tool
- Postgres / pgvector
- Newsletter feeds
- OpenAI embeddings
- Anthropic synthesis
- Inngest service
Connections 44
- Engineer / AI tool → HTTP API: calls
README.md - Engineer / AI tool → MCP server: connects
README.md - MCP server → MCP tools: registers
kb/mcp/server.py - MCP tools → Answer and citations: calls
kb/mcp/tools.py - MCP tools → Hybrid retrieval: searches
kb/mcp/tools.py - MCP tools → Health checks: checks
kb/mcp/tools.py - HTTP API → Health checks: routes
kb/main.py - HTTP API → Answer and citations: routes
kb/main.py - HTTP API → Feed discovery: dispatches
kb/main.py - Newsletter feeds → RSS handling: provides feeds
kb/sources/rss.py - Feed discovery → RSS handling: fetches and parses
kb/functions/discovery.py - Publication backfill → RSS handling: fetches and parses
kb/functions/backfill.py - Freshness polling → RSS handling: polls conditionally
kb/functions/freshness.py - Feed discovery → Publication allowlist: validates sources
kb/functions/discovery.py - Publication backfill → Publication allowlist: validates sources
kb/functions/backfill.py - Freshness polling → Publication allowlist: validates sources
kb/functions/freshness.py - Feed discovery → Event contracts: emits events
kb/schemas/events.py - Publication backfill → Event contracts: emits events
kb/schemas/events.py - Freshness polling → Event contracts: emits events
kb/schemas/events.py - Feed discovery → Durable orchestration: dispatches
kb/functions/discovery.py - Publication backfill → Durable orchestration: dispatches
kb/functions/backfill.py - Freshness polling → Durable orchestration: dispatches
kb/functions/freshness.py - Durable orchestration → Article ingestion: runs steps
kb/functions/ingest.py - Article ingestion → Publication allowlist: checks URLs
kb/functions/ingest.py - Article ingestion → Fetch parse chunk: fetches and parses
kb/functions/ingest.py - Article ingestion → Embeddings: embeds passages
kb/functions/ingest.py - Article ingestion → Database queries: persists articles
kb/functions/ingest.py - Article ingestion → Event contracts: emits outcomes
kb/functions/ingest.py - Article ingestion → Canonical identifiers: uses dedupe keys
kb/schemas/ids.py - Durable orchestration → Inngest service: communicates
README.md - Hybrid retrieval → Embeddings: embeds query
kb/retrieval/hybrid.py - Hybrid retrieval → Database queries: searches passages
kb/retrieval/hybrid.py - Answer and citations → Hybrid retrieval: retrieves candidates
kb/functions/ask.py - Answer and citations → Retrieval snapshots: records answer
kb/functions/ask.py - Answer and citations → Event contracts: emits answer event
kb/functions/ask.py - Answer and citations → Anthropic synthesis: synthesizes answer
kb/functions/ask.py - Embeddings → OpenAI embeddings: requests embeddings
kb/sources/embedder.py - Database queries → Postgres / pgvector: reads and writes
kb/db/queries.py - Database models → Postgres / pgvector: defines stored records
kb/db/models.py - Database sessions → Postgres / pgvector: opens sessions
kb/db/session.py - Database queries → Database models: queries records
kb/db/queries.py - Retrieval snapshots → Database queries: stores snapshot
kb/retrieval/snapshot.py - Durable orchestration → Database queries: records step costs
kb/inngest_client.py - Later course capabilities → Engineer / AI tool: offers planned features
README.md