A gRPC-based user management system implemented in Go that provides authentication, user CRUD operations, and session management.
- User authentication (login/logout)
- User CRUD operations
- Session management with JWT tokens
- Email validation
- Role-based access (Admin/SuperAdmin)
- Health check endpoint
- PostgreSQL database integration
- Go 1.21 or higher
- PostgreSQL database
- Protocol Buffers compiler (protoc)
Linux (using apt):
apt install -y protobuf-compiler
protoc --version # Ensure compiler version is 3+MacOS (using Homebrew):
brew install protobuf
protoc --version # Ensure compiler version is 3+
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latestCreate a .env file in the root directory with the following variables:
PROJECT_PORT_USER=50051
POSTGRES_HOST_USER=localhost
POSTGRES_DB_USER=your_db_name
POSTGRES_USER_USER=your_db_user
POSTGRES_PASSWORD_USER=your_db_password
POSTGRES_PORT_USER=5432
RandomStringValidation=your_random_string
SizeRandomStringValidation=32
RandomStringValidationRefresh=your_random_string_refresh
SizeRandomStringValidationRefresh=10
Issuer=your_app_name
JWT_KEY=your_jwt_secret
TOKEN_EXPIRATION_TIME=600 #ten minutes
TOKEN_EXPIRATION_TIME_REFRESH=604800 #seven days
ENV=localSet ENV local to run the project in your machine, set it DEV when run it in docker and our a server.
go run server/*.gogo run client/client.goThe service provides the following gRPC endpoints:
Create: Register a new userGet: Retrieve user by IDUpdate: Update user profileDelete: Delete user accountList: List all usersLogin: Authenticate userLogOut: End user sessionValidate: Validate user emailGetByEmail: Retrieve user by emailTokenToUser: Convert JWT token to user informationRefresh: Refresh JWT token
// Create a new gRPC client connection
conn, err := grpc.Dial("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer conn.Close()
// Create a new user client
client := pb.NewUserClient(conn)
// Example: Create a new user
user := &pb.UserRequest{
Email: "test@example.com",
Name: "Test User",
}
response, err := client.Create(context.Background(), user)
if err != nil {
log.Fatalf("Failed to create user: %v", err)
}/server: Server-side implementation/server: Server implementation/controllers: Business logic/db: Database interactions/models: Data models/services: Service layer/user-pb: Protocol buffer definitions and generated code
/client: Client implementation and examples
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
The service includes a gRPC health checking mechanism that allows clients to monitor the server's health status.
The health check provides a simple way to verify if the server is running and ready to handle requests. This can be useful for:
- Load balancers to determine service availability
- Monitoring systems to track service health
- Client applications to check server status before making requests