A production-ready, modular Rust API framework designed for scalability and maintainability. Built with Actix-web, SeaORM, and Utoipa.
Create a new project with cf new my-app, see cf-cli.
- Modular Architecture: Split into
cf-api,cf-entity,cf-migration,cf-repository, andcf-utilcrates. - REST API: Built with Actix-web.
- ORM: SeaORM for type-safe database interactions (PostgreSQL).
- Migrations: SeaORM Migration with a CLI (
up,down,status,fresh, ...), similar tophp artisan migrate. - Documentation: Auto-generated Swagger/OpenAPI documentation (
/swagger-ui). - Configuration: Environment variable based configuration.
- Pinned Toolchain: Rust version locked via
rust-toolchain.toml. - Containerization: Optimized Dockerfile for production.
- CI/CD: Jenkinsfile and Kubernetes manifests included.
├── cf-cli # Scaffolding CLI (`cf new`), outside the workspace
├── cf-api # Main API server, handlers, services, routes, DTOs
├── cf-entity # Database entities (SeaORM models)
├── cf-migration # Database migrations + migration CLI
├── cf-repository # Data access layer (Repositories)
├── cf-util # Shared utilities (S3, Sanitization, etc.)
├── k8s # Kubernetes manifests
├── Cargo.toml # Workspace configuration
├── rust-toolchain.toml # Pinned Rust version
└── Dockerfile # Multi-stage Docker build
- Rust: 1.94.0 (installed automatically by
rustupfromrust-toolchain.toml) - PostgreSQL: 14+
- Docker (optional)
Copy .env.example to .env and configure your database credentials:
cp .env.example .envCreate an empty database matching DATABASE_NAME. No extensions are required; tables are created by the migrations.
CREATE DATABASE your_database;cargo run -p cf-migrationcargo run -p cf-apiThe API also runs pending migrations on startup, so step 3 is optional for local development.
The server will start at http://localhost:3000 (configurable with API_HOST and API_PORT).
- Health Check:
http://localhost:3000/health - Swagger UI:
http://localhost:3000/swagger-ui/
| Command | Description |
|---|---|
cargo run -p cf-migration |
Apply all pending migrations (same as up) |
cargo run -p cf-migration -- status |
Show applied / pending migrations |
cargo run -p cf-migration -- down |
Roll back the last migration |
cargo run -p cf-migration -- refresh |
Roll back all, then apply all |
cargo run -p cf-migration -- reset |
Roll back all migrations |
cargo run -p cf-migration -- fresh |
Drop all tables, then apply all ( |
The CLI builds the connection URL from the DATABASE_* variables in .env.
- Create a new migration in
cf-migration/src/and register it incf-migration/src/lib.rs.- Use
gen_random_uuid()for UUID defaults (built into PostgreSQL 13+). Do not useuuid_generate_v4(), which requires theuuid-osspextension.
- Use
- Create the entity file in
cf-entity/src/entity/. - Register the entity in
cf-entity/src/entity/mod.rsandprelude.rs.
- Create a Repository in
cf-repository/src/repositories/and re-export it inmod.rs. - Create DTOs in
cf-api/src/dto/. - Create a Service in
cf-api/src/services/. - Create a Handler in
cf-api/src/handlers/. - Register Routes in
cf-api/src/routes/and add the scope inroutes/routes.rs. - In
cf-api/src/main.rs, register the handlers inpaths(...), the DTOs/models inschemas(...), and the service withapp_data(...).
Update the version in rust-toolchain.toml, rust-version in the root Cargo.toml, and the FROM rust: image in Dockerfile in the same commit.
docker build -t cf-framework .
docker run -p 3000:3000 --env-file .env cf-frameworkThe container runs cf-migration and then starts cf-api (see entrypoint.sh).
The k8s/ directory contains standard Kubernetes manifests:
deployment.yamlservice.yamlingress.yamlconfigmap.yamlsecret.yaml
Update configmap.yaml and secret.yaml with your production configuration before applying.