# tunar-ssp/tssp architecture

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

- Interactive diagram: https://gitdiagram.com/tunar-ssp/tssp
- Repository: https://github.com/tunar-ssp/tssp

## Overview

1. **Overall shape**
   This is a Rust monorepo for a self-hosted LAN-first storage and transfer system. The three main runtime products are the daemon (`tsspd`), the CLI client (`tssp`), and the embedded web dashboard (`tssp-web`) served by the daemon. The architecture is deliberately split into domain logic, application services, and adapters.

2. **Core layering**
   The cleanest architectural boundary is:
   - `tssp-domain`: pure types and validation rules
   - `tssp-ports`: abstract interfaces for storage, repositories, clocks, IDs, queries, sessions, and blobs
   - `tssp-app`: use-case services that orchestrate domain and ports
   - adapters: filesystem, SQLite, and system services
   - binaries/UI: `tsspd`, `tssp`, and the Svelte frontend

3. **Domain model**
   `tssp-domain` contains the invariant-heavy model for files, notes, tags, sessions, hashes, text, pagination, search queries, timestamps, and terminal/LSP-related concepts. This is where data correctness is enforced before anything touches storage or HTTP. It is the foundation shared by both the daemon and the CLI.

4. **Ports and abstract dependencies**
   `tssp-ports` defines the dependency boundaries the rest of the system targets: blob storage, repositories, queries, sessions, clocks, IDs, and workspace access. The application layer depends on these traits rather than on SQLite, the filesystem, or wall-clock APIs directly. This makes the storage backend swappable and keeps use cases testable.

5. **Application services**
   `tssp-app` implements the business workflows: upload, delete, folders, notes, tags, pins, sessions, audit, workspace file handling, and upload cleanup behavior. These services are the main coordination layer, combining validation, repository updates, blob writes, and side effects. Important cross-cutting behavior like idempotent tag mutation, final-reference blob cleanup, and upload rollback lives here rather than in controllers.

6. **Persistence and storage adapters**
   `tssp-adapter-fs` stores file blobs on disk using content-addressed BLAKE3 storage with fanout directories and deduplication. `tssp-adapter-sqlite` stores metadata in SQLite with migrations, WAL configuration, prepared statements, integrity checks, aggregate counts, and relation joins for tags and sessions. `tssp-adapter-system` supplies UTC time, UUIDv7 file IDs, and session tokens. These adapters satisfy the ports used by the app layer.

7. **Daemon (`tsspd`) as the orchestration boundary**
   `tsspd` is the primary server process. It wires config, auth, router, state, metrics, startup, cleanup jobs, rate limiting, public API, and workspace features into a single Axum-based service. It owns the runtime boundaries: HTTP, WebSocket/LSP integration, uploads/downloads, search, notes, admin functions, and background maintenance.

8. **HTTP API surface**
   The daemon exposes health/readiness probes plus `/api/v1/*` endpoints for files, tags, pins, search, notes, workspaces, sessions, and auth. The request path is: HTTP handler → application service → ports → adapters. The API layer also supports public/shared access patterns, bulk actions, file content streaming, and GCS-style static dashboard hosting.

9. **Authentication and authorization**
   Authentication is dual-mode: open on trusted LAN by default, but password/hash-based auth is required when exposed remotely. The `tsspd/src/auth` subtree contains handlers, middleware, device trust, user management, local-network heuristics, and auth storage. Admin-oriented flows are separated under `admin/`, while public links and public sessions are handled separately from authenticated user sessions.

10. **Workspace and editing subsystem**
   Workspace editing is its own subsystem spanning backend workspace state, filesystem interaction, terminal/LSP support, and front-end editor views. On the server side, `workspace_fs`, `workspace_features`, `terminal_*`, `lsp`, and `lsp_ws` support file-tree manipulation and interactive editing sessions. On the frontend, the workspace views, Monaco/Tiptap-style editors, and terminal client components consume those APIs. This is the main interactive “remote dev” boundary in the product.

11. **Notes, search, tags, pins, and trash**
   Notes are treated as a first-class object with dedicated handlers, query/response types, validation, and tests. Tags and pins are separate metadata dimensions with their own mutation and list flows. Search is a distinct query path, not just client-side filtering. Deletion and trash-related cleanup are explicit subsystems, with garbage collection and temp/terminal/trash cleanup jobs in the daemon.

