grpc

module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2025 License: MIT

README ΒΆ

gRPC Ticket Management System

A distributed ticket management system built with gRPC, Go, and PostgreSQL. This project demonstrates a complete microservices architecture with protocol buffers for service definitions, Docker containerization, and database persistence.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    gRPC     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    SQL     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   gRPC Client   β”‚ ◄────────► β”‚  Ticket Service β”‚ ◄───────► β”‚   PostgreSQL    β”‚
β”‚    (Port 50052) β”‚             β”‚   (Port 50051)  β”‚            β”‚   (Port 5432)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Components
  • gRPC Server (ticket-service-db/): Core ticket management service with PostgreSQL integration
  • gRPC Client (grpc-client/): Example client demonstrating API usage
  • PostgreSQL Database: Persistent storage for tickets with proper indexing
  • Protocol Buffers (proto/): Service definitions and data contracts

πŸš€ Features

  • CRUD Operations: Create, Read, Update, Delete tickets
  • Ticket Management:
    • Multiple status levels (Open, In Progress, Resolved, Closed)
    • Priority levels (Low, Medium, High, Critical)
    • Assignee and reporter tracking
    • Tagging system with JSON support
  • Database Integration: PostgreSQL with optimized indexes
  • Containerization: Full Docker Compose setup
  • Type Safety: Protocol Buffers for strongly-typed API contracts

πŸ› οΈ Technology Stack

  • Language: Go 1.23.2
  • RPC Framework: gRPC with Protocol Buffers
  • Database: PostgreSQL 15
  • Containerization: Docker & Docker Compose
  • Key Dependencies:
    • google.golang.org/grpc - gRPC framework
    • google.golang.org/protobuf - Protocol Buffers
    • github.com/lib/pq - PostgreSQL driver
    • github.com/google/uuid - UUID generation

πŸ“‹ Prerequisites

  • Docker and Docker Compose
  • Go 1.23+ (for local development)
  • Make (optional, for development scripts)

πŸš€ Quick Start

  1. Clone the repository:

    git clone <repository-url>
    cd gRPC
    
  2. Start all services:

    docker-compose up --build
    
  3. Verify services are running:

    • gRPC Server: localhost:50051
    • gRPC Client: localhost:50052
    • PostgreSQL: localhost:5432
Local Development
  1. Install dependencies:

    go mod download
    
  2. Start PostgreSQL (using Docker):

    docker-compose up ticket_db -d
    
  3. Set environment variables:

    export DB_HOST=localhost
    export DB_PORT=5432
    export DB_USER=ayushpandya
    export DB_PASSWORD=postgres
    export DB_NAME=ticketdb
    export DB_SSLMODE=disable
    
  4. Run the server:

    go run ticket-service-db/main.go
    
  5. Run the client (in another terminal):

    go run grpc-client/main.go
    

πŸ“‘ API Reference

Service Definition

The TicketService provides the following RPC methods:

service TicketService {
  rpc CreateTicket(CreateTicketRequest) returns (CreateTicketResponse);
  rpc GetTicket(GetTicketRequest) returns (GetTicketResponse);
  rpc ListTickets(ListTicketsRequest) returns (ListTicketsResponse);
  rpc UpdateTicket(UpdateTicketRequest) returns (UpdateTicketResponse);
  rpc DeleteTicket(DeleteTicketRequest) returns (DeleteTicketResponse);
}
Ticket Model
message Ticket {
  string id = 1;
  string title = 2;
  string description = 3;
  TicketStatus status = 4;
  TicketPriority priority = 5;
  string assignee_id = 6;
  repeated string tags = 7;
  google.protobuf.Timestamp created_at = 8;
  google.protobuf.Timestamp updated_at = 9;
}
Enums

TicketStatus: OPEN, IN_PROGRESS, RESOLVED, CLOSED

TicketPriority: LOW, MEDIUM, HIGH, CRITICAL

πŸ—„οΈ Database Schema

CREATE TABLE tickets (
    id VARCHAR(255) PRIMARY KEY,
    title VARCHAR(500) NOT NULL,
    description TEXT,
    status VARCHAR(50) NOT NULL DEFAULT 'OPEN',
    priority VARCHAR(50) NOT NULL DEFAULT 'MEDIUM',
    assignee_id VARCHAR(255),
    tags JSONB DEFAULT '[]',
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
    reporter_id VARCHAR(255) NOT NULL
);

πŸ”§ Configuration

Environment Variables
Variable Description Default
DB_HOST PostgreSQL host ticket_db
DB_PORT PostgreSQL port 5432
DB_USER Database user ayushpandya
DB_PASSWORD Database password postgres
DB_NAME Database name ticketdb
DB_SSLMODE SSL mode disable
Docker Compose Services
  • grpc-server: Ticket service (port 50051)
  • grpc-client: Example client (port 50052)
  • ticket_db: PostgreSQL database (port 5432)

πŸ§ͺ Testing

Using the Client

The included gRPC client demonstrates all available operations:

# Run the client to see example operations
docker-compose up grpc-client
Manual Testing with grpcurl
# List all tickets
grpcurl -plaintext localhost:50051 ticket.TicketService/ListTickets

# Get a specific ticket
grpcurl -plaintext -d '{"id": "ticket-id"}' localhost:50051 ticket.TicketService/GetTicket

πŸ“ Project Structure

gRPC/
β”œβ”€β”€ docker-compose.yaml          # Docker Compose configuration
β”œβ”€β”€ go.mod                       # Go module definition
β”œβ”€β”€ go.sum                       # Go module checksums
β”œβ”€β”€ init.sql                     # Database initialization script
β”œβ”€β”€ proto/
β”‚   └── ticket.proto            # Protocol Buffer definitions
β”œβ”€β”€ ticket-service-db/
β”‚   β”œβ”€β”€ Dockerfile              # Server container configuration
β”‚   └── main.go                 # gRPC server implementation
β”œβ”€β”€ grpc-client/
β”‚   β”œβ”€β”€ Dockerfile              # Client container configuration
β”‚   └── main.go                 # Example gRPC client
└── database/
    └── postgres.go             # Database repository layer

πŸ”„ Development Workflow

Regenerating Protocol Buffers

After modifying proto/ticket.proto:

protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    proto/ticket.proto
Building and Running
# Build all containers
docker-compose build

# Run in development mode
docker-compose up

# Run in background
docker-compose up -d

# View logs
docker-compose logs -f grpc-server

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL