khadem 1.0.3-beta
khadem: ^1.0.3-beta copied to clipboard
A modern Dart backend framework with CLI tools, ORM, authentication, and caching for scalable web applications.
Khadem #
β‘ A powerful, modern Dart backend framework for building scalable web applications
Khadem is a comprehensive backend framework built with Dart, designed for developers who demand performance, elegance, and full control. It provides a complete toolkit for building robust web applications with features like dependency injection, modular architecture, built-in CLI tools with automatic command discovery, database management, caching, authentication, and production-ready deployment capabilities.
π Key Features #
Core Architecture #
- π High Performance: Built with Dart for exceptional speed and efficiency
- π§± Modular Design: Service provider architecture for clean, maintainable code
- π¦ Dependency Injection: Flexible container-based dependency management
- βοΈ Configuration System: Environment-aware configuration with dot-notation support
Development Tools #
- π οΈ Powerful CLI: Comprehensive command-line tools with auto-discovery
- π€ Code Generation: Automated generation of models, controllers, middleware, providers, jobs, and listeners
- π₯ Hot Reload: Development server with hot reload support
- π Migration System: Database migration and seeding support
Data & Storage #
- ποΈ Database Layer: Support for MySQL with ORM capabilities
- πΎ Multiple Drivers: MySQL, Redis, and extensible driver system
- π§΅ Queue System: Background job processing with Redis support
- π File Storage: Flexible file upload and storage management
Security & Auth #
- π JWT Authentication: Secure token-based authentication system
- π‘οΈ Middleware System: Request/response middleware for security and processing
- β Input Validation: Comprehensive validation rules and error handling
- π Security Features: Built-in protection against common web vulnerabilities
Production Ready #
- π Caching: Multiple caching drivers (Redis, memory-based)
- β° Task Scheduling: Background job scheduling and processing
- π Logging: Structured logging with multiple output formats
π¦ Installation #
Install Khadem CLI globally for project management:
dart pub global activate khadem
Requirements #
- Dart SDK: >=3.0.0
- Supported Platforms: Windows, macOS, Linux
- Database: MySQL (optional)
- Cache: Redis (optional)
β‘ Quick Start #
Get started with Khadem in minutes:
1. Create New Project Structure #
# Create new project from GitHub template
khadem new --name=my_app
cd my_app
dart pub get
2. Start Development Server #
# Run your Khadem application
dart run lib/main.dart
# Or for development with hot reload:
khadem serve
Your application will be running at http://localhost:3000 with hot reload enabled!
π Project Structure #
A typical Khadem project follows this modern structure:
my_app/
βββ lib/
β βββ main.dart # Application entry point
β βββ app/
β β βββ http/
β β β βββ controllers/ # HTTP controllers
β β β βββ middleware/ # HTTP middleware
β β βββ jobs/ # Background job classes
β β βββ listeners/ # Event listeners
β β βββ models/ # Data models
β β βββ providers/ # Service providers
β βββ bin/ # CLI commands and utilities
β βββ config/
β β βββ app.dart # Application configuration
β βββ core/
β β βββ kernel.dart # Application kernel
β βββ database/
β β βββ migrations/ # Database migrations
β β βββ seeders/ # Database seeders
β βββ routes/
β βββ web.dart # Web routes
β βββ socket.dart # Socket routes
βββ config/
β βββ development/ # Development environment configs
β β βββ logging.json
β βββ production/ # Production environment configs
β βββ logging.json
βββ lang/
β βββ ar/ # Arabic translations
β β βββ ar.json
β β βββ fields.json
β β βββ validation.json
β βββ en/ # English translations
β βββ en.json
β βββ fields.json
β βββ validation.json
βββ public/
β βββ assets/ # Public assets
β βββ logo.png
βββ resources/
β βββ views/ # View templates
β βββ welcome.khdm.html
βββ storage/
β βββ logs/ # Application logs
β βββ app.log
βββ tests/ # Test files
βββ .env # Environment variables
βββ .gitignore # Git ignore rules
βββ pubspec.yaml # Package configuration
βββ pubspec.lock # Package lock file
π οΈ CLI Commands #
Khadem features a powerful CLI with automatic command discovery:
π― Available Commands #
Project Management #
# Create new project with modern structure
khadem new --name=project_name
# Start development server with hot reload
khadem serve
# Build Docker containers and production assets
khadem build --services=mysql,redis
Code Generation #
# Create models, controllers, and more in the proper lib/app/ structure
khadem make:model --name=User # β lib/app/models/
khadem make:controller --name=UserController # β lib/app/http/controllers/
khadem make:middleware --name=AuthMiddleware # β lib/app/http/middleware/
khadem make:provider --name=AuthServiceProvider # β lib/app/providers/
khadem make:job --name=SendEmailJob # β lib/app/jobs/
khadem make:listener --name=UserEventListener # β lib/app/listeners/
khadem make:migration --name=users # β lib/database/migrations/
# Support for nested folders
khadem make:controller --name=api/v1/UserController # β lib/app/http/controllers/api/v1/
khadem make:job --name=email/SendWelcomeEmailJob # β lib/app/jobs/email/
Version Information #
khadem --version # Show version information
The version command reads information dynamically from pubspec.yaml, ensuring version information is always up-to-date and synchronized with your package configuration.
π‘ Core Concepts #
Service Providers #
Organize your application logic with service providers:
// lib/app/providers/app_service_provider.dart
class AppServiceProvider extends ServiceProvider {
@override
void register(container) {
// Register services in the container
}
@override
Future<void> boot(container) async {
// Boot services after registration
}
}
Background Jobs #
Create background jobs for asynchronous processing:
// lib/app/jobs/send_email_job.dart
class SendEmailJob extends QueueJob {
final String email;
final String message;
SendEmailJob(this.email, this.message);
@override
Future<void> handle() async {
// Send email logic here
print('π§ Sending email to $email: $message');
}
}
Dependency Injection #
Use the container for clean dependency management:
// lib/app/http/controllers/user_controller.dart
class UserController {
final UserRepository repository;
UserController(this.repository);
Future<Response> index(Request request) async {
final users = await repository.all();
return Response.json(users);
}
}
Middleware System #
Add cross-cutting concerns with middleware:
// lib/app/http/middleware/auth_middleware.dart
class AuthMiddleware implements Middleware {
@override
MiddlewareHandler get handler => (req, res, next) async {
// Check authentication logic here (e.g., verify JWT token)
await next();
};
@override
String get name => 'Auth';
@override
MiddlewarePriority get priority => MiddlewarePriority.global;
}
Database Migrations #
Manage database schema with migrations:
// lib/database/migrations/123456_create_users_table.dart
class CreateUsersTable extends MigrationFile {
@override
Future<void> up(builder) async {
builder.create('users', (table) {
table.id();
table.string('name');
table.string('email').unique();
table.string('password');
table.timestamps();
});
}
@override
Future<void> down(builder) async {
builder.dropIfExists('users');
}
}
π Why Choose Khadem? #
- β‘ Performance First: Built with Dart for exceptional speed and efficiency
- π― Developer Experience: Intuitive API design with excellent tooling and auto-discovery
- ποΈ Modern Structure: Follows Dart package conventions with
lib/directory organization - π§ Full Control: No magic - complete transparency and control over your application
- π Scalable: Designed to handle growth from prototype to production scale
- π Secure: Security best practices built-in from the ground up
- π Growing Ecosystem: Active development with expanding feature set
- π€ Smart CLI: Powerful command-line tools with automatic discovery and nested folder support
- π₯ Modern: Takes advantage of latest Dart features and best practices
- π Dynamic Configuration: Version and metadata automatically synchronized
- π³ Production Ready: Docker support with optimized containers for deployment
οΏ½ License #
Khadem is licensed under the Apache License 2.0. This permissive license allows you to use, modify, and distribute the framework freely, including for commercial purposes, as long as you include the original copyright notice and license text.
For more details, see the LICENSE.md file in this repository.
οΏ½π Support & Community #
- π Bug Reports: GitHub Issues
- π‘ Feature Requests: GitHub Discussions
- π¬ Community: Join our growing community of Dart backend developers
Getting Help #
- Check the README - Most common questions are answered here
- Browse existing issues - Your question might already be answered
- Create a new issue - For bugs, include code examples and error messages
- Start a discussion - For feature requests and general questions
Built with β€οΈ for the Dart community by Khedr Mahmoud
"Empowering developers to build powerful backend applications with the elegance and performance of Dart"