How mochisuna/number-hit-bot works
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.