Moda Style Microservices
Moda Style is a cloud-native microservices architecture built with Go and designed for Kubernetes deployment. The application has been transformed from a monolithic structure into three independent microservices for better scalability and maintainability.
Microservices Architecture
π Auth Service (Port 3000)
- User authentication and registration
- JWT token management
- Endpoints:
/api/v1/auth/login, /api/v1/auth/register
π€ User Service (Port 3001)
- User profile management
- Authenticated user operations
- Endpoints:
/api/v1/profile
π¦ Product Service (Port 3002)
- Product catalog management
- Product CRUD operations
- Endpoints:
/api/v1/products
Features
- Microservices Architecture: Independent, scalable services
- Kubernetes Native: Production-ready with health checks and probes
- Service Discovery: Internal communication via Kubernetes services
- Security: JWT-based authentication across services
- Database: Shared PostgreSQL with service-specific access patterns
- Health Monitoring: Comprehensive health checks for each service
- Container Security: Non-root users, read-only filesystem, minimal images
Quick Start
π Local Kubernetes Deployment
Deploy all microservices to a local Kubernetes cluster:
# Clone the repository
git clone <repository-url>
cd moda-style
# Deploy all microservices to local K8s
./deploy.sh
βοΈ AWS EKS Deployment
Deploy to AWS EKS (Elastic Kubernetes Service) for production:
# Deploy to AWS EKS (creates cluster, ECR repos, and deploys services)
./deploy-eks.sh
# Or with custom settings
./deploy-eks.sh --cluster-name my-cluster --region us-east-1
For detailed AWS EKS deployment instructions, see AWS_EKS_DEPLOYMENT.md.
π Access Services
# Port forward individual services
kubectl port-forward -n moda-style service/auth-service 3000:80
kubectl port-forward -n moda-style service/user-service 3001:80
kubectl port-forward -n moda-style service/product-service 3002:80
π API Access
API Documentation
Auth Service Endpoints
Register User
POST http://localhost:3000/api/v1/auth/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "securepassword123"
}
Login User
POST http://localhost:3000/api/v1/auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "securepassword123"
}
User Service Endpoints
Get Profile (Authenticated)
GET http://localhost:3001/api/v1/profile
Authorization: Bearer <jwt-token>
Update Profile (Authenticated)
PUT http://localhost:3001/api/v1/profile
Authorization: Bearer <jwt-token>
Content-Type: application/json
{
"name": "Updated Name",
"email": "newemail@example.com"
}
Product Service Endpoints
Get All Products
GET http://localhost:3002/api/v1/products
Get Single Product
GET http://localhost:3002/api/v1/products/:id
Health Monitoring
Each service exposes health endpoints:
/health - Basic health check
/health/live - Liveness probe
/health/ready - Readiness probe
Example:
curl http://localhost:3000/health
curl http://localhost:3001/health/ready
curl http://localhost:3002/health/live
Development
Local Development Setup
- Clone the repository:
git clone https://github.com/adibfahimi/moda-style.git
cd moda-style
- Create environment configuration:
# Create .env file for local development
PORT=3000
DATABASE_URL=postgres://user:password@localhost:5432/mydatabase
JWT_SECRET=a-very-secret-key-that-is-long
- Run individual microservices locally:
# Terminal 1: Auth Service
cd cmd/auth-service && go run main.go
# Terminal 2: User Service (different terminal)
cd cmd/user-service && go run main.go
# Terminal 3: Product Service (different terminal)
cd cmd/product-service && go run main.go
Docker Development
- Build all microservice images:
./build-services.sh
- Run with Docker Compose (legacy monolith):
docker-compose up -d --build
Deployment
AWS EKS Production Deployment
For production deployment to AWS EKS, use the automated deployment script:
# Automated EKS deployment (creates cluster, ECR repos, deploys services)
./deploy-eks.sh
# Custom cluster configuration
./deploy-eks.sh --cluster-name my-production-cluster --region us-east-1
# Use existing EKS cluster
./deploy-eks.sh --cluster-name existing-cluster --skip-cluster
The EKS deployment script handles:
- EKS cluster creation with managed node groups
- ECR repository creation and image pushing
- Kubernetes manifest deployment with ECR image URLs
- Load balancer configuration for external access
See AWS_EKS_DEPLOYMENT.md for detailed instructions.
Manual Kubernetes Deployment
- Build and push images:
# Build all microservice images
./build-services.sh
# Tag and push to registry (if using remote cluster)
docker tag auth-service:latest your-registry/auth-service:latest
docker tag user-service:latest your-registry/user-service:latest
docker tag product-service:latest your-registry/product-service:latest
- Deploy to Kubernetes:
# Apply all manifests
kubectl apply -f k8s/namespace-and-config.yaml
kubectl apply -f k8s/postgresql.yaml
kubectl apply -f k8s/auth-service.yaml
kubectl apply -f k8s/user-service.yaml
kubectl apply -f k8s/product-service.yaml
kubectl apply -f k8s/ingress.yaml
Scaling Individual Services
# Scale auth service based on login load
kubectl scale deployment auth-service --replicas=5 -n moda-style
# Scale user service for profile operations
kubectl scale deployment user-service --replicas=3 -n moda-style
# Scale product service for catalog browsing
kubectl scale deployment product-service --replicas=4 -n moda-style
Configuration
Environment Variables
Each microservice can be configured independently:
# Auth Service
PORT=3000
DATABASE_URL=postgres://...
JWT_SECRET=shared-secret
# User Service
PORT=3001
DATABASE_URL=postgres://...
JWT_SECRET=shared-secret
# Product Service
PORT=3002
DATABASE_URL=postgres://...
Kubernetes Configuration
Configuration is managed through ConfigMaps and Secrets:
# View current configuration
kubectl get configmap moda-style-config -n moda-style -o yaml
kubectl get secret moda-style-secrets -n moda-style -o yaml
Testing
Health Check Testing
# Test each service health
curl http://localhost:3000/health # Auth service
curl http://localhost:3001/health # User service
curl http://localhost:3002/health # Product service
API Testing
# 1. Register a user via Auth service
curl -X POST http://localhost:3000/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"name":"Test User","email":"test@example.com","password":"password123"}'
# 2. Login via Auth service
TOKEN=$(curl -X POST http://localhost:3000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password123"}' | jq -r '.data.token')
# 3. Get profile via User service
curl -X GET http://localhost:3001/api/v1/profile \
-H "Authorization: Bearer $TOKEN"
# 4. Get products via Product service
curl -X GET http://localhost:3002/api/v1/products
Monitoring & Troubleshooting
Check Service Status
# Check all pods
kubectl get pods -n moda-style
# Check services
kubectl get services -n moda-style
# Check ingress
kubectl get ingress -n moda-style
View Logs
# Auth service logs
kubectl logs -f deployment/auth-service -n moda-style
# User service logs
kubectl logs -f deployment/user-service -n moda-style
# Product service logs
kubectl logs -f deployment/product-service -n moda-style
# Database logs
kubectl logs -f deployment/postgresql -n moda-style
Debug Connection Issues
# Test internal service communication
kubectl exec -it deployment/auth-service -n moda-style -- wget -O- http://user-service/health
kubectl exec -it deployment/user-service -n moda-style -- wget -O- http://product-service/health
Architecture Benefits
Microservices Advantages
- Independent Scaling: Scale each service based on demand
- Technology Flexibility: Each service can use different technologies
- Fault Isolation: Failure in one service doesn't affect others
- Development Velocity: Teams can work independently on services
- Deployment Independence: Deploy services separately
Cloud-Native Features
- Kubernetes Native: Designed for container orchestration
- Health Monitoring: Comprehensive health checks
- Service Discovery: Automatic service location
- Configuration Management: Environment-based config
- Security: Non-root containers, minimal attack surface
Documentation
License
This project is licensed under the MIT License.