Introduction
Rust Ironclad is an enterprise-grade backend framework built with Rust that follows Domain-Driven Design (DDD) principles with a clean 5-layer architecture. This design ensures maximum maintainability, testability, and scalability for your applications.Architecture Diagram
Core Design Principles
Clean Architecture
Each layer has a specific responsibility and depends only on layers below it. The Domain layer has no external dependencies.
Repository Pattern
Data access is abstracted through trait interfaces, making it easy to swap implementations or mock for testing.
Value Objects
Domain concepts are encapsulated in type-safe Value Objects with built-in validation, preventing invalid state.
Dependency Injection
Services are injected through constructor parameters, enabling loose coupling and easy testing.
The Five Layers
1. Routes Layer
Defines HTTP routing configuration and maps URLs to controllers. Location:src/routes/
src/routes/api.rs
2. Infrastructure Layer
Handles external concerns like HTTP requests, database access, and third-party integrations. Location:src/infrastructure/
Contains:
- Controllers: Handle HTTP requests and responses
- Persistence: Database repository implementations
- HTTP utilities: Authentication extractors, middleware
3. Application Layer
Orchestrates business logic through services and defines data transfer objects (DTOs). Location:src/application/
Contains:
- Services: Coordinate use cases and business workflows
- DTOs: Request/response structures with validation
4. Domain Layer
The heart of your application containing pure business logic. Location:src/domain/
Contains:
- Entities: Core business objects (User, Product, etc.)
- Value Objects: Immutable, self-validating domain concepts
- Business Rules: Pure domain logic with no external dependencies
5. Interfaces Layer
Defines contracts (traits) for data access and external services. Location:src/interfaces/
Contains:
- Repository traits: Define data access contracts
- Service interfaces: Abstract external dependencies
Key Design Patterns
Repository Pattern
Abstracts data access behind trait interfaces:src/interfaces/repositories/user_repository.rs
Smart Constructors
Value Objects validate their state upon creation:Data Flow Example
Here’s how a user registration request flows through the architecture:Benefits of This Architecture
Testability
Testability
Each layer can be tested independently. Mock repositories and services for fast unit tests.
Maintainability
Maintainability
Clear separation of concerns makes code easy to understand and modify. Changes in one layer rarely affect others.
Scalability
Scalability
Swap implementations (e.g., PostgreSQL to MongoDB) by changing only the Infrastructure layer.
Type Safety
Type Safety
Value Objects and strong typing prevent invalid state at compile time, not runtime.
Next Steps
DDD Principles
Deep dive into Domain-Driven Design concepts
Layer Details
Detailed explanation of each layer
Dependency Injection
How DI works in Ironclad
Quick Start
Build your first endpoint
Performance Features
Ironclad uses Actix-web, one of the fastest web frameworks available, capable of handling 50,000+ requests/second with non-blocking async I/O powered by Tokio.