# CalmAPI > CalmAPI 2 is a backend framework for Node.js and MongoDB where every line of framework code lives in your repo: resources, policies, auth, devtools, blocks and an upgrade path. CalmAPI 2 (npm package `calmapi`, Node.js 22.12+, Express 5, MongoDB with Mongoose, ESM) copies its framework code into each project as `calm/`. Resources are declared once with `f.*()` fields and access policies; services, custom routes, blocks and the `calm` CLI build on that. Each link below is the markdown source of a page; the same page is at the URL without `.md`. ## Getting started - [Why CalmAPI](https://docs.calmapi.dev/introduction.md): What CalmAPI 2 is, what makes it different, and what a resource looks like. - [Getting started](https://docs.calmapi.dev/getting-started.md): Create a project with npm create calmapi@latest, run it, and make your first requests with curl. - [Project structure](https://docs.calmapi.dev/project-structure.md): What lives in calm/, app/, calm.config.js and calm.lock, and how #calm and #app imports work. ## Guide - [Resources and fields](https://docs.calmapi.dev/resources.md): Declare a resource once with f.*() fields: schema, validation, visibility, queries, CRUD routes and status codes. - [Policies](https://docs.calmapi.dev/policies.md): Who may do what: policy tokens, combinations, functions, owner scoping and 401, 403 and 404 semantics. - [Services and hooks](https://docs.calmapi.dev/services.md): Business logic with ResourceService: scope(), before and after hooks, filterFor, other services and events. - [Custom routes](https://docs.calmapi.dev/routes.md): Add endpoints with the route builder: options, return values, ctx.reply, ctx.serialize and route order. - [Querying](https://docs.calmapi.dev/querying.md): Filter, search, sort, paginate, include references and pick fields on list endpoints. - [Authentication](https://docs.calmapi.dev/authentication.md): Register, login, sessions, password change and reset, lockout and password rules: every /api/auth endpoint with examples. - [Push notifications](https://docs.calmapi.dev/push-notifications.md): Send notifications to phones and browsers with app.push, register devices, try them on simulated phones in devtools and deliver with Expo or FCM. - [Errors](https://docs.calmapi.dev/errors.md): The error response shape, CalmError helpers, how database errors are mapped, and what never leaks. - [Configuration](https://docs.calmapi.dev/configuration.md): calm.config.js, every config key with its default, environment variables and production defaults. ## Tools - [Devtools](https://docs.calmapi.dev/devtools.md): The local dashboard at /_calm: requests with their MongoDB queries, data privacy lens and sample data, mail, push notifications on simulated phones, installed blocks, act as any user, agent activity, review and sign, budgets and security. - [Testing](https://docs.calmapi.dev/testing.md): Write API tests with createTestApp and node:test against a throwaway database. - [Replay and recorded tests](https://docs.calmapi.dev/replay.md): The dev server records requests as shapes, never values; calm replay sends them again as the same users against the new code and shows which answers changed. Save any request as a test. - [Budgets](https://docs.calmapi.dev/budgets.md): How many MongoDB queries, how much time and how many bytes each route may cost, in calm.config.js: measured in devtools and enforced in CI with calm budgets --ci. - [The behavior diff](https://docs.calmapi.dev/behavior-diff.md): calm diff compares two versions of your app by what they do: routes, policies, field visibility, env vars, hosts, events, blocks and invariants, and fails CI when access widens. calm diff --api sorts API contract changes into breaking, minor and patch. - [Review and sign](https://docs.calmapi.dev/review.md): calm review shows what changed since a person last signed, including the files AI agents wrote and what they declared; calm review --sign records the signature in .calm/reviews/ and --ci fails when access widens. - [Invariants](https://docs.calmapi.dev/invariants.md): Promises in calm.config.js the framework holds you to: checked by doctor and devtools, enforced at boot in production, visible in the behavior diff. - [Explain a request](https://docs.calmapi.dev/request-path.md): The Path tab in devtools and calm_explain for agents: the way a request took through the code, with the policy decision token by token and the reason for every 401, 403 and 404. - [Typed client](https://docs.calmapi.dev/client.md): calm client writes a typed, dependency-free client for your web or mobile app from the API itself, and calm dev keeps it current as the API changes. - [Checkpoints](https://docs.calmapi.dev/checkpoints.md): calm checkpoint and calm restore: snapshot the development database and put it back exactly, automatically before an agent session. - [What the framework does](https://docs.calmapi.dev/transparency.md): calm about: the request pipeline, headers, stored data and its lifetime, logging, the hosts the code can reach and every file the CLI writes, generated from your code. - [Security audit](https://docs.calmapi.dev/audit.md): calm audit calls every route as every role on a throwaway database and checks policies, field leaks, mass assignment and token handling. - [Exposure budget](https://docs.calmapi.dev/exposure-budget.md): calm audit --accept writes who may do what to security.snapshot.json; from then on wider access fails calm doctor and calm audit --ci until a person accepts it with a reason. - [CLI reference](https://docs.calmapi.dev/cli.md): Every calm command and flag: create, dev, make, add, block, seed, routes, openapi, client, doctor, diff, review, replay, budgets, about, audit, checkpoint, restore, admin, keygen, upgrade, mcp and agent-hook. - [AI agents](https://docs.calmapi.dev/ai-agents.md): AGENTS.md, the calm mcp server for coding agents, the activity log that shows what they change, a disposable database copy with calm dev --agent-db, and the mcp-server block. - [Upgrading](https://docs.calmapi.dev/upgrading.md): How calm.lock and calm upgrade merge framework fixes into your edited calm/ folder. ## Blocks - [Blocks](https://docs.calmapi.dev/blocks.md): Production features you copy into your project with calm add: notifications, webhooks, API keys, feature flags, jobs, storage, realtime, push, two-factor auth and more. - [API docs (api-docs)](https://docs.calmapi.dev/blocks/api-docs.md): An interactive API reference at /docs, rendered from your OpenAPI document. - [API keys (api-keys)](https://docs.calmapi.dev/blocks/api-keys.md): Personal and service API keys with scopes for scripts and integrations: shown once, hashed at rest, expiry and revoke. - [Audit log (audit-log)](https://docs.calmapi.dev/blocks/audit-log.md): Who changed what and when, with field-level diffs that never record private values. - [Response cache (cache)](https://docs.calmapi.dev/blocks/cache.md): GET responses cached per identity in MongoDB or memory, invalidated by resource events, with ETag and 304. - [CAPTCHA (captcha)](https://docs.calmapi.dev/blocks/captcha.md): Cloudflare Turnstile, hCaptcha or reCAPTCHA v3 on sign-up, sign-in and password reset, failing closed. - [Email verification (email-verification)](https://docs.calmapi.dev/blocks/email-verification.md): Verification links after sign-up and email changes, a verified policy, and required verification for routes or sign-in. - [Export and import (export)](https://docs.calmapi.dev/blocks/export.md): Streamed CSV, NDJSON or JSON exports that respect field visibility, and validated imports with dry runs. - [Feature flags (feature-flags)](https://docs.calmapi.dev/blocks/feature-flags.md): Kill switches, gradual rollouts, per user and per role targeting, weighted variants and route gates, stored in MongoDB. - [Idempotency keys (idempotency)](https://docs.calmapi.dev/blocks/idempotency.md): Safe retries for writes: the Idempotency-Key header replays the stored response instead of running an operation twice. - [Background jobs (jobs)](https://docs.calmapi.dev/blocks/jobs.md): A MongoDB job queue and cron: retries, schedules, event triggers and an admin API. No Redis. - [Magic link sign-in (magic-link)](https://docs.calmapi.dev/blocks/magic-link.md): Passwordless sign-in by email: single use links, a cooldown per address, a redirect allowlist and links bound to the browser that asked. - [Email via Postmark (mail-postmark)](https://docs.calmapi.dev/blocks/mail-postmark.md): Deliver email through Postmark with tags, message streams and attachments. - [Email via Resend (mail-resend)](https://docs.calmapi.dev/blocks/mail-resend.md): Deliver password resets and notifications through the Resend HTTP API. - [Email via SMTP (mail-smtp)](https://docs.calmapi.dev/blocks/mail-smtp.md): Deliver email through any SMTP server with Nodemailer. - [Maintenance mode (maintenance)](https://docs.calmapi.dev/blocks/maintenance.md): Maintenance and read-only modes at runtime or on a schedule, with allowlists and Retry-After. - [MCP server (mcp-server)](https://docs.calmapi.dev/blocks/mcp-server.md): Expose your resources to AI agents as MCP tools, enforced by your API rules. - [Notifications: inbox, push and email (notifications)](https://docs.calmapi.dev/blocks/notifications.md): One call writes the in-app inbox, sends a push and an email, following each user's preferences and quiet hours. - [Sign in with Google, GitHub and OpenID Connect (oauth)](https://docs.calmapi.dev/blocks/oauth.md): OAuth and OpenID Connect sign-in with PKCE, verified ID tokens and safe account linking. - [Payments with Stripe (payments-stripe)](https://docs.calmapi.dev/blocks/payments-stripe.md): Stripe Checkout, subscriptions and the customer portal without the SDK, verified webhooks and plan-gated routes. - [Privacy: export and delete (privacy)](https://docs.calmapi.dev/blocks/privacy.md): Users download everything they own and delete their account; per resource delete, anonymize or keep, with admin routes and a grace period. - [Push notifications via Expo (push-expo)](https://docs.calmapi.dev/blocks/push-expo.md): Deliver push notifications to Expo and React Native apps through the Expo push service. - [Push notifications via Firebase Cloud Messaging (push-fcm)](https://docs.calmapi.dev/blocks/push-fcm.md): Deliver push notifications to Android, iOS and web through Firebase Cloud Messaging HTTP v1, no SDK. - [Shared rate limits (rate-limit-mongo)](https://docs.calmapi.dev/blocks/rate-limit-mongo.md): Keep rate limit counters in MongoDB so limits hold across instances. - [Realtime (SSE) (realtime-sse)](https://docs.calmapi.dev/blocks/realtime-sse.md): Live resource events over Server-Sent Events, filtered per subscriber by your policies. - [Search with Meilisearch (search-meilisearch)](https://docs.calmapi.dev/blocks/search-meilisearch.md): Full-text search kept in sync with your resources, filtered by your policies. - [Error reporting with Sentry (sentry)](https://docs.calmapi.dev/blocks/sentry.md): 5xx and background errors to Sentry without the SDK, with secrets scrubbed, sampling and deduplication. - [Slack alerts (slack)](https://docs.calmapi.dev/blocks/slack.md): App events and security alerts to Slack, with escaped templates, digests and retries. - [SMS and phone verification with Twilio (sms-twilio)](https://docs.calmapi.dev/blocks/sms-twilio.md): An SMS transport and phone verification with hashed one-time codes and signed status callbacks. - [Soft delete (soft-delete)](https://docs.calmapi.dev/blocks/soft-delete.md): Opt-in soft delete per resource, with trash and restore for admins. - [Local file storage (storage-local)](https://docs.calmapi.dev/blocks/storage-local.md): File uploads to local disk with type and size allowlists, magic-byte checks and safe downloads. - [S3 file storage (storage-s3)](https://docs.calmapi.dev/blocks/storage-s3.md): Direct-to-S3 uploads with presigned URLs for AWS S3, Cloudflare R2 and MinIO. - [Teams and organizations (teams)](https://docs.calmapi.dev/blocks/teams.md): Organizations, roles, invitations and team-scoped resources with strict isolation. - [Two-factor authentication (totp)](https://docs.calmapi.dev/blocks/totp.md): Authenticator-app codes on login, with single-use recovery codes, replay protection and secrets encrypted at rest. - [Waitlist (waitlist)](https://docs.calmapi.dev/blocks/waitlist.md): A launch waitlist with referral codes, admin invites and invite-only registration. - [Webhooks (webhooks)](https://docs.calmapi.dev/blocks/webhooks.md): Outgoing webhooks for resource events: signed, queued, retried and logged, filtered by what each subscriber may read, SSRF safe. - [Building your own block](https://docs.calmapi.dev/building-blocks.md): Write a block with definePlugin: settings, env vars, routes, guards, credentials, named policies, doctor checks, the auth service helpers, its AGENTS.md for AI agents, and the calm make block, block check, block pack and gh: installs toolkit. - [Publishing your own block](https://docs.calmapi.dev/publishing-blocks.md): The registry item format, hosting blocks on GitHub or any static host, and registries of your own for calm add. ## Production - [Deployment](https://docs.calmapi.dev/deployment.md): Run CalmAPI in production: environment, health checks, graceful shutdown, proxies, Docker and several instances. - [Security](https://docs.calmapi.dev/security.md): Reporting vulnerabilities, secure defaults, encryption at rest, login lockout, security events, the exposure matrix and calm doctor. - [Security advisories](https://docs.calmapi.dev/security-advisories.md): Published advisories for code CalmAPI copied into projects, with the fix for each. - [Migrating from CalmAPI 1.x](https://docs.calmapi.dev/migrate-v1.md): Move a CalmAPI 1.x project to 2.0: concept map, API changes for clients, auth changes and a step by step plan. ## Reference - [Quick reference](https://docs.calmapi.dev/quick-reference.md): A one-page cheat sheet: fields, policies, services, routes, queries, auth endpoints and CLI. ## Optional - [All CalmAPI 2 docs in one file](https://docs.calmapi.dev/llms-full.txt): every page above, concatenated - [Block registry](https://docs.calmapi.dev/r/index.json): official blocks in the shadcn registry-item format, one item per block at https://docs.calmapi.dev/r/.json - [CalmAPI 1.x docs (legacy)](https://docs.calmapi.dev/v1): documentation for the previous major version, no longer developed