Skip to content
On this page

Apps

| apps/core-worker | File delivery, uploads, card processing, imports, exports, save by email and the API edge proxy | Cloudflare Workers | Cloudflare |— title: Architecture description: How Teak’s apps, backend and Cloudflare Workers fit together, and the rules every change keeps icon: network related:

  • /docs/adding-a-feature
  • /docs/development

Teak is a Turborepo monorepo. Every app talks to one Convex backend; one Cloudflare Worker handles files, background work and email. This page maps where each piece lives, how a saved card moves through them, and the rules that hold everywhere.

Teak’s apps talk to one Convex backend; the Core Worker processes cards, serves files from R2 and handles save by email

Apps

Path What it is Built with Runs on
apps/web The web app at app.teakvault.com Next.js Vercel
apps/docs teakvault.com: the website, these docs and the changelog Blume Vercel
apps/apple The iPhone, iPad and Mac app, with its share and Safari extensions SwiftUI App Store
apps/android The Android app Kotlin, Jetpack Compose Google Play
apps/extension The Chrome and Firefox extension WXT Chrome Web Store, Firefox Add-ons
apps/raycast The Raycast extension Raycast API Raycast Store
apps/cli The teak command line, published as teak-cli Bun, TypeScript npm
apps/core-worker File delivery, uploads, card processing, imports, exports, save by email and the API edge proxy Cloudflare Workers Cloudflare

Packages

Path What it is
packages/convex The Convex backend: schema, queries, mutations and actions, the public REST API, the MCP server, and shared/, the pure helpers other surfaces import
packages/files-protocol The contract between Convex and the Core Worker: operation shapes, a sign and a verify function for each signed request, op outcomes, storage keys, limits, and the card-processing stages and run params
packages/sdk teak-sdk, the public TypeScript client (SDK). The CLI and the browser extension send every request through it (createTeakClient, with the sign-in from createOAuthSession) and build it from source, as the docs and end-to-end tests do. Raycast pins the published version
packages/i18n The message catalogs for the web app and extension (Translating)
packages/mcp-app The card view MCP clients such as Claude show for Teak’s tools (Card views). bun run build writes it into packages/convex/mcp/appHtml.generated.ts, which the MCP server serves; a test fails when the two differ
packages/tests The end-to-end suite (Testing)

plugins/teak is Teak’s Claude plugin: the MCP server, a skill and slash commands. The root .claude-plugin/marketplace.json lists it, so Claude Code can install it from this repository.

How a saved card moves

  1. Save. A client calls a Convex mutation (the apps) or the public API (the CLI, Raycast, MCP and your scripts). Every signed-in surface gets its Convex identity from a WorkOS AuthKit session; WorkOS is the only sign-in provider in every environment.
  2. Queue. The mutation writes the card and, in the same transaction, a row in the workflow dispatch outbox (queueCardProcessing in packages/convex/card/processingRuns.ts). A flush (packages/convex/workflowDispatch.ts) hands due rows to the Core Worker, which starts a Cloudflare Workflow for each. A resend is safe: an instance that already exists counts as started. Each kind of row declares, beside its domain code, which workflow it starts, how long it may stay silent, and what happens when its run dies (card/processingRuns.ts, storage/objectDeletion.ts, and workflowRun.ts in export/, import/ and accountDeletion/); workflowDispatch/outbox.ts writes the rows and imports no domain code.
  3. Process. The card-processing Workflow (apps/core-worker/src/workflows/cardProcessing/run.ts) fetches link pages, renders thumbnails and previews, transcribes audio, reads text in images and asks Workers AI for tags and a summary. Each step reads and writes Convex through one signed endpoint, the workflow gateway.
  4. Show. Each write lands on the card, and every client’s live query updates. The card’s processingStatus records each stage (the list, and which ones a card type runs, are in packages/files-protocol/src/cardProcessing.ts), so a client can show what’s still running.

Every write a processing run makes carries the run’s processing revision. Editing a card bumps the revision and stops the older run, so a stale run can never overwrite newer work; its write is refused and the run ends as skipped.

  • Files live in a private R2 bucket. Convex mints signed URLs, and the Core Worker checks them, streams the object, and handles range requests and caching. Convex holds no R2 or Workers AI credentials: every byte and AI call goes through the Worker.
  • Media work runs in two Containers: a media renderer (ffmpeg and poppler, for video, audio and PDF) and a link fetcher that downloads remote images and media under the same SSRF rules as Convex. Link screenshots run on Browser Run.
  • Search by meaning uses Workers AI embeddings stored in Vectorize, one namespace per user, alongside Convex’s keyword search.
  • Scheduled work runs mostly as the Worker’s Cron Triggers, which call internal Convex functions for the table logic; packages/convex/cronSchedules.ts lists every schedule and where it runs.

Public API and MCP

The REST API, the MCP server, the OpenAPI spec and the OAuth discovery documents are Convex HTTP routes. In production, teakvault.com/api, /mcp and the discovery documents reach Convex only through the Core Worker’s edge proxy (apps/core-worker/src/edge/apiProxy.ts), which also rate-limits them. The docs site on Vercel has no rewrites for them. The API, MCP, SDK and CLI offer the same operations, and a test keeps them in step (Adding a Feature).

