# rajapremsai/microservices_using_go architecture

> Architecture diagram of the GitHub repository rajapremsai/microservices_using_go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rajapremsai/microservices_using_go
- Repository: https://github.com/rajapremsai/microservices_using_go

## Overview

##### Project Type and Purpose
- This is a Go-based microservices system with an API gateway.
- It implements three domain services (Account, Catalog, Order) communicating via gRPC, with a GraphQL gateway providing a unified HTTP API.
- It uses Docker Compose for deployment and separate databases per service (PostgreSQL and Elasticsearch).

##### File Structure
- Top-level directories:
- account/ – Account service code, protobuf definitions, Dockerfiles, SQL migrations
- catalog/ – Catalog service with protobuf, ES integration, Dockerfiles
- order/ – Order service depending on account/catalog services and PostgreSQL
- graphql/ – GraphQL gateway using gqlgen, resolvers, schema, Dockerfile
- Shared files: docker-compose.yaml orchestrates all containers; Makefile or scripts for building/testing.
- Each service has:
- cmd/<service>/main.go as entrypoint
- server.go, service.go, repository.go for service logic
- pb/ contains generated gRPC code from .proto
- client.go for calling other services (Order service depends on account/catalog)
- app.dockerfile and db.dockerfile for container images

##### README for Additional Insights
- Lists ports and technologies for each service.
- Emphasizes microservices pattern, GraphQL gateway, data stores, gRPC endpoints.
- Provides sample GraphQL queries/mutations, environment variables, and database schemas.

a. Main Components
- GraphQL Gateway (gqlgen)
- Account Service (Go + gRPC + PostgreSQL)
- Catalog Service (Go + gRPC + Elasticsearch)
- Order Service (Go + gRPC + PostgreSQL)
- Databases: Account DB, Order DB (both PostgreSQL), Catalog ES Cluster
- External Interfaces: GraphQL Playground, gRPC clients
b. Relationships & Data Flows
- Clients → HTTP → GraphQL Gateway
- Gateway → gRPC → Account, Catalog, Order services
- Order service → gRPC → Account, Catalog (to validate account and fetch product details)
- Each service → its own database
c. Architectural Patterns & Principles
- Microservices per bounded context (accounts, products, orders)
- API Gateway pattern implemented with GraphQL
- Database per service (encapsulation)
- gRPC for inter-service RPC and protobuf for contracts
- Separation of concerns: server, service logic, repository layers
d. Key Technologies/Frameworks
- Go modules (go.mod)
- gRPC/protobuf (account.proto, catalog.proto, order.proto)
- gqlgen for GraphQL gateway
- PostgreSQL, Elasticsearch
- Docker & Docker Compose

##### Elements
- Microservices (e.g., blue rectangles)
- API Gateway (e.g., orange rectangle)
- Annotations for ports, protocols (HTTP, gRPC), and major endpoints

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Client(("External Client")):::external

    %% API Gateway
    subgraph "API Gateway Layer"
        direction TB
        GraphQLGateway["GraphQL Gateway<br/>(Go, gqlgen, Port 8080)"]:::gateway
    end

    %% Microservices Layer
    subgraph "Services Layer"
        direction TB
        AccountSvc["Account Service<br/>(Go, gRPC, Port 8081)"]:::service
        CatalogSvc["Catalog Service<br/>(Go, gRPC, Port 8082)"]:::service
        OrderSvc["Order Service<br/>(Go, gRPC, Port 8083)"]:::service
    end

    %% Databases Layer
    subgraph "Datastores"
        direction TB
        AccountDB[(PostgreSQL<br/>Account DB)]:::db
        OrderDB[(PostgreSQL<br/>Order DB)]:::db
        CatalogES[(Elasticsearch<br/>Catalog ES)]:::db
    end

    %% Interactions
    Client -->|HTTP| GraphQLGateway
    GraphQLGateway -->|gRPC| AccountSvc
    GraphQLGateway -->|gRPC| CatalogSvc
    GraphQLGateway -->|gRPC| OrderSvc

    OrderSvc -->|gRPC| AccountSvc
    OrderSvc -->|gRPC| CatalogSvc

    AccountSvc -->|read/write| AccountDB
    OrderSvc -->|read/write| OrderDB
    CatalogSvc -->|read/write| CatalogES

    %% Click Events
    click GraphQLGateway "https://github.com/rajapremsai/microservices_using_go/tree/main/graphql/"
    click AccountSvc "https://github.com/rajapremsai/microservices_using_go/tree/main/account/"
    click CatalogSvc "https://github.com/rajapremsai/microservices_using_go/tree/main/catalog/"
    click OrderSvc "https://github.com/rajapremsai/microservices_using_go/tree/main/order/"
    click AccountDB "https://github.com/rajapremsai/microservices_using_go/blob/main/account/db.dockerfile"
    click OrderDB "https://github.com/rajapremsai/microservices_using_go/blob/main/order/db.dockerfile"
    click CatalogES "https://github.com/rajapremsai/microservices_using_go/blob/main/catalog/app.dockerfile"

    %% Styles
    classDef external fill:#E8F1FD,stroke:#1C7ED6,color:#1C7ED6;
    classDef gateway fill:#FFE8CC,stroke:#FF9F1C,color:#CC5200;
    classDef service fill:#D9E8FF,stroke:#228BE6,color:#1864AB;
    classDef db fill:#D8F5E0,stroke:#37B24D,color:#2B8A3E;
```
