# charmbracelet/soft-serve architecture

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

- Interactive diagram: https://gitdiagram.com/charmbracelet/soft-serve
- Repository: https://github.com/charmbracelet/soft-serve

## Overview

1. **What this repo is**
   Soft Serve is a single Go binary that hosts a self-contained Git service. It exposes the same repository through multiple entrypoints: SSH, HTTP(S), the Git protocol, and an SSH-driven TUI. The server is also its own admin UI for users, repos, access tokens, collaborators, and settings.

2. **Top-level process layout**
   `cmd/soft/main.go` is the CLI entry. It dispatches into four main modes: `serve` to run the server, `browse` for local repository browsing, `admin` for admin helpers, and `hook` for hook management. The `soft serve` mode is the long-running daemon; the other commands are mostly client-side tools.

3. **Server-facing transport boundary**
   The runtime server is split into transport-specific front doors:
   - `pkg/ssh` for interactive SSH sessions and SSH commands
   - `pkg/web` for HTTP endpoints, clone support, auth-token login, health checks, and Git LFS HTTP
   - `pkg/daemon` for the Git protocol daemon
   - `pkg/stats` for an optional stats endpoint
   Each transport feeds into the same backend and store layers, so protocol differences are mostly at the edge.

4. **SSH is the control plane**
   SSH is the primary administration and interactive channel. `pkg/ssh/cmd` contains the command router for repo, user, token, settings, webhook, and other server-admin operations. The same SSH session can also open the TUI instead of a command. Authentication and session middleware live in `pkg/ssh/middleware.go` and `pkg/ssh/session.go`.

5. **Repository serving and Git operations**
   Git repository behavior is coordinated by `pkg/backend` and `pkg/git`, with the repository metadata and access decisions flowing through the store layer. This is where repo creation, import, rename, delete, branch/tag listing, tree/blob views, mirror pull behavior, and collaborator management are orchestrated. The root `git/` package provides lower-level repository and object utilities used by these features.

6. **Persistence model**
   Persistent state is split between the repository filesystem and the database. `pkg/store` is the application-facing data access layer for users, repos, collaborators, access tokens, settings, webhooks, and LFS metadata. `pkg/db` is the actual database layer with migrations and driver support for SQLite and Postgres. Repositories themselves live on disk under the configured data path, while metadata and permissions live in the DB.

7. **Authentication and authorization**
   Access control is centralized rather than per-transport. `pkg/access`, `pkg/backend/auth.go`, and related store code implement the access levels described in the README: `no-access`, `read-only`, `read-write`, and `admin-access`. SSH public keys are the primary identity mechanism, while HTTP access can use user access tokens. Anonymous and keyless access are configuration-driven and affect SSH, HTTP, and Git protocol behavior.

8. **Git LFS support**
   LFS is a first-class subsystem, not an add-on. `pkg/lfs` handles pointer parsing, transfer negotiation, and HTTP/SSH client behavior, while `pkg/backend/lfs.go` and `pkg/web/git_lfs.go` expose server-side endpoints. The architecture supports HTTP LFS out of the box and can optionally enable pure SSH transfer.

9. **Hooks, webhooks, and background work**
   There are two eventing paths:
   - server-side Git hooks: generated and managed via `pkg/hooks`, with per-repo and global hooks
   - repository webhooks: validated and dispatched by `pkg/webhook` and persisted via the store/DB
   Background work such as mirror pulls is scheduled through `pkg/jobs` and `pkg/cron`, with `pkg/sync/workqueue.go` handling queued asynchronous work.

10. **TUI and local browsing**
    The interactive UI is in `pkg/ui`. It is a terminal UI with repo-centric pages for files, commits, refs, stash, README, and empty states. The SSH session can launch this UI remotely, and `soft browse` can launch it locally against a filesystem repository. This UI is a consumer of the same backend data model used by the server commands.

11. **Configuration and runtime wiring**
    `pkg/config` loads YAML plus environment overrides and resolves server paths, listen addresses, URLs, and key files. It also governs which transports are enabled and where the data directory lives. `pkg/backend/context.go`, `pkg/db/context.go`, and similar context packages show that the app passes infrastructure objects through context rather than relying on globals.

12. **Data flow in practice**
    A typical request path is: transport entrypoint → auth/access check → backend/service logic → store/db and/or repository filesystem → response. For example, an SSH `repo blob` command reads repository data and permission state, then renders output through the SSH UI layer; a `git push` may create a repo on demand, update refs, run hooks, persist metadata, and enqueue follow-up work.

13. **Operational and packaging boundaries**
    The repo is packaged as a single deployable binary with release automation, Docker, and systemd integration. The `.nfpm`, `Dockerfile`, and GitHub Actions files support distribution, but they do not change the runtime architecture. The important deployment knobs are the data path, SSH host/client keys, database driver, and enabled listen addresses.