Save by email

Mail to [email protected] arrives through Cloudflare Email Routing at the Core Worker’s email handler (apps/core-worker/src/email), which checks the sender’s DMARC result and posts a signed request to Convex. Convex finds the account and makes the cards; attachments go to the Core Worker’s own signed upload URLs, so their bytes never pass through Convex.

Card types

Teak has eight card types: text, link, image, video, audio, document, palette and quote. Every surface handles all eight and tolerates values it doesn’t know (Adding a Feature).

Rules every change keeps

  • Client reads use the cached Convex query hooks; writes use Convex mutations or actions.
  • Import backend APIs from @teak/convex, generated data types from @teak/convex/_generated/dataModel, and shared constants from @teak/convex/shared/constants.
  • The web app owns its UI in apps/web/src. The browser extension keeps its own small copies of the button, wordmark and theme tokens. Pure helpers that several surfaces share (web, docs, extension, native ports) go in packages/convex/shared.
  • The Apple and Android apps port the same pure logic (Apple’s TeakCore, Android’s core:model: filters, card edits, Markdown blocks, save links, date search, grid rules) with the same test cases. Shared rows live as JSON in packages/convex/__tests__/shared/fixtures, which the TypeScript tests, Swift Testing and JUnit all read, so add a case there rather than to one port. A behavior change on one is ported to the other.
  • Card processing keeps its workflow retries, the processing-revision guard on every write, and a consistent processingStatus.
  • Workflow step names are durable history: a step is never renamed, and new steps go after the existing ones.
  • Every package moves in lockstep: one version across every manifest for each release.

Working in each workspace

Each workspace’s AGENTS.md points here. Run commands from the repository root unless a step says otherwise.

Web app (apps/web)

The web app owns all of its UI; nothing under src is shared with another workspace. src is grouped by kind of file; put new code in the folder that fits and keep a feature’s pieces together inside it.

Folder What goes there
app/ Routes, layouts and route handlers. Pages stay thin: they render a screen or compose components.
screens/ Page-level views that routes render: LibraryScreen (the library, a view or a folder, driven by its URL), TagsScreen, SettingsShell.
components/ui/ shadcn new-york primitives, added with the shadcn CLI (components.json).
components/<feature>/ One folder per area (cards, card-modal, search, settings…). Where a folder has an index.ts, import it through that from outside.
components/app-shell/ The signed-in frame: the shell, its skeletons, IntentLink and the WebMCP tools.
components/providers/ Providers and auth gates that layouts mount: WorkOS, Convex, PostHog, theme, the global file drop, and the library’s command bus (LibraryCommandsProvider: a shortcut or the command palette asks the composer to upload or record, Trash to empty, the shell to list shortcuts).
components/feedback/ Loading, empty, error and retry states that screens share.
hooks/ React hooks (use*). A hook that calls Convex keeps its testable core beside it (useFileUpload.ts wires useFileUploadCore.ts). useCardMutations holds the only binding of each card mutation, with its optimistic update; useCardActions runs the card actions; useCardTagEditor edits one card’s tags.
lib/ Modules without UI: the card actions (cardActions: each action’s key, label, where it works and what it does to a selection, which every menu, key and the shortcuts list read), card types, card tags, the library URL, search state, optimistic query updates (one predictor for single and bulk edits), shortcuts, the cached Convex query hooks, uploads, auth and security headers.
constants/, styles/ Static values; the theme tokens, prose styles and fonts.

Import with the @/ alias when you leave a feature folder. Tests go in a __tests__ folder beside the code (Testing).

Convex backend (packages/convex)

Read packages/convex/_generated/ai/guidelines.md before editing; its Convex rules override general guidance. Tables and indexes live in schema.ts (validators in schema/validators/), schedules in cronSchedules.ts. Schema changes, indexes and backfills follow Adding a Feature; tests follow Testing.

