How kodaimura/goat works
Main Components
• Command-Line Interface (CLI) Tools: Include the “goat” binary used to scaffold projects and the “gent” tool (found under template/cmd/gent) for auto-generating model and repository code.
• Web Application Core:
• Frontend/Web Layer: Represented by the template/web folder, which contains static assets (CSS, JavaScript, images) and HTML templates for rendering interfaces.
• API/Controller Layer: The “template/internal/controller” directory contains controllers (for example, account.go and index.go) that receive HTTP requests routed from the front-end.
• Service/Business Logic Layer: The “template/internal/service” directory implements business logic (account.go, common.go) that the controllers call upon.
• Data Access Layer (Repository): Located in “template/internal/repository” for database interactions.
• Models & DTOs: Models (template/internal/model) and Data Transfer Objects (template/internal/dto) represent domain data and data structures for data flow.
• Middleware and Security: Middleware (template/internal/middleware) for request processing and the JWT module in “template/internal/core/jwt” for authentication.
• Platform Core and Utilities:
• Core utilities such as logging (“template/internal/core/logger”), error handling (“template/internal/core/errs”), email sending (“template/internal/core/mail”), and common utilities (“template/internal/core/utils”).
• Configuration: The configuration files and environment variables are stored under template/config and template/config/env.
• Server and Routing: The “template/internal/server” directory encapsulates the HTTP server startup and route definitions.
• Database Modules: Although the core application code is stored under the “template” directory, the project provides separate “template_sub” directories for different database engines (MySQL, PostgreSQL, SQLite3). Each has its Dockerfile, configuration, SQL scripts, and a repository implementation, representing an interchangeable persistence layer.
Relationships and Data Flow
• A layered flow starting from an HTTP request sent by a client via the web layer.
• The request flows into the Controller layer, which then calls the Service layer.
• The Service layer interacts with the Repository (data access) layer that talks to a Database backend (one of the supported databases).
• The response flows back from the Repository to the Service, then to the Controller, and eventually back to the client.
Important Architectural Patterns
• Layered (or n-tier) Architecture: Illustrate separation between presentation (web), business logic (services), and persistence (repositories/databases).
• Modular Components: Show how modules such as configuration, logging, JWT, and emailing are integrated. Also, highlight the flexibility provided by the multi-database support in the “template_sub” hierarchy.
• Separation of Concerns: Clearly mark out different components so that each has a well-defined responsibility (controllers for handling web requests, services for operations, etc.).
• Use of CLI for scaffolding projects and automatic code generation (gent) to keep the infrastructure flexible and DRY.
Technologies, Frameworks, and Tools
• Go (with the Gin framework) for HTTP server, routing, and controllers.
• Built-in tools: “gent” for automatic code generation.
• Any tooling or configuration management (Makefile scripts and configuration files) can be depicted as supporting elements.