daravel 1.13.0
daravel: ^1.13.0 copied to clipboard
A Laravel-inspired, AOT-native backend framework for Dart with routing, validation, an ORM, auth, queues and Laravel-compatible wire formats.
English · Bahasa Indonesia
The Laravel developer experience, compiled to a single native binary.
A Laravel-inspired, AOT-native backend framework for Dart with routing, validation, ORM, auth, queues, and wire compatibility.
Documentation · Why Daravel · Laravel ↔ Daravel · Architecture · Features · Quick Start · Ecosystem
About Daravel #
Daravel brings the beloved developer experience of Laravel 11/12 to Dart and Flutter developers. It combines expressive, elegant syntax and convention-over-configuration with the unrivaled superpowers of the Dart runtime: single-binary AOT compilation, static types from routes to database queries, and multi-isolate concurrency across all CPU cores on a single port.
Daravel is built to coexist side-by-side with Laravel on the same database: error payloads, paginator JSON, Sanctum personal access tokens, $2y$ bcrypt hashes, Crypt payloads, and framework tables share the exact same wire format, locked by a rigorous conformance suite.
Why Daravel? #
┌────────────────────────────────────────────────────────────────────────┐
│ DARAVEL RUNTIME ARCHITECTURE │
├────────────────────────────────────────────────────────────────────────┤
│ │
│ HTTP Client Request ──► [:8000] Supervisor Engine │
│ │ │
│ ┌─────────────────────────────┼─────────────────────────────┐ │
│ ▼ ▼ ▼ │
│ Worker Isolate #1 Worker Isolate #2 Worker #N│
│ ┌─────────────────┐ ┌─────────────────┐ ┌────────┐│
│ │ Zone Request │ │ Zone Request │ │ Zone ││
│ │ ├─ Auth Context │ │ ├─ Auth Context │ │ Request││
│ │ ├─ DB Tx / Save │ │ ├─ DB Tx / Save │ │ Context││
│ │ └─ Response │ │ └─ Response │ │ ││
│ └────────┬────────┘ └────────┬────────┘ └───┬────┘│
│ │ │ │ │
│ └──────────────────────┬──────┴───────────────────────┘ │
│ ▼ │
│ Coordinator Isolate (Shared RAM) │
│ ├─ Atomic Locks (no Redis needed) │
│ ├─ Fixed-Window Rate Limiter & Leases │
│ └─ L1 Near-Cache & Multi-Worker State │
│ │
└────────────────────────────────────────────────────────────────────────┘
- ⚡ One Native Bundle (14 ms Cold Boot & 11 MB RAM):
dartisan buildcompiles your entire backend into machine code with SQLite embedded via native build hooks. No Dart SDK, PHP-FPM, or Node.js runtime required on the server. - 🛡️ Zero Reflection, Zero
build_runner:
Unlike traditional Dart frameworks, Daravel requires no code-generation wait loops. The CLI writes explicit, clean Dart registries that the AOT compiler sees directly. - 🚀 Every Core on One Port Without Redis:
A supervisor isolate orchestrates worker isolates with automatic crash respawn and gracefulSIGTERMdraining. A dedicated coordinator isolate maintains atomic locks, rate-limits, and in-memory caches across all workers without an external Redis instance. - 🔒 Zone-Scoped State Isolation:
Every request, queue job, and command runs in its own DartZonescope. Facades (Auth,DB,Cache,Log) resolve transparently per request.DB.transactionis zone-aware: nested transactions become savepoints, and queued jobs wait for the outer commit. - 🤝 100% Laravel Coexistence:
Migrate from Laravel endpoint by endpoint behind a reverse proxy. Both frameworks can read and write to the same SQLite, PostgreSQL, or MySQL database without conflict. - 📖 Self-Documenting Routes & OpenAPI 3.1:
.validates(StorePostRequest())and.returns(PostResource.schema)enforce validation before the handler runs, populaterequest.validated(), and generate interactive OpenAPI 3.1 documentation automatically. - 📱 Full-Stack Flutter Client Generation:
dartisan client:fluttergenerates type-safe Dart/Flutter API clients that share the server's validation rules on mobile devices before network transmission.
Laravel ↔ Daravel at a Glance #
Daravel keeps Laravel's names, semantics, and design patterns, adapting only the syntax to idiomatic modern Dart:
| Laravel 12 (PHP) | Daravel (Dart) |
|---|---|
Route::post('/posts', [PostController::class, 'store']) |
router.post('/posts', posts.store) |
->middleware(['auth:sanctum', 'throttle:api']) |
.middleware(const ['auth:sanctum', 'throttle:api']) |
public function rules(): array { return ['email' => 'required|email']; } |
Map<String, Object> rules() => {'email': 'required|email'}; |
$request->validate([...]) |
await request.validate({...}) |
$request->validated() |
request.validated() |
User::where('active', true)->paginate(15) |
await User.query().where('active', true).paginate(15) |
DB::transaction(fn () => ...) |
await DB.transaction(() async => ...) |
UserRegistered::dispatch($user) |
UserRegistered(user).dispatch() |
return new UserResource($user) |
return UserResource(user) |
Auth::user() / Auth::id() |
Auth.user() / Auth.id() |
Cache::remember('key', 3600, fn () => ...) |
await Cache.remember('key', 1.hours, () async => ...) |
Batteries-Included Showcase #
1. Expressive Routing with Automatic Validation & OpenAPI #
// routes/api.dart
router.post('/assessments', assessmentController.store)
.validates(const StoreAssessmentRequest())
.returns(AssessmentResource.schema, status: 201)
.middleware(const ['auth:sanctum', 'throttle:60,1']);
2. Eloquent-Style ORM with Eager Loading & Savepoints #
// app/controllers/assessment_controller.dart
Future<Response> store(Request request) async {
final data = request.validated();
final assessment = await DB.transaction(() async {
final record = await Assessment.create({
'title': data['title'],
'score': data['score'],
'user_id': Auth.id(),
});
// Nested transaction automatically becomes a SQL savepoint:
await DB.transaction(() async {
await record.auditLogs().create({'action': 'created'});
});
return record;
});
// Dispatched only after the outer transaction successfully commits:
AssessmentCreated(assessment).dispatch();
return Response.created(AssessmentResource(assessment));
}
3. Asynchronous Queues & Background Workers #
// app/jobs/send_assessment_report_job.dart
final class SendAssessmentReportJob extends Job {
final int assessmentId;
const SendAssessmentReportJob(this.assessmentId);
@override
int get tries => 3;
@override
Duration get backoff => const Duration(seconds: 5);
@override
Future<void> handle() async {
final assessment = await Assessment.findOrFail(assessmentId);
await Mail.to(assessment.user.email).send(AssessmentReportMail(assessment));
}
}
4. Real-Time WebSockets & Server-Sent Events (SSE) #
// routes/web.dart
router.get('/live-feed', (request) {
return Response.sse((stream) async {
await for (final event in Event.listen<LiveScoreUpdated>()) {
stream.send(event: 'score', data: event.toJson());
}
});
});
Quick Start #
Option A: The Dartisan CLI (Recommended) #
Create a production-ready application with generators, migrations, and live-reloading:
# 1. Install Dartisan globally
dart pub global activate dartisan_cli
# 2. Scaffold a new Daravel project
dartisan new my_app
cd my_app
# 3. Run database migrations & seeders
dartisan migrate --seed
# 4. Start the dev server with Hot Reload
dartisan serve --watch
Option B: Add to an Existing Package #
dart pub add daravel
Create bin/server.dart:
import 'package:daravel/daravel.dart';
Application createApp() => Application.configure(basePath: '.')
.withRouting(
api: (router) {
router.get('/ping', (_) => {'status': 'ok', 'framework': 'Daravel'});
router.post('/echo', (request) async {
final data = await request.validate({'message': 'required|string'});
return Response.ok(data.toMap());
});
},
)
.create();
Future<void> main() async => Application.serveWith(createApp);
Run with native performance:
dart run bin/server.dart
The Daravel Ecosystem #
The Daravel framework is designed around modular, high-cohesion packages:
| Package | pub.dev | Description |
|---|---|---|
daravel |
Core framework: Router, ORM, Auth, Queues, Mail, Cache, Supervisor | |
dartisan_cli |
CLI developer tool: generators, dev server, migration engine, native builds | |
daravel_test |
Testing toolkit: TestClient, database fakes, Laravel wire conformance |
|
daravel_lints |
AST-based lint rules against reflection, SQL interpolation, and memory leaks | |
daravel_mysql |
High-performance MySQL & MariaDB driver | |
daravel_permission |
Database roles & permissions on spatie/laravel-permission's tables | |
daravel_teorion |
Request-driven query filters with whitelists (laravel-teorion) | |
daravel_livekit |
LiveKit server SDK: access tokens, rooms and participants, verified webhooks | |
daravel_redis |
Redis & Valkey across servers: cache, locks, rate limits, queues, broadcasting | |
daravel_postgres |
High-performance PostgreSQL driver with binary float8 support | |
daravel_sqlite |
Embedded SQLite driver bundled with native build hooks |
Documentation & Community #
Comprehensive documentation and interactive guides are available at the official website: 👉 https://daravel.dev
- Getting Started & Installation
- Routing & Middleware
- Validation & Form Requests
- Database & Eloquent ORM
- Authentication & Sanctum Tokens
- Laravel ⇄ Daravel Parity Table
- Migrating from Laravel (Strangler Fig)
License & Trademarks #
- License: Open-source software licensed under the MIT License.
- Trademarks: "Laravel" is a trademark of Laravel Holdings Inc. "Dart" and "Flutter" are trademarks of Google LLC. Daravel is an independent open-source project and is not affiliated with or endorsed by Laravel Holdings Inc. or Google LLC.