Capy
A calmer way to build web apps in Rust.
Strong conventions. Sensible defaults. No framework assembly required.
Capy is an opinionated full-stack Rust web framework with strong conventions and sensible defaults. It combines a Rust backend with a first-class frontend workflow so you can start building the application instead of assembling the framework.
[]
= { = "capy-framework", = "0.10.0" }
Application code normally starts with use capy::prelude::*;. Native Axum,
SeaORM, Tokio and Serde APIs remain available through named re-exports.
Generate a complete application with capy new blog using capy-cli.
Generated resources keep entities separate from serialized DTOs. Use bounded Page<ResponseDto> collections and explicit public DTOs; see the executable tutorial below.
Production uses JSON request logs with request ID, method, route, status, and latency.
Set RUST_LOG to override the default INFO filter. Responses include x-request-id;
internal errors are sanitized. Prefer running the compiled release binary in production.
MIT licensed. See LICENSE. This is an initial developer preview, not a production-readiness claim.
New applications use App::api_routes(routes) to mount paths under /api and
App::frontend("frontend/dist") for static assets and SPA fallback. App::routes
continues to register unprefixed routes. Explicit web routes and API handlers take
precedence; API 404s never return the SPA. Missing static assets return 404, while
GET/HEAD browser paths without a file extension fall back to index.html.
capy dev runs the backend and Vite together; capy build produces frontend assets
and a release binary. The production backend requires no Node server. Deploy the
frontend/dist directory with the binary and run from the project root with
APP_ENVIRONMENT=production; missing frontend builds fail before database startup.
into_router constructs only the HTTP service; run/run_command perform startup
validation. Existing backend-only apps keep their current behavior.
Optional identity
Capy 0.6.0 introduced experimental cookie sessions through the auth feature. Run
capy make:auth to install conventional SeaORM migrations, safe DTOs, CSRF-aware
React helpers and an application-owned reset-delivery hook. Use AuthUser or
OptionalAuth and ordinary Policy implementations for protected resources.
Production requires HTTPS and a real reset-delivery adapter; generated local
delivery is development-only. See the auth API.
Build a Complete Feature
Run capy make:auth --frontend then
capy make:resource Post title:string slug:string:unique body:text published:boolean=false --frontend.
Apply capy db:migrate, capy db:seed, then capy dev. The
primary tutorial
connects generated CRUD, auth pages, typed client calls, TestApp/TestSession and fixtures.
The lower-level API tutorial follows below.
Your first Posts API
This tutorial targets Capy 0.10.0, with Rust 1.88 or later. Keep the CLI and framework on the same release. For the primary generated full-stack workflow, start with Build a Complete Feature.
It creates a JSON API with SQLite first, then shows PostgreSQL and generated React
contracts. All application imports come from capy; no direct Axum, SeaORM, Serde,
Tokio or Schemars dependencies are needed.
1. Install and create
Install Rust through rustup, with a native linker/toolchain for your OS. Install the matching CLI and create an application:
The generated Cargo.toml uses capy-framework 0.10.0 from crates.io, including its testing feature in development dependencies. No local source override is needed.
Cargo installs the executable in $HOME/.cargo/bin; make sure that directory is
on PATH (rustup normally configures it). The first installation/application build
compiles dependencies and takes longer than later runs. A minimal Linux image needs
a C compiler/linker, such as Debian/Ubuntu's build-essential package. SQLite is
bundled; no SQLite service or PostgreSQL client library is required.
2. Choose a database
The generated SQLite configuration works immediately:
DATABASE_URL=sqlite://database/app.sqlite?mode=rwc
You do not need to create a .env file for this default. For PostgreSQL, create a
disposable tutorial database. One option is Docker:
Wait for docker exec capy-postgres pg_isready -U postgres -d capy_blog to report
that connections are accepted. Keep DATABASE_URL in the shell used for migration
and serving, or put it in an ignored .env file. The same code and migrations below
work on both databases. Use application-specific credentials outside this tutorial.
3. Generate the components
These commands register compilable skeletons. Add your domain fields and handlers
by replacing the indicated files with the complete examples below. Keep the
registrations generated in each mod.rs file.
4. Add the model field
Replace app/models/post.rs. The generator already supplies serialization; we add
one title column. The Post entity and PostModel aliases are already registered.
use ;
5. Define the migration
Replace the generated file ending in _create_posts_table.rs under
database/migrations/. Keep its generated filename and the migrator registry.
Apply migrations explicitly; starting the server never changes the schema.
use ;
;
6. Validate input
Replace app/requests/create_post_request.rs. Both create and update require a title
between 2 and 200 characters. Invalid input receives HTTP 422 before the handler runs.
use *;
7. Implement the controller
Replace app/controllers/post_controller.rs. Context supplies the typed database
connection. Native SeaORM errors convert through ?; missing rows become JSON 404s.
Query<Pagination> defaults to page 1 with 20 items and rejects page sizes outside
1–100. Try /api/posts?page=2&per_page=20; lists return data plus meta with
page, per_page, total, and last_page. Empty collections have last_page: 1.
The explicit PostResponse keeps future private database columns out of the API.
use crate;
use ;
;
8. Register the routes
Replace routes/api.rs. Generator module registration does not implicitly add HTTP routes.
The generated application mounts these paths under /api via App::api_routes.
use crate;
use *;
9. Migrate and run
The server listens at http://127.0.0.1:8000. GET /api/health returns HTTP 200 and
{"status":"ok"}. Use APP_PORT=8001 capy serve if port 8000 is occupied.
10. Call the API
In another terminal, while capy serve is running:
On a fresh database, the created ID is 1; otherwise use the ID returned by POST.
Expect 201 on create, 200 on list/show/update, 422 for the short title, and 204 on
delete. Fetching a deleted ID gives {"message":"Resource not found"} with 404.
Every response has x-request-id; supply your own valid ID to correlate logs.
Internal database failures receive a sanitized JSON 500.
Stop the server with Ctrl-C. Unix SIGTERM to the capy serve PID also shuts down
and reaps its server. In production, run the compiled application binary directly.
11. Test the application
Create tests/posts.rs. These tests use an isolated in-memory SQLite database,
regardless of the server database chosen above.
use application;
use ;
async
You can also use capy test. To practice migration rollback after stopping the
server, run capy migrate:rollback, check capy migrate:status, then capy migrate
to reapply. Rolling back this migration deletes its table and data.
If you started the disposable PostgreSQL container, remove it when finished:
See the API documentation for configuration types and native escape hatches. This release is an initial developer preview.
12. Use the contract from React
For a full-stack project, start with capy new blog (omit --api) and follow the
same Rust steps. capy types writes generated/openapi.json and
frontend/src/generated/api-types.ts. Run pnpm install --frozen-lockfile inside
frontend/ first, or let capy dev install dependencies and generate the contracts
after the backend compiles.
import { api } from '@/lib/api'
import type { CreatePostRequest } from '@/generated/api-types'
const payload: CreatePostRequest = { title: 'Hello, Capy!' }
const post = await api.post('/api/posts', {
body: payload,
})
const page = await api.get('/api/posts', { params: { query: { page: 1 } } })
await api.delete('/api/posts/{id}', { params: { path: { id: post.id } } })
Keep generated files in source control. CI runs capy types --check after installing
frontend dependencies, followed by the Rust tests and pnpm build. A stale contract
causes a non-zero exit without rewriting files. capy dev regenerates after
successful Rust builds, and capy build generates before compiling React.
These are compile-time JSON contracts, not runtime response validators. Database models stay separate from response DTOs. See API contracts for Serde semantics, validation metadata, API documentation, and custom wire types.