-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Version: 0.1.0
Author: ProDeSquare
License: GNU General Public License v3.0 (GPL-3.0)
Website: https://prodesquare.com
Contact: hamza@prodesquare.com
Axumite is a lightweight, high-performance API framework built on top of Axum and Tower. It provides a structured, production-ready foundation for building database-backed web APIs in Rust with built-in rate limiting, connection pooling, distributed caching, request tracing, and graceful shutdown capabilities.
Originally crafted for personal use, Axumite embodies a preferred architecture for service designβsimple, predictable, and efficient. Anyone is free to use, modify, or extend it for both personal and commercial projects under the GPL-3.0 license.
- Built on Axum 0.8.6 - Leverages Axum's ergonomic routing and handler system
- Tower Middleware Integration - Composable middleware stack using Tower 0.5.2
- Structured Route Organization - Modular route definitions with easy extensibility
- Custom Error Handling - Centralized error handling with proper logging
- 404 Fallback Handler - Graceful handling of unknown routes with JSON responses
-
PostgreSQL Connection Pooling - Powered by Deadpool (deadpool-postgres 0.14.1)
- Configurable pool size (default: 16 connections)
- Fast recycling method for optimal performance
- Automatic connection health checks
-
Redis Connection Manager - Async Redis integration (redis 0.32.7)
- Connection manager for efficient connection reuse
- Built-in connection recovery
- Tokio-compatible async operations
-
Environment-Aware Rate Limiting - Automatic configuration based on environment
- Development Mode: Global key extractor (no IP tracking)
- Production Mode: Smart IP key extractor with real IP detection
-
Configurable Limits:
- 10 requests per second per key
- Burst capacity of 20 requests
- Built with Governor & Tower-Governor - Industry-standard rate limiting
-
Distributed Tracing - Built-in request tracing with tracing 0.1.41
- Configurable log levels via
RUST_LOGenvironment variable - Request/response logging with Tower HTTP trace layer
- Automatic span creation for all HTTP requests
- Configurable log levels via
- Response Compression - Full compression support (gzip, br, deflate, zstd)
- Environment-Based Configuration - All settings via environment variables
-
Optimized Release Profile:
- Link-Time Optimization (LTO) enabled
- Single codegen unit for maximum optimization
- Panic abort for smaller binary size
- Debug symbols stripped
- Graceful Shutdown - Proper signal handling (Ctrl+C) with connection draining
-
Health Check Endpoint - Built-in
/healthendpoint for load balancers
axumite/
βββ src/
β βββ main.rs # Entry point
β βββ app.rs # Application initialization & server setup
β βββ config.rs # Configuration management
β βββ state.rs # Shared application state
β βββ error.rs # Error handling
β βββ controllers/ # Request handlers
β β βββ mod.rs
β β βββ root_controller.rs
β β βββ health_controller.rs
β β βββ error_controller.rs
β βββ routes/ # Route definitions
β β βββ mod.rs
β β βββ health_routes.rs
β βββ models/ # Data models
β β βββ mod.rs
β β βββ health_model.rs
β βββ middleware/ # Custom middleware
β β βββ mod.rs
β β βββ rate_limit.rs
β βββ db/ # Database connections
β βββ mod.rs
β βββ postgres.rs
β βββ redis.rs
βββ Cargo.toml
βββ .env.example
Requests flow through the following middleware layers (in order):
- Rate Limiter - Enforces request rate limits based on environment
- Trace Layer - Logs request/response information
- Compression Layer - Compresses responses when supported by client
- Router - Routes requests to appropriate handlers
The AppState struct is shared across all handlers and contains:
pub struct AppState {
pub db_pool: Arc<DbPool>, // PostgreSQL connection pool
pub redis: Arc<RedisPool>, // Redis connection manager
pub config: Arc<AppConfig>, // Application configuration
}
State is cloned efficiently using Arc for thread-safe shared access.
- Rust 1.80+ (2024 edition)
- PostgreSQL 12+
- Redis 6+
-
Clone or copy the Axumite framework:
git clone <your-repo-url> cd axumite -
Copy the environment configuration:
cp .env.example .env -
Configure your environment variables:
# Application Settings APP_NAME="axumite" APP_HOST="127.0.0.1" APP_PORT="8080" APP_ENV="development" # or "production"PostgreSQL Configuration
DATABASE_HOST="127.0.0.1" DATABASE_PORT="5432" DATABASE_USER="postgres" DATABASE_PASS="your_password" DATABASE_NAME="prodesquare"
Redis Configuration
REDIS_URL="redis://127.0.0.1:6379"
Logging Configuration
RUST_LOG="axumite=debug,tower_http=info"
-
Build and run:
# Development cargo runProduction (optimized)
cargo build --release ./target/release/axumite
| Variable | Required | Default | Description |
|---|---|---|---|
| APP_NAME | No | prodesquare_api | Application name (used in logs) |
| APP_HOST | No | 127.0.0.1 | Host address to bind |
| APP_PORT | No | 8080 | Port to listen on |
| APP_ENV | No | production | Environment mode (development or production) |
| DATABASE_HOST | No | 127.0.0.1 | PostgreSQL host |
| DATABASE_PORT | No | 5432 | PostgreSQL port |
| DATABASE_USER | No | postgres | PostgreSQL username |
| DATABASE_PASS | No | "" | PostgreSQL password |
| DATABASE_NAME | No | prodesquare | PostgreSQL database name |
| REDIS_URL | Yes | - | Redis connection URL |
| RUST_LOG | No | - | Log level configuration |
Conditionally applies the appropriate rate limiter based on environment.
Usage:
let app = apply_rate_limiter!(routes::create_router())
.with_state(state);
Behavior:
- In production: Applies IP-based rate limiter
- In development: Applies global rate limiter
Return Result<T, AppError> from handlers to get automatic error logging and consistent error responses.
Database pools and Redis connections are already wrapped in Arc in AppState. Clone the state cheaply.
Move business logic to separate service modules. Handlers should focus on HTTP concerns.
Return appropriate status codes with responses:
-
200 OK- Successful GET/PUT -
201 Created- Successful POST -
204 No Content- Successful DELETE -
400 Bad Request- Invalid input -
404 Not Found- Resource not found -
500 Internal Server Error- Server errors
Use Axum extractors and validation libraries to ensure data integrity before processing.
Acquire database connections late and release them early. Don't hold connections across await points unnecessarily.
In production, monitor rate limit rejections to identify potential issues or adjust limits.
- Verify PostgreSQL is running and accessible
- Check
DATABASE_*environment variables - Ensure database exists and credentials are correct
- Verify Redis is running
- Check
REDIS_URLformat:redis://host:port - Test connection with
redis-cli ping
- Verify
APP_ENVis set correctly - Check proxy headers if behind reverse proxy
- Review rate limiter constants in
rate_limit.rs
- Reduce
max_sizein database pool configuration - Check for connection leaks (not releasing pool connections)
- Monitor active connections in PostgreSQL
Axumite is licensed under the GNU General Public License v3.0 (GPL-3.0).
You are free to use, modify, and distribute this software, provided that derivative works remain open source under the same license.
For the full license text, see: https://github.com/ProDeSquare/axumite/blob/master/LICENSE
For questions, issues, or contributions:
- Website: https://prodesquare.com
- Email: hamza@prodesquare.com
Built with β€οΈ by ProDeSquare