# subeesesh/lenny architecture

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

- Interactive diagram: https://gitdiagram.com/subeesesh/lenny
- Repository: https://github.com/subeesesh/lenny

## Overview

Lenny Growth Assistant is a transcript-grounded chat product that answers with timestamped citations and can produce essays and one-pagers. Users enter through the React chat, which sends messages to FastAPI; the backend routes the turn, retrieves transcript passages, generates a response, and persists messages, citations, and artifacts. A separate ingestion workflow prepares transcript chunks and embeddings for retrieval. The README documents the provider options and sandboxed artifact rendering; some subsystem links rely on that documentation because their implementation was not sampled.

Main entry points: [`backend/app/agent/skills.py`](https://github.com/subeesesh/lenny/blob/main/backend/app/agent/skills.py) (Answer skills), [`web/src/App.tsx`](https://github.com/subeesesh/lenny/blob/main/web/src/App.tsx) (Chat interface), [`backend/app/api/sessions.py`](https://github.com/subeesesh/lenny/blob/main/backend/app/api/sessions.py) (Session messaging), [`backend/app/retrieval/search.py`](https://github.com/subeesesh/lenny/blob/main/backend/app/retrieval/search.py) (Transcript retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_app_ui["Chat interface<br/>[App.tsx]"]
  node_client_api["HTTP and SSE client<br/>[api.ts]"]
  node_message_view["Answer and citations<br/>[MessageView.tsx]"]
  node_artifact_view["Artifact viewer<br/>[ArtifactPane.tsx]"]
  node_safe_render["Safe rendering<br/>[render.ts]"]
end

subgraph group_service["API and orchestration"]
  node_fastapi["FastAPI application<br/>[main.py]"]
  node_session_api["Session messaging<br/>[sessions.py]"]
  node_turn_router["Turn routing<br/>[router.py]"]
  node_turn_skills["Answer skills<br/>[skills.py]"]
  node_context["Prompt and citations<br/>[context.py]"]
  node_artifact_generation["One-pager generation<br/>[artifact.py]"]
  node_essay_generation["Essay generation<br/>[essay.py]"]
end

subgraph group_knowledge["Transcript knowledge"]
  node_retrieval["Transcript retrieval<br/>[search.py]"]
  node_retrieval_guards["Retrieval guards<br/>[guards.py]"]
  node_ingest_pipeline["Ingestion pipeline<br/>[pipeline.py]"]
  node_transcript_processing["Clean and chunk<br/>[clean.py]"]
  node_embedding["Transcript embeddings<br/>[embed.py]"]
end

subgraph group_generation["Generation"]
  node_provider_factory["Provider selection<br/>[providers.py]"]
  node_ollama["Ollama provider<br/>[ollama.py]"]
  node_anthropic["Anthropic provider<br/>[anthropic.py]"]
end

subgraph group_persistence["Persistent data"]
  node_db_repo["Session repositories<br/>[repo.py]"]
  node_postgres[("PostgreSQL and pgvector<br/>[pool.py]")]
end

node_user(("Assistant user"))
node_ollama_service["Ollama service"]
node_anthropic_service["Anthropic service"]

node_user -->|"asks or creates"| node_app_ui
node_app_ui -->|"sends messages"| node_client_api
node_client_api -->|"HTTP and SSE"| node_session_api
node_session_api -->|"runs turn"| node_turn_skills
node_turn_skills -->|"routes request"| node_turn_router
node_turn_skills -->|"retrieves passages"| node_retrieval
node_retrieval -->|"checks request"| node_retrieval_guards
node_retrieval -->|"embeds query"| node_ollama_service
node_retrieval -->|"searches vectors"| node_postgres
node_turn_skills -->|"builds context"| node_context
node_turn_skills -->|"selects provider"| node_provider_factory
node_provider_factory -->|"creates provider"| node_ollama
node_provider_factory -->|"creates provider"| node_anthropic
node_ollama -->|"streams generation"| node_ollama_service
node_anthropic -->|"streams generation"| node_anthropic_service
node_turn_skills -->|"writes essays"| node_essay_generation
node_turn_skills -->|"creates one-pagers"| node_artifact_generation
node_session_api -->|"loads and saves"| node_db_repo
node_db_repo -->|"reads and writes"| node_postgres
node_ingest_pipeline -->|"cleans and chunks"| node_transcript_processing
node_ingest_pipeline -->|"embeds chunks"| node_embedding
node_ingest_pipeline -->|"stores transcripts"| node_postgres
node_session_api -->|"streams events"| node_app_ui
node_app_ui -->|"renders answers"| node_message_view
node_app_ui -->|"opens artifacts"| node_artifact_view
node_message_view -->|"formats response"| node_safe_render
node_artifact_view -->|"renders sandbox"| node_safe_render

click node_app_ui "https://github.com/subeesesh/lenny/blob/main/web/src/App.tsx"
click node_client_api "https://github.com/subeesesh/lenny/blob/main/web/src/api.ts"
click node_message_view "https://github.com/subeesesh/lenny/blob/main/web/src/components/MessageView.tsx"
click node_artifact_view "https://github.com/subeesesh/lenny/blob/main/web/src/components/ArtifactPane.tsx"
click node_safe_render "https://github.com/subeesesh/lenny/blob/main/web/src/render.ts"
click node_fastapi "https://github.com/subeesesh/lenny/blob/main/backend/app/main.py"
click node_session_api "https://github.com/subeesesh/lenny/blob/main/backend/app/api/sessions.py"
click node_turn_router "https://github.com/subeesesh/lenny/blob/main/backend/app/agent/router.py"
click node_turn_skills "https://github.com/subeesesh/lenny/blob/main/backend/app/agent/skills.py"
click node_context "https://github.com/subeesesh/lenny/blob/main/backend/app/agent/context.py"
click node_artifact_generation "https://github.com/subeesesh/lenny/blob/main/backend/app/agent/artifact.py"
click node_essay_generation "https://github.com/subeesesh/lenny/blob/main/backend/app/agent/essay.py"
click node_retrieval "https://github.com/subeesesh/lenny/blob/main/backend/app/retrieval/search.py"
click node_retrieval_guards "https://github.com/subeesesh/lenny/blob/main/backend/app/retrieval/guards.py"
click node_ingest_pipeline "https://github.com/subeesesh/lenny/blob/main/backend/app/ingest/pipeline.py"
click node_transcript_processing "https://github.com/subeesesh/lenny/blob/main/backend/app/ingest/clean.py"
click node_embedding "https://github.com/subeesesh/lenny/blob/main/backend/app/ingest/embed.py"
click node_provider_factory "https://github.com/subeesesh/lenny/blob/main/backend/app/llm/providers.py"
click node_ollama "https://github.com/subeesesh/lenny/blob/main/backend/app/llm/ollama.py"
click node_anthropic "https://github.com/subeesesh/lenny/blob/main/backend/app/llm/anthropic.py"
click node_db_repo "https://github.com/subeesesh/lenny/blob/main/backend/app/db/repo.py"
click node_postgres "https://github.com/subeesesh/lenny/blob/main/backend/app/db/pool.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_app_ui,node_client_api,node_message_view,node_artifact_view,node_safe_render,node_user toneBlue
class node_fastapi,node_session_api,node_turn_router,node_turn_skills,node_context,node_artifact_generation,node_essay_generation toneAmber
class node_retrieval,node_retrieval_guards,node_ingest_pipeline,node_transcript_processing,node_embedding toneMint
class node_provider_factory,node_ollama,node_anthropic toneRose
class node_db_repo,node_postgres,node_ollama_service,node_anthropic_service toneIndigo
```

## Components

### Chat client

- [Chat interface](https://github.com/subeesesh/lenny/blob/main/web/src/App.tsx): `web/src/App.tsx`
- [HTTP and SSE client](https://github.com/subeesesh/lenny/blob/main/web/src/api.ts): `web/src/api.ts`
- [Answer and citations](https://github.com/subeesesh/lenny/blob/main/web/src/components/MessageView.tsx): `web/src/components/MessageView.tsx`
- [Artifact viewer](https://github.com/subeesesh/lenny/blob/main/web/src/components/ArtifactPane.tsx): `web/src/components/ArtifactPane.tsx`
- [Safe rendering](https://github.com/subeesesh/lenny/blob/main/web/src/render.ts): `web/src/render.ts`

### API and orchestration

- [FastAPI application](https://github.com/subeesesh/lenny/blob/main/backend/app/main.py): `backend/app/main.py`
- [Session messaging](https://github.com/subeesesh/lenny/blob/main/backend/app/api/sessions.py): `backend/app/api/sessions.py`
- [Turn routing](https://github.com/subeesesh/lenny/blob/main/backend/app/agent/router.py): `backend/app/agent/router.py`
- [Answer skills](https://github.com/subeesesh/lenny/blob/main/backend/app/agent/skills.py): `backend/app/agent/skills.py`
- [Prompt and citations](https://github.com/subeesesh/lenny/blob/main/backend/app/agent/context.py): `backend/app/agent/context.py`
- [One-pager generation](https://github.com/subeesesh/lenny/blob/main/backend/app/agent/artifact.py): `backend/app/agent/artifact.py`
- [Essay generation](https://github.com/subeesesh/lenny/blob/main/backend/app/agent/essay.py): `backend/app/agent/essay.py`

### Transcript knowledge

- [Transcript retrieval](https://github.com/subeesesh/lenny/blob/main/backend/app/retrieval/search.py): `backend/app/retrieval/search.py`
- [Retrieval guards](https://github.com/subeesesh/lenny/blob/main/backend/app/retrieval/guards.py): `backend/app/retrieval/guards.py`
- [Ingestion pipeline](https://github.com/subeesesh/lenny/blob/main/backend/app/ingest/pipeline.py): `backend/app/ingest/pipeline.py`
- [Clean and chunk](https://github.com/subeesesh/lenny/blob/main/backend/app/ingest/clean.py): `backend/app/ingest/clean.py`
- [Transcript embeddings](https://github.com/subeesesh/lenny/blob/main/backend/app/ingest/embed.py): `backend/app/ingest/embed.py`

### Generation

- [Provider selection](https://github.com/subeesesh/lenny/blob/main/backend/app/llm/providers.py): `backend/app/llm/providers.py`
- [Ollama provider](https://github.com/subeesesh/lenny/blob/main/backend/app/llm/ollama.py): `backend/app/llm/ollama.py`
- [Anthropic provider](https://github.com/subeesesh/lenny/blob/main/backend/app/llm/anthropic.py): `backend/app/llm/anthropic.py`

### Persistent data

- [Session repositories](https://github.com/subeesesh/lenny/blob/main/backend/app/db/repo.py): `backend/app/db/repo.py`
- [PostgreSQL and pgvector](https://github.com/subeesesh/lenny/blob/main/backend/app/db/pool.py): `backend/app/db/pool.py`

### Other components

- **Assistant user**
- **Ollama service**
- **Anthropic service**

## Connections

- Assistant user → Chat interface: asks or creates (evidence: `README.md`)
- Chat interface → HTTP and SSE client: sends messages (evidence: `web/src/App.tsx`)
- HTTP and SSE client → Session messaging: HTTP and SSE (evidence: `README.md`)
- Session messaging → Answer skills: runs turn (evidence: `backend/app/api/sessions.py`)
- Answer skills → Turn routing: routes request (evidence: `backend/app/agent/skills.py`)
- Answer skills → Transcript retrieval: retrieves passages (evidence: `README.md`)
- Transcript retrieval → Retrieval guards: checks request (evidence: `backend/app/retrieval/search.py`)
- Transcript retrieval → Ollama service: embeds query (evidence: `README.md`)
- Transcript retrieval → PostgreSQL and pgvector: searches vectors (evidence: `README.md`)
- Answer skills → Prompt and citations: builds context (evidence: `backend/app/agent/skills.py`)
- Answer skills → Provider selection: selects provider (evidence: `README.md`)
- Provider selection → Ollama provider: creates provider (evidence: `backend/app/llm/providers.py`)
- Provider selection → Anthropic provider: creates provider (evidence: `backend/app/llm/providers.py`)
- Ollama provider → Ollama service: streams generation (evidence: `backend/app/llm/ollama.py`)
- Anthropic provider → Anthropic service: streams generation (evidence: `README.md`)
- Answer skills → Essay generation: writes essays (evidence: `README.md`)
- Answer skills → One-pager generation: creates one-pagers (evidence: `README.md`)
- Session messaging → Session repositories: loads and saves (evidence: `backend/app/api/sessions.py`)
- Session repositories → PostgreSQL and pgvector: reads and writes (evidence: `README.md`)
- Ingestion pipeline → Clean and chunk: cleans and chunks (evidence: `backend/app/ingest/pipeline.py`)
- Ingestion pipeline → Transcript embeddings: embeds chunks (evidence: `backend/app/ingest/pipeline.py`)
- Ingestion pipeline → PostgreSQL and pgvector: stores transcripts (evidence: `README.md`)
- Session messaging → Chat interface: streams events (evidence: `README.md`)
- Chat interface → Answer and citations: renders answers (evidence: `web/src/App.tsx`)
- Chat interface → Artifact viewer: opens artifacts (evidence: `web/src/App.tsx`)
- Answer and citations → Safe rendering: formats response (evidence: `web/src/components/MessageView.tsx`)
- Artifact viewer → Safe rendering: renders sandbox (evidence: `web/src/components/ArtifactPane.tsx`)
