🐍 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.
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