Project Templates Guide
Armature provides starter templates to help you quickly bootstrap new projects. Each template is designed for a specific use case and includes best practices.
Table of Contents
Overview
Templates are located in the templates/ directory:
templates/
โโโ README.md
โโโ api-minimal/ # Bare-bones REST API
โโโ api-full/ # Full-featured API
โโโ graphql-api/ # GraphQL API server
โโโ microservice/ # Queue-connected worker
Available Templates
| Template | Description | Best For |
|---|---|---|
api-minimal |
Single-file REST API | Learning, prototyping |
api-full |
Auth, validation, Docker | Production APIs |
graphql-api |
GraphQL API with queries, mutations, subscriptions | GraphQL APIs |
microservice |
Job queue worker | Background processing |
Using Templates
Quick Start
# Copy a template
cp -r templates/api-minimal my-project
cd my-project
# Update project name in Cargo.toml
# Configure .env from .env.example
# Run
cargo run
Template-Specific Setup
api-minimal
cp -r templates/api-minimal my-api
cd my-api
cp .env.example .env
cargo run
# Server at http://localhost:3000
api-full
cp -r templates/api-full my-api
cd my-api
cp .env.example .env
# Edit .env with your JWT_SECRET
cargo run
# Server at http://localhost:3000
For production with Docker:
docker-compose up -d
graphql-api
cp -r templates/graphql-api my-graphql
cd my-graphql
cp .env.example .env
cargo run
# GraphQL Playground at http://localhost:3000/graphql
microservice
cp -r templates/microservice my-worker
cd my-worker
cp .env.example .env
# Configure REDIS_URL
cargo run
Template Details
api-minimal
The simplest starting point for learning Armature.
Features:
- Single
main.rsfile - Basic CRUD operations
- Health check endpoint
- In-memory data store
Structure:
api-minimal/
โโโ Cargo.toml
โโโ .env.example
โโโ src/
โโโ main.rs
Endpoints:
GET /health- Health checkGET /api/users- List usersGET /api/users/:id- Get userPOST /api/users- Create userDELETE /api/users/:id- Delete user
api-full
Production-ready API with authentication and validation.
Features:
- JWT authentication
- Request validation
- Structured logging
- Docker support
- Health checks (liveness/readiness)
- Error handling
Structure:
api-full/
โโโ Cargo.toml
โโโ Dockerfile
โโโ docker-compose.yml
โโโ .env.example
โโโ src/
โโโ main.rs
โโโ config.rs
โโโ models.rs
โโโ middleware.rs
โโโ controllers/
โ โโโ mod.rs
โ โโโ auth.rs
โ โโโ health.rs
โ โโโ user.rs
โโโ services/
โโโ mod.rs
โโโ auth.rs
โโโ user.rs
Endpoints:
GET /health- Full health checkGET /health/live- Liveness probeGET /health/ready- Readiness probePOST /api/auth/login- LoginPOST /api/auth/register- RegisterGET /api/users- List users (authenticated)GET /api/users/:id- Get user (authenticated)DELETE /api/users/:id- Delete user (authenticated)
graphql-api
Production-ready GraphQL API with queries, mutations, and subscriptions.
Features:
- GraphQL Playground/GraphiQL
- Query and Mutation resolvers
- Subscription support
- Type-safe schema
- Pagination support
- Authentication integration
- Structured logging
Structure:
graphql-api/
โโโ Cargo.toml
โโโ .env.example
โโโ src/
โโโ main.rs
โโโ config.rs
โโโ context.rs
โโโ schema/
โ โโโ mod.rs
โ โโโ query.rs
โ โโโ mutation.rs
โ โโโ subscription.rs
โ โโโ types.rs
โโโ services/
โโโ mod.rs
โโโ auth.rs
โโโ user.rs
โโโ book.rs
Endpoints:
GET /graphql- GraphQL PlaygroundPOST /graphql- GraphQL endpointGET /health- Health checkGET /health/live- Liveness probeGET /health/ready- Readiness probe
Example Queries:
# List all users
query {
users {
items { id name email role }
total
hasMore
}
}
# Get a specific book with author
query {
book(id: "1") {
id
title
author { name email }
}
}
# Create a user
mutation {
createUser(input: { name: "Alice", email: "alice@example.com" }) {
id
name
}
}
# Search books
query {
searchBooks(query: "Rust") {
id
title
publishedYear
}
}
microservice
Background job processor with health monitoring.
Features:
- Job queue processing
- Retry with backoff
- Prometheus metrics
- Graceful shutdown
- Docker support
Structure:
microservice/
โโโ Cargo.toml
โโโ Dockerfile
โโโ .env.example
โโโ src/
โโโ main.rs
โโโ config.rs
โโโ handlers.rs
โโโ jobs.rs
Endpoints:
GET /health- Service health with job statsGET /health/live- Liveness probeGET /health/ready- Readiness probeGET /metrics- Prometheus metrics
Job Types:
send_email- Email sendingsend_notification- Push/SMS/Slack notificationsprocess_data- Data processing
Customization
Adding a Database
# Cargo.toml
[dependencies]
sqlx = { version = "0.7", features = ["runtime-tokio", "postgres"] }
// src/main.rs
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&env::var("DATABASE_URL")?)
.await?;
Adding Rate Limiting
# Cargo.toml
[dependencies]
armature-framework = { version = "0.1", features = ["ratelimit"] }
use armature_ratelimit::{RateLimiter, Algorithm};
let limiter = RateLimiter::builder()
.token_bucket(100, 10.0)
.build()
.await?;
Adding Caching
# Cargo.toml
[dependencies]
armature-framework = { version = "0.1", features = ["cache"] }
Adding Validation
# Cargo.toml
[dependencies]
armature-framework = { version = "0.1", features = ["validation"] }
Adding OpenAPI Docs
# Cargo.toml
[dependencies]
armature-framework = { version = "0.1", features = ["openapi"] }
Best Practices
1. Configuration
Always use environment variables for configuration:
let config = AppConfig::from_env();
Never commit secrets to version control. Use .env.example as a template.
2. Logging
Use structured logging with tracing:
use tracing::{info, debug, error};
info!(user_id = %user.id, "User logged in");
3. Error Handling
Return consistent error responses:
#[derive(Serialize)]
struct ApiError {
code: String,
message: String,
}
HttpResponse::bad_request().json(ApiError {
code: "VALIDATION_ERROR".into(),
message: "Invalid input".into(),
})
4. Health Checks
Always include health endpoints for container orchestration:
/health- Full health check/health/live- Is the process alive?/health/ready- Can it accept traffic?
5. Docker Best Practices
Use multi-stage builds:
# Build stage
FROM rust:1.85 AS builder
# ... build ...
# Runtime stage
FROM debian:bookworm-slim
# ... minimal runtime ...
6. Security
- Use strong JWT secrets (32+ random bytes)
- Hash passwords with bcrypt/argon2
- Validate all input
- Use HTTPS in production
- Implement rate limiting
Creating New Templates
To add a new template:
- Create directory under
templates/ - Include minimum files:
Cargo.tomlsrc/main.rs.env.example
- Follow existing patterns
- Update
templates/README.md - Add to this guide
Summary
Templates provide a quick start for common project types:
| Need | Use |
|---|---|
| Learning Armature | api-minimal |
| Production REST API | api-full |
| GraphQL API | graphql-api |
| Background jobs | microservice |
All templates follow Armature best practices and can be customized as needed.