Build scalable microservices with NestLaravel.
NestLaravel brings together Nx, Laravel and Apache Kafka — organised with a NestJS-style modular architecture — into a structured development platform for building modular, scalable and event-driven backend systems.
Ready to build
Built on proven technologies
NestLaravel does not replace these technologies. It gives you a structured, tested way to combine them.
Nx
Monorepo and workspace orchestration: project graph, cached and affected builds and tests.
NestJS-style architecture
Module structure and dependency-injected contracts (Domain / Application / Infrastructure / Presentation) behind a single gateway. NestJS itself is not a runtime dependency.
Laravel
The backend microservices and gateway: APIs, business logic, queues and the Laravel ecosystem.
Apache Kafka
Event-driven communication between services with an outbox, retries and dead-letter topics.
What is NestLaravel?
NestLaravel is a hybrid microservice development framework. It combines Nx workspace management and a NestJS-style modular architecture with Laravel-based backend microservices and Kafka-based event communication.
You organise several backend services inside one consistent workspace while each service keeps Laravel's mature ecosystem. A single API gateway is the only public interface; services are internal and trust only signed gateway calls.
Developer
│
▼
NestLaravel CLI
│
▼
Nx workspace
├── apps/api gateway (public)
├── apps/users-service
├── apps/orders-service
├── apps/payments-service
└── other Laravel services
│
▼
KafkaWhy NestLaravel?
Modular microservices
Independent Laravel services in a structured workspace, each with its own database and secrets.
Nx workspace
Applications and packages managed from one workspace with cached, affected-only tasks.
Event driven
Connect services with Kafka events using one versioned envelope.
Laravel backend
Use Laravel for business logic and APIs; keep the packages you already know.
Developer CLI
Create projects and services, generate Kafka topics and events, run, test, build and upgrade.
Standardised architecture
Every generated service follows the same conventions, so teams can move between services.
Built to grow
Start with one gateway and add services as the system grows; deploy and scale them independently.
Production practices included
Docker images, health probes, tests, CI templates, security controls and a documented upgrade path.
Start building in minutes
- Create a project
npx nestlaravel create my-project - Enter the workspace
cd my-project - Start development
npx nestlaravel dev
What you will see
✓ Workspace files written to my-project/
✓ .env files created with fresh random secrets
✓ Dependencies installed (Composer + npm)
✓ Workspace validated
my-project is ready.The dev command starts Kafka, PostgreSQL and Redis with Docker when it is available and serves every app through Nx. Output above is what create prints; see the full installation guide.
Requirements
Versions come from the framework's supported runtime matrix (packages/cli/src/versions.js) and are checked by npx nestlaravel doctor.
| Tool | Version | Notes |
|---|---|---|
| Node.js | ≥ 20.11.0 | Tested on 20, 22, 24 |
| npm | ≥ 10.0.0 | Ships with Node.js |
| PHP | ≥ 8.3.0 | Tested on 8.3, 8.4; extensions: mbstring, openssl, pdo, tokenizer, xml, ctype, json, fileinfo, bcmath |
| Composer | ≥ 2.6.0 | |
| Laravel / Nx | ^13.30 / ^23.2 | Installed for you |
| Database | SQLite, PostgreSQL >=15 (dev image 16) or MySQL | SQLite needs no setup |
| Apache Kafka | >=3.6 (KRaft; dev image apache/kafka 4.0) | Bundled dev broker via Docker; php-rdkafka to reach a broker from PHP outside Docker |
| Redis | >=7 | Required for queues/cache in production; optional locally |
Create a microservice
Generate a standardised Laravel microservice inside the workspace. It is registered with the gateway, Nx and Docker in one step.
npx nestlaravel generate service users- Own
.env,APP_KEYand database credentials - Gateway route
/api/v1/users, protected by signed requests - Nx targets:
serve,test,lint,migrate,build
apps/
└── users-service/
├── app/
│ ├── Http/Middleware/VerifyGatewaySignature.php
│ └── Modules/Users/{Domain,Application,Infrastructure,Presentation}
├── bootstrap/
├── config/ (kafka.php, internal.php, …)
├── database/
├── routes/
├── tests/
├── .env.example
├── composer.json
└── project.json (Nx targets)Event-driven microservices
Services never read each other's databases. They publish events; other services react.
Users service
│ users.user.created
▼
Kafka topic
│
├──────────────┐
▼ ▼
Orders service Notifications service- Producers write events to a transactional outbox; a publisher ships them after broker confirmation.
- Consumers & groups run in a consumer group per service; offsets are committed only after success.
- Topics & events use one envelope:
event_id,event_type,version,source,correlation_id,payload. - Retries & dead letters: exponential backoff, then
<topic>.dlq; poison messages skip retries. - Versioning: consumers dead-letter events newer than the schema they support.
- Correlation IDs flow from the gateway request into events and logs.
See it in code
Examples are taken from the framework's generators and documentation.
# service + topic + event (with a consumer handler)
npx nestlaravel generate service orders
npx nestlaravel generate kafka-topic order-events --service orders --create
npx nestlaravel generate kafka-event order.created --service orders --consumeruse NestLaravel\Kafka\Contracts\EventBus;
DB::transaction(function () use ($order, $events) {
$order->save();
// written to the outbox in the same transaction
$events->publish(new OrderCreated((string) $order->id, ['total' => $order->total]));
});# run a consumer for a topic
php artisan kafka:consume orders.events "App\Modules\Payments\Infrastructure\Messaging\OrderCreatedHandler"
# the handler receives the standard event envelope
final class OrderCreatedHandler implements MessageHandler
{
public function handle(array $event): void
{
$payload = $event['payload'];
}
}# clients only ever talk to the gateway
curl -H "Authorization: Bearer $TOKEN" \
http://127.0.0.1:8000/api/v1/orders/health# apps/orders-service/.env.example (excerpt)
INTERNAL_SERVICE_SECRET=
KAFKA_ENABLED=false
KAFKA_CLIENT_ID=orders-service
KAFKA_GROUP_ID=orders-service
KAFKA_TOPIC_DEFAULT=orders.events
KAFKA_SECURITY_PROTOCOL=plaintextArchitecture
Laravel is used for the backend microservices. Nx and the modular architecture organise them; they do not compete with Laravel.
Nx workspace
│
├── apps/api gateway: auth, throttling, routing (Laravel)
├── apps/<name>-service Laravel microservices
│ ├── Users
│ ├── Orders
│ └── Payments …
├── packages/laravel-kafka shared Kafka kit
├── packages/laravel-tenancy optional multi-tenancy
└── infrastructure/ Dockerfile, scripts, Postgres init
│
Kafka| Nx | Task graph, caching, affected builds/tests. |
| Modular architecture | Domain / Application / Infrastructure / Presentation modules; controllers call actions only. |
| Laravel | Gateway and every microservice. |
| Kafka | Asynchronous service-to-service integration. |
| CLI | Scaffold, generate, develop, upgrade. |
Learn NestLaravel
- 01
Introduction
Understand the architecture.
- 02
Installation
Create your first project.
- 03
Workspace
Understand Nx and the layout.
- 04
Microservices
Create Laravel services.
- 05
APIs
Build backend APIs behind the gateway.
- 06
Kafka
Connect services through events.
- 07
Databases
Configure service databases.
- 08
Testing
Test services and events.
- 09
Deployment
Deploy to production.
- 10
Scaling
Organise larger systems.
Documentation portal
Searchable documentation generated from the repository's own guides. Press / or Ctrl+K anywhere to search.
CLI
Only commands that exist in the shipped CLI are listed. Full reference.
| Command | Purpose |
|---|---|
npx nestlaravel create my-project | New workspace with gateway, Kafka kit, secrets and validation |
npx nestlaravel generate service users | New Laravel microservice wired into gateway, Nx and Docker |
npx nestlaravel generate kafka-topic|kafka-event | Register a topic / create a domain event (and consumer) |
npx nestlaravel dev | Start infrastructure and serve all apps |
npx nestlaravel test / lint | Run every app's tests / style checks via Nx |
npx nestlaravel build | Build production Docker images |
npx nestlaravel update | Safe, backed-up upgrade (--dry-run first) |
npx nestlaravel add tenancy | Install the optional multi-tenancy package |
npx nestlaravel doctor | Check Node, PHP, Composer, Docker |
Examples
Worked examples that exist in the documentation today.
Multiple microservices
Generate services, register them on the gateway and call them.
From development to production
Docker
One production image per Laravel app, with ext-rdkafka, run as web, worker, outbox publisher or consumer.
Linux / VPS
Supervisor programs and nginx; firewall services to the gateway host.
CI/CD
GitHub Actions templates for tests, audits and image builds.
Kubernetes (optional)
Not required. Guidance for Deployments, probes and network policies is in the deployment guide.
Security by design
Controls are documented and covered by tests. No system is perfectly secure — the guide lists known limitations too.
Authentication & authorization
Sanctum tokens with expiry; roles and permissions; privileged roles cannot be self-assigned.
Service isolation
Internal services accept only HMAC-signed gateway calls and fail closed when unconfigured.
Secrets & databases
Generated per-app secrets, git-ignored env files, one database and role per service.
Validation & rate limiting
Form requests, path sanitising, per-IP and per-account throttling.
Kafka security
TLS/SASL settings, acks=all with idempotence, ACL guidance.
Secure deployment
Pinned images, private networks, no published service ports.
Built for developers. Open to exploration.
View on GitHub Read Documentation Report an Issue Contribute
About NestLaravel
NestLaravel is developed by Intelfric Technology Limited as a developer-focused framework for building structured, modular and event-driven backend systems.