12. **CLI client (`tssp`)**
   `tssp` is a thin command surface that mirrors the daemon’s API and local workspace operations. It includes commands like status, list, search, info, pull, tag/untag, pin/unpin, pins, remove, upload, login/logout, and workspace-related actions. The CLI is organized around command modules plus shared config/discovery/session helpers, and uses `tssp-cli-core` for output formatting and exit codes.

13. **Web frontend**
   The `frontend/` package is a Svelte/Vite UI that talks to the daemon through typed API service modules. It is organized around views for auth, drive/files, notes, workspace, public links, search, admin, and operations, with component libraries, stores, and utility layers beneath. The frontend is a consumer of server APIs rather than a separate backend.

14. **Cross-cutting operational concerns**
   The repo includes explicit handling for metrics, rate limiting, integrity checks, status/health reporting, startup sequencing, and cleanup tasks. There are also extensive integration and HTTP tests in the daemon and adapter crates, which suggests the architecture is validated across the main boundaries: storage, API, auth, uploads, and workspace behavior.

15. **How to draw the system**
   A useful architecture diagram would center on `tsspd` as the hub, with arrows to:
   - filesystem blob storage
   - SQLite metadata store
   - system services for time/IDs/tokens
   - CLI clients over HTTP
   - browser frontend over HTTP/WebSocket
   - optional public/shared access paths
   Above that, show `tssp-app` as the use-case layer between transport and adapters, and `tssp-domain`/`tssp-ports` as the shared policy boundary underneath.

Main entry points: [`crates/tsspd/src/lib.rs`](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/lib.rs) (tsspd), [`crates/tsspd/src/router.rs`](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/router.rs) (router), [`crates/tssp-ports/src/lib.rs`](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-ports/src/lib.rs) (tssp-ports), [`crates/tssp-app/src/lib.rs`](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-app/src/lib.rs) (tssp-app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core policy"]
  node_tssp_domain["tssp-domain<br/>domain model<br/>[lib.rs]"]
  node_tssp_ports["tssp-ports<br/>interfaces<br/>[lib.rs]"]
  node_tssp_app["tssp-app<br/>use-case layer<br/>[lib.rs]"]
end

subgraph group_adapters["Adapters"]
  node_adapter_fs[("fs adapter<br/>blob storage<br/>[lib.rs]")]
  node_adapter_sqlite[("sqlite adapter<br/>metadata store<br/>[lib.rs]")]
  node_adapter_system(("system adapter<br/>system services<br/>[lib.rs]"))
end

subgraph group_daemon["Daemon"]
  node_tsspd["tsspd<br/>daemon<br/>[lib.rs]"]
  node_daemon_auth["auth<br/>[mod.rs]"]
  node_daemon_router["router<br/>HTTP routing<br/>[router.rs]"]
  node_daemon_api_files["files<br/>API handlers<br/>[file.rs]"]
  node_daemon_api_notes["notes<br/>API handlers<br/>[mod.rs]"]
  node_daemon_api_tags["tags<br/>API handlers<br/>[tags.rs]"]
  node_daemon_api_workspace["workspace<br/>editing subsystem"]
  node_daemon_api_public["public api<br/>sharing<br/>[public_api.rs]"]
  node_daemon_ops["ops<br/>background jobs<br/>[startup.rs]"]
end

subgraph group_cli["CLI"]
  node_tssp_cli["tssp<br/>cli client<br/>[main.rs]"]
  node_cli_core["cli core<br/>presentation helpers<br/>[lib.rs]"]
end

subgraph group_frontend["Frontend"]
  node_frontend_app["frontend<br/>svelte ui<br/>[App.svelte]"]
  node_frontend_api["api client<br/>typed services<br/>[index.ts]"]
  node_frontend_workspace["workspace ui<br/>editor surface"]
end

node_tssp_app -->|"validates"| node_tssp_domain
node_tssp_app -->|"depends on"| node_tssp_ports
node_adapter_fs -->|"implements"| node_tssp_ports
node_adapter_sqlite -->|"implements"| node_tssp_ports
node_adapter_system -->|"implements"| node_tssp_ports
node_tsspd -->|"orchestrates"| node_tssp_app
node_tsspd -->|"uses"| node_adapter_fs
node_tsspd -->|"uses"| node_adapter_sqlite
node_tsspd -->|"uses"| node_adapter_system
node_tsspd -->|"contains"| node_daemon_auth
node_tsspd -->|"contains"| node_daemon_router
node_daemon_router -->|"routes to"| node_daemon_api_files
node_daemon_router -->|"routes to"| node_daemon_api_notes
node_daemon_router -->|"routes to"| node_daemon_api_tags
node_daemon_router -->|"routes to"| node_daemon_api_workspace
node_daemon_router -->|"routes to"| node_daemon_api_public
node_daemon_ops -->|"supports"| node_tsspd
node_tssp_cli -->|"formats via"| node_cli_core
node_tssp_cli -->|"calls"| node_tsspd
node_frontend_app -->|"uses"| node_frontend_api
node_frontend_app -->|"contains"| node_frontend_workspace
node_frontend_api -->|"calls"| node_tsspd
node_daemon_api_public -->|"serves"| node_frontend_app
node_daemon_api_workspace -->|"supports"| node_frontend_workspace

click node_tssp_domain "https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-domain/src/lib.rs"
click node_tssp_ports "https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-ports/src/lib.rs"
click node_tssp_app "https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-app/src/lib.rs"
click node_adapter_fs "https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-adapter-fs/src/lib.rs"
click node_adapter_sqlite "https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-adapter-sqlite/src/lib.rs"
click node_adapter_system "https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-adapter-system/src/lib.rs"
click node_tsspd "https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/lib.rs"
click node_daemon_auth "https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/auth/mod.rs"
click node_daemon_router "https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/router.rs"
click node_daemon_api_files "https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/file.rs"
click node_daemon_api_notes "https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/notes/mod.rs"
click node_daemon_api_tags "https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/tags.rs"
click node_daemon_api_workspace "https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/workspace_features.rs"
click node_daemon_api_public "https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/public_api.rs"
click node_daemon_ops "https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/startup.rs"
click node_tssp_cli "https://github.com/tunar-ssp/tssp/blob/main/crates/tssp/src/main.rs"
click node_cli_core "https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-cli-core/src/lib.rs"
click node_frontend_app "https://github.com/tunar-ssp/tssp/blob/main/frontend/src/App.svelte"
click node_frontend_api "https://github.com/tunar-ssp/tssp/blob/main/frontend/src/lib/api/index.ts"
click node_frontend_workspace "https://github.com/tunar-ssp/tssp/blob/main/frontend/src/views/workspace/WorkspaceView.svelte"

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_tssp_domain,node_tssp_ports,node_tssp_app toneBlue
class node_adapter_fs,node_adapter_sqlite,node_adapter_system toneAmber
class node_tsspd,node_daemon_auth,node_daemon_router,node_daemon_api_files,node_daemon_api_notes,node_daemon_api_tags,node_daemon_api_workspace,node_daemon_api_public,node_daemon_ops toneMint
class node_tssp_cli,node_cli_core toneRose
class node_frontend_app,node_frontend_api,node_frontend_workspace toneIndigo
```

## Components

### Core policy

Shared domain model, ports, and application workflows.

- [tssp-domain](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-domain/src/lib.rs): domain model · Invariant-heavy types for files, notes, tags, sessions, hashes, text, pagination, search, time, terminal, and LSP concepts. · `crates/tssp-domain/src/lib.rs`
- [tssp-ports](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-ports/src/lib.rs): interfaces · Abstract traits for blob storage, repositories, queries, sessions, clocks, IDs, records, and workspace access. · `crates/tssp-ports/src/lib.rs`
- [tssp-app](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-app/src/lib.rs): use-case layer · Business workflows that coordinate validation, repository updates, blob writes, and cleanup side effects. · `crates/tssp-app/src/lib.rs`

### Adapters

Storage and system implementations behind the ports.

- [fs adapter](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-adapter-fs/src/lib.rs): blob storage · Content-addressed filesystem blob storage with deduplication and workspace file handling. · `crates/tssp-adapter-fs/src/lib.rs`
- [sqlite adapter](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-adapter-sqlite/src/lib.rs): metadata store · SQLite persistence for metadata, queries, notes, sessions, migrations, and joins. · `crates/tssp-adapter-sqlite/src/lib.rs`
- [system adapter](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-adapter-system/src/lib.rs): system services · Clock, UUIDv7 IDs, and session token generation. · `crates/tssp-adapter-system/src/lib.rs`

### Daemon

Primary server process and its major subsystems.

- [tsspd](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/lib.rs): daemon · Axum-based server process that wires auth, API routes, workspace features, metrics, cleanup, and runtime state. · `crates/tsspd/src/lib.rs`
- [auth](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/auth/mod.rs): authentication · LAN-aware auth, device trust, user management, middleware, and auth storage. · `crates/tsspd/src/auth/mod.rs`
- [router](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/router.rs): HTTP routing · Top-level HTTP route assembly for API, health, public access, and dashboard hosting. · `crates/tsspd/src/router.rs`
- [files](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/file.rs): API handlers · File transfer, content access, deletion, renaming, moving, and trash flows. · `crates/tsspd/src/file.rs`
- [notes](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/notes/mod.rs): API handlers · Notes query, validation, response shaping, and handlers. · `crates/tsspd/src/notes/mod.rs`
- [tags](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/tags.rs): API handlers · Tag mutation and listing endpoints. · `crates/tsspd/src/tags.rs`
- [workspace](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/workspace_features.rs): editing subsystem · Workspace filesystem, file tree, terminals, LSP, WebSocket integration, and interactive editing state. · `crates/tsspd/src/workspace_features.rs`
- [public api](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/public_api.rs): sharing · Public/shared sessions, links, and unauthenticated access paths. · `crates/tsspd/src/public_api.rs`
- [ops](https://github.com/tunar-ssp/tssp/blob/main/crates/tsspd/src/startup.rs): background jobs · Startup sequencing, integrity checks, metrics, rate limiting, garbage collection, and cleanup tasks. · `crates/tsspd/src/startup.rs`

### CLI

Command-line client and shared presentation helpers.

- [tssp](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp/src/main.rs): cli client · Command-line client that mirrors daemon capabilities for status, list, search, uploads, tags, pins, sessions, auth, and workspace actions. · `crates/tssp/src/main.rs`
- [cli core](https://github.com/tunar-ssp/tssp/blob/main/crates/tssp-cli-core/src/lib.rs): presentation helpers · Shared CLI output formatting and exit codes. · `crates/tssp-cli-core/src/lib.rs`

### Frontend

Browser UI and its feature surfaces.

- [frontend](https://github.com/tunar-ssp/tssp/blob/main/frontend/src/App.svelte): svelte ui · Svelte/Vite browser application that consumes typed daemon APIs for drive, notes, workspace, public, search, auth, and admin flows. · `frontend/src/App.svelte`
- [api client](https://github.com/tunar-ssp/tssp/blob/main/frontend/src/lib/api/index.ts): typed services · Frontend service modules for drive, notes, auth, workspace, sharing, search, and admin endpoints. · `frontend/src/lib/api/index.ts`
- [workspace ui](https://github.com/tunar-ssp/tssp/blob/main/frontend/src/views/workspace/WorkspaceView.svelte): editor surface · Browser workspace surface with Monaco/Tiptap editors, terminal client, file tree, and inspector views. · `frontend/src/views/workspace/WorkspaceView.svelte`

## Connections

- tssp-app → tssp-domain: validates · Business workflows enforce domain invariants before persistence.
- tssp-app → tssp-ports: depends on · Use cases target abstract repository, blob, clock, ID, query, and workspace ports.
- fs adapter → tssp-ports: implements · Filesystem blob storage satisfies the blob/workspace boundary.
- sqlite adapter → tssp-ports: implements · SQLite satisfies repository, query, notes, and session ports.
- system adapter → tssp-ports: implements · System time, IDs, and tokens fulfill infrastructure ports.
- tsspd → tssp-app: orchestrates · The daemon wires HTTP handlers to application services.
- tsspd → fs adapter: uses · Runtime stores and reads blobs from the filesystem adapter.
- tsspd → sqlite adapter: uses · Runtime persists and queries metadata through SQLite.
- tsspd → system adapter: uses · Runtime draws time and identity services from the system adapter.
- tsspd → auth: contains · Authentication and authorization are handled inside the daemon.
- tsspd → router: contains · Route assembly is the daemon's HTTP boundary.
- router → files: routes to · File-related endpoints are exposed through the router.
- router → notes: routes to · Notes endpoints are exposed through the router.
- router → tags: routes to · Tag endpoints are exposed through the router.
- router → workspace: routes to · Workspace and editing endpoints are exposed through the router.
- router → public api: routes to · Public/shared access paths are exposed separately.
- ops → tsspd: supports · Background maintenance supports the daemon runtime.
- tssp → cli core: formats via · Commands rely on shared output and exit-code helpers.
- tssp → tsspd: calls · The CLI talks to the daemon over its API surface.
- frontend → api client: uses · UI screens consume typed service modules.
- frontend → workspace ui: contains · The browser app includes the remote workspace editor surface.
- api client → tsspd: calls · Frontend services interact with daemon endpoints.
- public api → frontend: serves · The daemon serves the browser dashboard and public views.
- workspace → workspace ui: supports · Workspace transport and editing features back the UI.
