This project demonstrates a simple gRPC-based microservices architecture with two services: User Service and Payment Service. The User Service manages user profiles, while the Payment Service handles payment transactions and interacts with the User Service to verify user details.
- 🗂 Project Structure
- 🔍 Services Overview
- 📋 Requirements
- ⚙️ Setup
- 🛠 Usage
- 📜 Protobuf
- 💾 Database
- 🏃♂️ Running the Services
This service handles user-related operations such as:
- CreateUser
- GetUser
- UpdateUser
- DeleteUser
The gRPC definitions for this service can be found in proto/user.proto
, and the implementation is in user-service/user.go
.
This service handles payment-related operations such as:
- ProcessPayment
- RefundTransaction
- CheckBalance
The gRPC definitions for this service can be found in proto/payment.proto
, and the implementation is in payment-service/payment.go
.
`grpc-user-payment-services/
├── database # Database models and connection setup
│ ├── db.go
│ └── models.go
├── docs # Documentation files
│ └── PROTOBUF_PATH_SETUP.md
├── gen # Generated protobuf files
│ ├── payment/
│ └── user/
├── payment-service # Payment service implementation
│ ├── main.go
│ └── payment.go
├── proto # Protobuf definition files
│ ├── payment.proto
│ └── user.proto
├── user-service # User service implementation
│ ├── main.go
│ └── user.go
└── README.md # Project documentation`
- Clone the repository:
git clone https://github.com/your-repo/grpc-user-payment-services.git
cd grpc-user-payment-services`
- Install the required Go modules:
go mod tidy
-
Generate the protobuf files:
`protoc --go_out=. --go-grpc_out=. proto/*.proto`
-
Configure your database connection in
database/db.go
.
To run both services, you first need to build them. Navigate to the project root and build the services:
go build -o tmp/user-service-executable user-service/main.go
go build -o tmp/payment-service-executable payment-service/main.go`
This will create the executables for both services in the tmp/
directory.
You can now start both services simultaneously by running the executables:
./tmp/user-service-executable &
./tmp/payment-service-executable &`
Alternatively, you can run them directly from their respective directories without building:
go run user-service/main.go
go run payment-service/main.go`
Once the services are running, they will listen on different ports as specified in their respective main.go
files.
To manually run the User Service, navigate to the user-service
directory:
cd user-service
go run main.go`
To manually run the Payment Service, navigate to the payment-service
directory:
cd payment-service
go run main.go`
The service contracts are defined using protobuf files located in the proto/
directory.
To update or modify protobuf definitions, edit the .proto
files and regenerate the .pb.go
files using the following command:
`protoc --go_out=. --go-grpc_out=. proto/*.proto`
Refer to PROTOBUF_PATH_SETUP.md for more information on setting up the Protobuf path.
- The project uses GORM for database interactions.
- Models are defined in the
database/models.go
file. - Database initialization and configuration are handled in
database/db.go
.
Make sure to set the correct database connection details in db.go
.
- Refactor responses
- Implement OAuth2/JWT & TLS
- Add service discovery
- Integrate message broker
- Implement health checks
- Use Redis for caching
- Write tests
- Document API
- Optimize database
- Set up monitoring
For any queries, feel free to reach out at [email protected].