kronix 0.2.0
kronix: ^0.2.0 copied to clipboard
A high-performance, architecturally hardened web framework for Dart.
๐ Kronix #
The Architecturally Hardened Web Framework for Dart. #
Kronix is a high-performance, batteries-included web framework for the Dart ecosystem. It is designed for developers who demand speed, type-safety, and architectural integrity without the boilerplate of traditional enterprise frameworks.
๐ Key Features #
- โก Radix-Trie Router: O(log n) path matching with pre-compiled middleware chains.
- ๐๏ธ Sophisticated DI: Hierarchical Dependency Injection with automatic request scoping.
- ๐ฆ Advanced ORM: Active Record pattern with typed relationships (
belongsTo,hasMany). - ๐ก๏ธ HARDENED Security: Built-in backpressure control, body size limits, and JWT/Session support.
- ๐ Unified Caching: Elegant
Cachefacade supporting Memory and Redis drivers. - โ๏ธ CLI Power: Rapid scaffolding of controllers, models (with migrations), and services.
- ๐ฅ Real-time: First-class WebSocket support with Hubs, Rooms, and Middleware protection.
๐ Quick Start #
1. Installation #
Add Kronix to your pubspec.yaml:
dependencies:
kronix: ^0.2.0
2. A Simple Server #
import 'package:kronix/kronix.dart';
void main() async {
final app = App();
// Basic Route
app.get('/welcome', (ctx) async {
return Response.json({'message': 'Welcome to Kronix!'});
});
// Typed Validation
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);
}
๐ ๏ธ Deep Dive #
๐ฆ The ORM (Model) #
Define your relationships easily:
class User extends Model {
@override String get tableName => 'users';
// Relationship: User has many Posts
Future<List<Post>> posts() => hasMany<Post>(Post.fromRow);
}
๐ Caching #
Switch from Memory to Redis with one line in .env:
// Fetch from cache or compute and store for 1 hour
final stats = await Cache.remember('users.count', Duration(hours: 1), () async {
return await User.query().count();
});
๐ฅ Middleware #
Compose logic across routes globally or in groups:
app.group('/api/v1', middleware: [AuthMiddleware()], callback: (router) {
router.get('/profile', ProfileController().show);
});
๐ Why Kronix? #
In a world of micro-frameworks, Kronix provides the structure needed for long-term maintainability. It is not just a router; it's a foundation that handles the "boring" parts of web developmentโsecurity, concurrency, and data integrityโso you can focus on building your product.
- Drained Gracefully: Handles
SIGINT/SIGTERMto allow active requests to finish. - Isolated Tests: Built-in
MockHttpRequestand container-swapping for 100% test coverage. - Type Casting: Automatic conversion of query/body parameters to
int,double, orbool.
๐ค Contributing #
We welcome contributions! Please see our Contributing Guide to get started.
๐ License #
Kronix is open-sourced software licensed under the MIT license.