# skarllot/enumutilities architecture

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

- Interactive diagram: https://gitdiagram.com/skarllot/enumutilities
- Repository: https://github.com/skarllot/enumutilities

## Overview

##### Project Type and Purpose
- This is a source generator tool for C#. It plugs into the build process by leveraging the Roslyn compiler to auto-generate boilerplate code for enums.
- The README explains that developers use the [EnumGenerator] attribute on their enums so that a set of extension methods and factories (e.g., parsing, validation, JSON conversion) are generated at compile time. There’s also special handling for bit flag enums and support for attributes like [EnumMember], [Description], and [Display].

##### File Structure
- The top-level directories like src, gen, perf, and tests indicate different aspects of the project:
- src: Contains the core EnumUtilities library. This comprises the attribute definitions and parts that might be required at runtime.
- gen: Contains the Roslyn source generators. Notice that there are different folders, for example, separate versions (Roslyn4_3_1 and Roslyn4_4_0) to support different compiler/version scenarios.
- perf: Contains benchmarks to evaluate performance, demonstrating that efficiency is a design goal.
- tests: Contains integration and unit tests to verify that generated code meets expectations.
- There is also extensive configuration for continuous integration (in the .github folder), build settings (Directory.Build.props, global.json), and other metadata files (LICENSE, README, etc.) that show the project’s commitment to quality and standard practices.

##### Additional Insights from the README
- The README highlights the three main types of generated code per enum: Extensions, Factories, and Validation classes.
- The documentation lays out examples for both “regular” and “[Flags]” enums, and it explains supported attributes (EnumMember, Display, Description) along with JSON converter generation.
- The README also introduces usage examples indicating how the source generator flows: when a developer marks an enum with [EnumGenerator], the generator intervenes during compilation and produces additional code.

a. Main Components:
- EnumUtilities Core Library: In the src directory, define a block for the library that includes utilities like EnumGeneratorAttribute, parsers, and formatters.
- Roslyn Source Generator: Represent the generator modules housed in the “gen” folder (with separate nodes if necessary for different Roslyn versions). This component consumes enums with specific attributes and outputs generated code.
- Testing & Benchmarking: Include nodes for the integration/unit tests (tests folder) and performance benchmarks (perf folder) to ensure quality and performance.
- CI/CD Systems: Optionally, include a node for GitHub Actions (.github/workflows) that show the build, dependency review, and package creation pipelines.
- Developer or External Code Base: Conceptually indicate how a client project (using the NuGet package) will include the EnumUtilities package and see the generated extensions integrated at compile time.

b. Relationships and Interactions:
- That the Core Library (src) is referenced by both the source generation process and by consuming applications.
- How tests and benchmarks interact with the generated code to verify behavior and performance.

c. Architectural Patterns and Design Principles:
- Separation of Concerns: The project distinctly separates the source generation logic (gen), the core runtime libraries (src), and verification (tests and perf).
- Compile-time Code Generation: Emphasize that code generation is integrated into the build process – an essential design principle here.
- Modularity and Version Support: Acknowledge that the project modularizes support for different Roslyn versions, as seen in the two separate generator folders.
- Extensibility: The design accommodates different attributes ([EnumMember], [Description], [Display]), meaning the generator is built to be extensible.

d. Technologies, Frameworks, and Framework Integration:
- C# with .NET 6 SDK (at minimum), Roslyn compiler for source generation, and use of NuGet packaging.
- GitHub Actions for CI/CD and various configuration files (e.g., dotnet-tools.json) indicating integration with standard .NET development tooling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CICD["CI/CD Pipeline"]:::cicd
    Developer["Developer's Code (Annotated Enums)"]:::developer
    Compiler["Roslyn Compiler"]:::compiler
    subgraph "Source Generators"
        GS1["Source Generator (Roslyn 4.3.1)"]:::generator
        GS2["Source Generator (Roslyn 4.4.0)"]:::generator
    end
    Core["EnumUtilities Core Library"]:::core
    Generated["Generated Code Artifacts"]:::integration
    UnitTests["Unit Testing (Core Library)"]:::unit
    Perf["Performance Benchmarks"]:::performance

    CICD -->|"triggers build"| Compiler
    CICD -->|"triggers tests"| UnitTests
    CICD -->|"triggers benchmarks"| Perf

    Developer -->|"initiates compile"| Compiler
    Compiler -->|"invokes"| GS1
    Compiler -->|"invokes"| GS2
    GS1 -->|"generates code"| Generated
    GS2 -->|"generates code"| Generated
    GS1 -- "uses" --> Core
    GS2 -- "uses" --> Core
    Core -->|"validated by"| UnitTests
    Generated -->|"verified by"| UnitTests
    Generated -->|"benchmarked"| Perf

    classDef developer fill:#ADD8E6,stroke:#0000FF,stroke-width:2px
    classDef compiler fill:#B0C4DE,stroke:#000080,stroke-width:2px
    classDef generator fill:#FFA500,stroke:#FF8C00,stroke-width:2px
    classDef core fill:#DA70D6,stroke:#8B008B,stroke-width:2px
    classDef integration fill:#90EE90,stroke:#008000,stroke-width:2px
    classDef unit fill:#98FB98,stroke:#2E8B57,stroke-width:2px
    classDef performance fill:#FFFF99,stroke:#CCCC00,stroke-width:2px
    classDef cicd fill:#D3D3D3,stroke:#696969,stroke-width:2px

    click Core "https://github.com/skarllot/enumutilities/tree/main/src/EnumUtilities"
    click GS1 "https://github.com/skarllot/enumutilities/blob/main/gen/EnumUtilities.Generators.Roslyn4_3_1"
    click GS2 "https://github.com/skarllot/enumutilities/blob/main/gen/EnumUtilities.Generators.Roslyn4_4_0"
    click Generated "https://github.com/skarllot/enumutilities/blob/main/tests/EnumUtilities.Generators.IntegrationTests/Generated/Raiqub.Generators.EnumUtilities.EnumUtilitiesGenerator"
    click UnitTests "https://github.com/skarllot/enumutilities/blob/main/tests/EnumUtilities.Tests"
    click Perf "https://github.com/skarllot/enumutilities/blob/main/perf/EnumUtilities.Benchmark"
    click CICD "https://github.com/skarllot/enumutilities/tree/main/.github/workflows"
```
