# akash-aman/microservice architecture

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

- Interactive diagram: https://gitdiagram.com/akash-aman/microservice
- Repository: https://github.com/akash-aman/microservice

## Overview

##### Main Components to Highlight
- Shared Packages: Represent the common “pkg” directory, which contains utilities like database access, service discovery, different networking protocols (gRPC, HTTP, WebSocket), logging, OpenTelemetry instrumentation, and workerpool implementations.
- External Dependencies: Mark external service integrations such as Consul for service discovery, Kafka for messaging, and third-party libraries (Viper, Ants, Fx, etc.) that are used in initialization and runtime.
- Infrastructure and Observability: Use dedicated modules for infrastructure (bulk-factory, scheduler, states) and observability (OpenTelemetry – with metrics, logs, and tracing; various loggers like Zap, Logrus, and Zerolog) as core architectural elements.
- Configuration & Deployment: Include components like the Dockerfile, docker-compose, and the configuration files located in the “conf” directory that facilitate deployment and setup.

##### Relationships and Interactions
- Interactions between the “app” layer (the actual business-logic implementation including versioned API endpoints for “get_all” and “get_by_id”), infrastructure elements (like schedulers or bulk-factory processors), and the underlying database/ORM (using Ent).
- Communication channels for real-time and asynchronous processing: include WebSocket modules and Kafka messaging flows where applicable, along with workerpool management including custom implementations for adapting fixed or adaptive workloads.

##### Architectural Patterns and Design Principles
- Modularity & Reusability: Emphasize the modular nature of shared “pkg” components reused by multiple services.
- Dependency Injection/Initialization: Call out the use of frameworks like Fx that manage the lifecycle of service components.

