elif-core

Core architecture foundation for the elif.rs LLM-friendly web framework


Keywords
ai, dependency-injection, framework, llm, web
License
MIT

Documentation

elif.rs

A web framework designed for both AI agents and developers. Simple, intuitive, productive.

Rust License: MIT Build Status Crates.io

⚠️ IMPORTANT NOTICE: This project is under heavy active development. APIs may change, features are being added rapidly, and breaking changes can occur between versions. While the core functionality is stable, please pin to specific versions in production and expect frequent updates.

elif.rs combines Rust's performance and safety with exceptional developer experience. Convention over configuration, zero boilerplate, and intuitive APIs that maximize productivity.

πŸš€ 5-Second Quick Start

# Install elif CLI
cargo install elifrs

# Create a new app
elifrs new my-app
cd my-app

# Start developing
cargo run

Your API server starts at http://localhost:3000 with zero configuration πŸŽ‰

πŸ†• Zero-Boilerplate Bootstrap

The new #[elif::bootstrap] macro requires zero configuration:

use elif::prelude::*;

#[elif::bootstrap]  // ← That's it!
async fn main() -> Result<(), HttpError> {
    // Everything happens automatically:
    // ✨ Controllers auto-discovered
    // ✨ Dependencies auto-injected  
    // ✨ Routes auto-registered
    // ✨ Server auto-started
    Ok(())
}

No AppModule. No configuration. No boilerplate. Just works.

⚑ True Zero-Boilerplate Experience

Build production-ready APIs with minimal code:

use elif::prelude::*;

// Your controllers - declarative and clean
#[controller("/api/users")]
#[middleware("cors")]
impl UserController {
    #[get("")]
    async fn list(&self) -> HttpResult<ElifResponse> {
        let users = vec!["Alice", "Bob"];
        Ok(ElifResponse::ok().json(&users)?)
    }
    
    #[post("")]
    #[middleware("auth")]
    async fn create(&self, req: ElifRequest) -> HttpResult<ElifResponse> {
        let user: CreateUser = req.json().await?;
        Ok(ElifResponse::created().json(&user)?)
    }
}

// Your services - dependency injection built-in
#[derive(Default)]
struct UserService;

// Your app module - NestJS-style organization
#[module(
    controllers: [UserController],
    providers: [UserService], 
    is_app
)]
struct AppModule;

// Zero-boilerplate server setup! ✨
#[elif::bootstrap(AppModule)]
async fn main() -> Result<(), HttpError> {
    println!("πŸš€ Server starting...");
    // Everything happens automatically:
    // βœ… Module discovery and dependency injection
    // βœ… Route registration with middleware  
    // βœ… Server startup on 127.0.0.1:3000
}

That's it! From project creation to running server - zero configuration, zero boilerplate.

🎯 Before and After

Before: Traditional Rust Web Development

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let container = IocContainer::new();
    container.register::<UserService>();
    
    let router = Router::new()
        .route("/users", get(list_users))
        .route("/users", post(create_user));
    
    let app = App::new()
        .wrap(Logger::default())
        .wrap(Cors::default())
        .service(scope("/api").configure(|cfg| {
            cfg.service(router);
        }));
    
    HttpServer::new(move || app.clone())
        .bind("127.0.0.1:3000")?
        .run()
        .await
}

After: elif.rs Way

use elif::prelude::*;

#[elif::bootstrap]  // ← Zero boilerplate!
async fn main() -> Result<(), HttpError> {
    println!("πŸš€ Server starting!");
    // Everything automatic:
    // - Controllers auto-discovered and registered
    // - IoC container auto-configured
    // - Router setup automatically
    // - Server starts on 127.0.0.1:3000
    Ok(())
}

Result: 85% less code, exceptional developer experience, full Rust performance.

πŸ—οΈ Production-Ready Configuration

Need custom settings? elif.rs scales with your needs:

// Development setup - zero boilerplate!
#[elif::bootstrap]
async fn main() -> Result<(), HttpError> {
    // Everything auto-configured!
    Ok(())
}

// Production setup with custom config
#[elif::bootstrap(
    addr = "0.0.0.0:8080",
    config = HttpConfig::production(),
    middleware = [cors(), auth(), rate_limiting(), logging()]
)]
async fn main() -> Result<(), HttpError> {
    run_migrations().await?;
    warm_caches().await?;
    println!("πŸš€ Production server ready!");
    Ok(())
}

✨ Declarative Everything

Controllers - 70% Less Boilerplate

#[controller("/api/posts")]
#[middleware("cors", "auth")]
impl PostController {
    // GET /api/posts
    #[get("")]
    #[middleware("cache")]
    async fn list(&self) -> HttpResult<ElifResponse> {
        Ok(ElifResponse::ok().json(&get_posts())?)
    }
    
    // POST /api/posts
    #[post("")]
    async fn create(&self, req: ElifRequest) -> HttpResult<ElifResponse> {
        let post: CreatePost = req.json().await?;
        Ok(ElifResponse::created().json(&create_post(post))?)
    }
    
