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.

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
- 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.
- Queue. The mutation writes the card and, in the same transaction, a row in the workflow dispatch outbox (
queueCardProcessinginpackages/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, andworkflowRun.tsinexport/,import/andaccountDeletion/);workflowDispatch/outbox.tswrites the rows and imports no domain code. - 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. - Show. Each write lands on the card, and every client’s live query updates. The card’s
processingStatusrecords each stage (the list, and which ones a card type runs, are inpackages/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, AI and search
- 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.tslists 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 inpackages/convex/shared. - The Apple and Android apps port the same pure logic (Apple’s
TeakCore, Android’score:model: filters, card edits, Markdown blocks, save links, date search, grid rules) with the same test cases. Shared rows live as JSON inpackages/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, runapps/apple/scripts/generate-project.sh, and commitTeak.xcodeprojwith it; CI fails when they differ. The workspace has nopackage.json, so Turbo,bun run devand doctor don’t see it; the@teak/scriptsworkspace typechecks and tests its TypeScript inscripts/andtests/. CI and releases run on GitHub’sxcode-27image with Xcode pinned byapps/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/andSafariExtension/. - Convex calls go through
ConvexFunctions, which binds each function to its result type; every number argument is aDouble(v.number()rejects int64). Shared constants come fromSharedConstants.json, generated from the manifest both native apps share,scripts/repo/native-constants.ts; regenerate it withbun --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
BackgroundActivitytime, asFileCredentialLockdoes: 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/TeakKitandbun --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
AppLanguageis one value per process, so every suite takes.englishor.switchesLanguage, and localized@Test(arguments:)are passed as closures;apps/apple/tests/teakkit-language.test.tsenforces it. - UI flows run against the local end-to-end stack:
bun run --cwd packages/tests e2e:stack, thenapps/apple/scripts/ui-tests.sh ios|ipad|mac.bun --no-env-file run apps/apple/scripts/e2e-session.tsprints 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
./gradlewfromapps/androidwith JDK 17+ andlocal.propertiesholdingsdk.dir../gradlew :app:installDebuginstalls “Teak Dev”, which talks to the development deployment and WorkOS staging. The version comes from the rootpackage.json. - Checks:
./gradlew lint testDebugUnitTest :app:assembleReleaseandbun --no-env-file test apps/android/tests/(the@teak/scriptsworkspace typechecks and tests the TypeScript inscripts/andtests/). - Modules follow Now in Android:
app,core:model,core:data,core:designsystem,core:testing, onefeature:*per area, shared setup inbuild-logic, versions ingradle/libs.versions.toml. Each ViewModel exposes oneStateFlowUI state; build ViewModels inside a test, not in a field initializer, soMainDispatcherRuleapplies. - Convex calls go through
ConvexApiwith an entry fromConvexFunctions;LiveConvexApisends every number as aDouble. Shared constants live in the generatedSharedConstants.kt, from the samescripts/repo/native-constants.tsmanifest as Apple’s; regenerate withbun --no-env-file run apps/android/scripts/shared-constants.ts --write.testDebugUnitTestalso runscore: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
rayCLI ships inside@raycast/api.build,lint,typecheckandtestrun headless;devneeds the Raycast app installed, running and signed in. package-lock.jsonis committed because the Raycast store runsnpm ci. Regenerate it fromapps/raycastwithnpm install --package-lock-only --ignore-scripts --workspaces=false.src/lib/api.tssends every request throughteak-sdk’screateTeakClient. Raycast pins the publishedteak-sdk, but Bun resolves the workspace copy, so use only what the pinned version publishes. To prove it, copyapps/raycastout of the monorepo, runnpm ci,npx tsc --noEmit,bun test src/__tests__ --isolateandnpx ray buildthere.scripts/repo/raycast-parity.test.tschecks Raycast’s copies of Teak’s tables, outside the published extension.src/lib/teakCardLinks.tsis generated frompackages/convex/shared/cardLinks.ts; regenerate it withbun --no-env-file run scripts/repo/raycast-card-links.ts --write.
CLI (apps/cli) and SDK (packages/sdk)
bun run dev cliwatch-buildsapps/cli/dist; run it withbun dist/index.js <args>.bun run buildis the executable build.packages/sdk/src/index.tsis 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.jsonpointsexportsatsrc/for the monorepo;build.tswrites the published manifest intodist/, andscripts/repo/sdk-package.test.tsinstalls that outside the monorepo and type-checks it. Run it after changingbuild.tsor the public types.
Repository scripts (scripts)
scripts/is the@teak/scriptsworkspace: dev, setup, env, release and Cloudflare tooling, and the repo checks that compare workspaces with each other (scripts/repo). Turbo runs itstypecheck,lintandtestwith the rest;scripts/README.mdmaps 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,
.tsimport extensions, no dependencies.
Adding a Feature has the rules for fields, tables, indexes, API operations and backfills.