A modern e-commerce platform built with microservices architecture using Go, MongoDB, Docker, and Kubernetes.
Handles user management and authentication:
- User registration and login
- Profile management
- JWT authentication
- Role-based access control (RBAC)
Manages product catalog:
- Product CRUD operations
- Product categories
- Product search
- Stock availability check
Manages shop operations:
- Shop registration
- Shop management
- Shop products
- Shop analytics
Handles order processing:
- Order creation
- Order status management
- Payment integration
- Order history
Manages inventory and stock:
- Stock management
- Multi-warehouse support
- Stock transfer between warehouses
- Stock level monitoring
- Automated stock release
- Go (Gin Framework)
- MongoDB
- JWT Authentication
- Swagger Documentation
- Docker
- Kubernetes
- Prometheus & Grafana
- Consul (Service Discovery)
- Air (Hot Reload)
- Zap (Logging)
- Prometheus (Metrics)
- Circuit Breaker
- Rate Limiter
- Microservices Architecture
- RESTful APIs
- JWT Authentication
- Role-Based Access Control
- API Documentation (Swagger)
- Monitoring & Metrics
- Distributed Logging
- Circuit Breaker Pattern
- Rate Limiting
- Service Discovery
- Load Balancing
- Horizontal Scaling
-
Install required tools:
# Install Go brew install go # For MacOS # or download from https://golang.org/dl/ # Install Docker brew install docker # For MacOS # or follow https://docs.docker.com/get-docker/ # Install Kubernetes tools brew install kubectl brew install minikube # Install MongoDB brew install mongodb-community # For MacOS # or use Docker: docker run -d -p 27017:27017 mongo
-
Clone the repository:
git clone <repository-url> cd ecommerce
-
Start MongoDB:
# Using local MongoDB brew services start mongodb-community # Or using Docker docker run -d -p 27017:27017 --name mongodb mongo
-
Run Warehouse Service:
cd services/warehouse-service # Install dependencies make deps # Generate Swagger docs make swagger # Run service make run # or for development with hot reload: make dev
-
Test the API:
# Generate JWT token curl -X POST http://localhost:8085/api/v1/auth/token \ -H "Content-Type: application/json" \ -d '{ "user_id": "user123", "roles": ["admin"] }' # Save token export TOKEN="<token-from-response>" # Create warehouse curl -X POST http://localhost:8085/api/v1/warehouses \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $TOKEN" \ -d '{ "name": "Main Warehouse", "location": "Jakarta" }' # Get all warehouses curl http://localhost:8085/api/v1/warehouses \ -H "Authorization: Bearer $TOKEN"
-
Start all services:
docker-compose -f docker/docker-compose.yml up -d
-
Start specific service:
docker-compose -f docker/docker-compose.yml up -d warehouse-service
-
View logs:
docker-compose -f docker/docker-compose.yml logs -f warehouse-service
-
Stop services:
docker-compose -f docker/docker-compose.yml down
-
Start development environment:
cd docker/development docker-compose up -d -
View logs:
docker-compose logs -f
-
Stop development environment:
docker-compose down
-
Start Minikube:
minikube start
-
Apply Kubernetes configurations:
kubectl create namespace ecommerce kubectl apply -f k8s/warehouse-service/
-
Verify deployment:
kubectl get pods -n ecommerce kubectl get services -n ecommerce
-
Access service:
# Get service URL minikube service warehouse-service -n ecommerce --url
| Service | Local URL | Swagger Documentation |
|---|---|---|
| User Service | http://localhost:8081 | http://localhost:8081/swagger/index.html |
| Product Service | http://localhost:8082 | http://localhost:8082/swagger/index.html |
| Shop Service | http://localhost:8083 | http://localhost:8083/swagger/index.html |
| Order Service | http://localhost:8084 | http://localhost:8084/swagger/index.html |
| Warehouse Service | http://localhost:8085 | http://localhost:8085/swagger/index.html |
| Service | URL | Credentials |
|---|---|---|
| Prometheus | http://localhost:9090 | N/A |
| Grafana | http://localhost:3000 | admin/admin |
| Service Metrics | http://localhost:8084/metrics | N/A |
Collection includes:
-
Order Service Endpoints:
- POST
/api/v1/orders- Create new order - GET
/api/v1/orders/{order_id}- Get order by ID - GET
/api/v1/orders/user- Get user orders - GET
/api/v1/orders/shop/{shop_id}- Get shop orders - POST
/api/v1/orders/{order_id}/process- Process order - POST
/api/v1/orders/{order_id}/complete- Complete order - POST
/api/v1/orders/{order_id}/cancel- Cancel order
- POST
-
Product Service Endpoints:
- POST
/api/v1/products- Create product - GET
/api/v1/products- Get all products - GET
/api/v1/products/{product_id}- Get product by ID - PUT
/api/v1/products/{product_id}- Update product - PATCH
/api/v1/products/{product_id}/stock- Update stock - DELETE
/api/v1/products/{product_id}- Delete product
- POST
-
Shop Service Endpoints:
- GET
/api/v1/shops/{shop_id}- Get shop by ID - GET
/api/v1/shops- Get all shops - POST
/api/v1/shops- Create shop - PUT
/api/v1/shops/{shop_id}- Update shop - POST
/api/v1/shops/{shop_id}/warehouses/{warehouse_id}- Add warehouse to shop - DELETE
/api/v1/shops/{shop_id}/warehouses/{warehouse_id}- Remove warehouse from shop - DELETE
/api/v1/shops/{shop_id}- Delete shop
- GET
-
User Service Endpoints:
- POST
/api/v1/auth/register- Register new user - POST
/api/v1/auth/login- Login user - GET
/api/v1/users/me- Get current user - PUT
/api/v1/users/me- Update user profile
- POST
-
Warehouse Service Endpoints:
- PUT
/api/v1/warehouses/{warehouse_id}/stock- Update stock - POST
/api/v1/warehouses- Create warehouse - POST
/api/v1/auth/token- Generate JWT token - GET
/api/v1/warehouses- Get all warehouses - GET
/api/v1/warehouses/{warehouse_id}- Get warehouse by ID - PUT
/api/v1/warehouses/{id}/stock- Update stock - POST
/api/v1/warehouses/transfer- Transfer stock - PUT
/api/v1/warehouses/{id}/{status}- Update warehouse status (activate/deactivate)
- PUT