PitchHut logo
A robust Rust web API template utilizing modern technologies.
Pitch

AxumKit serves as a comprehensive, production-ready template for Rust web APIs, integrating powerful tools like Axum, PostgreSQL, and Redis. Designed with a layered architecture and built-in features such as session-based authentication and background job processing, it streamlines the development of scalable, efficient web applications.

Description

AxumKit is a production-ready web API template built in Rust, leveraging the power and flexibility of Axum, SeaORM, PostgreSQL, Redis, and OAuth2 technologies.

Key Features

  • Robust Web Framework: Built on Axum with a layered architecture, ensuring separation of concerns across API, Service, Repository, and Entity layers for maintainable code.
  • Database Integration: Utilizes PostgreSQL along with SeaORM for data management and migrations.
  • Authentication Mechanism: Supports session-based authentication via Redis and OAuth2 integration for Google and GitHub.
  • Background Processing: Includes capabilities to handle background jobs through NATS JetStream for operations such as email handling, search indexing, and scheduled tasks.
  • Storage Solutions: Integrated with SeaweedFS for content storage and Cloudflare R2 for file management.
  • Advanced Search Functionality: Incorporates MeiliSearch for powerful full-text search capabilities.
  • API Documentation: Automatically generates OpenAPI/Swagger documentation for easier development and testing.
  • Effective Testing: Employs parallelized end-to-end (E2E) tests utilizing Docker to ensure code reliability.
  • Continuous Integration & Deployment: Features automated CI/CD workflows via GitHub Actions for Docker build and deployment to GitHub Container Registry (GHCR).

Architecture Overview

The architecture of AxumKit is distinctly modular:

  • API Layer: Contains HTTP handlers, routing, and OpenAPI documentation.
  • Service Layer: Manages business logic and input validation processes.
  • Repository Layer: Handles database queries and interactions.
  • Entity Layer: Defines SeaORM models for data representation.

Error Handling

Error management is centralized through an Errors enum, providing automatic conversion to the appropriate HTTP response status codes. The error handling mechanism varies between development environments (detailed error information) and production settings (safeguarding internal details).

pub async fn handler() -> Result<Json<Response>, Errors> {
    let user = repo::get_by_id(&conn, id)
        .await
        .map_err(|_| Errors::UserNotFound)?;
    Ok(Json(response))
}

Configuration

Customizable through environment variables defined in the .env file, AxumKit allows easy configuration for server settings, authentication, database connections, caching, storage, search options, and more. A sample configuration is provided in the .env.example file.

CategoryVariables
ServerHOST, PORT, ENVIRONMENT
AuthTOTP_SECRET, AUTH_SESSION_*, OAUTH_PENDING_SIGNUP_TTL_MINUTES
DatabasePOSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_NAME
RedisREDIS_SESSION_HOST, REDIS_SESSION_PORT, REDIS_CACHE_HOST, REDIS_CACHE_PORT
OAuthGOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET
StorageR2_*, SEAWEEDFS_ENDPOINT
SearchMEILISEARCH_HOST, MEILISEARCH_API_KEY
QueueNATS_URL
CORSCORS_ALLOWED_ORIGINS, CORS_ALLOWED_HEADERS, CORS_MAX_AGE

AxumKit is designed for developers looking to streamline the creation of secure and performant web APIs in Rust.

0 comments

No comments yet.

Sign in to be the first to comment.