# TOSV implementation root How the vault is built, end to end, in one guided tour. This page narrates; [SPEC](../SPEC.md) normates. On any conflict the spec wins and this page gets fixed the same commit. No sharding: the spec stays the shardable canonical doc, this root stays a readable single file with links outward. ## Shape Two files plus one shared core (`tosv.cpp` for HTTP, `tosv-sftp.cpp` for SSH plus SFTP, both C++17 stdlib plus POSIX plus pthreads plus pinned static libsodium, both including `vault.inc` for the DB, crypt, cache, audit, and rate-limit core), built by `make build` (vendored sodium plus hardened flags) in the [Makefile](../Makefile), versioned by [VERSION](../VERSION). Data root is the working directory: `.env.json`, `tosv_db.txt`, `tosv_audit.log`, `tosv_store/`, plus `sftp_gateway_keys` and the SFTP host key. Subsystem mechanics live in [tosv.AGENTS](../tosv.AGENTS.md) and [sftp.AGENTS](../sftp.AGENTS.md). ## Request path Accept loop on 127.0.0.1:8765, one detached thread per connection, raw header parse to 64KB, Content-Length body read, route match, auth gate, handler, close. Shared state (sessions, rate windows, audit, DB save) holds short mutexes, never across socket IO. Routes and codes: SPEC 6.2; surfaces: SPEC 4. ## Auth ladder Bootstrap once ([bootstrap](sec-bootstrap.md)), session cookie for the wizard ([session](sec-session.md)), Basic store creds for upload, Basic grant creds plus [IP](sec-ip-gate.md) plus [window](sec-time-window.md) for fetch and WebDAV, duress pair for [wipe](sec-duress.md). Guessing dies on [rate limits](sec-rate-limit.md). ## Crypto walk Per request: per-blob salt, Argon2id key from store auth, secretstream seal over 64KB chunks ([AEAD](sec-future-crypto.md)), 64KB chunk streaming ([streaming](sec-streaming.md)), buffers wiped after use ([memory](sec-memory.md)). No stored keys; version plus hash travel in the tag. v2 is tamper-evident; v1 blobs stay readable through the frozen [legacy path](sec-layers.md). ## Storage Grants in an atomic flat DB ([DB](sec-db.md)), blobs as UUID-named ciphertext ([UUID](sec-uuid.md)), events in a minimal [audit](sec-audit.md) log, modes defaulting append-only ([modes](sec-modes.md)). WebDAV serves the same store with the same identity model ([dav](sec-dav.md)). ## SSH plus SFTP `tosv-sftp` is a standalone daemon, no OpenSSH linkage: own SSH-2.0 transport (mlkem768x25519-sha256 hybrid or curve25519-sha256 with strict-kex required, chacha20-poly1305 at openssh.com, ssh-ed25519 host and client keys, rekey at 1GB or 3600s), own SFTP v3 layer over the vault store. Clients authenticate by gateway key (`sftp_gateway_keys`, label plus bound gids), then prove each grant in-band by addressing `///`; passes never appear in audit lines. One session channel, subsystem `sftp` only; exec, shell, pty, env, and TCP forwarding are refused. Full contract in [sftpserver](sftpserver.md) (60 SF plus 8 INT), decision in [ADR 0008](adr/0008-own-ssh-sftp.md), ops in the [SFTP runbook](runbooks/sftp.md). ## Transport and ops Loopback in binary, stunnel at edge ([transport](sec-transport.md)), [caps](sec-caps.md) on every input, boring shutdown per D-04, daily restic backups with monthly restore drill, seven runbooks (see the [runbook index](runbooks/README.md)), DTAP separation, 48h postmortems. Gates G0-G4 in SPEC 6.5; status in [BUILD-TRACK](../BUILD-TRACK.md). ## Build order M1 core HTTP plus DB plus auth plus wizard, M2 crypto plus streaming fixes, M3 WebDAV plus rates plus audit plus duress, M4 tests plus runbooks plus drill plus gates, M5 issue-zero, M6 critical pass, M7 v2 AEAD, M8 load tests, M9 key cache, M10 own SSH plus SFTP daemon. Estimates and freeze: SPEC 7 and D-12. Decisions: SPEC 9 plus [ADR 0001](adr/0001-adopt-seriousdevelopment.md), [ADR 0002](adr/0002-use-cpp-single-file.md), [ADR 0005](adr/0005-v2-aead-migration.md), and [ADR 0008](adr/0008-own-ssh-sftp.md). ## Vision and threats Start at the [concept](concept.md) for why, then the [security index](security.md) for the full 22-measure map with pros, cons, and recursive resolutions. ## See also - [Concept](concept.md), [security index](security.md), [SPEC](../SPEC.md), [tosv.AGENTS](../tosv.AGENTS.md), [sftp.AGENTS](../sftp.AGENTS.md), [SFTP requirements](sftpserver.md), [status](status.md)