This repository implements CollegeDB: a Cloudflare-oriented D1 sharding router and tools for running, testing, and benchmarking multi-shard SQLite-style databases (D1 / Drizzle / other SQL backends) with KV-backed primary-key mappings and a Durable Object shard coordinator.
Purpose of this file
- Give Claude (and new contributors) an immediate orientation to the repo and development workflows.
- Capture the commands and CI behaviors you want automated or respected.
- Provide safe workflows Claude should follow before making changes.
Project Snapshot
- Primary language: TypeScript (ESM), targeted for Node and Cloudflare Workers runtime.
- Build system: Bun + TypeScript; tests use Vitest.
- Documentation: TypeDoc-generated HTML under
typedoc/(script:docs:build). - Packaging: distributed as an npm package (
dist/), version inpackage.json.
High-level architecture
src/contains library code that provides the API surface (index.tsexports).router.ts(main router implementation, exported API surface insrc/index.ts).durable.tsimplementsShardCoordinatorβ a Cloudflare Durable Object used to coordinate shard allocation and stats.providers.tscontains adapters for multiple backend types (D1, Postgres, MySQL, SQLite, Redis, Valkey, Drizzle, etc.).providers-memory.tsincludes in-memory mock providers used in tests.kvmap.tsholds KV mapping utilities.migrations.tsprovides migration helpers for schema creation and migration across shards.errors.ts,types.tscontain error classes and shared types.
Sandbox environment
sandbox/worker.tsis a runnable Cloudflare-style sandbox harness exposing convenience HTTP endpoints for:- Schema initialization (
POST /init), seeding (/api/benchmark/seed-users), CRUD endpoints forusersand benchmark/migration helpers. - The sandbox supports multiple profiles (
native,drizzle,nuxthub) selecting provider compatibility layers.
- Schema initialization (
- Sandbox scripts and Docker compose exist under
sandbox/β used by CI sandbox benchmarks and local benchmarking. - Commands to exercise the sandbox locally (from repo root):
bun run test:memoryβ in-memory quick runbun run test:sandboxβ run sandbox benchmarks (CI also runs this)- For specific profiles:
bun run test:sandbox:drizzle,bun run test:sandbox:nuxthub, etc.
Tests
- Tests are under
tests/(Vitest). Key patterns:tests/all.spec.tscontains integration-style tests usingMockD1Database,MockKVNamespace, andMockDurableObjectNamespaceto simulate runtimes.tests/*.spec.tsexercisemigrations,providers,durablelogic and router behaviors.
- Common test commands:
bun test(runs tests once)bun run test:coverage(collect coverage)bun run test:memory(sandbox/memory quick-run harness)
Documentation generation
- Docs are generated with TypeDoc:
bun run docs:buildrunstypedoc src --out ./typedoc. - CI build job runs the same command and uploads
typedoc/as a build artifact. - Deploy docs:
.github/workflows/docs.ymlcallsbash typedoc.sh ${GITHUB_SHA::7}βtypedoc.shperforms publish oftypedoc/(Pages or other hosting); treattypedoc.shas the canonical publish script.
Continuous Integration (see .github/workflows)
build.yml(Build and Test):- Triggers: push & PR on
main,master,develop. - Jobs:
format(Prettier),test(tsc + tests),build(build + docs:build + upload typedoc artifact).
- Triggers: push & PR on
coverage.yml(Coverage & Sandbox):- Triggers: push & pull_request.
- Jobs:
coverage(run tests, upload to Codecov; also produces coverage artifacts) andsandbox(runs sandbox benchmarks; requires Docker + Docker Compose; uploadssandbox/results/artifacts). - Notes:
sandboxjob verifies Docker availability and runsbun run test:sandbox. It collectssandbox/results/latest.mdinto the job summary.
docs.yml(Deploy Documentation):- Triggers: push to
masterand manual dispatch. - Runs
bun run docs:buildthentypedoc.shto deploy.
- Triggers: push to
release.yml(Manual release):- Manual trigger (workflow_dispatch). Verifies tests, builds, publishes to npm and GitHub Packages, and creates a GitHub release using a changelog builder.
- Publishing uses
NPM_TOKEN/GITHUB_TOKENsecrets β Claude must never write or expose secrets.
What Claude must do before changing code
- Never publish releases or change CI secrets; these are privileged operations. If asked, create a PR and note required secret values for maintainers to set.
- Before modifying code that affects runtime behavior (anything under
src/):- Run the test suite locally:
bun testandbun run test:coveragefor coverage-sensitive changes. - For changes touching migrations or schema, run sandbox harnesses:
bun run test:memoryand/orbun run test:sandbox(Docker required for some sandbox profiles). - If the change affects public API (exports from
src/index.ts), updateCHANGELOG.md/ release notes and ensure TypeScript types compile:bunx tsc --noEmit. - Provide a concise test plan in PR description and include reproducer steps (commands to run locally). If the change modifies durability or migration logic, include migration safety checks and a rollback plan.
- Run the test suite locally:
- For performance / architecture changes:
- Produce a short design summary before code changes.
- Add targeted unit and integration tests replicating the performance scenario.
Standard workflow for Claude when asked to implement changes
- Use the explore-plan-code-commit workflow: explore repository β propose a focused plan (short bullets) β implement minimal change with tests β run tests locally β open a PR with description and test evidence.
- If a requested change is large or architectural, ask clarifying questions and generate a design doc before any code edits.
Common commands (copy-paste friendly)
- Install deps:
bun install --frozen-lockfile - Type check:
bunx tsc --noEmit - Run tests:
bun testorbun run test:coverage - Run sandbox memory harness:
bun run test:memory - Run sandbox benchmarks (requires Docker for some profiles):
bun run test:sandbox - Build library & types:
bun run build - Build docs:
bun run docs:build - Format:
bun run prettier:check/bun run prettier
File-level notes and cautions
src/durable.ts(ShardCoordinator): centralized coordination logic β changes may affect live shard allocations. Add tests and review Durable Object storage usage.src/providers.ts: many adapter contracts; avoid breaking public provider signatures without a major version bump.migrations.ts: destructive operations (dropSchema, flush) exist β mark such operations with clear warnings in any PR touching them.sandbox/worker.ts: convenient for local testing and benchmarks; changes here affect CI benchmarks and should be validated by runningbun run test:sandbox.typedoc.sh: deployment script for docs; it is invoked bydocs.yml. Do not hard-code secrets in this script.
Testing & Quality expectations
- New code should come with unit tests or integration tests as appropriate to the change's scope.
- Keep changes small and iterative: prefer many tiny PRs with focused scope over large, invasive commits.
- Run
bunx tsc --noEmitto ensure type-safety; CI runs this as part oftestjob. - Prettier formatting is enforced in CI (
build.ymlformat job). Usebun run prettierto autofix.
Documentation & maintainability
- TypeDoc is the canonical code documentation generator. Update JSDoc comments where public APIs change.
typedoc/is built in CI and shipped as an artifact; thedocs.ymlworkflow deploys these artifacts to the project's pages viatypedoc.sh.
Security & secrets
- Never add secrets or credentials to
CLAUDE.mdor commit them to the repo. - Publishing, Codecov tokens and npm tokens are stored in GitHub secrets. If a change requires new secrets, mention this in the PR and do not attempt to set secrets.
Recommended small improvements for maintainers (suggestions Claude may propose on PRs)
- Add a
CONTRIBUTING.mdthat codifies the local sandbox run steps (Docker prerequisites) and release checklist. - Add a short
docs/index that links totypedoc/artifacts and sandbox benchmark reports insandbox/results/for easier discovery. - Add a
scripts/verify-ci.shhelper that runs the CI job sequence locally (format β type-check β tests β build docs) for maintainers.
Quick contact / context hints
- Primary author: Gregory Mitchell (see
src/index.tsheader comment). - Keep messages concise in PRs: what you changed, why, how to test, and risk/rollout notes.
Workflow guidance for Claude
- When asked to fix or modify code: always (a) run tests and type-check locally, (b) propose the exact commands you will run in the PR description, (c) avoid pushing release or secret changes β create a PR and request human approval for publishing.
- Use subagents (or a separate conversation) for long, multi-phase tasks like performance reviews vs. code changes so context doesn't bleed between phases.