##### Relevant Technologies and How They Fit
- Golang: Underlies the entire project.
- Echo: Represent as the HTTP server component providing RESTful endpoints.
- Ent and gqlgen: Include these near the ORM and GraphQL layers respectively.
- WebSocket: Detail both the “gobwas” and “gorilla” implementations available to the service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Products Service Subgraph
    subgraph "Products Service"
        Inits["Inits (Initialization Scripts)"]
        subgraph "API Layer"
            Echo["Echo Server (HTTP)"]
            ProdAPIs["Products APIs (REST)"]
            GRPCProd["GRPC Service"]
            GraphQLProd["GraphQL API"]
        end
        Core["Core Business Logic"]
        subgraph "Data Access"
            SQLCConfig["SQLC Config"]
            SQLCData["SQLC Data"]
            Ent["Ent ORM"]
        end
        subgraph "Infrastructure"
            Bulk["Bulk-factory"]
            Sched["Scheduler"]
            States["States"]
        end
    end

    %% Inventory Service Subgraph
    subgraph "Inventory Service"
        Inventory["Inventory Service"]
    end

    %% Shared Packages
    SharedPkg["Common Libraries & Utilities (pkg)"]

    %% External Dependencies and Integrations
    GRPCUtil["GRPC Utilities"]
    GraphQLCfg["GraphQL Config"]
    KafkaMsg["Kafka Messaging"]
    Discovery["Service Discovery (Consul)"]
    Logger["Logger (Zap,Logrus,Zerolog)"]
    Otel["OpenTelemetry"]
    Workerpool["Workerpool"]

    %% Configuration & Deployment
    subgraph "Configuration & Deployment"
        Dockerfile["Dockerfile"]
        DockerCompose["docker-compose.yml"]
        ServiceConf["Service Configs"]
    end

    %% Internal Connections within Products Service
    Inits --> Echo
    Inits --> ProdAPIs
    Inits --> GRPCProd
    Inits --> GraphQLProd

    Echo --> Core
    ProdAPIs --> Core
    GRPCProd --> Core
    GraphQLProd --> Core

    Core --> SQLCConfig
    Core --> SQLCData
    Core --> Ent

    SQLCConfig --> Bulk
    SQLCConfig --> Sched
    SQLCConfig --> States

    SQLCData --> Bulk
    SQLCData --> Sched
    SQLCData --> States

    Ent --> Bulk
    Ent --> Sched
    Ent --> States

    %% External Integrations for Products Service
    Inits --> GRPCUtil
    GraphQLProd --> GraphQLCfg
    Core --> Logger
    Core --> Otel
    Inits --> Discovery
    Inits --> SharedPkg
    Core --> Workerpool

    %% Communication between Products and Inventory via Kafka
    Core --> KafkaMsg
    KafkaMsg --> Inventory

    %% Configuration influences startup
    Dockerfile --> Inits
    DockerCompose --> Inits
    ServiceConf --> Inits

    %% Click Events
    click Inits "https://github.com/akash-aman/microservice/tree/main/internal/services/products/app/inits"
    click Inventory "https://github.com/akash-aman/microservice/tree/main/internal/services/inventory"
    click SharedPkg "https://github.com/akash-aman/microservice/tree/main/internal/pkg"
    click SQLCConfig "https://github.com/akash-aman/microservice/blob/main/internal/services/products/sqlc.yml"
    click SQLCData "https://github.com/akash-aman/microservice/tree/main/internal/services/products/app/data"
    click Ent "https://github.com/akash-aman/microservice/tree/main/internal/services/products/cgfx/ent"
    click Echo "https://github.com/akash-aman/microservice/blob/main/internal/pkg/http/server/echo.go"
    click ProdAPIs "https://github.com/akash-aman/microservice/tree/main/internal/services/products/app/apis"
    click GRPCUtil "https://github.com/akash-aman/microservice/tree/main/internal/pkg/grpc"
    click GRPCProd "https://github.com/akash-aman/microservice/blob/main/internal/services/products/app/grpc/server/products_service.go"
    click GraphQLCfg "https://github.com/akash-aman/microservice/blob/main/internal/pkg/gql/config.go"
    click GraphQLProd "https://github.com/akash-aman/microservice/tree/main/internal/services/products/cgfx/gql"
    click KafkaMsg "https://github.com/akash-aman/microservice/blob/main/internal/pkg/kafka/kafka.go"
    click Discovery "https://github.com/akash-aman/microservice/blob/main/internal/pkg/discovery/consul.go"
    click Logger "https://github.com/akash-aman/microservice/tree/main/internal/pkg/logger"
    click Otel "https://github.com/akash-aman/microservice/tree/main/internal/pkg/otel"
    click Workerpool "https://github.com/akash-aman/microservice/tree/main/internal/pkg/workerpool"
    click Bulk "https://github.com/akash-aman/microservice/tree/main/internal/services/products/app/infra/bulk-factory"
    click Sched "https://github.com/akash-aman/microservice/tree/main/internal/services/products/app/infra/scheduler"
    click States "https://github.com/akash-aman/microservice/tree/main/internal/services/products/app/infra/states"
    click Dockerfile "https://github.com/akash-aman/microservice/tree/main/Dockerfile"
    click DockerCompose "https://github.com/akash-aman/microservice/blob/main/docker-compose.yml"
    click ServiceConf "https://github.com/akash-aman/microservice/tree/main/internal/services/products/conf"

    %% Styles
    class Inits,Core,Echo,ProdAPIs,GRPCProd,GraphQLProd,SQLCConfig,SQLCData,Ent productsService
    class Inventory inventory
    class SharedPkg shared
    class GRPCUtil,GraphQLCfg,KafkaMsg,Discovery,Logger,Otel,Workerpool external
    class Bulk,Sched,States infra
    class Dockerfile,DockerCompose,ServiceConf config

    %% Class Definitions
    classDef productsService fill:#AED6F1,stroke:#1B4F72,stroke-width:2px
    classDef inventory fill:#FADBD8,stroke:#922B21,stroke-width:2px
    classDef shared fill:#F9E79F,stroke:#B7950B,stroke-width:2px
    classDef external fill:#D2B4DE,stroke:#6C3483,stroke-width:2px
    classDef infra fill:#ABEBC6,stroke:#1E8449,stroke-width:2px
    classDef config fill:#FDEBD0,stroke:#D35400,stroke-width:2px
```
