# fergana-labs/stash architecture

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

- Interactive diagram: https://gitdiagram.com/fergana-labs/stash
- Repository: https://github.com/fergana-labs/stash

## Overview

1. **This is a multi-surface product, not a single app.** The repo contains the core backend, an authenticated web app, a public marketing site, a Python CLI, agent plugins, a browser extension, a collab service, and a separate PowerPoint export service. The main architectural idea is “agent memory + content store + integrations.”

2. **The central backend is the system of record.** The `backend/` Python service owns users, workspaces/content, sessions, files, pages, tables, shares, comments, skills, sources, integrations, and audit/security features. Its structure is split into `routers/` for HTTP endpoints, `services/` for business logic, `models.py`, and `migrations/` for schema evolution.

3. **Persistence is relational, with explicit schema history.** The long Alembic migration chain shows the backend’s data model has evolved around entities like sessions, files, pages, share links, integrations, permissions, embeddings, trash, and skills. The architecture is clearly database-centric, with migrations capturing product evolution and reserved fields for future workflows.

4. **Async background work is a major subsystem.** `backend/celery_app.py`, `backend/tasks/`, and `backend/workers/` handle delayed jobs such as extraction, embeddings, source sync, session title generation, visualization updates, and other heavy processing. This keeps ingestion and indexing off the request path.

5. **Ingestion flows from agents into the backend through hooks and uploads.** The `stashai/plugin/` package and the multiple `plugins/*` directories adapt to Claude, Cursor, Codex, OpenCode, Gemini, Openclaw, and others. These plugins capture prompts, tool use, session start/end, and transcript events, then upload session data back to the backend. The README’s “sessions stream in automatically” path is the core data flow.

6. **The CLI is an operational client, not just a thin wrapper.** `cli/` exposes sign-in, repo connection, VFS browsing, importing history, sharing/upload helpers, and MCP-server integration. It acts as the agent/operator interface for reading and writing Stash content locally and remotely.

7. **Search, “ask,” and filesystem-style access sit on top of the content store.** The backend has services for embeddings, file search, memory, session browsing, user knowledge, and tool-loop/ask flows. The product behavior is to let agents query Stash like a persistent filesystem, with semantic and keyword retrieval spanning sessions, files, pages, and tables.

8. **Integrations are a separate adapter layer with providers, indexers, and importers.** `backend/integrations/` is organized by source system: GitHub, Slack, Gmail, Google, Notion, Jira, Linear, Gong, Asana, Granola, Telegram, Twitter, and more. Each integration typically has a provider, an indexer, and sometimes importers/exporters or sync helpers, which means external data is normalized before it lands in the core store.

9. **Content rendering and export are their own subsystem.** `backend/exports/` contains HTML/canvas and native PowerPoint generation logic, including PPTX builders, layout probing, rasterization, and Playwright/network helpers. There is also a separate `powerpoint-mcp/` service, indicating that slide generation is packaged as a specialized export/runtime boundary rather than embedded in the main app.

10. **The authenticated UI and the public site are separate frontends.** `frontend/` is the app for signed-in users: files, folders, sessions, skills, integrations, tables, memory, trash, settings, and onboarding. `www/` is the marketing/docs site with landing pages, blog, docs, public page rendering, contact flows, and lightweight public APIs for pages/comments/track. They share branding and some auth overlay logic, but they serve different audiences and routes.

11. **Collaboration and sharing are first-class product boundaries.** The backend includes permissions, shares, invite tokens, public/private publish state, comments, pinning/recents, and trash. The `collab/` service and frontend comment/editing components indicate live collaboration or document coordination is handled alongside the main content model rather than as an afterthought.

12. **Auth and secrets are layered around the core app.** There is a normal self-hosted path plus a “managed” Auth0 overlay in both backend and frontend. OAuth tokens for integrations are encrypted server-side, and the README emphasizes optional LLM usage, opt-in transcript uploads, and private-by-default visibility.

13. **Deployment is containerized and proxy-fronted.** Docker Compose is the primary self-host story, with a Caddy reverse proxy for public HTTPS deployments. GitHub Actions handle testing, publishing, and versioning, so the operational diagram should include build/test/release automation around the runtime services.

