How mochisuna/ssh-mysql-sample works
Project Type & Purpose
• This is a Go-based sample application that establishes an SSH connection to a bastion host and then sends database (MySQL) requests to a target server.
• The functionality is triggered via the command line (see cmd/app/main.go) with configuration parameters specified in TOML files (located in _tools/config/{env}/conf.toml).
File Structure & Identify Main Components
• Entry Point/CLI Application:
– Located in the cmd/app directory (main.go) which parses command-line flags (store_id and environment).
• Configuration:
– The _tools/config folder contains different environment setups (dev, stg, prd) using TOML files.
– Also a config directory contains config.go which may be used as a runtime configuration loader.
• Domain Layer:
– The domain directory encapsulates the business logic:
• domain/store.go: Likely represents the core Store entity.
• domain/service/store.go: Contains business service logic related to store operations.
• domain/repository/store.go: Deals with persistence or data retrieval strategies for the store.
• Application Layer:
– The application directory (e.g., application/store.go) might contain a sample implementation that ties together various domain services.
• Handlers:
– The handler folder (handler/handler.go and handler/store.go) – they may expose the interface endpoints (for example, if this was integrated with a web handler or serving as a facade for CLI command execution).
• Infrastructure (Infra):
– The infra directory contains support for external services:
• infra/ssh/ssh.go: Manages the SSH connection to the bastion server.
• infra/mysql/mysql.go: Handles connections/queries to the MySQL database.
• infra/store.go: Likely provides an implementation that brings together SSH and MySQL actions, possibly acting as an adapter between domain logic and external systems.
Relationships & Data Flow
• The CLI (cmd/app/main.go) initializes the application by parsing parameters and setting up the environment-specific configuration.
• The main application routes calls to the handler layer, which then interacts with the domain layer (services and repositories) for business logic.
• The domain repository/service interacts with the infrastructure layer to establish an SSH tunnel (via infra/ssh) and execute MySQL operations (via infra/mysql and infra/store).
• The configuration is loaded early (from the config or _tools/config files) and injected into various components as needed.
Architectural Patterns & Principles
• Use of a layered architecture (possibly Clean Architecture or Hexagonal Architecture):
– Presentation/Handler layer
– Application/Domain layer
– Infrastructure layer
• Separation of concerns: Each directory (handler, domain, infra) is dedicated to a specific area of responsibility.
• Environment-specific configuration is managed externally via TOML files, indicating a focus on flexibility and deployment portability.
Relevant Technologies/Frameworks
• Go (the project's language with modules indicated by go.mod/go.sum)
• TOML for configuration management.
• SSH for secure tunneling.
• MySQL as the database backend.