# tadrianonet/go-clean-arch-generator architecture

> Architecture diagram of the GitHub repository tadrianonet/go-clean-arch-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tadrianonet/go-clean-arch-generator
- Repository: https://github.com/tadrianonet/go-clean-arch-generator

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Code Generator Process
    subgraph "Code Generator Process"
        CLI["CLI Input"]:::generator
        GenCore["Generator Core"]:::generator
        TempEngine["Template Engine"]:::generator
        TemplatesRepo["Template Assets Repository"]:::generator
        Exec["Executables and Build Artifacts"]:::generator
    end
    CLI -->|"providesName"| GenCore
    GenCore -->|"triggers"| TempEngine
    TempEngine -->|"readsTemplates"| TemplatesRepo
    GenCore -->|"builds"| Exec
    TempEngine -->|"generates"| GP

    %% Generated Project Structure
    GP["Generated Project Structure"]:::project
    GP -->|"includes"| GoMod["go.mod"]:::dependency
    GP -->|"includes"| GitIgnore[".gitignore"]:::dependency

    %% Clean Architecture Layers within Generated Project
    subgraph "Clean Architecture Layers"
        CMD["cmd Layer"]:::project
        ENT["entities"]:::project
        UC["usecases"]:::project
        INTF["interfaces"]:::project
        REPO["repositories"]:::project
        INF["infra (OpenTelemetry,DB)"]:::project
        REQ["requests.http (API Testing)"]:::project
    end
    GP --> CMD
    GP --> ENT
    GP --> UC
    GP --> INTF
    GP --> REPO
    GP --> INF
    GP --> REQ

    %% Interactions within Clean Architecture Layers
    CMD -->|"calls"| UC
    UC -->|"calls"| REPO
    INTF -->|"communicates"| UC

    %% Click Events
    click GenCore "https://github.com/tadrianonet/go-clean-arch-generator/blob/main/main.go"
    click TemplatesRepo "https://github.com/tadrianonet/go-clean-arch-generator/tree/main/templates/"
    click Exec "https://github.com/tadrianonet/go-clean-arch-generator/tree/main/executables/"
    click GoMod "https://github.com/tadrianonet/go-clean-arch-generator/blob/main/go.mod"
    click GitIgnore "https://github.com/tadrianonet/go-clean-arch-generator/blob/main/.gitignore"

    %% Class Definitions
    classDef generator fill:#f9c,stroke:#333,stroke-width:2px;
    classDef project fill:#ccf,stroke:#333,stroke-width:2px;
    classDef dependency fill:#afa,stroke:#333,stroke-width:2px;
```