    // GET /api/posts/{id}
    #[get("/{id}")]
    #[param(id: int)]
    async fn show(&self, id: u32) -> HttpResult<ElifResponse> {
        let post = find_post(id)?;
        Ok(ElifResponse::ok().json(&post)?)
    }
}

Modules - NestJS-Style Organization

#[module(
    controllers: [PostController, CommentController],
    providers: [PostService, EmailService],
    imports: [DatabaseModule, AuthModule],
    exports: [PostService]
)]
struct BlogModule;

Database - Laravel-Inspired ORM

// Models with relationships
#[derive(Debug, Serialize, Model)]
struct User {
    id: Uuid,
    name: String, 
    email: String,
    created_at: DateTime<Utc>,
}

// Laravel-style query builder
let users = User::query()
    .where_eq("active", true)
    .where_gt("age", 18)
    .with("posts.comments")  // Eager loading relationships
    .order_by("created_at", "DESC")
    .paginate(10)
    .get(&db)
    .await?;

πŸ€– AI-Native Development

elif.rs was designed with AI agents in mind:

βœ… Intuitive patterns that LLMs understand naturally
βœ… Convention over configuration reduces decision complexity
βœ… Consistent APIs across the entire framework
βœ… Self-documenting code with derive macros
βœ… Clear error messages with actionable suggestions

Perfect for Claude, GPT-4, Cursor, and GitHub Copilot.

πŸ› οΈ Powerful CLI Commands

# Project Management
elifrs new blog-api                    # Create new project with modular structure
elifrs generate                        # AI-powered code generation
elifrs serve --reload                  # Hot reload development server

# Code Scaffolding  
elifrs make:module UserModule          # Generate complete module
elifrs make:controller UserController  # Generate declarative controller
elifrs make:service UserService        # Generate injectable service
elifrs make:resource User              # Generate complete CRUD resource

# Database Management
elifrs migrate run                     # Run pending migrations
elifrs migrate create create_users     # Create new migration
elifrs db:seed                         # Seed database with test data

# API Documentation
elifrs openapi generate               # Generate OpenAPI spec
elifrs openapi serve                  # Start Swagger UI server

πŸ“¦ Modular Project Structure

Generated projects use a clean, organized structure:

my-app/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs                   # Zero-boilerplate bootstrap
β”‚   └── modules/
β”‚       β”œβ”€β”€ app/
β”‚       β”‚   β”œβ”€β”€ app.module.rs     # Root app module
β”‚       β”‚   β”œβ”€β”€ app.controller.rs # Health check endpoints
β”‚       β”‚   └── app.service.rs    # Core services
β”‚       └── users/
β”‚           β”œβ”€β”€ users.module.rs   # Feature module
β”‚           β”œβ”€β”€ users.controller.rs
β”‚           β”œβ”€β”€ users.service.rs  
β”‚           └── dto/
β”‚               β”œβ”€β”€ create_user.rs
β”‚               └── update_user.rs
β”œβ”€β”€ migrations/                   # Database migrations
β”œβ”€β”€ tests/                       # Integration tests
└── Cargo.toml                   # Minimal dependencies

πŸ§ͺ Framework-Native Testing

use elif::testing::*;

#[tokio::test]
async fn test_user_api() {
    let app = TestApp::new(AppModule).await;
    
    // Test API endpoints
    let response = app.get("/api/users").await;
    assert_eq!(response.status(), 200);
    
    // Test with authentication
    let response = app
        .post("/api/users")
        .auth("Bearer token")
        .json(&new_user)
        .await;
    assert_eq!(response.status(), 201);
}

πŸ“š Framework Architecture

Core Crates (Published on crates.io)

  • elif-http v0.8.2 - HTTP server, routing, middleware + declarative macros
  • elif-http-derive v0.2.0 - Controller and module derivation macros
  • elif-macros v0.1.1 - Bootstrap and main function macros
  • elif-core v0.7.0 - Dependency injection and IoC container with auto-configuration
  • elifrs v0.10.3 - Powerful CLI with modular project generation
  • elif-orm v0.7.0 - Type-safe ORM with relationships
  • elif-auth v0.4.0 - Authentication and authorization
  • elif-cache v0.3.0 - Caching with multiple backends

CLI & Development Tools

  • elifrs v0.10.3 - Enhanced CLI with auto-configuration support
  • Modular project generation with NestJS-style module discovery
  • Provider auto-configuration with dependency injection optimization
  • Controller auto-registration with route conflict detection
  • AI-powered code generation from natural language specs
  • Hot reload development with automatic recompilation
  • Built-in testing framework with mocking support

πŸ—ΊοΈ Current State (v0.8.2+)

πŸ”„ Coming in v0.9.0

  • WebSocket channels for real-time features
  • Advanced validation with custom rule sets
  • GraphQL integration with automatic schema generation
  • Enhanced ORM relationships with eager loading optimization
  • Background job processing with Redis/database queues

πŸ“„ License

MIT License - see LICENSE for details.


elif.rs
Convention over Configuration β€’ Zero Boilerplate β€’ AI-Native

elif.rs β€’ GitHub β€’ Docs