# mochisuna/number-hit-bot architecture

> Architecture diagram of the GitHub repository mochisuna/number-hit-bot, 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/mochisuna/number-hit-bot
- Repository: https://github.com/mochisuna/number-hit-bot

## Overview

##### Project Overview
- This is a Go-based bot application for the Line messaging platform that implements a game, "number hit".
- The project follows a layered or hexagonal/clean architecture approach by organizing code into directories like "cmd" (entry points), "application" (game logic), "domain" (business logic and repository interfaces), "handler" (API or service handling), and "infrastructure" (external integrations like the Firestore database).

##### Main Components
a. Bot Entry Point:
- Located in cmd/bot/main.go, this component starts up the bot service and integrates with Line's API.
b. Application Layer:
- Found in the application directory (e.g., application/callback.go) that processes callbacks from the game or bot interactions.
c. Domain Layer:
- Resides in the domain directory with core business logic and interfaces (e.g., domain/user.go; domain/repository and domain/service).
- It defines core models and logic for operations such as managing users or callbacks.
d. Handlers:
- Present in the handler directory (e.g., handler/bot.go, handler/http.go) which route and process incoming bot actions and HTTP requests.
e. Infrastructure:
- The infrastructure directory (e.g., infrastructure/database/firestore.go, infrastructure/user.go) encapsulates external services/integrations like Firestore.
f. Configuration and Tools:
- _tools, config, and Docker-related files provide local & development configurations (firebase_auth.json, config.toml), Dockerfile, and docker-compose.yml, indicating containerized deployment.

##### Setting Up Relationships and Interactions
- The bot entry point (cmd/bot/main.go) initiates the service and connects to the handlers.
- Handlers capture incoming requests/callbacks from Line’s API and forward them to the Application and Domain layers.
- The Domain layer orchestrates the core game logic and interacts with the Infrastructure for persistence (Firestore) or external authentication.
- Dependencies flow from Infrastructure and external services back to the Domain, ensuring clean separation between business logic and framework/driver details.

##### Architectural Patterns & Technologies
- Clean/Hexagonal Architecture: Separation of concerns is evident with distinct application, domain, and infrastructure layers.
- Containerization: Dockerfile and docker-compose indicate that container deployment is supported.
- Firebase/Firestore: Integration for data persistence or authentication as seen in the Firebase config files under _tools.
- Go Modules: go.mod and go.sum denote dependency management in Go.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Layer
    subgraph "Entry Layer"
        BE("Bot Entry Point"):::entry
    end

    %% Handlers Layer
    subgraph "Handlers Layer"
        BH("Bot Handler"):::handlers
        HH("HTTP Handler"):::handlers
        AH("Action Handler"):::handlers
    end

    %% Application Layer
    subgraph "Application Layer"
        AL("Application Logic"):::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DU("Domain User"):::domain
        DR("Domain Repository"):::domain
        DS("Domain Service"):::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure/External Services"
        FS("Firestore Database"):::infrastructure
        IU("User Infrastructure"):::infrastructure
    end

    %% Deployment & Configuration
    subgraph "Deployment & Configuration"
        T("Tools"):::deployment
        C("Config"):::deployment
        Df("Dockerfile"):::deployment
        Dc("docker-compose"):::deployment
    end

    %% Connections from Entry Layer to Handlers
    BE -->|"initiates"| BH
    BE -->|"initiates"| HH
    BE -->|"initiates"| AH

    %% Handlers forwarding to Application Logic
    BH -->|"processes"| AL
    HH -->|"processes"| AL
    AH -->|"processes"| AL

    %% Application Layer calling Domain Layer
    AL -->|"calls"| DU
    AL -->|"calls"| DR
    AL -->|"calls"| DS

    %% Domain Layer interactions with Infrastructure
    DU -->|"persists"| FS
    DR -->|"reads/writes"| FS
    DS -->|"executes actions via"| IU
    FS -->|"returns data to"| DU

    %% Deployment & Configuration influencing the system
    T -->|"provides config"| FS
    C -->|"provides config"| DU
    Df -->|"builds"| BE
    Dc -->|"deploys"| BE

    %% Styles
    classDef entry fill:#f9f,stroke:#333,stroke-width:2px;
    classDef handlers fill:#bbf,stroke:#333,stroke-width:2px;
    classDef application fill:#bfb,stroke:#333,stroke-width:2px;
    classDef domain fill:#ffb,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#fdb,stroke:#333,stroke-width:2px;
    classDef deployment fill:#dfd,stroke:#333,stroke-width:2px;

    %% Click Events
    click BE "https://github.com/mochisuna/number-hit-bot/blob/master/cmd/bot/main.go"
    click BH "https://github.com/mochisuna/number-hit-bot/blob/master/handler/bot.go"
    click HH "https://github.com/mochisuna/number-hit-bot/blob/master/handler/http.go"
    click AH "https://github.com/mochisuna/number-hit-bot/blob/master/handler/action.go"
    click AL "https://github.com/mochisuna/number-hit-bot/blob/master/application/callback.go"
    click DU "https://github.com/mochisuna/number-hit-bot/blob/master/domain/user.go"
    click DR "https://github.com/mochisuna/number-hit-bot/tree/master/domain/repository"
    click DS "https://github.com/mochisuna/number-hit-bot/tree/master/domain/service"
    click FS "https://github.com/mochisuna/number-hit-bot/blob/master/infrastructure/database/firestore.go"
    click IU "https://github.com/mochisuna/number-hit-bot/blob/master/infrastructure/user.go"
    click T "https://github.com/mochisuna/number-hit-bot/tree/master/_tools"
    click C "https://github.com/mochisuna/number-hit-bot/blob/master/config/config.go"
    click Df "https://github.com/mochisuna/number-hit-bot/tree/master/Dockerfile"
    click Dc "https://github.com/mochisuna/number-hit-bot/blob/master/docker-compose.yml"
```