Apple app (apps/apple)

  • Xcode 27 (Swift 6.4). The project is generated: edit project.yml, run apps/apple/scripts/generate-project.sh, and commit Teak.xcodeproj with it; CI fails when they differ. The workspace has no package.json, so Turbo, bun run dev and doctor don’t see it; the @teak/scripts workspace typechecks and tests its TypeScript in scripts/ and tests/. CI and releases run on GitHub’s xcode-27 image with Xcode pinned by apps/apple/scripts/select-xcode.sh.
  • Debug talks to the development deployment and WorkOS staging; Release talks to production. The Convex Rust core is Apple silicon only, so Mac and Simulator builds are arm64.
  • Layout: Packages/TeakKit (TeakCore: models, ported logic, session, Convex over HTTPS, uploads; TeakSync: the live Convex client; TeakUI), Teak/ (the app), ShareExtension/ and SafariExtension/.
  • Convex calls go through ConvexFunctions, which binds each function to its result type; every number argument is a Double (v.number() rejects int64). Shared constants come from SharedConstants.json, generated from the manifest both native apps share, scripts/repo/native-constants.ts; regenerate it with bun --no-env-file run apps/apple/scripts/shared-constants.ts --write.
  • The session lives in the shared keychain group, and refreshes take the cross-process lock in the app group because WorkOS rotates refresh tokens. Hold a file lock in the app group only inside BackgroundActivity time, as FileCredentialLock does: iOS kills a process suspended while holding one (0xdead10cc). Never log tokens.
  • SF Rounded everywhere, Teak red only for meaning, system components first. Keyboard shortcuts must not collide with system ones: UIKit throws on duplicate menu shortcuts.
  • Checks: swift test --package-path Packages/TeakKit and bun --no-env-file test apps/apple/tests/. CI doesn’t build the app, so build it for iPhone and Mac before pushing app changes.
  • Swift Testing runs suites in parallel and AppLanguage is one value per process, so every suite takes .english or .switchesLanguage, and localized @Test(arguments:) are passed as closures; apps/apple/tests/teakkit-language.test.ts enforces it.
  • UI flows run against the local end-to-end stack: bun run --cwd packages/tests e2e:stack, then apps/apple/scripts/ui-tests.sh ios|ipad|mac. bun --no-env-file run apps/apple/scripts/e2e-session.ts prints the launch environment for a manual run. Mac UI tests need UI automation allowed (automationmodetool), so CI runs iPhone and iPad.

Android app (apps/android)

  • One Gradle project; use ./gradlew from apps/android with JDK 17+ and local.properties holding sdk.dir. ./gradlew :app:installDebug installs “Teak Dev”, which talks to the development deployment and WorkOS staging. The version comes from the root package.json.
  • Checks: ./gradlew lint testDebugUnitTest :app:assembleRelease and bun --no-env-file test apps/android/tests/ (the @teak/scripts workspace typechecks and tests the TypeScript in scripts/ and tests/).
  • Modules follow Now in Android: app, core:model, core:data, core:designsystem, core:testing, one feature:* per area, shared setup in build-logic, versions in gradle/libs.versions.toml. Each ViewModel exposes one StateFlow UI state; build ViewModels inside a test, not in a field initializer, so MainDispatcherRule applies.
  • Convex calls go through ConvexApi with an entry from ConvexFunctions; LiveConvexApi sends every number as a Double. Shared constants live in the generated SharedConstants.kt, from the same scripts/repo/native-constants.ts manifest as Apple’s; regenerate with bun --no-env-file run apps/android/scripts/shared-constants.ts --write. testDebugUnitTest also runs core:model’s JVM tests.
  • Sign-in builds the PKCE URL with the WorkOS SDK, but posts the code exchange and refresh itself without client_secret (SDK 0.4.0 always sends one). Sessions are encrypted with an Android Keystore key in no-backup storage. JNA stays pinned to 5.17 or newer for 16 KB-page devices.

Raycast extension (apps/raycast)

  • The ray CLI ships inside @raycast/api. build, lint, typecheck and test run headless; dev needs the Raycast app installed, running and signed in.
  • package-lock.json is committed because the Raycast store runs npm ci. Regenerate it from apps/raycast with npm install --package-lock-only --ignore-scripts --workspaces=false.
  • src/lib/api.ts sends every request through teak-sdk’s createTeakClient. Raycast pins the published teak-sdk, but Bun resolves the workspace copy, so use only what the pinned version publishes. To prove it, copy apps/raycast out of the monorepo, run npm ci, npx tsc --noEmit, bun test src/__tests__ --isolate and npx ray build there. scripts/repo/raycast-parity.test.ts checks Raycast’s copies of Teak’s tables, outside the published extension. src/lib/teakCardLinks.ts is generated from packages/convex/shared/cardLinks.ts; regenerate it with bun --no-env-file run scripts/repo/raycast-card-links.ts --write.

CLI (apps/cli) and SDK (packages/sdk)

  • bun run dev cli watch-builds apps/cli/dist; run it with bun dist/index.js <args>. bun run build is the executable build.
  • packages/sdk/src/index.ts is the SDK’s only entry; tests sit beside the code (bun run --cwd packages/sdk test). Import shared values from @teak/convex/shared/*, never from Convex functions. package.json points exports at src/ for the monorepo; build.ts writes the published manifest into dist/, and scripts/repo/sdk-package.test.ts installs that outside the monorepo and type-checks it. Run it after changing build.ts or the public types.

Repository scripts (scripts)

  • scripts/ is the @teak/scripts workspace: dev, setup, env, release and Cloudflare tooling, and the repo checks that compare workspaces with each other (scripts/repo). Turbo runs its typecheck, lint and test with the rest; scripts/README.md maps the folders.
  • Other workspaces import it as @teak/scripts/<path> and list it as a dependency, so Turbo reruns their tasks when it changes.
  • Release scripts run on plain Node before Bun is installed: only erasable TypeScript, .ts import extensions, no dependencies.

Adding a Feature has the rules for fields, tables, indexes, API operations and backfills.

Last updated on

Was this page helpful?