Skip to content

Microservices Project - Uses Golang, gRPC, GraphQL, Postgres, Elasticsearch, Docker Compose

Notifications You must be signed in to change notification settings

bianavic/go-microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gRPC Microservices Project with GraphQL API

This project demonstrates a microservices architecture using gRPC for inter-service communication and GraphQL as the API gateway. It includes services for account management, product catalog, and order processing.

microservice.png

Project Structure

The project consists of the following main components:

  • Account Service
  • Catalog Service
  • Order Service
  • GraphQL API Gateway

Each service has its own database:

  • Account and Order services use PostgreSQL
  • Catalog service uses Elasticsearch

project-structure.png

Getting Started

  1. Clone the repository:

    git clone <https://github.com/bianavic/go-microservice.git>
    cd <go-microservice>
    
  2. Start the services using Docker Compose:

    docker-compose up -d --build
    
  3. Access the GraphQL playground at http://localhost:8000/playground

Create an Account

mutation {
  createAccount(account: {name: "New Account 1"}) {
    id
    name
  }
}

Response

{
  "data": {
    "createAccount": {
      "id": "351EYSISpLmj80FtdVBxK3xGFy7",
      "name": "New Account 1"
    }
  }
}

Query Accounts

query {
  accounts {
    id
    name
  }
}

Response

{
  "data": {
    "accounts": [
      {
        "id": "351jWooTazORjuLqlN5QCSoBiSO",
        "name": "New Account 2"
      },
      {
        "id": "351jHF16EuftmBnEoHHDRLzYt3K",
        "name": "New Account 1"
      }
    ]
  }
}

Create a Product

mutation {
  createProduct(product: {name: "New Product 1", description: "A new product 1", price: 19.99}) {
    id
    name
    price
  }
}

Response

{
  "data": {
    "createProduct": {
       "id": "351fvBgwUN46Dzh2kej9MPOR9HM",
      "name": "New Product 1",
      "price": 19.99
    }
  }
}

Query Products

query {
    products {
        id
        name
        price
    }
}

Response

{
  "data": {
    "products": [
      {
        "id": "351fvBgwUN46Dzh2kej9MPOR9HM",
        "name": "New Product 1",
        "price": 19.99
      },
      {
        "id": "351jHVm8nTUU0zLvK3JR4Mxl6am",
        "name": "New Product 1",
        "price": 19.99
      }
    ]
  }
}

Create an Order

mutation {
  createOrder(order: {
    accountId: "351jHF16EuftmBnEoHHDRLzYt3K", 
    products: [{id: "351fvBgwUN46Dzh2kej9MPOR9HM", quantity: 2}]}) {
    id
    totalPrice
    products {
      name
      quantity
    }
  }
}

Response

{
  "data": {
    "createOrder": {
      "id": "351jbVAyl9fUskE9dYYgk43xa5t",
      "totalPrice": 39.98,
      "products": []
    }
  }
}

Query Account with Orders

query {
  accounts(id: "351jHF16EuftmBnEoHHDRLzYt3K") {
    name
    orders {
      id
      createdAt
      totalPrice
      products {
        name
        quantity
        price
      }
    }
  }
}

Response

{
  "data": {
    "accounts": [
      {
        "name": "New Account 1",
        "orders": [
          {
            "id": "351jbVAyl9fUskE9dYYgk43xa5t",
            "createdAt": "2025-11-04T20:07:40.499766593Z",
            "totalPrice": 39.98,
            "products": [
              {
                "name": "New Product 1",
                "quantity": 2,
                "price": 19.99
              }
            ]
          }
        ]
      }
    ]
  }
}

Pagination and Filtering

query {
  products(pagination: {skip: 0, take: 5}, query: "New") {
    id
    name
    description
    price
  }
}

Response

{
  "data": {
    "products": [
      {
        "id": "351fvBgwUN46Dzh2kej9MPOR9HM",
        "name": "New Product 1",
        "description": "A new product 1",
        "price": 19.99
      },
      {
        "id": "351jHVm8nTUU0zLvK3JR4Mxl6am",
        "name": "New Product 1",
        "description": "A new product 1",
        "price": 19.99
      }
    ]
  }
}

Calculate Total Spent by an Account

query {
  accounts(id: "351jHF16EuftmBnEoHHDRLzYt3K") {
    name
    orders {
      totalPrice
    }
  }
}

Response

{
  "data": {
    "accounts": [
      {
        "name": "New Account 1",
        "orders": [
          {
            "totalPrice": 39.98
          }
        ]
      }
    ]
  }
}

About

Microservices Project - Uses Golang, gRPC, GraphQL, Postgres, Elasticsearch, Docker Compose

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published