Skip to content

Architecture

cyril-fl edited this page Nov 30, 2026 · 1 revision

Architecture

Tide is one Go module (github.com/cyril-fl/tide) and a Nuxt web app (web/), on PostgreSQL and an S3 store. This page is the map for someone who reads or changes the code.

The shape

 Web app (Nuxt)      CLI (tide)         Agent (MCP)
       \                |                  /
        \               |        tide mcp, stdio  ·  /mcp over HTTP
         +------ the JSON API (/api, core/api) ------+
                         |
              processes (core/services/process)
                         |
          domain models (core/domain, Bun)
                         |
              PostgreSQL            Silo (S3): the images

Every client goes through the API, which holds the business code. A rule (a title, a tag, the trash) is written once and applies the same way on every side. The CLI never opens the database.

Two binaries

Binary Folder Role
tide-server cmd/tide-server/, core/server/ The only one on the database and Silo. serve runs the API (and the web app, and the MCP over HTTP when asked); it also holds the admin's commands (user add, user reset-password, rotate-secret).
tide cmd/tide/, cli/ The CLI and tide mcp. A client of the API only (Cobra, plus Huh forms and Bubble Tea screens).

Folders

Folder Content
cmd/ The two binaries and the Cobra wiring
config/ config.yaml: the commands, their help texts and flags, built into the binary
core/api/ The routes, one folder per route (<verb>-<noun>/route.go), wired in router.go
core/server/ tide-server serve, the admin's commands, the MCP over HTTP and its OAuth
core/services/process/ The business logic: one process per use case
core/domain/ The models (Bun structs), their JSON tags are the API's JSON
core/services/ The rest: encryption (secret), Silo (silo), titles (notetitle), links (wikilink), the graph layout (forcelayout), line diffs (linediff), the schema…
cli/ One folder per command (cli/cmd-<verb>-<noun>/), the MCP (cli/cmd-mcp/), the API client (cli/services/apiclient/, generated from the OpenAPI)
web/ The Nuxt web app
docs/ The OpenAPI contract (generated) and the reference

Processes

A use case is a process built on plum's Process: a list of guarded steps that run in order, stop at the first error and cache their result.

func (p *run) Run() {
    p.makeFolder()
    p.saveFolder()
}

Each step starts with if p.HasErr() { return }; the caller checks HasErr() then reads GetErr(). A process takes a bun.IDB, so a test passes a transaction that is rolled back. Errors are sentinels (ErrNoTitle…), wrapped with %w; the API maps them to HTTP statuses in one table (core/api/services/respond/respond.go).

A request, end to end

  1. The router wraps the mux in guard (the Origin check) then auth (the session cookie or the bearer token; the account goes into the context).
  2. A route handler decodes the body (unknown fields refused, 10 MiB at most), runs the process with the request's context, then answers JSON or an error.
  3. The process runs its steps. Every query filters by account (domain.UserID(ctx)).
  4. Text, titles, folder names, tags and snippets are encrypted with the account's key before they are written (Administration).
  5. Changes are published on the account's event stream, which the open web apps follow (GET /api/events).

The schema

There is no migration tool. At every start, the server creates the missing tables, indexes and the columns a model gained. A rename, a type change or data to rewrite goes in a one-time migration of createschema/migrations.go, run once per database and never edited once shipped. See Data for the tables.

The web app

Nuxt 4 and Nuxt UI 4, client side only (ssr: false): the build is static, and the server serves it next to the API in production. API calls go through one composable (useApi()), types come from the generated api.d.ts, every text is in fr.json and en.json, and colors come from theme tokens, never hard-coded.

The CLI and the MCP move together

What one can do on the notes, the other can: a change to a tool, an argument or a flag lands on both, and what both need (decoding, saved searches, snippets, files, batched reads) lives once in cli/services/apiclient. The CLI's --json output is a contract held by a golden test.

Background work

tide-server serve runs a cleanup at startup and every hour: it purges the notes and folders past the trash's retention, the files no note cites, the expired invitations and sessions.

Clone this wiki locally