A simple backend application built with Node.js following Clean Architecture / DDD-inspired layering.
The project includes:
- REST API with Express
- MongoDB persistence using Mongoose
- Kafka event publishing and consuming
- Dockerized setup using Docker Compose
- EC2 deployment support
- Postman Collection
The project is separated into layers:
src/
├── API/ # Routes & controllers
├── Application/ # Use cases
├── Domain/ # Entities & repository contracts
├── Infrastructure/ # Database, repositories, Kafka
Handles:
- HTTP requests
- Routing
- Dependency Injection
- Controllers
Contains:
- Business use cases
- Application logic
Examples:
- CreateItem
- ListItems
- GetById
Contains:
- Domain entities
- Repository abstractions
Handles external systems:
- MongoDB
- Kafka
- Repository implementations
- Node.js
- Express.js
- MongoDB
- Mongoose
- Apache Kafka
- Docker
- Docker Compose
- Create item
- Get all items
- Get item by ID
- Kafka event publishing on item creation
- Kafka consumer support
- Dockerized environment
Create a .env file inside the project root:
PORT=3000
MONGO_URI=mongodb://localhosst:27017/itemsdb
KAFKA_BROKER=localhost:9092Install:
- Docker
- Docker Compose
docker compose up --buildThe API will run on:
http://localhost:3000
POST /items{
"name": "Laptop",
"stock": 1000
}GET /itemsGET /items/:idWhen an item is created:
- an event is published to Kafka
- the consumer listens for item events
Kafka and Zookeeper are configured using Docker Compose.
The application runs using the following containers:
- API
- MongoDB
- Kafka
- Zookeeper
The project can be deployed on AWS EC2 using Docker Compose.
Basic deployment flow:
git clone <repo>
cd <project>
docker compose up --build -d- Kafka integration was implemented and tested locally using Docker Compose.
- Due to resource limitations on small cloud instances, service restart policies were added to improve container recovery and stability.
Ahmad Ibrahim