Skip to content

About

BloomCafeV2 is a full-stack cafe ordering platform built with Java/Spring Boot microservices backend and a React SPA frontend. It features customer browsing, cart management, order placement, and an admin panel for managing products, categories, inventory, orders, and users. Uses Docker Compose for orchestration with PostgreSQL, Redis, and Kafka.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

33 Commits

Folders and files

Repository files navigation

BloomsCafe

A full-stack café ordering platform for a Rajpur Road café in Dehradun. The React and TypeScript storefront connects to Java/Spring Boot services for accounts, catalog, carts, inventory, orders, payments, and notifications. Customers can browse, order for pickup, and pay by cash on delivery or Razorpay. Admins manage products, categories, stock, orders, and users.

Contents


Quick Start (Docker)

Prerequisites: Docker Desktop (or Docker Engine + Compose v2), with about 8 GB of memory available. The first build downloads Maven and npm dependencies and may take several minutes.

git clone https://github.com/lieutenant-Rohit/Cafe-Ecommerce-Microservices.git
cd Cafe-Ecommerce-Microservices
docker compose up --build

No .env file is required for a local demo. Defaults include a development JWT secret, a shared PostgreSQL password, and mock email mode (emails are logged, not sent). These defaults are for local development only. To customize supported settings, copy the example file:

cp .env.example .env

COD works with the local demo defaults. To try Razorpay, set RAZORPAY_KEY_ID, RAZORPAY_KEY_SECRET, and RAZORPAY_WEBHOOK_SECRET in .env with test credentials. For a publicly reachable environment, configure the Razorpay webhook at https://<your-domain>/api/payments/webhook for payment.captured and payment.failed. The app treats a payment as paid only after capture is confirmed.

Never share or commit a real .env. It is git-ignored, but it can still end up in a ZIP archive. If it contains a Gmail app password, revoke that password and create a new one.

Wait for the services to start (the first build may take several minutes). Check their state with docker compose ps, then open:

To stop everything:

docker compose down

To stop and permanently delete the local database volume (the next start creates an empty database):

docker compose down -v

This deletes local accounts, orders, catalog changes, inventory changes, and payment records. Use it only when you want a complete reset.

To follow logs:

docker compose logs -f              # all services
docker compose logs -f order-service # one service

Troubleshooting

Problem Fix
Port 3100, 8180, 6380, or 19092 already in use Set FRONTEND_PORT, GATEWAY_PORT, REDIS_PORT, or KAFKA_PORT in .env, then run docker compose up -d again.
Containers exited after changing code Rebuild only what changed: docker compose up -d --build user-service (or --build with no service for all).
Database looks stale or schema is out of date docker compose down -v then docker compose up --build. This deletes all local data.
Need to check why a service failed docker compose logs --tail=200 <service-name>.
Frontend loads but API calls fail Check docker compose ps, then inspect docker compose logs nginx-gateway and the affected service. PostgreSQL, Redis, and Kafka have healthchecks; application services may need extra startup time.

Services and ports

Service Port Description
Frontend 3100 React SPA served by Nginx
Nginx Gateway 8180 Reverse proxy, routes /api/* to backend
User Service 8081 (internal) Registration, login, JWT, user management
Catalog Service 8082 (internal) Products, categories, Redis cache
Cart Service 8083 (internal) Shopping carts; clears them after order events
Order Service 8084 (internal) Checkout, order lifecycle, inventory coordination
Inventory Service 8085 (internal) Available and reserved stock
Notification Service 8086 (internal) Order email and WebSocket notifications
Payment Service 8087 (internal) Razorpay checkout, verification, refunds
PostgreSQL 5432 (internal) 7 databases (one per service)
Redis 6380 → 6379 Catalog caching (host port 6380 avoids clashing with local Redis)
Kafka 19092 → 29092 Async inter-service messaging (services use kafka:9092 internally)

The frontend, API gateway, Redis, and Kafka are bound to loopback host ports 3100, 8180, 6380, and 19092 by default. Backend service ports and PostgreSQL are only available inside the Compose network. Override the local ports with FRONTEND_PORT, GATEWAY_PORT, REDIS_PORT, and KAFKA_PORT in .env if they conflict with local software.

Payments and order recovery

COD orders are created immediately and reserve inventory before confirmation. Their initial payment status is PENDING because payment is due on collection. Customers can pay a COD order later through Razorpay from My Orders.

For Razorpay checkout, the payment service creates an attempt and verifies the provider signature and payment state. An order is created only after a captured payment is confirmed. Captured-payment and order-created events are persisted in service outboxes before Kafka publication, so events can be retried after service or broker interruptions.

If payment is captured but inventory cannot be reserved, the order service releases any earlier reservations and requests a full refund. The payment attempt moves to REFUND_PENDING until Razorpay accepts the idempotent refund request; the payment service retries pending refunds if the provider is unavailable. A refund is not instantaneous in every payment method, so customers should check the payment provider/bank for settlement timing. Closing checkout leaves the cart intact. A payment that is still being confirmed should not be retried until its status is checked.

Order confirmation emails

When an order is placed, order-service stores an OrderCreated event in its outbox, the scheduler publishes it to Kafka, and notification-service emails the confirmation to the customer's registered address.

Mock mode is the default (the email is logged by notification-service). To send real email through Gmail SMTP, add this to .env and restart the affected services:

NOTIFICATION_EMAIL_MOCK=false
GMAIL_SMTP_USER=your-address@gmail.com
GMAIL_SMTP_PASS=your-16-char-app-password

GMAIL_SMTP_PASS must be a Google App Password (2-Step Verification required), not the normal Gmail password. Then rebuild and restart:

docker compose up -d --build notification-service
docker compose logs -f notification-service

Tech Stack

Frontend

Technology Purpose
React 18 UI framework
TypeScript Type safety
Vite Build tool & dev server
Tailwind CSS Utility-first styling
shadcn/ui Reusable UI components
Zustand State management
React Router v6 Client-side routing
Axios HTTP client with JWT interceptor
Motion Page transitions & animations
Lenis Smooth scrolling

Backend

Technology Purpose
Java 21 Language
Spring Boot 4.x Application framework
Spring Security JWT authentication & role-based access
Spring Data JPA ORM / database access
Spring Kafka Event-driven messaging
Spring WebSocket Real-time push notifications
PostgreSQL Primary database (one per service)
Redis Caching layer (catalog service)
Apache Kafka Async inter-service messaging
Lombok Boilerplate reduction

Infrastructure

Technology Purpose
Docker Compose Container orchestration
Nginx Reverse proxy & API gateway

Architecture

Architecture

Communication patterns:

  • Synchronous (REST): Cart → Catalog for product validation; Order → Cart, Catalog, Inventory, User, and Payment during checkout; Payment → Razorpay.
  • Asynchronous (Kafka): Payment → Order after capture; Order → Cart for cart clearing; Order → Notification for confirmation.
  • WebSocket/STOMP: Notification service exposes order updates at /topic/orders/{userId} for subscribed clients.
  • Transactional outboxes: Order and Payment services persist messages alongside their database changes, then publish them asynchronously. Notification consumers deduplicate processed order events.

Features

Customer

  • Browse paginated product catalog with category filtering
  • Add, update, and remove items from shopping cart
  • Backend-synced cart for authenticated users and an in-memory cart for guests
  • Place orders with automatic inventory reservation
  • View order history and payment status
  • Responsive UI with smooth scroll, page transitions, and micro-interactions

Admin

  • Dashboard with order and user overview
  • Manage products, categories, orders, users, and inventory
  • Role-based access control (CUSTOMER / ADMIN)
  • Order status lifecycle management

Technical

  • Stateless JWT authentication with 1-hour expiry
  • Redis caching on catalog reads (10-minute TTL)
  • Inventory reservation and compensation during checkout
  • Idempotent Razorpay refund request and retry when a captured order cannot be fulfilled
  • Event-driven architecture with Kafka for async decoupling
  • Per-service database isolation (database-per-service pattern)

Creating an Account

The app doesn't seed any users. To get started, register at http://localhost:3100/register, then promote yourself to admin:

-- Connect to the database
psql -U root1 -d blooms_user

-- Update your role (replace the email with yours)
UPDATE users SET role='ADMIN' WHERE email='your@email.com';

Or via Docker:

docker exec -it blooms-postgres psql -U root1 -d blooms_user -c "UPDATE users SET role='ADMIN' WHERE email='your@email.com';"

Project Structure

BloomCafeV2/
├── docker-compose.yml          # Full stack orchestration
├── init.sql                    # Auto-creates PostgreSQL databases
├── nginx.conf                  # API gateway routing
├── cors-headers.conf           # Shared CORS headers for Nginx
├── .env.example                # Optional local overrides (copy to .env)
├── .env                        # Local secrets, git-ignored — never share
│
├── frontend/
│   ├── Dockerfile              # Multi-stage: Node build + Nginx serve
│   ├── nginx.conf              # SPA routing + API proxy
│   ├── package.json
│   ├── vite.config.ts
│   ├── tailwind.config.js
│   └── src/
│       ├── main.tsx            # React entry point
│       ├── App.tsx             # Auth init + cart hydration
│       ├── router/index.tsx    # Application routes and transitions
│       ├── store/              # Zustand stores (auth, cart)
│       ├── api/                # Axios API clients
│       ├── types/index.ts      # TypeScript interfaces
│       ├── pages/              # Public pages (Home, Menu, Cart...)
│       ├── pages/admin/        # Admin panel (Dashboard, CRUD...)
│       ├── components/         # UI components, layout, animations
│       ├── hooks/              # Custom hooks (useCafeStatus)
│       └── utils/              # JWT helpers
│
├── backend/
│   ├── user-service/           # :8081 — Auth, JWT, User CRUD
│   ├── catalog-service/        # :8082 — Products, Categories, Redis
│   ├── cart-service/           # :8083 — Shopping cart, Kafka consumer
│   ├── order-service/          # :8084 — Order orchestration, Kafka producer
│   ├── inventory-service/      # :8085 — Stock management
│   ├── notification-service/   # :8086 — Kafka consumer, WebSocket push
│   └── payment-service/        # :8087 — Razorpay integration, payment outbox

Local Development (without Docker)

If you prefer running services locally:

Prerequisites

  • Java 21+
  • Node.js 18+
  • PostgreSQL 16+ on localhost:5432
  • Docker (only for Kafka + Redis)

1. Start infrastructure

docker compose up -d redis kafka

The containerized Redis is published on host port 6380 (to avoid clashing with a local Redis on 6379) and Kafka on host port 19092. If you want the locally-run services to use these containers, set:

export SPRING_DATA_REDIS_PORT=6380
export SPRING_KAFKA_BOOTSTRAP_SERVERS=localhost:19092

2. Create databases

CREATE DATABASE blooms_user;
CREATE DATABASE blooms_catalog;
CREATE DATABASE blooms_cart;
CREATE DATABASE blooms_order;
CREATE DATABASE blooms_inventory;
CREATE DATABASE blooms_notification;
CREATE DATABASE blooms_payment;

3. Set environment variable

export JWT_SECRET=replace-with-a-random-secret-at-least-32-characters-long
export RAZORPAY_KEY_ID=your-razorpay-test-key-id
export RAZORPAY_KEY_SECRET=your-razorpay-test-key-secret
export RAZORPAY_WEBHOOK_SECRET=your-razorpay-webhook-secret
export PAYMENT_INTERNAL_TOKEN=your-long-random-internal-token

4. Start backend services

Start each service in its own terminal from the repository root. Keep each process running in its terminal. For example:

cd backend/user-service && ./mvnw spring-boot:run

Repeat for backend/catalog-service, backend/cart-service, backend/order-service, backend/inventory-service, and backend/notification-service, using ./mvnw spring-boot:run in each service directory. payment-service currently reuses the order service Maven wrapper:

cd backend/payment-service && ../order-service/mvnw spring-boot:run

5. Start frontend

cd frontend && npm install && npm run dev

Frontend runs on http://localhost:5173 and proxies API requests to the backend services.

The Vite proxy routes the storefront APIs to local services, but does not currently include /api/payments. Use the Docker-served frontend at http://localhost:3100 for Razorpay checkout, or add a /api/payments proxy to http://localhost:8087 in frontend/vite.config.ts for local checkout development.

Frontend build and lint

cd frontend
npm ci
npm run build
npm run lint

API Endpoints

Auth (user-service — :8081)

Method Endpoint Description
POST /api/auth/register Register a new user
POST /api/auth/login Login and receive JWT token

Users (user-service — :8081)

Method Endpoint Description
GET /api/users List all users (admin)
GET /api/users/me Get current user profile
GET /api/users/{id} Get user by ID (admin)
DELETE /api/users/{id} Delete user (admin)

Products (catalog-service — :8082)

Method Endpoint Description
GET /api/products List products (paginated)
GET /api/products/batch Get products by IDs (?ids=1,2,3)
GET /api/products/{id} Get product by ID
GET /api/products/category/{categoryId} List products by category
POST /api/products Create product (admin)
PUT /api/products/{id} Update product (admin)
DELETE /api/products/{id} Delete product (admin)

Categories (catalog-service — :8082)

Method Endpoint Description
GET /api/categories List categories (paginated)
GET /api/categories/{id} Get category by ID
POST /api/categories Create category (admin)
PUT /api/categories/{id} Update category (admin)
DELETE /api/categories/{id} Delete category (admin)

Cart (cart-service — :8083)

Method Endpoint Description
POST /api/carts Create cart for current user
GET /api/carts Get current user's cart
GET /api/carts/user/{userId} Get cart by user ID
POST /api/carts/items Add item (?productId=&quantity=)
PUT /api/carts/items/{productId} Update item quantity
DELETE /api/carts/items/{productId} Remove item from cart
DELETE /api/carts/items Clear cart

Orders (order-service — :8084)

Method Endpoint Description
GET /api/orders/checkout Preview cart for checkout
POST /api/orders Place order (orchestrates inventory + cart)
POST /api/orders/razorpay/checkout Create Razorpay checkout attempt for cart
POST /api/orders/{orderId}/razorpay/checkout Pay an existing COD order online
GET /api/orders/payment-attempt/{attemptId} Find order created from a payment attempt
GET /api/orders Get current user's orders
GET /api/orders/all Get all orders (admin)
GET /api/orders/{orderId} Get order by ID
PATCH /api/orders/{orderId}/status Update order status (admin)
DELETE /api/orders/{orderId} Delete order (admin)

Inventory (inventory-service — :8085)

Method Endpoint Description
GET /api/inventory/{productId} Get inventory for product
POST /api/inventory Create inventory record
POST /api/inventory/{productId}/reserve Reserve stock (?quantity=)
POST /api/inventory/{productId}/release Release reserved stock

Notifications (notification-service — :8086)

No REST endpoints. Listens to Kafka order-created topic and pushes WebSocket/STOMP notifications to /topic/orders/{userId}.

Payments (payment-service — :8087)

Method Endpoint Description
POST /api/payments/verify Verify Razorpay Checkout signature and provider payment status
GET /api/payments/{attemptId} Read payment status (CREATED, AUTHORIZED, PAID, FAILED, CANCELLED, REFUND_PENDING, or REFUNDED)
POST /api/payments/{attemptId}/cancel Mark an open checkout attempt cancelled
POST /api/payments/webhook Receive signed Razorpay payment webhooks

Frontend Routes

Route Component Access
/ Home Public
/login Login Public
/register Register Public
/menu Menu Public
/cart Cart Public
/my-orders MyOrders Logged-in customer
/admin Dashboard Admin
/admin/products Products Admin
/admin/categories Categories Admin
/admin/orders Orders Admin
/admin/users Users Admin
/admin/inventory Inventory Admin

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m "Add your feature")
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a Pull Request

Ideas for contributions

  • Add unit and integration tests for backend services
  • Set up CI/CD with GitHub Actions
  • Write API documentation with Swagger/OpenAPI

Acknowledgments

About

BloomCafeV2 is a full-stack cafe ordering platform built with Java/Spring Boot microservices backend and a React SPA frontend. It features customer browsing, cart management, order placement, and an admin panel for managing products, categories, inventory, orders, and users. Uses Docker Compose for orchestration with PostgreSQL, Redis, and Kafka.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages