khadem 1.0.4-beta
khadem: ^1.0.4-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
๏ฟฝ๐ 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"