A modern, scalable microservices application built with Go, featuring multiple services that communicate with each other through a central API Gateway. This project demonstrates microservices best practices, containerization, and database integration.
-
Go (Golang) - Primary programming language for all microservices
-
Gin Framework - HTTP web framework for the API Gateway and services
-
GORM - ORM library for database operations
-
PostgreSQL - Relational database for User Service
-
MongoDB - NoSQL database for Product Service
-
Docker - Containerization platform
-
Docker Compose - Multi-container orchestration
-
Environment Configuration - Using .env files
-
RESTful APIs - For service-to-service communication
-
JSON - Data exchange format
This project implements a microservices architecture with the following components:
Client
|
v
Gateway
|
+----------------+
| |
v v
User Service Product Service
| |
v v
PostgreSQL MongoDB
-
Client: Sends requests to the system.
-
Gateway: Acts as the entry point and routes requests to the appropriate microservices.
-
User Service: Handles user-related operations and stores data in PostgreSQL.
-
Product Service: Manages product-related operations and stores data in MongoDB.
-
Language: Go
-
Database: PostgreSQL
-
Description: Manages user data and authentication
-
Language: Go
-
Database: MongoDB
-
Description: Manages product data and inventory
-
Language: Go
-
Framework: Gin
-
Description: Routes requests to the appropriate service
/project-root
β
βββ /api-gateway
β βββ main.go
β βββ ...
β
βββ /user-service
β βββ main.go
β βββ ...
β
βββ /product-service
β βββ main.go
β βββ ...
β
βββ docker-compose.yml
βββ .env.example
βββ README.md
-
Docker
-
Docker Compose
-
Go (for local development)
- Create an Environment File
Copy the contents of .env.example into a new file named .env in the project root and adjust values as needed.
- Start with Docker Compose
docker-compose up --build
This command will build and start your services and databases.
-
POST /users
-
Description: Create a new user
-
Request Body:
{ "username": "string", "password": "string" } -
Response:
{ "id": "string", "username": "string" } -
GET /users/{id}
-
Description: Get user details by ID
-
Response:
{ "id": "string", "username": "string" }
-
POST /products
-
Description: Create a new product
-
Request Body:
{ "name": "string", "price": "number" } -
Response:
{ "id": "string", "name": "string", "price": "number" } -
GET /products/{id}
-
Description: Get product details by ID
-
Response:
{ "id": "string", "name": "string", "price": "number" }
You can send requests to user and product endpoints through the Gateway (http://localhost:8000):
-
Example:
POST http://localhost:8000/users -
Example:
POST http://localhost:8000/products
To run the services locally without Docker:
- User Service
cd user-service
go run main.go
- Product Service
cd product-service
go run main.go
- API Gateway
cd api-gateway
go run main.go
-
Database Connection Issues: Ensure your
.envfile has the correct database connection strings. -
Service Not Starting: Check the logs for error messages and ensure all dependencies are installed.
Contributions via pull requests or issues are welcome.
This project is licensed under the MIT License.