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.3.1" }
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 models support Json<Vec<PostModel>> without a direct Serde dependency.
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.
Your first Posts API
This tutorial uses Capy 0.3.1 and Rust 1.88 or later. It creates a JSON API with
SQLite first, then shows how to use PostgreSQL. All application imports come from
capy; no direct Axum, SeaORM, Serde, or Tokio dependencies are needed.
1. Install and create
Install Rust through rustup, with a native linker/toolchain for your OS. Install the formatter once, then create an application:
Expect capy 0.3.1. Cargo installs the executable in $HOME/.cargo/bin; make sure
that directory is on PATH (rustup normally configures it). The first installation
and application build compile Rust dependencies and take longer than later runs.
A minimal Linux image needs a C compiler/linker, such as the build-essential
package on Debian/Ubuntu. 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.
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 cratePostController;
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 ;
use ;
use Arc;
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.