# z9905080/slot-framework architecture

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

- Interactive diagram: https://gitdiagram.com/z9905080/slot-framework
- Repository: https://github.com/z9905080/slot-framework

## Overview

##### Main Components
- Game Logic Service – Found in the folder “internal/game_logic”. This service has its own domain, implementation, interfaces (including GRPC adapters), and use cases.
- Gateway Service – Located under “internal/gateway”. This acts as an intermediary that coordinates between external inputs and the back-end services. It too is organized with domain, repository, implementation, and use case layers.
- Player Service – Housed in “internal/player”. Similar architectural subdivision into domain, adapter (using GRPC), handler, and use case components.
- Common Packages – The “pkg” directory contains shared modules such as definitions, logging, encoding, microservice providers (with a Consul registry provider), and protobuf definitions which facilitate inter-service communication.
- Executable Commands – The “cmd” directory holds the entry point files for running each service (game_logic.go, gateway.go, and player.go) plus a root command.
- Configuration & Environment – “environment” contains configuration settings (e.g., config.go and JSON configuration files under “dev”) ensuring that environment-specific settings are clearly separated.

##### Relationships and Interactions
- Direct interactions exist between the Gateway and other services (Game Logic and Player), likely through defined GRPC or HTTP APIs provided in the adapter layers.
- Shared infrastructure such as logging and microservice registries (Consul) suggest that each microservice is discoverable and can report its status via the common “pkg/micro_service” packages.
- Communication is facilitated by protobuf interfaces defined in “pkg/protobuf”, indicating that the services interact using defined contracts.
- The flow might be: a client sends requests to the Gateway, which then coordinates with the Game Logic and Player services. Each service handles its business logic through well-separated, layered components (domain, use cases, and adapters).

##### Architectural Patterns and Design Principles
- Domain-Driven Design (DDD) evident from separate domains, entities, services, and interfaces in each service.
- Microservices architecture – each component (Game Logic, Gateway, Player) is clearly segregated with its own lifecycle and entry point.
- Clean separation of concerns – Each module (domain, adapter, implementation, usecase) has a clear responsibility.
- Use of external libraries and frameworks for logging, microservice registration, and message/contract handling (protobuf).

## Diagram (Mermaid)

```mermaid
graph TD
    Client("Client Request"):::external

    Client -->|"HTTP"| GW_Entry

    subgraph "Gateway Service"
        GW_Entry("Entry: gateway.go"):::entry
        GW_Domain("Domain Layer"):::domain
        GW_UseCase("UseCase Layer"):::usecase
        GW_Adapter("API Adapter Layer"):::adapter
        GW_Impl("Implementation"):::infra

        GW_Entry --> GW_Domain
        GW_Domain --> GW_UseCase
        GW_UseCase --> GW_Adapter
        GW_Adapter --> GW_Impl
    end

    subgraph "Game Logic Service"
        GL_Entry("Entry: game_logic.go"):::entry
        GL_Domain("Domain Layer"):::domain
        GL_UseCase("UseCase Layer"):::usecase
        GL_Adapter("GRPC Adapter"):::adapter
        GL_Impl("Implementation"):::infra

        GL_Entry --> GL_Domain
        GL_Domain --> GL_UseCase
        GL_UseCase --> GL_Adapter
        GL_Adapter --> GL_Impl
    end

    subgraph "Player Service"
        P_Entry("Entry: player.go"):::entry
        P_Domain("Domain Layer"):::domain
        P_UseCase("UseCase Layer"):::usecase
        P_Adapter("GRPC Handler/Adapter"):::adapter
        P_Impl("Implementation"):::infra

        P_Entry --> P_Domain
        P_Domain --> P_UseCase
        P_UseCase --> P_Adapter
        P_Adapter --> P_Impl
    end

    subgraph "Shared Infrastructure"
        CP("Common Packages"):::common
        EC1("Config: config.go"):::common
        EC2("Dev Config: config.json"):::common
    end

    %% Inter-service communications
    GW_Adapter -->|"GRPC"| GL_Adapter
    GW_Adapter -->|"GRPC"| P_Adapter

    %% Service to Shared Infrastructure
    GL_Impl --> CP
    GL_Impl --> EC1
    GL_Impl --> EC2

    GW_Impl --> CP
    GW_Impl --> EC1
    GW_Impl --> EC2

    P_Impl --> CP
    P_Impl --> EC1
    P_Impl --> EC2

    %% Styles
    classDef external fill:#ffebcd,stroke:#000,stroke-width:2px;
    classDef entry fill:#FFD700,stroke:#B8860B,stroke-width:1px;
    classDef domain fill:#FFA07A,stroke:#CD5C5C,stroke-width:1px;
    classDef usecase fill:#87CEFA,stroke:#4682B4,stroke-width:1px;
    classDef adapter fill:#98FB98,stroke:#2E8B57,stroke-width:1px;
    classDef infra fill:#DDA0DD,stroke:#9932CC,stroke-width:1px;
    classDef common fill:#FFE4B5,stroke:#CD853F,stroke-width:1px;

    %% Click Events
    click GL_Impl "https://github.com/z9905080/slot-framework/tree/main/internal/game_logic"
    click GL_Entry "https://github.com/z9905080/slot-framework/blob/main/cmd/game_logic.go"
    click GW_Impl "https://github.com/z9905080/slot-framework/tree/main/internal/gateway"
    click GW_Entry "https://github.com/z9905080/slot-framework/blob/main/cmd/gateway.go"
    click P_Impl "https://github.com/z9905080/slot-framework/tree/main/internal/player"
    click P_Entry "https://github.com/z9905080/slot-framework/blob/main/cmd/player.go"
    click CP "https://github.com/z9905080/slot-framework/tree/main/pkg"
    click EC1 "https://github.com/z9905080/slot-framework/blob/main/environment/config.go"
    click EC2 "https://github.com/z9905080/slot-framework/blob/main/environment/dev/config.json"
```
