Skip to content

Repository files navigation

FoodFlow System

A food delivery backend I built to learn microservices, Kafka, and Docker. The idea was simple, instead of building one big app, split everything into small independent services that talk to each other through events.


What is this project?

FoodFlow is a backend system for a food delivery app. When a customer places an order, a chain of events happens automatically:

  1. Order gets saved
  2. Restaurant gets notified and confirms the order
  3. A delivery driver gets assigned
  4. Notifications are sent at each step

All of this happens through Kafka events, meaning the services don't directly call each other. They just publish and listen to events. If one service goes down, the others keep working.


Services

I built 6 services. Each one does one specific thing and has its own database.

Service Port What it does
API Gateway 8080 The front door, where all requests come here first.
User Service 8081 Create and manage users.
Order Service 8082 Place orders, publishes to Kafka event.
Restaurant Service 8083 Manage restaurants, confirms orders via Kafka.
Delivery Service 8084 Assigns a driver after order is confirmed.
Notification Service 8085 Listens to all events and logs notifications.

Tech Stack

  • Java 17 + Spring Boot 3.5.
  • Apache Kafka (using Confluent Docker images) for async communication.
  • PostgreSQL as it has separate database for each service.
  • Spring Cloud Gateway for routing.
  • Docker + Docker Compose to run everything once.
  • Maven multi-module project.

How the Kafka events flow

Customer places order.
       |
Order Service publishes "order-created".
       |
Restaurant Service confirms, publishes "order-confirmed".
Notification Service logs "order placed" notification.
       |
Delivery Service assigns driver, publishes "order-assigned".
Notification Service logs "order confirmed" notification.
       |
Notification Service logs "driver assigned" notification.

---

## How to run it

You just need Docker Desktop installed. That's it.

```bash
git clone https://github.com/Sneha110500/FoodFlow-System.git
cd FoodFlow-System
docker-compose up --build

Then we have to wait a few minutes for everything to start up. Then test it using Postman.

To stop everything:

docker-compose down

Testing it

All requests go through port 8080 (the API Gateway).

Step 1: Create a user

POST http://localhost:8080/api/users
{
    "name": "Sneha",
    "email": "sneha@gmail.com",
    "password": "pass1234",
    "phone": "9876543210",
    "address": "Rolla, MO",
    "role": "CUSTOMER"
}

Step 2: Create a restaurant

POST http://localhost:8080/api/restaurants
{
    "name": "Pizza Palace",
    "address": "123 Main St",
    "phone": "9876543210",
    "cuisine": "Italian",
    "status": "OPEN",
    "ownerId": 1
}

Step 3: Place an order

POST http://localhost:8080/api/orders
{
    "userId": 1,
    "restaurantId": 1,
    "items": ["Pizza", "Burger"],
    "totalAmount": 25.99,
    "deliveryAddress": "Rolla, MO"
}

Step 4: Check deliveries

GET http://localhost:8080/api/deliveries

You should see a driver automatically assigned to the order.


What I learned building this

  • How to structure a microservices project with Maven multi-module?
  • Why services should have their own databases (no shared DB)?
  • How Kafka producers and consumers work?
  • The difference between tight coupling (REST calls between services) and loose coupling (Kafka events)?
  • How Docker Compose networks work — containers talking to each other by name?
  • Why localhost inside Docker is not the same as localhost on your machine?

Things I would improve

  • Add proper authentication with JWT in the API Gateway.
  • Store notifications in a database so users can see their notification history.
  • Add a proper driver management system instead of randomly picking from a list.
  • Write unit tests for all services.
  • Add Swagger UI for API documentation.

Project structure

FoodFlowSystem/
├── APIGateway/
├── UserService/
├── OrderService/
├── RestaurantService/
├── DeliveryService/
├── NotificationService/
├── docker-compose.yml
└── pom.xml

Each service folder has the same structure:

ServiceName/
├── src/main/java/com/foodflow/servicename/
│   ├── controller/
│   ├── service/
│   ├── repository/
│   ├── entity/
│   ├── dto/
│   ├── kafka/
│   └── exception/
├── src/main/resources/
│   └── application.yml
└── Dockerfile

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages