A production-ready, scalable e-commerce platform built with microservices architecture
Features • Architecture • Quick Start • Services • API Documentation • Monitoring
BuyNest is a comprehensive e-commerce platform designed with modern microservices principles. It demonstrates enterprise-grade patterns including service discovery, API gateway, event-driven communication, circuit breakers, and centralized monitoring. The platform is fully containerized and ready for deployment in cloud environments.
- 🔐 User Management - Registration, authentication, and profile management with JWT security
- 📦 Product Catalog - Full product lifecycle management with categories and inventory tracking
- 🛒 Shopping Cart - Persistent cart with Redis caching for optimal performance
- 📋 Order Processing - Complete order workflow with status tracking
- 💳 Payment Integration - Secure payment processing with webhook support
- 📧 Notifications - Real-time email and SMS notifications via Kafka
- 🔄 Service Discovery - Netflix Eureka for dynamic service registration
- 🚪 API Gateway - Centralized routing with Spring Cloud Gateway
- 📨 Event-Driven Architecture - Apache Kafka for asynchronous communication
- ⚡ Caching - Redis for session management and data caching
- 🛡️ Resilience - Circuit breakers with Resilience4j
- 📊 Observability - Prometheus metrics and Grafana dashboards
- 🗃️ Database Per Service - Isolated PostgreSQL databases for each microservice
- 🔄 Database Migrations - Flyway for version-controlled schema migrations
┌─────────────────────────────────────────┐
│ Client Applications │
│ (Web, Mobile, Third-party) │
└────────────────────┬────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ API Gateway (:8080) │
│ (Routing, Auth, Rate Limiting) │
└────────────────────┬────────────────────┘
│
┌────────────────────────────┼────────────────────────────┐
│ │ │
▼ ▼ ▼
┌──────────────────────┐ ┌──────────────────────┐ ┌──────────────────────┐
│ User Service │ │ Product Service │ │ Shopping Cart │
│ (:8081) │ │ (:8082) │ │ Service (:8083) │
│ ┌────────────┐ │ │ ┌────────────┐ │ │ ┌────────────┐ │
│ │ PostgreSQL │ │ │ │ PostgreSQL │ │ │ │ PostgreSQL │ │
│ │ user_db │ │ │ │ catalog_db │ │ │ │ cart_db │ │
│ └────────────┘ │ │ └────────────┘ │ │ └────────────┘ │
└──────────────────────┘ └──────────────────────┘ └──────────────────────┘
│ │ │
└────────────────────────────┼────────────────────────────┘
│
┌────────────────────┴────────────────────┐
│ │
▼ ▼
┌──────────────────────────────────┐ ┌──────────────────────────────────┐
│ Order Service │ │ Payment Service │
│ (:8084) │ │ (:8085) │
│ ┌────────────────┐ │ │ ┌────────────────┐ │
│ │ PostgreSQL │ │ │ │ PostgreSQL │ │
│ │ order_db │ │ │ │ payment_db │ │
│ └────────────────┘ │ │ └────────────────┘ │
└──────────────────────────────────┘ └──────────────────────────────────┘
│ │
└─────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────┐
│ Apache Kafka │
│ (Event Streaming Platform) │
└────────────────────┬─────────────────────┘
│
▼
┌──────────────────────────────────────────┐
│ Notification Service (:8086) │
│ (Email, SMS, Push) │
│ ┌──────────────────────┐ │
│ │ PostgreSQL │ │
│ │ notification_db │ │
│ └──────────────────────┘ │
└──────────────────────────────────────────┘
┌───────────────────────────────────────────────────────────────────────────────────────┐
│ Supporting Infrastructure │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Eureka │ │ Redis │ │ Prometheus │ │ Grafana │ │
│ │ (:8761) │ │ (:6379) │ │ (:9090) │ │ (:3000) │ │
│ │ Discovery │ │ Caching │ │ Metrics │ │ Dashboards │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Zookeeper │ │ PGAdmin │ │
│ │ (:2181) │ │ (:9999) │ │
│ │ Kafka Coord │ │ DB Admin │ │
│ └──────────────┘ └──────────────┘ │
└───────────────────────────────────────────────────────────────────────────────────────┘
Ensure you have the following installed on your system:
| Tool | Minimum Version | Purpose |
|---|---|---|
| Java | 17+ | Runtime environment |
| Maven | 3.8+ | Build automation |
| Docker | 20.10+ | Containerization |
| Docker Compose | 2.0+ | Multi-container orchestration |
git clone https://github.com/DAMMAK/buynest.git
cd buynestCopy the example environment file and update the values:
cp .env.example .envUpdate the .env file with your configuration:
# Database Configuration
POSTGRES_DB=ecommerce_main
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_secure_password
# Redis Configuration
REDIS_PASSWORD=your_redis_password
# JWT Configuration
JWT_SECRET=your_jwt_secret_key_at_least_32_characters
# Email Configuration (for notifications)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=[email protected]
SMTP_PASSWORD=your_app_password
# Monitoring
GRAFANA_USER=admin
GRAFANA_PASSWORD=your_grafana_password# Build all microservices
./build-all.sh
# Or build individually
cd user-service && ./mvnw clean package -DskipTests && cd ..
cd product-service && ./mvnw clean package -DskipTests && cd ..
cd shopping-cart-service && ./mvnw clean package -DskipTests && cd ..
cd order-service && ./mvnw clean package -DskipTests && cd ..
cd payment-service && ./mvnw clean package -DskipTests && cd ..
cd notification-service && ./mvnw clean package -DskipTests && cd ..
cd api-gateway && ./mvnw clean package -DskipTests && cd ..
cd eureka-server && ./mvnw clean package -DskipTests && cd ..# Start all services with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f
# Check service status
docker-compose ps| Service | URL | Description |
|---|---|---|
| API Gateway | http://localhost:8080 | Main entry point |
| Eureka Dashboard | http://localhost:8761 | Service registry |
| PGAdmin | http://localhost:9999 | Database management |
| Prometheus | http://localhost:9090 | Metrics collection |
| Grafana | http://localhost:3000 | Monitoring dashboards |
Handles user authentication, authorization, and profile management.
Key Features:
- User registration and login with JWT authentication
- Password encryption with BCrypt
- Role-based access control (RBAC)
- Profile management
- Email verification
Tech Stack:
- Spring Security
- Spring Data JPA
- PostgreSQL
- Flyway Migrations
- Kafka Producer
API Endpoints:
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/auth/register |
User registration |
| POST | /api/v1/auth/login |
User authentication |
| GET | /api/v1/users/me |
Get current user profile |
| PUT | /api/v1/users/me |
Update user profile |
Manages the product catalog, categories, and inventory.
Key Features:
- Product CRUD operations
- Category management
- Inventory tracking
- Product search and filtering
- Image management
Tech Stack:
- Spring Data JPA
- PostgreSQL
- Kafka Producer/Consumer
API Endpoints:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/products |
List all products |
| GET | /api/v1/products/{id} |
Get product details |
| POST | /api/v1/products |
Create new product |
| PUT | /api/v1/products/{id} |
Update product |
| DELETE | /api/v1/products/{id} |
Delete product |
| GET | /api/v1/categories |
List categories |
Manages user shopping carts with Redis caching for performance.
Key Features:
- Add/remove items from cart
- Update item quantities
- Cart persistence
- Redis caching for fast access
- Cart expiration handling
Tech Stack:
- Spring Data JPA
- Spring Data Redis
- PostgreSQL
- Redis
- Scheduled Tasks
API Endpoints:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/cart |
Get user's cart |
| POST | /api/v1/cart/items |
Add item to cart |
| PUT | /api/v1/cart/items/{id} |
Update cart item |
| DELETE | /api/v1/cart/items/{id} |
Remove item from cart |
| DELETE | /api/v1/cart |
Clear cart |
Handles the complete order lifecycle from creation to fulfillment.
Key Features:
- Order creation and management
- Order status tracking
- Order history
- Integration with payment service
- Kafka event publishing
Tech Stack:
- Spring Data JPA
- PostgreSQL
- Kafka Producer/Consumer
- Feign Clients
API Endpoints:
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/orders |
Create new order |
| GET | /api/v1/orders |
List user orders |
| GET | /api/v1/orders/{id} |
Get order details |
| PUT | /api/v1/orders/{id}/status |
Update order status |
| DELETE | /api/v1/orders/{id} |
Cancel order |
Handles secure payment processing and transaction management.
Key Features:
- Payment processing
- Transaction management
- Payment method management
- Refund processing
- Webhook handling
Tech Stack:
- Spring Data JPA
- PostgreSQL
- Kafka Producer/Consumer
- Payment Gateway Integration
API Endpoints:
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/payments |
Process payment |
| GET | /api/v1/payments/{id} |
Get payment details |
| POST | /api/v1/payments/{id}/refund |
Process refund |
| POST | /api/v1/webhooks/payment |
Payment webhook |
Manages all user notifications across multiple channels.
Key Features:
- Email notifications
- SMS notifications (configurable)
- Push notifications
- Template management
- Notification history
Tech Stack:
- Spring Mail
- PostgreSQL
- Kafka Consumer
- Template Engine
Kafka Topics Consumed:
user.registered- Welcome emailsorder.created- Order confirmationsorder.shipped- Shipping notificationspayment.completed- Payment receipts
Central entry point for all client requests with routing and security.
Key Features:
- Request routing
- JWT validation
- Rate limiting
- Circuit breaker patterns
- CORS configuration
- Request/Response logging
Tech Stack:
- Spring Cloud Gateway
- Spring Security
- Resilience4j
- Redis (for rate limiting)
Route Configuration:
| Path | Target Service |
|---|---|
/api/v1/auth/** |
user-service |
/api/v1/users/** |
user-service |
/api/v1/products/** |
product-service |
/api/v1/cart/** |
shopping-cart-service |
/api/v1/orders/** |
order-service |
/api/v1/payments/** |
payment-service |
Service discovery and registration for all microservices.
Features:
- Service registration
- Health monitoring
- Load balancing support
- Service discovery dashboard
All services expose Actuator endpoints with Prometheus metrics:
http://localhost:{service-port}/actuator/prometheus
Available Metrics:
- JVM metrics (memory, threads, GC)
- HTTP request metrics
- Database connection pool metrics
- Custom business metrics
Pre-configured dashboards available at http://localhost:3000:
- Overview Dashboard - System-wide health
- JVM Dashboard - Memory and GC metrics
- HTTP Dashboard - Request rates and latencies
- Database Dashboard - Connection pool stats
- Kafka Dashboard - Message throughput
Each service exposes health information:
# Check service health
curl http://localhost:{port}/actuator/health
# Get detailed health info
curl http://localhost:{port}/actuator/health | jq1. User registers/logs in via /api/v1/auth/*
2. User Service validates credentials
3. JWT token generated and returned
4. Client includes token in Authorization header
5. API Gateway validates token for protected routes
6. Request forwarded to appropriate service
Tokens are configured with:
- Algorithm: HS256
- Expiration: 24 hours (configurable)
- Payload: User ID, roles, email
The API Gateway adds security headers:
X-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=block
buynest/
├── api-gateway/ # Spring Cloud Gateway service
│ ├── src/main/java/
│ │ └── dev/dammak/apigateway/
│ │ ├── config/ # Gateway & security configuration
│ │ ├── controller/ # Fallback controllers
│ │ ├── filter/ # JWT & request filters
│ │ └── util/ # Utility classes
│ └── pom.xml
│
├── eureka-server/ # Service discovery server
│ └── src/main/java/
│
├── user-service/ # User management microservice
│ ├── src/main/java/
│ │ └── dev/dammak/userservice/
│ │ ├── config/ # Security, Kafka config
│ │ ├── controller/ # REST controllers
│ │ ├── dto/ # Data transfer objects
│ │ ├── entity/ # JPA entities
│ │ ├── exception/ # Custom exceptions
│ │ ├── filter/ # Auth filters
│ │ ├── repository/ # Data repositories
│ │ ├── service/ # Business logic
│ │ └── util/ # JWT utilities
│ └── pom.xml
│
├── product-service/ # Product catalog microservice
│ ├── src/main/java/
│ │ └── dev/dammak/productservice/
│ │ ├── config/
│ │ ├── controller/
│ │ ├── dto/
│ │ ├── entity/
│ │ ├── exception/
│ │ ├── mapper/ # DTO mappers
│ │ ├── repository/
│ │ ├── service/
│ │ └── util/
│ └── pom.xml
│
├── shopping-cart-service/ # Shopping cart microservice
│ ├── src/main/java/
│ │ └── dev/dammak/shoppingcartservice/
│ │ ├── config/
│ │ ├── controller/
│ │ ├── dto/
│ │ ├── entity/
│ │ ├── exception/
│ │ ├── repository/
│ │ ├── scheduler/ # Cart cleanup jobs
│ │ ├── service/
│ │ └── util/
│ └── pom.xml
│
├── order-service/ # Order management microservice
│ ├── src/main/java/
│ │ └── dev/dammak/orderservice/
│ │ ├── client/ # Feign clients
│ │ ├── config/
│ │ ├── controller/
│ │ ├── dto/
│ │ ├── entity/
│ │ ├── enums/
│ │ ├── exception/
│ │ ├── listener/ # Kafka listeners
│ │ ├── repository/
│ │ ├── service/
│ │ └── util/
│ └── pom.xml
│
├── payment-service/ # Payment processing microservice
│ ├── src/main/java/
│ │ └── dev/dammak/paymentservice/
│ │ ├── config/
│ │ ├── controller/
│ │ ├── dto/
│ │ ├── entity/
│ │ ├── enums/
│ │ ├── exception/
│ │ ├── listener/ # Kafka listeners
│ │ ├── repository/
│ │ ├── service/
│ │ └── util/
│ └── pom.xml
│
├── notification-service/ # Notification microservice
│ ├── src/main/java/
│ │ └── dev/dammak/notificationservice/
│ │ ├── config/
│ │ ├── controller/
│ │ ├── dto/
│ │ ├── entity/
│ │ ├── enums/
│ │ ├── exception/
│ │ ├── listener/ # Kafka listeners
│ │ ├── repository/
│ │ ├── service/
│ │ └── util/
│ └── pom.xml
│
├── config-server/ # Centralized configuration (optional)
│
├── monitoring/ # Monitoring configuration
│ ├── prometheus.yml # Prometheus config
│ └── grafana/ # Grafana dashboards
│
├── init-scripts/ # Database initialization
│ └── init-multiple-databases.sh
│
├── logs/ # Application logs
├── docker-compose.yml # Container orchestration
├── .env # Environment variables
└── README.md
# Run tests for all services
./mvnw test
# Run tests for a specific service
cd user-service && ./mvnw test# Start test containers
docker-compose -f docker-compose.test.yml up -d
# Run integration tests
./mvnw verify -P integration-tests# Register a new user
curl -X POST http://localhost:8080/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "SecurePass123!",
"firstName": "John",
"lastName": "Doe"
}'
# Login
curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "SecurePass123!"
}'
# Get products (with token)
curl http://localhost:8080/api/v1/products \
-H "Authorization: Bearer <your-jwt-token>"docker-compose up -ddocker-compose -f docker-compose.prod.yml up -dKubernetes manifests and Helm charts are planned for future releases.
| Service | Port | Description |
|---|---|---|
| API Gateway | 8080 | Main entry point |
| User Service | 8081 | User management |
| Product Service | 8082 | Product catalog |
| Shopping Cart | 8083 | Cart management |
| Order Service | 8084 | Order processing |
| Payment Service | 8085 | Payment handling |
| Notification | 8086 | Notifications |
| Eureka Server | 8761 | Service discovery |
| PostgreSQL | 5432-5437 | Databases |
| Redis | 6379 | Caching |
| Kafka | 9092 | Message broker |
| Zookeeper | 2181 | Kafka coordination |
| Prometheus | 9090 | Metrics |
| Grafana | 3000 | Dashboards |
| PGAdmin | 9999 | DB admin |
See .env file for all configurable variables.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Java code conventions
- Use meaningful variable and method names
- Write unit tests for new features
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- Spring Boot - Application framework
- Spring Cloud - Microservices patterns
- Apache Kafka - Event streaming
- Docker - Containerization
Built with ❤️ by Dammak