How tadrianonet/go-clean-arch-generator works
Main Components
• Code Generator Core
– The central executable (main.go) coordinates the code generation flow.
– It receives command-line input (the project name) and triggers template rendering.
• Template Engine and Template Assets
– The “templates” directory holds the predefined templates (e.g., cmd_main.tmpl, dependencies.tmpl, entities_user.tmpl, etc.).
– This component reads the templates and injects relevant project-specific details.
• Generated Project Structure (Output)
– The generator outputs a new project with a typical Clean Architecture layout:
• cmd/ (entry-point with main.go)
• internal/ containing subdirectories for entities, infra (e.g., OpenTelemetry, database configuration), usecases (business logic), interfaces (handlers and repository interfaces), and repositories (implementations).
• Additional files like requests.http (for API testing) and the pre-configured .gitignore.
• Executables and Build Artifacts
– The “executables” folder includes pre-built binaries (e.g., clean-arch-generator.exe) for different platforms.
• External Dependencies and Configuration
– Dependencies (as defined in go.mod) include libraries for OpenTelemetry, among others.
– The README and provided templates indicate that pre-commit hooks and linting configurations are also part of the setup.
Component Relationships and Data Flow
• The user invokes the generator (via CLI) which then:
– Processes command-line input (project name).
– Calls the Template Engine to generate files based on the provided templates.
– Writes out the generated project structure (with folders like cmd, internal, etc.) to disk.
• Within the generated project, the components interact based on Clean Architecture:
– The cmd layer initializes the application and sets up dependency injection.
– The internal layer houses the core business logic, segregated into entities, usecases, and interfaces.
– Handlers in the interfaces directory communicate with the usecase layer, and the repositories provide the concrete persistence implementations.
Architectural Patterns and Technologies
• Clean Architecture
– The partitions into entities, usecases, interfaces, and repositories clearly exemplify the Clean Architecture separation of concerns.
• Template-Driven Code Generation
– The system leverages a series of Go template files to dynamically produce boilerplate code.
• Go Ecosystem and OpenTelemetry
– The tool is built with Go (using go.mod, main.go).
– Pre-integrated OpenTelemetry tools and the mentioned zipkin setup are key features for observability within the generated projects.
• CLI-based Interaction
– The generator is invoked via command-line, taking parameters and driving the file generation process.