14. **Useful diagram anchors**
    If you draw this system, the main boxes are: client protocols, SSH/web/git-daemon/stats front ends, backend/service layer, store/DB, repository filesystem, Git LFS, webhooks/hooks/jobs, and the TUI. The most important arrows are from transport to backend, backend to store/DB and repo storage, and backend to hooks/webhooks/jobs for side effects.

Main entry points: [`pkg/backend/backend.go`](https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/backend.go) (Backend), [`cmd/soft/serve/serve.go`](https://github.com/charmbracelet/soft-serve/blob/main/cmd/soft/serve/serve.go) (Serve), [`pkg/backend/repo.go`](https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/repo.go) (Repos), [`pkg/ssh/ssh.go`](https://github.com/charmbracelet/soft-serve/blob/main/pkg/ssh/ssh.go) (SSH)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entrypoints["Entrypoints"]
  node_cmd_main["soft<br/>cli entry<br/>[main.go]"]
  node_cmd_serve["Serve<br/>daemon runner<br/>[serve.go]"]
  node_cmd_browse["Browse<br/>local client<br/>[browse.go]"]
end

subgraph group_frontdoors["Front Doors"]
  node_ssh_front["SSH<br/>transport<br/>[ssh.go]"]
  node_web_front["HTTP<br/>transport<br/>[server.go]"]
  node_gitd_front["Git Daemon<br/>transport<br/>[daemon.go]"]
  node_stats_front["Stats<br/>endpoint<br/>[stats.go]"]
  node_ssh_cmds["SSH Cmds<br/>command router<br/>[cmd.go]"]
  node_ssh_session["Session<br/>[session.go]"]
end

subgraph group_core["Core Services"]
  node_backend["Backend<br/>service coordinator<br/>[backend.go]"]
  node_authz["Access<br/>policy<br/>[auth.go]"]
  node_repo_svc["Repos<br/>repo service<br/>[repo.go]"]
  node_lfs_bridge["LFS<br/>[lfs.go]"]
end

subgraph group_data["Data Layer"]
  node_store[("Store<br/>[store.go]")]
  node_db[("DB<br/>database layer<br/>[db.go]")]
  node_repo_fs[("Repo Files<br/>filesystem storage<br/>[local.go]")]
  node_git_core["Git Core<br/>git engine<br/>[git.go]"]
end

subgraph group_aux["Auxiliary Systems"]
  node_lfs_core["LFS Core<br/>lfs engine<br/>[transfer.go]"]
  node_hooks["Hooks<br/>[hooks.go]"]
  node_webhooks["Webhooks<br/>event dispatch<br/>[webhook.go]"]
  node_jobs["Jobs<br/>background work<br/>[jobs.go]"]
  node_tui["TUI<br/>terminal ui<br/>[repo.go]"]
  node_config["Config<br/>[config.go]"]
end

node_cmd_main -->|"serve"| node_cmd_serve
node_cmd_main -->|"browse"| node_cmd_browse
node_cmd_serve -->|"loads"| node_config
node_cmd_serve -->|"starts"| node_ssh_front
node_cmd_serve -->|"starts"| node_web_front
node_cmd_serve -->|"starts"| node_gitd_front
node_cmd_serve -->|"starts"| node_stats_front
node_ssh_front -->|"routes"| node_ssh_cmds
node_ssh_front -->|"session"| node_ssh_session
node_web_front -->|"calls"| node_backend
node_gitd_front -->|"serves"| node_backend
node_stats_front -->|"reads"| node_backend
node_ssh_cmds -->|"uses"| node_backend
node_ssh_session -->|"opens"| node_tui
node_backend -->|"checks"| node_authz
node_backend -->|"orchestrates"| node_repo_svc
node_backend -->|"delegates"| node_lfs_bridge
node_backend -->|"persists"| node_store
node_backend -->|"operates on"| node_repo_fs
node_repo_svc -->|"uses"| node_git_core
node_repo_svc -->|"triggers"| node_hooks
node_repo_svc -->|"emits"| node_webhooks
node_repo_svc -->|"enqueues"| node_jobs
node_lfs_bridge -->|"uses"| node_lfs_core
node_lfs_bridge -->|"reads"| node_store
node_store -->|"backed by"| node_db
node_webhooks -->|"persists"| node_db
node_jobs -->|"tracks"| node_db
node_cmd_browse -->|"launches"| node_tui
node_tui -->|"consumes"| node_backend

click node_cmd_main "https://github.com/charmbracelet/soft-serve/blob/main/cmd/soft/main.go"
click node_cmd_serve "https://github.com/charmbracelet/soft-serve/blob/main/cmd/soft/serve/serve.go"
click node_cmd_browse "https://github.com/charmbracelet/soft-serve/blob/main/cmd/soft/browse/browse.go"
click node_ssh_front "https://github.com/charmbracelet/soft-serve/blob/main/pkg/ssh/ssh.go"
click node_web_front "https://github.com/charmbracelet/soft-serve/blob/main/pkg/web/server.go"
click node_gitd_front "https://github.com/charmbracelet/soft-serve/blob/main/pkg/daemon/daemon.go"
click node_stats_front "https://github.com/charmbracelet/soft-serve/blob/main/pkg/stats/stats.go"
click node_ssh_cmds "https://github.com/charmbracelet/soft-serve/blob/main/pkg/ssh/cmd/cmd.go"
click node_ssh_session "https://github.com/charmbracelet/soft-serve/blob/main/pkg/ssh/session.go"
click node_backend "https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/backend.go"
click node_authz "https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/auth.go"
click node_repo_svc "https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/repo.go"
click node_lfs_bridge "https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/lfs.go"
click node_store "https://github.com/charmbracelet/soft-serve/blob/main/pkg/store/store.go"
click node_db "https://github.com/charmbracelet/soft-serve/blob/main/pkg/db/db.go"
click node_repo_fs "https://github.com/charmbracelet/soft-serve/blob/main/pkg/storage/local.go"
click node_git_core "https://github.com/charmbracelet/soft-serve/blob/main/pkg/git/git.go"
click node_lfs_core "https://github.com/charmbracelet/soft-serve/blob/main/pkg/lfs/transfer.go"
click node_hooks "https://github.com/charmbracelet/soft-serve/blob/main/pkg/hooks/hooks.go"
click node_webhooks "https://github.com/charmbracelet/soft-serve/blob/main/pkg/webhook/webhook.go"
click node_jobs "https://github.com/charmbracelet/soft-serve/blob/main/pkg/jobs/jobs.go"
click node_tui "https://github.com/charmbracelet/soft-serve/blob/main/pkg/ui/pages/repo/repo.go"
click node_config "https://github.com/charmbracelet/soft-serve/blob/main/pkg/config/config.go"

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_cmd_main,node_cmd_serve,node_cmd_browse toneBlue
class node_ssh_front,node_web_front,node_gitd_front,node_stats_front,node_ssh_cmds,node_ssh_session toneAmber
class node_backend,node_authz,node_repo_svc,node_lfs_bridge toneMint
class node_store,node_db,node_repo_fs,node_git_core toneRose
class node_lfs_core,node_hooks,node_webhooks,node_jobs,node_tui,node_config toneIndigo
```

## Components

### Entrypoints

CLI modes that start the daemon or local tooling

- [soft](https://github.com/charmbracelet/soft-serve/blob/main/cmd/soft/main.go): cli entry · Main command that dispatches serve, browse, admin, and hook modes · `cmd/soft/main.go`
- [Serve](https://github.com/charmbracelet/soft-serve/blob/main/cmd/soft/serve/serve.go): daemon runner · Long-running server process and runtime wiring · `cmd/soft/serve/serve.go`
- [Browse](https://github.com/charmbracelet/soft-serve/blob/main/cmd/soft/browse/browse.go): local client · Local repository browser launcher · `cmd/soft/browse/browse.go`

### Front Doors

Protocol-specific server entrypoints

- [SSH](https://github.com/charmbracelet/soft-serve/blob/main/pkg/ssh/ssh.go): transport · Interactive SSH sessions and SSH command access · `pkg/ssh/ssh.go`
- [HTTP](https://github.com/charmbracelet/soft-serve/blob/main/pkg/web/server.go): transport · HTTP(S) endpoints for web UI, clone, auth, and LFS · `pkg/web/server.go`
- [Git Daemon](https://github.com/charmbracelet/soft-serve/blob/main/pkg/daemon/daemon.go): transport · Git protocol daemon entrypoint · `pkg/daemon/daemon.go`
- [Stats](https://github.com/charmbracelet/soft-serve/blob/main/pkg/stats/stats.go): endpoint · Optional stats endpoint · `pkg/stats/stats.go`
- [SSH Cmds](https://github.com/charmbracelet/soft-serve/blob/main/pkg/ssh/cmd/cmd.go): command router · Repo, user, token, settings, webhook, and other SSH-admin commands · `pkg/ssh/cmd/cmd.go`
- [Session](https://github.com/charmbracelet/soft-serve/blob/main/pkg/ssh/session.go): ssh session · Session middleware and interactive TUI handoff · `pkg/ssh/session.go`

### Core Services

Backend orchestration and policy

- [Backend](https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/backend.go): service coordinator · Central orchestration for repository, auth, settings, and side effects · `pkg/backend/backend.go`
- [Access](https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/auth.go): policy · Access control and identity checks across transports · `pkg/backend/auth.go`
- [Repos](https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/repo.go): repo service · Repository creation, import, rename, delete, refs, tree/blob, and collaborator flows · `pkg/backend/repo.go`
- [LFS](https://github.com/charmbracelet/soft-serve/blob/main/pkg/backend/lfs.go): lfs service · Server-side Git LFS integration and negotiation · `pkg/backend/lfs.go`

### Data Layer

Database and repository storage

- [Store](https://github.com/charmbracelet/soft-serve/blob/main/pkg/store/store.go): application store · Application-facing persistence for users, repos, tokens, settings, webhooks, and LFS metadata · `pkg/store/store.go`
- [DB](https://github.com/charmbracelet/soft-serve/blob/main/pkg/db/db.go): database layer · Driver, migrations, and database access for SQLite and Postgres · `pkg/db/db.go`
- [Repo Files](https://github.com/charmbracelet/soft-serve/blob/main/pkg/storage/local.go): filesystem storage · On-disk repository data under the configured data path · `pkg/storage/local.go`
- [Git Core](https://github.com/charmbracelet/soft-serve/blob/main/pkg/git/git.go): git engine · Repository and object utilities used by backend and transports · `pkg/git/git.go`

### Auxiliary Systems

UI, hooks, webhooks, jobs, and LFS

- [LFS Core](https://github.com/charmbracelet/soft-serve/blob/main/pkg/lfs/transfer.go): lfs engine · Pointer parsing, transfer, and client/server LFS helpers · `pkg/lfs/transfer.go`
- [Hooks](https://github.com/charmbracelet/soft-serve/blob/main/pkg/hooks/hooks.go): git hooks · Generated server-side hooks and hook management · `pkg/hooks/hooks.go`
- [Webhooks](https://github.com/charmbracelet/soft-serve/blob/main/pkg/webhook/webhook.go): event dispatch · Repository webhook validation, persistence, and dispatch · `pkg/webhook/webhook.go`
- [Jobs](https://github.com/charmbracelet/soft-serve/blob/main/pkg/jobs/jobs.go): background work · Mirror pulls and queued asynchronous work · `pkg/jobs/jobs.go`
- [TUI](https://github.com/charmbracelet/soft-serve/blob/main/pkg/ui/pages/repo/repo.go): terminal ui · Repo-centric terminal interface for files, commits, refs, stash, and README · `pkg/ui/pages/repo/repo.go`
- [Config](https://github.com/charmbracelet/soft-serve/blob/main/pkg/config/config.go): runtime config · YAML and environment configuration for transports, paths, keys, and listen addresses · `pkg/config/config.go`

## Connections

- soft → Serve: serve · Starts the daemon process
- soft → Browse: browse · Starts local repository browsing
- Serve → Config: loads · Resolves runtime paths, listeners, and enabled transports
- Serve → SSH: starts · Opens SSH transport
- Serve → HTTP: starts · Opens HTTP transport
- Serve → Git Daemon: starts · Opens Git daemon transport
- Serve → Stats: starts · Optionally opens stats endpoint
- SSH → SSH Cmds: routes · Dispatches SSH admin and repo commands
- SSH → Session: session · Handles interactive sessions and TUI launch
- HTTP → Backend: calls · Delegates web requests to backend services
- Git Daemon → Backend: serves · Bridges Git protocol operations to backend logic
- Stats → Backend: reads · Exposes runtime and repository stats
- SSH Cmds → Backend: uses · Performs admin and repo operations through backend
- Session → TUI: opens · Launches repo UI inside SSH session
- Backend → Access: checks · Central access and identity validation
- Backend → Repos: orchestrates · Coordinates repository and collaborator flows
- Backend → LFS: delegates · Handles LFS-specific server behavior
- Backend → Store: persists · Reads and writes application metadata
- Backend → Repo Files: operates on · Reads and writes repository contents on disk
- Repos → Git Core: uses · Performs repository and object operations
- Repos → Hooks: triggers · Runs server-side hook generation and execution
- Repos → Webhooks: emits · Dispatches repository events
- Repos → Jobs: enqueues · Schedules mirror pulls and async follow-up work
- LFS → LFS Core: uses · Shares pointer and transfer logic
- LFS → Store: reads · Uses stored LFS metadata and auth state
- Store → DB: backed by · Database-backed metadata persistence
- Webhooks → DB: persists · Stores webhook configuration and events
- Jobs → DB: tracks · Uses database state for queued work
- Browse → TUI: launches · Uses the same repo UI locally
- TUI → Backend: consumes · Reads repository data through backend services