Main entry points: [`backend/main.py`](https://github.com/fergana-labs/stash/blob/main/backend/main.py) (API app), [`backend/services`](https://github.com/fergana-labs/stash/tree/main/backend/services) (Domain services), [`frontend/src/app/(app)`](https://github.com/fergana-labs/stash/tree/main/frontend/src/app/(app)) (App UI), [`docker-compose.yml`](https://github.com/fergana-labs/stash/blob/main/docker-compose.yml) (Docker stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core platform"]
  node_backend_main["API app<br/>[main.py]"]
  node_backend_routers["HTTP routers<br/>api routes"]
  node_backend_services["Domain services<br/>business logic"]
  node_backend_models[("Data models<br/>orm schema<br/>[models.py]")]
  node_backend_migrations["Schema history<br/>alembic migrations"]
  node_backend_celery["Job runner<br/>celery async<br/>[celery_app.py]"]
  node_backend_tasks["Async tasks<br/>background jobs"]
  node_backend_integrations["Integrations<br/>adapter layer"]
  node_backend_exports["Export engine<br/>render/export"]
  node_powerpoint_mcp["PPT runtime<br/>mcp service"]
end

subgraph group_clients["Client surfaces"]
  node_frontend_app["App UI<br/>next.js web app"]
  node_frontend_components["UI components<br/>frontend components"]
  node_www_site["Public site<br/>next.js marketing"]
  node_cli_client["CLI client<br/>operator cli"]
  node_plugin_runtime["Plugin runtime<br/>session hooks"]
  node_agent_plugins["Agent plugins<br/>tool adapters"]
  node_browser_extension["Browser extension<br/>chrome extension"]
  node_collab_service["Collab service<br/>realtime server<br/>[server.ts]"]
end

subgraph group_ops["Operations"]
  node_docker_stack["Docker stack<br/>compose deployment<br/>[docker-compose.yml]"]
  node_caddy_proxy["Edge proxy<br/>caddy config"]
  node_github_actions["Release CI<br/>github actions<br/>[workflows]"]
end

node_backend_main -->|"mounts"| node_backend_routers
node_backend_main -->|"uses"| node_backend_services
node_backend_routers -->|"calls"| node_backend_services
node_backend_services -->|"persists"| node_backend_models
node_backend_models -->|"evolves via"| node_backend_migrations
node_backend_services -->|"enqueues"| node_backend_tasks
node_backend_celery -->|"runs"| node_backend_tasks
node_backend_integrations -->|"ingests to"| node_backend_services
node_backend_integrations -->|"syncs via"| node_backend_tasks
node_backend_exports -->|"delegates"| node_powerpoint_mcp
node_frontend_app -->|"reads/writes"| node_backend_main
node_frontend_components -->|"compose"| node_frontend_app
node_www_site -->|"public api"| node_backend_main
node_cli_client -->|"syncs"| node_backend_main
node_cli_client -.->|"shares client flows"| node_plugin_runtime
node_plugin_runtime -->|"uploads"| node_backend_main
node_agent_plugins -->|"use"| node_plugin_runtime
node_browser_extension -->|"syncs"| node_backend_main
node_collab_service -->|"supports"| node_frontend_app
node_docker_stack -->|"orchestrates"| node_backend_main
node_docker_stack -->|"orchestrates"| node_frontend_app
node_docker_stack -->|"orchestrates"| node_www_site
node_caddy_proxy -->|"fronts"| node_www_site
node_caddy_proxy -->|"fronts"| node_frontend_app
node_github_actions -->|"builds"| node_docker_stack
node_github_actions -->|"publishes"| node_agent_plugins

click node_backend_main "https://github.com/fergana-labs/stash/blob/main/backend/main.py"
click node_backend_routers "https://github.com/fergana-labs/stash/tree/main/backend/routers"
click node_backend_services "https://github.com/fergana-labs/stash/tree/main/backend/services"
click node_backend_models "https://github.com/fergana-labs/stash/blob/main/backend/models.py"
click node_backend_migrations "https://github.com/fergana-labs/stash/tree/main/backend/migrations/versions"
click node_backend_celery "https://github.com/fergana-labs/stash/blob/main/backend/celery_app.py"
click node_backend_tasks "https://github.com/fergana-labs/stash/tree/main/backend/tasks"
click node_backend_integrations "https://github.com/fergana-labs/stash/tree/main/backend/integrations"
click node_backend_exports "https://github.com/fergana-labs/stash/tree/main/backend/exports"
click node_powerpoint_mcp "https://github.com/fergana-labs/stash/tree/main/powerpoint-mcp/src"
click node_frontend_app "https://github.com/fergana-labs/stash/tree/main/frontend/src/app/(app)"
click node_frontend_components "https://github.com/fergana-labs/stash/tree/main/frontend/src/components"
click node_www_site "https://github.com/fergana-labs/stash/tree/main/www/app"
click node_cli_client "https://github.com/fergana-labs/stash/tree/main/cli"
click node_plugin_runtime "https://github.com/fergana-labs/stash/tree/main/stashai/plugin"
click node_agent_plugins "https://github.com/fergana-labs/stash/tree/main/plugins"
click node_browser_extension "https://github.com/fergana-labs/stash/tree/main/chrome_extension"
click node_collab_service "https://github.com/fergana-labs/stash/blob/main/collab/src/server.ts"
click node_docker_stack "https://github.com/fergana-labs/stash/blob/main/docker-compose.yml"
click node_caddy_proxy "https://github.com/fergana-labs/stash/tree/main/Caddyfile"
click node_github_actions "https://github.com/fergana-labs/stash/blob/main/.github/workflows"

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_backend_main,node_backend_routers,node_backend_services,node_backend_models,node_backend_migrations,node_backend_celery,node_backend_tasks,node_backend_integrations,node_backend_exports,node_powerpoint_mcp toneBlue
class node_frontend_app,node_frontend_components,node_www_site,node_cli_client,node_plugin_runtime,node_agent_plugins,node_browser_extension,node_collab_service toneAmber
class node_docker_stack,node_caddy_proxy,node_github_actions toneMint
```

## Components

### Core platform

Backend system of record, async processing, integrations, and export services.

- [API app](https://github.com/fergana-labs/stash/blob/main/backend/main.py): fastapi app · Main backend entrypoint and application wiring. · `backend/main.py`
- [HTTP routers](https://github.com/fergana-labs/stash/tree/main/backend/routers): api routes · Endpoint surface for files, sessions, shares, skills, integrations, tasks, and more. · `backend/routers`
- [Domain services](https://github.com/fergana-labs/stash/tree/main/backend/services): business logic · Core workflows for memory, search, permissions, ask, sessions, files, comments, and sharing. · `backend/services`
- [Data models](https://github.com/fergana-labs/stash/blob/main/backend/models.py): orm schema · Relational model definitions for the product’s content and account data. · `backend/models.py`
- [Schema history](https://github.com/fergana-labs/stash/tree/main/backend/migrations/versions): alembic migrations · Evolution of the database schema over product generations. · `backend/migrations/versions`
- [Job runner](https://github.com/fergana-labs/stash/blob/main/backend/celery_app.py): celery async · Background queue and worker setup for heavy processing and delayed work. · `backend/celery_app.py`
- [Async tasks](https://github.com/fergana-labs/stash/tree/main/backend/tasks): background jobs · Embeddings, extraction, source sync, titles, and visualization jobs. · `backend/tasks`
- [Integrations](https://github.com/fergana-labs/stash/tree/main/backend/integrations): adapter layer · Provider/indexer/importer adapters for external systems such as GitHub, Slack, Gmail, Notion, Jira, Linear, and others. · `backend/integrations`
- [Export engine](https://github.com/fergana-labs/stash/tree/main/backend/exports): render/export · HTML, canvas, PDF, and native PowerPoint generation pipeline. · `backend/exports`
- [PPT runtime](https://github.com/fergana-labs/stash/tree/main/powerpoint-mcp/src): mcp service · Separate service boundary for specialized slide generation and session management. · `powerpoint-mcp/src`

### Client surfaces

Authenticated web app, public site, CLI, browser extension, and plugins.

- [App UI](https://github.com/fergana-labs/stash/tree/main/frontend/src/app/(app)): next.js web app · Authenticated product surface for files, sessions, skills, integrations, memory, and settings. · `frontend/src/app/(app)`
- [UI components](https://github.com/fergana-labs/stash/tree/main/frontend/src/components): frontend components · Shared editor, browser, collaboration, sharing, export, and visualization components. · `frontend/src/components`
- [Public site](https://github.com/fergana-labs/stash/tree/main/www/app): next.js marketing · Marketing, docs, blog, public pages, and lightweight public APIs. · `www/app`
- [CLI client](https://github.com/fergana-labs/stash/tree/main/cli): operator cli · Local command-line interface for sign-in, VFS browsing, imports, sharing, and MCP integration. · `cli`
- [Plugin runtime](https://github.com/fergana-labs/stash/tree/main/stashai/plugin): session hooks · Shared agent hook and upload runtime used by plugins and agent adapters. · `stashai/plugin`
- [Agent plugins](https://github.com/fergana-labs/stash/tree/main/plugins): tool adapters · Claude, Cursor, Codex, Gemini, OpenCode, OpenClaw, and related adapters. · `plugins`
- [Browser extension](https://github.com/fergana-labs/stash/tree/main/chrome_extension): chrome extension · In-browser capture and sync surface for agent/chat sessions. · `chrome_extension`
- [Collab service](https://github.com/fergana-labs/stash/blob/main/collab/src/server.ts): realtime server · Dedicated collaboration/runtime boundary for shared editing and coordination. · `collab/src/server.ts`

### Operations

Container, proxy, release, and deployment automation.

- [Docker stack](https://github.com/fergana-labs/stash/blob/main/docker-compose.yml): compose deployment · Local and production container orchestration and proxy setup. · `docker-compose.yml`
- [Edge proxy](https://github.com/fergana-labs/stash/tree/main/Caddyfile): caddy config · Public HTTPS reverse proxy and routing layer. · `Caddyfile`
- [Release CI](https://github.com/fergana-labs/stash/blob/main/.github/workflows): github actions · Test, publish, and versioning workflows for the repository. · `.github/workflows`

## Connections

- API app → HTTP routers: mounts · App wires all HTTP surfaces through routers.
- API app → Domain services: uses · Request handlers delegate to domain services.
- HTTP routers → Domain services: calls · Routers translate API requests into service workflows.
- Domain services → Data models: persists · Services operate on relational records and content objects.
- Data models → Schema history: evolves via · Schema changes are tracked through Alembic history.
- Domain services → Async tasks: enqueues · Heavy work is pushed to asynchronous jobs.
- Job runner → Async tasks: runs · Celery worker/process orchestration executes task modules.
- Integrations → Domain services: ingests to · External data is normalized before landing in core storage.
- Integrations → Async tasks: syncs via · Integration sync and indexing use background jobs.
- Export engine → PPT runtime: delegates · Specialized slide generation can be handled by a separate runtime.
- App UI → API app: reads/writes · Authenticated UI talks to the backend API.
- UI components → App UI: compose · Reusable UI pieces power the app surface.
- Public site → API app: public api · Public pages, comments, and tracking coordinate with backend services.
- CLI client → API app: syncs · CLI authenticates and exchanges content with the backend.
- CLI client → Plugin runtime: shares client flows · CLI and plugin ecosystems overlap on uploads and agent tooling.
- Plugin runtime → API app: uploads · Captured sessions and transcripts stream into the backend.
- Agent plugins → Plugin runtime: use · Individual agent adapters reuse the shared hook/upload runtime.
- Browser extension → API app: syncs · Extension captures browser-side agent activity and uploads it.
- Collab service → App UI: supports · Collaboration features surface through the authenticated UI.
- Docker stack → API app: orchestrates · Compose stack deploys the backend and adjacent services.
- Docker stack → App UI: orchestrates · Compose stack deploys the app frontend.
- Docker stack → Public site: orchestrates · Compose stack deploys the public site.
- Edge proxy → Public site: fronts · Reverse proxy terminates HTTPS and routes public traffic.
- Edge proxy → App UI: fronts · Reverse proxy also serves the authenticated frontend.
- Release CI → Docker stack: builds · CI publishes and validates containerized deployments.
- Release CI → Agent plugins: publishes · Workflows bump and release plugin packages.
