ignitia 0.2.4

A blazing fast, lightweight web framework for Rust that ignites your development journey
Documentation
# Ignitia Documentation

Welcome to the comprehensive documentation for **Ignitia** - a blazing fast, lightweight web framework for Rust that ignites your development journey! πŸ”₯

Ignitia is designed to provide developers with a powerful, async HTTP server framework featuring modern web development capabilities including HTTP/2 support, WebSockets, middleware, file uploads, and robust security features.

## πŸ“š Documentation Index

### Getting Started
- **[πŸ“‹ Installation Guide]INSTALLATION.md** - Step-by-step installation instructions and feature flags
- **[πŸš€ Quick Start]QUICK_START.md** - Get up and running with Ignitia in minutes
- **[πŸ“– Examples]EXAMPLES.md** - Practical code examples and use cases

### Core Concepts
- **[πŸ›£οΈ Routing Guide]ROUTING_GUIDE.md** - Complete routing system documentation including path parameters, nested routers, and route matching
- **[⚑ Middleware Guide]MIDDLEWARE_GUIDE.md** - Built-in middleware and creating custom middleware
- **[πŸ”§ Extractors]EXTRACTORS.md** - JSON, Form, Query, Path, Headers, Cookies, and custom extractors
- **[πŸ“„ API Reference]API_REFERENCE.md** - Comprehensive API reference for Ignitia's modules and components
- **[❌ Error Handling]ERROR_HANDLING.md** - Error types, custom errors, and error responses

### Advanced Features
- **[🌐 WebSockets]WEB_SOCKETS.md** - Real-time communication with WebSocket support
- **[πŸ“ File Uploads]FILE_UPLOADS.md** - Multipart form data and file handling
- **[πŸ–₯️ Server Configuration]SERVER_CONFIG.md** - HTTP/2, TLS, and server optimization

### Production Deployment
- **[πŸ”’ Security]SECURITY.md** - Security middleware, HTTPS, and protection mechanisms

### Static Files and I/O
- **[πŸ“¦ Static Files]STATIC_FILES.md** - Handling of static file serving and caching
- **[πŸ“¬ Responses]RESPONSES.md** - Response structure, builders, and helpers
- **[πŸ“₯ Requests]REQUESTS.md** - Request structure, body extraction, and parameters

### Project Information
- **[πŸ“ Migration Guide]MIGRATION.md** - Upgrading between versions
- **[🀝 Contributing]CONTRIBUTING.md** - How to contribute to Ignitia
- **[πŸ“‹ Changelog]CHANGELOG.md** - Version history and breaking changes


## 🎯 Quick Navigation

**New to Ignitia?** Start with the [Quick Start Guide](QUICK_START.md) to build your first application.

**Looking for specific features?**
- Building APIs? β†’ [Extractors]EXTRACTORS.md + [Error Handling]ERROR_HANDLING.md
- Real-time apps? β†’ [WebSockets]WEB_SOCKETS.md
- File uploads? β†’ [File Uploads]FILE_UPLOADS.md
- Production deployment? β†’ [Server Config]SERVER_CONFIG.md + [Security]SECURITY.md

**Need help?** Check out [Examples](EXAMPLES.md) for practical implementations.

## πŸ”₯ What Makes Ignitia Special

- **πŸš€ Blazing Fast**: Built on Tokio with HTTP/2 support and optimized for performance
- **πŸ› οΈ Developer Friendly**: Intuitive API design with comprehensive error messages
- **πŸ“¦ Modular**: Optional features mean you only include what you need
- **πŸ”’ Secure by Default**: Built-in security middleware and best practices
- **🌟 Modern**: Async/await throughout, leveraging Rust's powerful type system

## πŸ—οΈ Architecture Overview

Ignitia follows a layered, modular architecture built on Rust's async ecosystem. The framework is designed for performance, type safety, and developer productivity.

### High-Level Architecture

```
                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                          β”‚           Application               β”‚
                          β”‚        (Your Business Logic)       β”‚
                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                                 Ignitia Framework                           β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
    β”‚  β”‚   Handlers  β”‚  β”‚  Extractors  β”‚  β”‚ Middleware  β”‚  β”‚     Router      β”‚   β”‚
    β”‚  β”‚ (Business)  β”‚  β”‚ (Type-Safe   β”‚  β”‚ (Pipeline)  β”‚  β”‚ (Smart Route    β”‚   β”‚
    β”‚  β”‚   Logic     β”‚  β”‚  Request     β”‚  β”‚ Processing  β”‚  β”‚   Matching)     β”‚   β”‚
    β”‚  β”‚             β”‚  β”‚ Parsing)     β”‚  β”‚             β”‚  β”‚                 β”‚   β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                             Core Infrastructure                              β”‚
    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
    β”‚  β”‚   Server    β”‚  β”‚   Protocol   β”‚  β”‚   Request/  β”‚  β”‚   WebSocket     β”‚   β”‚
    β”‚  β”‚ (HTTP/1&2,  β”‚  β”‚  Detection   β”‚  β”‚  Response   β”‚  β”‚    Support      β”‚   β”‚
    β”‚  β”‚  TLS, H2C)  β”‚  β”‚  (ALPN/Auto) β”‚  β”‚   Engine    β”‚  β”‚                 β”‚   β”‚
    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                          Tokio Runtime & Hyper                              β”‚
    β”‚               (Async I/O, Connection Management, HTTP Protocol)             β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

### Core Components Deep Dive

#### πŸš€ **Server Layer**
The server layer handles connection management and protocol negotiation:

- **Multi-Protocol Support**: HTTP/1.1, HTTP/2, and HTTP/2 Cleartext (H2C)
- **TLS Integration**: Optional TLS with ALPN protocol negotiation
- **Connection Management**: Efficient connection pooling and lifecycle management
- **Protocol Detection**: Automatic protocol detection and upgrade handling

```
// Example server configuration
let server = Server::new(router, "127.0.0.1:3000".parse().unwrap())
    .with_config(ServerConfig {
        http2: Http2Config {
            enabled: true,
            max_concurrent_streams: Some(1000),
            ..Default::default()
        },
        ..Default::default()
    });
```

#### πŸ›£οΈ **Router System**
Advanced routing with performance optimizations:

- **Pre-compiled Routes**: Routes are compiled to optimized regex patterns at startup
- **Smart Matching**: Routes sorted by specificity for faster matching
- **Nested Routing**: Support for modular route organization
- **Parameter Extraction**: Type-safe path and wildcard parameter extraction

```
// Router architecture
Router::new()
    .get("/users/{id}", user_handler)           // Path parameters
    .post("/users", create_user_handler)       // HTTP methods
    .nest("/api/v1", api_routes)               // Nested routing
    .websocket("/ws", websocket_handler)       // WebSocket endpoints
```

#### βš™οΈ **Middleware Pipeline**
Composable middleware system with before/after hooks:

- **Layered Processing**: Request flows through middleware chain
- **Built-in Middleware**: CORS, auth, logging, rate limiting, compression
- **Custom Middleware**: Easy to implement custom processing logic
- **Error Handling**: Centralized error processing with custom handlers

```
// Middleware execution flow
Request β†’ Middleware₁.before() β†’ Middlewareβ‚‚.before() β†’ Handler β†’
        ← Middlewareβ‚‚.after()  ← Middleware₁.after()  ← Response
```

#### πŸ”§ **Type-Safe Extractors**
Automatic request data extraction with compile-time guarantees:

- **JSON/Form Data**: Automatic deserialization with serde
- **Path Parameters**: Type-safe path parameter extraction
- **Query Strings**: Structured query parameter parsing
- **Headers & Cookies**: Easy access to request metadata
- **Custom Extractors**: Implement `FromRequest` for custom types

```
// Extractor examples
async fn handler(
    Path(user_id): Path<u32>,           // Path parameter
    Query(params): Query<SearchQuery>,   // Query parameters
    Json(data): Json<CreateUser>,        // JSON body
    State(db): State<Database>,          // Shared state
) -> Result<Response> { /* ... */ }
```

#### πŸ”Œ **Extension System**
Type-safe shared state management:

- **Dependency Injection**: Store and retrieve shared resources
- **Type Safety**: Compile-time guarantees for state access
- **Arc-wrapped**: Efficient shared ownership with `Arc<T>`
- **Request-scoped**: Per-request data storage

#### 🌐 **WebSocket Integration**
Full-featured WebSocket support with optimizations:

- **Protocol Upgrade**: Automatic WebSocket handshake handling
- **Message Types**: Text, Binary, Ping/Pong, Close frames
- **Batch Processing**: Efficient batch message handling
- **Custom Handlers**: Flexible handler patterns for different use cases

### Performance Optimizations

#### πŸ“Š **Routing Performance**
- **Compiled Regex**: Routes pre-compiled to optimized regex patterns
- **Smart Sorting**: Routes ordered by specificity for faster matching
- **Early Rejection**: Quick path length and segment count checks
- **Cache-friendly**: Memory layout optimized for CPU cache performance

#### πŸš€ **Connection Handling**
- **HTTP/2 Multiplexing**: Concurrent request handling over single connection
- **Connection Pooling**: Efficient resource reuse
- **Protocol Negotiation**: ALPN-based protocol selection
- **Keep-Alive**: Configurable connection persistence

#### πŸ’Ύ **Memory Management**
- **Zero-Copy**: Minimal data copying with `Bytes` and `Arc`
- **Streaming**: Large request/response body streaming
- **Bounded Channels**: Prevent memory exhaustion in WebSocket handling
- **Efficient Parsing**: Optimized HTTP header and body parsing

### Security Architecture

#### πŸ›‘οΈ **Built-in Security**
- **HTTPS/TLS**: Full TLS 1.2/1.3 support with modern cipher suites
- **Security Headers**: Automatic security header injection
- **CORS**: Flexible cross-origin resource sharing
- **Rate Limiting**: Token bucket algorithm for DDoS protection

#### πŸ”’ **Input Validation**
- **Type Safety**: Compile-time request validation
- **Size Limits**: Configurable request/field size limits
- **Content Validation**: MIME type and encoding validation
- **Sanitization**: Built-in XSS and injection protection

### Extension Points

#### πŸ”§ **Custom Middleware**
```
#[async_trait::async_trait]
impl Middleware for CustomMiddleware {
    async fn before(&self, req: &mut Request) -> Result<()> { /* ... */ }
    async fn after(&self, req: &Request, res: &mut Response) -> Result<()> { /* ... */ }
}
```

#### πŸ“Š **Custom Extractors**
```
#[async_trait::async_trait]
impl FromRequest for CustomExtractor {
    fn from_request(req: &Request) -> Result<Self> { /* ... */ }
}
```

#### ❌ **Custom Error Handling**
```
impl CustomError for MyError {
    fn status_code(&self) -> StatusCode { /* ... */ }
    fn error_type(&self) -> &'static str { /* ... */ }
}
```

### Development Workflow

```
1. Define Routes     β†’ 2. Add Middleware  β†’ 3. Implement Handlers
       ↓                      ↓                    ↓
4. Configure Server  β†’ 5. Add Extensions  β†’ 6. Handle Errors
       ↓                      ↓                    ↓
7. Test & Debug     β†’ 8. Deploy          β†’ 9. Monitor
```

This architecture ensures that Ignitia applications are:
- **Fast**: Optimized routing and connection handling
- **Safe**: Type-safe extractors and error handling
- **Scalable**: Async architecture with efficient resource usage
- **Maintainable**: Clear separation of concerns and modular design
- **Extensible**: Rich plugin system for custom functionality

## 🚦 Status

- **Current Version**: 0.2.4
- **Stability**: Beta (API may change)
- **Minimum Rust Version**: 1.70+

## πŸ“ž Support & Community

- πŸ“š **Documentation**: You're reading it!
- πŸ› **Issues**: Report bugs and request features
- πŸ’¬ **Discussions**: Ask questions and share projects
- 🀝 **Contributing**: See [Contributing Guide](CONTRIBUTING.md)

---

*Ready to ignite your next Rust web project? Start with the [Quick Start Guide](QUICK_START.md)!* πŸ”₯