A modern, scalable e-commerce microservices architecture built with Go Fiber and Next.js.
graph TB
Client[Next.js Client<br/>Port: 3000]
Gateway[API Gateway<br/>Port: 8000]
User[User Service<br/>Port: 8001]
Product[Product Service<br/>Port: 8002]
Basket[Basket Service<br/>Port: 8003]
Payment[Payment Service<br/>Port: 8004]
Client -->|HTTP/REST| Gateway
Gateway -->|Proxy| User
Gateway -->|Proxy| Product
Gateway -->|Proxy| Basket
Gateway -->|Proxy| Payment
Product -.->|gRPC Auth| User
Basket -.->|gRPC Auth| Product
Payment -.->|gRPC Auth| User
style Gateway fill:#ff6b6b
style User fill:#4ecdc4
style Product fill:#45b7d1
style Basket fill:#96ceb4
style Payment fill:#ffeaa7
style Client fill:#dfe6e9
graph LR
subgraph "API Gateway :8000"
GW[Fiber v2 Gateway]
GW_Features[Rate Limiting<br/>JWT Auth<br/>CORS<br/>Metrics<br/>Health Checks]
end
subgraph "User Service :8001"
US[Fiber v2]
US_DB[(PostgreSQL<br/>:5432)]
US_GRPC[gRPC Server<br/>:50051]
end
subgraph "Product Service :8002"
PS[Fiber v2]
PS_DB[(PostgreSQL<br/>:5433)]
PS_GRPC[gRPC Client]
end
subgraph "Basket Service :8003"
BS[Fiber v2]
BS_Redis[(Redis<br/>:6379)]
BS_GRPC[gRPC Client]
end
subgraph "Payment Service :8004"
PayS[Fiber v2]
PayS_DB[(MariaDB<br/>:3306)]
PayS_GRPC[gRPC Client]
PayS_Kafka[Kafka Events]
end
GW --> US
GW --> PS
GW --> BS
GW --> PayS
PS_GRPC -.->|Auth| US_GRPC
BS_GRPC -.->|Auth| US_GRPC
PayS_GRPC -.->|Auth| US_GRPC
sequenceDiagram
participant C as Client
participant G as API Gateway
participant U as User Service
participant P as Product Service
participant B as Basket Service
participant Pay as Payment Service
C->>G: POST /auth/login
G->>U: Proxy to User Service
U-->>G: JWT Token
G-->>C: JWT Token
C->>G: GET /products (+ JWT)
G->>G: Validate JWT
G->>P: Proxy with JWT
P-->>G: Products List
G-->>C: Products List
C->>G: POST /basket/items (+ JWT)
G->>G: Validate JWT
G->>B: Proxy with JWT
B->>U: gRPC Auth Validation
U-->>B: Auth OK
B-->>G: Item Added
G-->>C: Success
C->>G: POST /orders (+ JWT)
G->>G: Validate JWT
G->>Pay: Proxy with JWT
Pay->>U: gRPC Auth Validation
U-->>Pay: Auth OK
Pay->>Pay: Create Order
Pay->>Pay: Publish Kafka Event
Pay-->>G: Order Created
G-->>C: Order Response
- Framework: Fiber v2
- Databases: PostgreSQL, MariaDB, Redis
- Communication: gRPC, HTTP/REST
- Event Streaming: Kafka (Sarama)
- Documentation: Swagger/OpenAPI
- Authentication: JWT
- Framework: Next.js 14
- Language: TypeScript
- Containerization: Docker Compose
- Build Tool: Make
- Testing: Shell Scripts
- Go 1.21+
- Docker & Docker Compose
- Node.js 18+ (for client)
- Make
cd go-server
docker-compose up -d
This starts:
- PostgreSQL (User Service - :5432)
- PostgreSQL (Product Service - :5433)
- Redis (Basket Service - :6379)
- MariaDB (Payment Service - :3306)
make build-all
./integrations/start-all-services.sh
Services will be available at:
- API Gateway: http://localhost:8000
- User Service: http://localhost:8001
- Product Service: http://localhost:8002
- Basket Service: http://localhost:8003
- Payment Service: http://localhost:8004
# Test via API Gateway
./integrations/test-gateway-flow.sh
# Test all services individually
./integrations/test-all.sh
./integrations/stop-all-services.sh
graph TD
Request[Incoming Request] --> RateLimit[Rate Limiter<br/>100 req/min]
RateLimit --> Auth{Auth<br/>Required?}
Auth -->|Yes| JWT[JWT Validation]
Auth -->|No| Route[Route Matching]
JWT --> Route
Route --> Proxy[HTTP Proxy]
Proxy --> Backend[Backend Service]
Backend --> Response[Response]
Response --> Metrics[Metrics Collection]
Metrics --> Client[Client Response]
- Health:
GET /health
- Metrics:
GET /metrics
- API Base:
/api/v1/*
- User registration & authentication
- JWT token generation
- gRPC auth server for other services
- User profile management
- Product & category management
- Product search & filtering
- Inventory management
- gRPC client for auth
- Shopping cart operations
- Redis-based session storage
- TTL-based cart expiration (1 day)
- gRPC client for auth
- Order creation & management
- Payment processing simulation
- Kafka event publishing
- MariaDB for transactional data
graph LR
Pay[Payment Service] -->|Publish| Kafka[Kafka Topics]
Kafka -->|order.completed| Consumer1[Order Consumer]
Kafka -->|basket.cleared| Consumer2[Basket Consumer]
Kafka -->|product.stock.updated| Consumer3[Stock Consumer]
style Kafka fill:#ff6b6b
order.completed
: Triggered on successful paymentbasket.cleared
: User's basket cleared after orderproduct.stock.updated
: Product inventory updated
make swagger
make run-user
make run-product
make run-basket
make run-payment
make run-gateway
make build-user
make build-product
make build-basket
make build-payment
make build-gateway
make proto
fiber-enchanted/
├── client/ # Next.js frontend
├── go-server/
│ ├── api/proto/ # Protocol Buffer definitions
│ ├── cmd/ # Service entry points
│ │ ├── userservice/
│ │ ├── productservice/
│ │ ├── basketservice/
│ │ ├── paymentservice/
│ │ └── gateway/
│ ├── fiber-gateway/ # API Gateway implementation
│ ├── event-driven/ # Kafka publishers/consumers
│ ├── internal/ # Service implementations
│ ├── integrations/ # Integration test scripts
│ ├── docker-compose.yml
│ └── Makefile
└── README.md
graph TD
Test[Integration Tests] --> Direct[Direct Service Tests]
Test --> Gateway[Gateway Proxy Tests]
Direct --> UserTest[test-user-service.sh]
Direct --> ProductTest[test-product-service.sh]
Direct --> BasketTest[test-basket-service.sh]
Direct --> PaymentTest[test-payment-service.sh]
Gateway --> GatewayTest[test-gateway-flow.sh]
Test --> Full[test-all.sh<br/>Complete Test Suite]
sequenceDiagram
participant C as Client
participant G as Gateway
participant U as User Service
participant S as Protected Service
C->>G: POST /auth/login
G->>U: Forward Request
U->>U: Validate Credentials
U->>U: Generate JWT
U-->>G: JWT Token
G-->>C: JWT Token
C->>G: GET /protected/resource<br/>(Authorization: Bearer JWT)
G->>G: Validate JWT<br/>(Check signature)
G->>S: Proxy Request<br/>(Forward JWT)
S->>U: gRPC ValidateToken
U-->>S: User Info
S-->>G: Protected Resource
G-->>C: Resource Data
graph TD
Request[Request] --> Recovery[Panic Recovery]
Recovery --> RequestID[Request ID Generator]
RequestID --> Logger[Request Logger]
Logger --> CORS[CORS Handler]
CORS --> Compress[Response Compression]
Compress --> RateLimit[Rate Limiter]
RateLimit --> Metrics[Metrics Collector]
Metrics --> Auth{Auth<br/>Middleware}
Auth -->|Protected| JWT[JWT Validation]
Auth -->|Public| Route[Route Handler]
JWT --> Route
Route --> Proxy[HTTP Proxy]
Proxy --> Backend[Backend Service]
curl http://localhost:8000/health
Returns service health status for all microservices.
curl http://localhost:8000/metrics
Provides:
- Total requests
- Active requests
- Error count
- Response times per service
MIT License - see LICENSE file for details.
This is a demonstration project showcasing microservices architecture with Go Fiber.
Built with ❤️ using Go Fiber v2