This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Draftmark is a markdown sharing platform for async collaboration between humans and AI agents, part of Rumbo Labs (alongside PixelVault and ContentVitals). The core loop: agent/human writes markdown → shares link → reviewer reads + comments → agent consumes feedback via API.
MVP complete. All core features implemented.
- Framework: Next.js (Node)
- Database: PostgreSQL (via Docker, port 5434)
- ORM: Prisma v7 with
@prisma/adapter-pg(driver adapters required in v7) - Markdown rendering: react-markdown + remark-gfm + rehype-highlight
- Diagrams: Mermaid.js (client-side, lazy loaded)
- Auth model: No user accounts. Magic tokens + API keys only (both SHA-256 hashed)
- Testing: Vitest (unit + integration split via
projectsconfig) - Domain: draftmark.app
- Hosting: Hetzner (shared instance with other Rumbo Labs projects)
docker compose up -d postgres # Start DB (port 5434)
npx prisma generate # Generate client
npx prisma migrate dev # Run migrations
npm run dev # Start Next.js on port 3333
npm test # Run all testsImportant: Dev server must be restarted after npx prisma generate to pick up schema changes.
prisma/schema.prisma — Data models
src/app/api/v1/docs/ — Doc CRUD API
src/app/api/v1/docs/[slug]/ — Doc read/update/delete + comments, reactions, reviews
src/app/api/v1/collections/ — Collection CRUD API
src/app/new/page.tsx — Create doc UI
src/app/share/[slug]/page.tsx — View doc (server component)
src/app/share/[slug]/edit/page.tsx — Edit doc (client component)
src/app/c/[slug]/page.tsx — View collection
src/components/ — DocView, CommentSection, ReactionsBar, ReviewsSection, etc.
src/lib/ — prisma, auth, tokens, slug, markdown helpers
src/__tests__/ — Unit tests (lib/) and integration tests (api/)
Seven models: Doc, DocVersion, Comment, Collection, CollectionDoc, Reaction, Review.
Doc fields: slug (nanoid 8), title, content, visibility (public|private), status (open|review_closed), magic_token, api_key, views_count, expected_reviews, review_deadline, meta (JSONB).
Slugs are nanoid, 8 chars, URL-safe. Visibility is "public" or "private" (magic link only).
Base: /api/v1. Auth via Authorization: Bearer {api_key} for read ops on private docs. X-Magic-Token header or ?token= param for write ops (PATCH/DELETE).
Key endpoints:
POST /docs— Create doc (accepts content, visibility, expected_reviews, review_deadline, meta)GET /docs/:slug— Get doc with metadata (includes computed fields: review_complete, review_expired, accepting_feedback). Owner-only fields (meta, views_count) require?token=magic_token. Supports?format=rawto return raw markdown astext/markdown.GET /share/:slug.md— Raw markdown shortcut (rewrites to API via middlewarex-formatheader). Agents cancurl https://draftmark.app/share/abc123.mddirectly.PATCH /docs/:slug— Update content, status, review settings (requires magic_token)DELETE /docs/:slug— Delete (requires magic_token)GET/POST /docs/:slug/comments— List/add comments (409 if review closed/expired). Acceptsauthor_type: "agent"to display agent badge.POST /docs/:slug/comments/batch— Batch create comments (max 50, same auth as single comment). Each comment acceptsauthor_type.POST /docs/:slug/reactions— Add reaction (409 if review closed/expired)GET/POST /docs/:slug/reviews— List/mark reviewed (409 if review closed/expired). Acceptsreviewer_type: "agent"to display agent badge.POST /collections— Create collectionGET/PATCH/DELETE /collections/:slug— Collection CRUD
Three mechanisms:
- Explicit close: PATCH with
status: "review_closed" - Threshold: Set
expected_reviews—review_complete: truewhen met (signal only, doesn't auto-close) - Time-based: Set
review_deadline— auto-rejects feedback after deadline
Feedback gates: POST comments/reactions/reviews return 409 when doc not accepting feedback.
npm install -g draftmark installs the dm CLI (draftmark-app/cli).
Commands: create, update, status, comments, comment, react, review, raw, browse, list, close, open, delete, login, logout, whoami, config.
Config resolves from: CLI flags → env vars (DM_API_KEY, DM_MAGIC_TOKEN) → .draftmark.json → global config (~/.config/draftmark/config.json via dm login).
Key features: stdin support (dm create -), --agent flag (auto-inherited by comment/review), --meta <json>, --format table|json|minimal, --since date filter, -q quiet mode, --base-url override, structured JSON errors, exit codes (0 ok, 1 error, 2 auth, 3 not found, 4 conflict).
OpenAPI 3.1 spec at openapi.yaml (source of truth) and public/openapi.yaml (served). Interactive docs at /api-docs (Redoc, standalone route handler with dark/light theme support).
.draftmark.json convention: agents write this file after creating a doc so future sessions can discover pending reviews. Stores api_key (not magic_token). Should be .gitignored.
docs/draftmark-v3.html is a self-contained static page with inline CSS. Fonts: Instrument Serif, Geist, Geist Mono (Google Fonts). Dark theme with CSS custom properties in :root.