How neozhu/cleanarchitecturecodegenerator works
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).