# neozhu/cleanarchitecturecodegenerator architecture

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

- Interactive diagram: https://gitdiagram.com/neozhu/cleanarchitecturecodegenerator
- Repository: https://github.com/neozhu/cleanarchitecturecodegenerator

## Overview

##### Project type and purpose
- This is a Visual Studio Extension (VSIX) whose purpose is to scaffold Clean Architecture layers and code artifacts in C# (and optionally TypeScript) by generating files and folders using user-selected templates.
- Key indicators: presence of `.vsixmanifest`, `source.extension.cs`, `CodeGeneratorPackage.cs`, `.xaml` dialog, and a large `Templates` tree.

##### File structure
- Top-level “src” folder contains:
- Package entry point (`source.extension.cs`, `source.extension.vsixmanifest`, `CleanArchitectureCodeGenerator.csproj`)
- Command & UI (`FileNameDialog.xaml` + code-behind)
- Services (e.g., `GenerationService.cs`, `IntellisenseWriter.cs`)
- Helpers (VS integration, logging, utility, project interrogation)
- Models (IntelliSense parser and object abstractions)
- Templatemap and raw `Templates` directory of `.txt` files
- Build and CI: GitHub workflows, Appveyor, `CleanArchitectureCodeGenerator.sln`.

##### Extract architecture insights from README
- The extension registers a Solution Explorer context-menu command (Shift+F2).
- It opens a modal dialog to capture entity/folder input.
- On confirmation, it parses the target project’s code, selects templates, and writes new files following Clean Architecture conventions.
- It supports C#, VB, Razor, HTML, JSON, Markdown templates, plus TypeScript `.d.ts` generation.

##### Main components & their interactions
a. Visual Studio Host
- Loads the VSIX Package at startup.
- Provides APIs for Solution Explorer integration, command routing, and project file I/O.
b. VSIX Package (`CodeGeneratorPackage`)
- Registers the context-menu command (Shift+F2).
- Provides MEF composition and services registration.
c. UI Layer (`FileNameDialog`)
- A WPF dialog (MVVM-style) that gathers the entity name, folder path, and options.
- Binds user inputs to the generation request model.
d. Orchestrator (`GenerationService`)
- Coordinates: parsing the existing code base (IntellisenseParser → IntellisenseObject/Type/Property models), template selection (Templatemap), and output writing (IntellisenseWriter).
e. Helpers
- `VSHelpers`, `ProjectHelpers`: locate projects, add files/folders to the `.csproj`.
- `Logger`, `Utility`: logging and string/path manipulations.
f. Models/Parser
- Parse existing code via Roslyn or VS Intellisense APIs into typed models.
- Provide metadata (properties, types) for template tokens.
g. Template Engine
- Templatemap: maps feature types (Commands, DTOs, Queries, EventHandlers, Pages) to `.txt` templates.
- The engine does token replacement and generates code strings.
h. Output Layer (`IntellisenseWriter`)
- Persists generated code to disk.
- Updates the project file via VS APIs to include new items.
i. Distribution & CI
- GitHub Actions / Appveyor: build and package VSIX.
- Hosted on Visual Studio Marketplace / VSIX Gallery.

1. User → 2. VS Host → 3. VSIX Package → 4. UI Dialog → 5. GenerationService orchestrator → 6a. Parser (Models) & 6b. Template Engine → 7. Writer → 8. Project File System/Project
- External systems at the periphery (GitHub Actions CI, Marketplace).
- MVVM boundary between UI and services.

##### Architectural patterns & principles
- Plugin architecture (VSIX with MEF).
- Separation of concerns: UI, orchestration, parsing, templating, I/O.
- Convention-over-configuration: templates drive folder and namespace structure.
- Clean Architecture design alignment: inner (models/parsers) vs. outer (I/O, VS APIs).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External User
    User["User"]:::external

    %% Visual Studio Host Integration
    subgraph "Visual Studio Host Integration"
        direction TB
        VSHostCS["source.extension.cs"]:::external
        VSHostManifest["source.extension.vsixmanifest"]:::external
    end

    %% VSIX Package
    CodeGenPkg["CodeGeneratorPackage"]:::vsix

    %% Command Definition
    subgraph "Command Definition"
        direction TB
        CommandCS["CodeGenerator.cs"]:::vsix
        CommandVSCT["CodeGenerator.vsct"]:::vsix
    end

    %% UI Layer
    subgraph "UI Layer (WPF MVVM)" 
        direction TB
        FileNameDialogXAML["FileNameDialog.xaml"]:::vsix
        FileNameDialogCode["FileNameDialog.xaml.cs"]:::vsix
    end

    %% Orchestrator
    GenerationService["GenerationService"]:::service

    %% Helpers
    subgraph "Helpers"
        direction TB
        Logger["Logger.cs"]:::helper
        ProjectHelpers["ProjectHelpers.cs"]:::helper
        Utility["Utility.cs"]:::helper
        VSHelpers["VSHelpers.cs"]:::helper
        VsTheme["VsTheme.cs"]:::helper
    end

    %% Models / Parser
    subgraph "Models / Parser"
        direction TB
        Parser["IntellisenseParser.cs"]:::model
        ObjModel["IntellisenseObject.cs"]:::model
        TypeModel["IntellisenseType.cs"]:::model
        PropModel["IntellisenseProperty.cs"]:::model
        NewItemTarget["NewItemTarget.cs"]:::model
    end

    %% Template Mapping Engine
    TemplateMap["Templatemap.cs"]:::asset

    %% Template Assets
    Templates["Templates\n(.txt files)"]:::asset

    %% Output Layer
    Writer["IntellisenseWriter.cs"]:::service

    %% Project & Packaging
    subgraph "Project & Packaging"
        direction TB
        CSProj["CleanArchitectureCodeGenerator.csproj"]:::external
        SLN["CleanArchitectureCodeGenerator.sln"]:::external
    end

    %% Continuous Integration
    subgraph "Continuous Integration"
        direction TB
        GHActions[".github/workflows/build.yml"]:::ci
        Appveyor["appveyor.yml"]:::ci
    end

    %% External Marketplace
    Marketplace["Visual Studio Marketplace"]:::external

    %% Connections
    User -->|"invokes command"| VSHostCS
    VSHostCS --> VSHostManifest
    VSHostManifest -->|loads| CodeGenPkg
    CodeGenPkg -->|registers| CommandCS
    CodeGenPkg --> CommandVSCT
    CommandCS -->|opens| FileNameDialogXAML
    FileNameDialogXAML --> FileNameDialogCode
    FileNameDialogCode -->|calls| GenerationService
    GenerationService --> Parser
    GenerationService --> TemplateMap
    Parser --> ObjModel
    Parser --> TypeModel
    Parser --> PropModel
    Parser --> NewItemTarget
    TemplateMap --> Templates
    GenerationService --> Writer
    Writer --> ProjectHelpers
    Writer --> VSHelpers
    Writer -->|writes files| CSProj
    CSProj --> SLN
    GHActions -->|builds| SLN
    Appveyor -->|builds| SLN
    SLN -->|publishes| Marketplace

    %% Click Events
    click VSHostCS "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/source.extension.cs"
    click VSHostManifest "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/source.extension.vsixmanifest"
    click CodeGenPkg "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/CodeGeneratorPackage.cs"
    click CommandCS "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/CodeGenerator.cs"
    click CommandVSCT "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/CodeGenerator.vsct"
    click FileNameDialogXAML "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/FileNameDialog.xaml"
    click FileNameDialogCode "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/FileNameDialog.xaml.cs"
    click GenerationService "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Services/GenerationService.cs"
    click Writer "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Services/IntellisenseWriter.cs"
    click Logger "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Helpers/Logger.cs"
    click ProjectHelpers "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Helpers/ProjectHelpers.cs"
    click Utility "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Helpers/Utility.cs"
    click VSHelpers "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Helpers/VSHelpers.cs"
    click VsTheme "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Helpers/VsTheme.cs"
    click Parser "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Models/IntellisenseParser.cs"
    click ObjModel "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Models/IntellisenseObject.cs"
    click TypeModel "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Models/IntellisenseType.cs"
    click PropModel "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Models/IntellisenseProperty.cs"
    click NewItemTarget "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/NewItemTarget.cs"
    click TemplateMap "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/Templatemap.cs"
    click Templates "https://github.com/neozhu/cleanarchitecturecodegenerator/tree/main/src/Templates"
    click CSProj "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/src/CleanArchitectureCodeGenerator.csproj"
    click SLN "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/CleanArchitectureCodeGenerator.sln"
    click GHActions "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/.github/workflows/build.yml"
    click Appveyor "https://github.com/neozhu/cleanarchitecturecodegenerator/blob/main/appveyor.yml"

    %% Styles
    classDef external fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef vsix fill:#2196f3,stroke:#1e88e5,stroke-width:1px
    classDef service fill:#42a5f5,stroke:#1e88e5,stroke-width:1px
    classDef helper fill:#ffb74d,stroke:#fb8c00,stroke-width:1px
    classDef model fill:#fff176,stroke:#fbc02d,stroke-width:1px
    classDef asset fill:#66bb6a,stroke:#43a047,stroke-width:1px
    classDef ci fill:#b0bec5,stroke:#78909c,stroke-width:1px
```
