
Kronix
A fast and flexible web framework for Dart.
Kronix is a web framework for the Dart ecosystem designed for performance and ease of use. It includes everything you need to build web applications without the boilerplate, including routing, dependency injection, and a lightweight ORM.
Key Features
- Fast Routing: Radix-Trie based router for efficient path matching.
- Dependency Injection: Hierarchical DI with request scoping.
- ORM: Active Record pattern with support for relationships (
belongsTo,hasMany). - Security: Built-in body size limits, backpressure control, and JWT support.
- Caching: Simple cache facade with Memory and Redis drivers.
- CLI: Scaffolding for controllers, models, and migrations.
- Real-time: WebSocket support with rooms and middleware.
Quick Start
1. Installation
Add kronix to your pubspec.yaml:
dependencies:
kronix: ^0.2.0
2. Basic Example
import 'package:kronix/kronix.dart';
void main() async {
final app = App();
// Simple GET route
app.get('/welcome', (ctx) async {
return Response.json({'message': 'Welcome to Kronix!'});
});
// Validation example
app.post('/register', (ctx) async {
final data = await ctx.validate({
'email': 'required|email',
'password': 'required|min:8',
});
return Response.json({'status': 'registered', 'user': data['email']});
});
await app.listen(port: 3000);
}
Features
ORM (Active Record)
Define relationships easily:
class User extends Model {
@override String get tableName => 'users';
Future<List<Post>> posts() => hasMany<Post>(Post.fromRow);
}
Caching
Switch between Memory and Redis with config:
final stats = await Cache.remember('users.count', Duration(hours: 1), () async {
return await User.query().count();
});
Middleware
Group routes and apply common logic:
app.group('/api/v1', middleware: [AuthMiddleware()], callback: (router) {
router.get('/profile', ProfileController().show);
});
Contributing
We welcome contributions! Please see our Contributing Guide to get started.
License
Kronix is open-sourced software licensed under the MIT license.
Libraries
- auth/jwt
- cache/cache
- cache/driver
- cache/memory_driver
- cache/redis_driver
- controllers/user_controller
- core/config
- core/context
- core/exception_handler
- core/exceptions
- core/explorer
- core/logger
- core/middleware
- core/router
- core/server
- core/validator
- core/websocket
- database/adapter
- database/middleware
- database/migration
- database/migration_runner
- database/model
- database/model_query
- database/postgres_adapter
- database/query_builder
- database/schema
- di/container
- filesystem/storage
- http/file
- http/request
- http/response
- kronix
- orm/model
- plugins/cors
- plugins/plugin_base
- plugins/rate_limiter
- plugins/size_limit
- queue/database_driver
- queue/driver
- queue/job
- queue/metrics
- queue/queue
- queue/worker
- session/middleware
- session/session
- session/store
- testing/fluent_test