# davidfineboym/loggingdecoratorgenerator architecture

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

- Interactive diagram: https://gitdiagram.com/davidfineboym/loggingdecoratorgenerator
- Repository: https://github.com/davidfineboym/loggingdecoratorgenerator

## Overview

##### Project Type and Purpose
- This is a .NET Source Generator library.
- It plugs into the Roslyn compiler and, at compile-time, scans annotated interfaces to emit “logging decorator” classes that wrap user interfaces with Microsoft.Extensions.Logging calls (and, optionally, metric instrumentation).

##### Top-Level Components (to be nodes
A. Developer Project Code (Input)
- Interfaces annotated with `[DecorateWithLogger]`, `[LogMethod]`, and `[NotLogged]`.
B. Roslyn Compiler Platform
- Hosts ISourceGenerator implementations.
- Loads the “Fineboym.Logging.Generator” analyzer package.
C. LoggingDecoratorGenerator Package
1. Attributes.cs
2. Parser.cs – reads interface syntax trees.
3. MethodToGenerate.cs / Parameter.cs – data models representing methods and their parameters.
4. DecoratorGenerator.cs – entry point implementing `ISourceGenerator`.
5. DecoratorClass.cs & SourceGenerationHelper.cs – build the C# code nodes.
6. DiagnosticDescriptors.cs – defines compile-time warnings/errors.
7. RoslynExtensions.cs – helper methods for syntax analysis.
8. LogLevelConverter.cs – maps attribute settings to `LogLevel`.
D. Generated Output
- `.g.cs` files such as `SomeServiceLoggingDecorator` in the user’s namespace.
- Each method uses `LoggerMessage.Define<>` actions, optional try-catch, stopwatch for duration, and optional IMeterFactory metrics.
E. Test Projects
1. LoggingDecoratorGenerator.Tests
- Snapshot tests (Verify) that the generator produces the expected code.
2. LoggingDecoratorGenerator.IntegrationTests
- Compiles real sample interfaces and executes code to validate runtime behavior (e.g., metrics, exception logging).

##### Relationships and Data Flow
- Snapshot Tests drive the generator in isolation and compare output text
- Integration Tests run the generated decorator at runtime and verify logs/metrics

##### Architectural Patterns & Principles
- Plugin Pattern: the generator is a Roslyn analyzer plugin loaded by the compiler.
- Code-First Generation: source attributes drive code emission—no reflection at runtime.
- Single Responsibility: distinct modules for parsing, diagnostics, code construction, and log-level conversion.
- High-Performance Logging: uses `LoggerMessage.Define<>` and SkipEnabledCheck pattern.
- Optional Metrics: conditional injection of `IMeterFactory` and `Histogram<double>` based on `ReportDurationAsMetric`.

##### Must-Include Elements
- Clear component names (e.g., DecoratorGenerator, Parser, SourceGenerationHelper).
- Call out external dependencies: Microsoft.CodeAnalysis, Microsoft.Extensions.Logging, System.Diagnostics.Metrics.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Input
    DeveloperInput["Developer Project Code\n(Input Interfaces)"]:::user
    click DeveloperInput "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator.IntegrationTests/*.cs"

    %% Roslyn Platform
    RoslynPlatform["Roslyn Compiler Platform\n(Analyzer Package)"]:::roslyn
    click RoslynPlatform "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/Fineboym.Logging.Generator.csproj"

    %% Generator Internals
    subgraph "LoggingDecoratorGenerator Package"
        Attributes["Attributes.cs"]:::generator
        click Attributes "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/Attributes.cs"
        Parser["Parser.cs"]:::generator
        click Parser "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/Parser.cs"
        Model1["MethodToGenerate.cs"]:::generator
        click Model1 "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/MethodToGenerate.cs"
        Model2["Parameter.cs"]:::generator
        click Model2 "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/Parameter.cs"
        DecoratorGenerator["DecoratorGenerator.cs\n(ISourceGenerator)"]:::generator
        click DecoratorGenerator "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/DecoratorGenerator.cs"
        DecoratorClass["DecoratorClass.cs"]:::generator
        click DecoratorClass "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/DecoratorClass.cs"
        SourceHelper["SourceGenerationHelper.cs"]:::generator
        click SourceHelper "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/SourceGenerationHelper.cs"
        Diagnostics["DiagnosticDescriptors.cs"]:::generator
        click Diagnostics "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/DiagnosticDescriptors.cs"
        RoslynExt["RoslynExtensions.cs"]:::generator
        click RoslynExt "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/RoslynExtensions.cs"
        LogLevelConv["LogLevelConverter.cs"]:::generator
        click LogLevelConv "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator/LogLevelConverter.cs"
    end

    %% Generated Output
    GeneratedOutput["Generated Output\n(.g.cs files)"]:::generated

    %% Tests
    subgraph "Tests"
        Snap1["GeneratorSnapshotTests.cs"]:::test
        click Snap1 "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator.Tests/GeneratorSnapshotTests.cs"
        SnapHelper["TestHelper.cs"]:::test
        click SnapHelper "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator.Tests/TestHelper.cs"
        Verified["*.verified.cs"]:::test
        click Verified "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator.Tests/*.verified.cs"
        IntegrationTests["Integration Tests\n(Runtime Validation)"]:::test
        click IntegrationTests "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator.IntegrationTests/*.cs"
    end

    %% Solution File
    Solution["Solution File\nLoggingDecoratorGenerator.sln"]:::user
    click Solution "https://github.com/davidfineboym/loggingdecoratorgenerator/blob/master/LoggingDecoratorGenerator.sln"

    %% Connections
    DeveloperInput -->|"Annotated Interfaces"| RoslynPlatform
    RoslynPlatform -->|"loads Generator"| DecoratorGenerator
    DecoratorGenerator -->|"reads SyntaxTree"| Parser
    Parser -->|"uses extensions"| RoslynExt
    Parser -->|"produces models"| Model1
    Parser -->|"produces models"| Model2
    Model1 -->|"model data"| DecoratorClass
    Model2 -->|"model data"| DecoratorClass
    DecoratorClass -->|"uses helper"| SourceHelper
    DecoratorClass -->|"reports diagnostics"| Diagnostics
    DecoratorClass -->|"log level mapping"| LogLevelConv
    SourceHelper -->|"generates code"| GeneratedOutput
    GeneratedOutput -->|"compiled into"| RoslynPlatform
    Snap1 -->|"invoke generator"| DecoratorGenerator
    IntegrationTests -->|"consume output"| GeneratedOutput
    Solution --> DeveloperInput
    Solution --> RoslynPlatform
    Solution --> Attributes

    %% Styles
    classDef user fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef roslyn fill:#FFA500,stroke:#333,stroke-width:1px
    classDef generator fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef generated fill:#90EE90,stroke:#333,stroke-width:1px
    classDef test fill:#D8BFD8,stroke:#333,stroke-width:1px
```
