Skip to content

IgweDaniel/lithium

Repository files navigation

Product Microservice

This project implements a microservice for managing products and subscription plans using gRPC, Golang, and GORM. The microservice is designed to handle various types of products, each with specific fields and associated subscription plans.

Table of Contents

Overview

The microservice exposes the following gRPC services:

  • ProductService: Manages products with endpoints to create, retrieve, update, delete, and list products.
  • SubscriptionService: Manages subscription plans associated with products, providing endpoints to create, retrieve, update, delete, and list subscription plans.

Setup Instructions

  1. Clone the repository:

    git clone https://github.com/yourusername/github.com/IgweDaniel/lithium.git
    cd github.com/IgweDaniel/lithium
    
  2. Install dependencies:

    go mod tidy
    
  3. Set up the database:

    • Ensure you have a SQL-based database (PostgreSQL or MySQL) running.
    • Update the database connection settings in pkg/db/connection.go.
  4. Copy the example environment file and update the environment variables:

    cp .env.example .env

Running the gRPC Server

To run the gRPC server, execute the following command:

go run cmd/server/main.go

The server will start listening for incoming gRPC requests.

Docker Setup

There are two ways to run the application with Docker Compose:

  1. Development Setup (only runs PostgreSQL):
    make dev/compose
  2. Full Application Setup (only runs PostgreSQL):
    docker compose up -d
    
    This will start both the application and PostgreSQL database with the following configuration:
    - Application runs on port 8080
    - PostgreSQL runs on port 5432
    - Default database name: lithium
    - Default database user: postgres
    - Default database password: postgres
    
  3. View logs (only runs PostgreSQL):
    docker compose logs -f
    

Example gRPC Client Calls

To interact with the gRPC services, you can use the proto-gen command in the Makefile to generate client stubs. Here’s an example of how to call the CreateProduct method:

  1. Generate the gRPC client code:

    make proto-gen
    
  2. Use the generated client in your application to make calls to the gRPC server.

    conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())
    if err != nil {
        log.Fatalf("did not connect: %v", err)
    }
    defer conn.Close()
    
    client := pb.NewProductServiceClient(conn)
    
    createRequest := &pb.CreateProductRequest{
        Name:  "New Product",
        Price: 25.0,
    }
    
    createResp, err := client.CreateProduct(context.Background(), createRequest)
    if err != nil {
        log.Fatalf("could not create product: %v", err)
    }
    log.Printf("Product created: %v", createResp.Product)

Assumptions and Constraints

  • The microservice is designed to be scalable and maintainable, following clean architecture principles.
  • Proper error handling and data validation are implemented.
  • The project is dockerized for easy deployment (see Dockerfile for instructions).

Feel free to explore the codebase and contribute to the project!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published