# ardalis/smartenum architecture

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

- Interactive diagram: https://gitdiagram.com/ardalis/smartenum
- Repository: https://github.com/ardalis/smartenum

## Overview

##### Project Type & Purpose
- The project is a library (with multiple NuGet packages) that provides “Smart Enum” functionality.
- The README and file structure show that while the core functionality is provided in the “src/SmartEnum” directory, the project is extended via several integration packages (e.g., SmartEnum.Dapper, SmartEnum.EFCore, SmartEnum.JsonNet, etc.), each targeting specific external frameworks or concerns.

##### File Structure
- Top-Level Components:
- Root files (e.g., .editorconfig, .gitignore, LICENSE, README.md, and solution file [SmartEnum.sln]).
- GitHub workflows and CI configurations for building, testing, and publishing.
- Core Code:
- Located in the “src” folder, which is subdivided into:
▪ “SmartEnum” – the main library providing the enums implementation.
▪ Subdirectories for integration libraries (e.g., SmartEnum.AutoFixture, SmartEnum.Dapper, SmartEnum.EFCore, SmartEnum.GuardClauses, SmartEnum.JsonNet, SmartEnum.MessagePack, SmartEnum.ModelBinding, SmartEnum.ProtoBufNet, SmartEnum.SystemTextJson, SmartEnum.Utf8Json).
- Additional Supporting Components:
- Tests: Organized under “test” (unit tests and integration tests for each integration package).
- Benchmarks: Found under “benchmarks”, used to measure performance.
- Build and packaging configuration files (Directory.Build.props, Directory.Packages.props) that tie the solution together.

- Main Components to Include:
- Client Applications (consumers) that will install the NuGet packages.
- The Core “SmartEnum” library, which implements the central type-safe enum logic.
- Integration Libraries/Extensions:
▪ AutoFixture integration – allows AutoFixture to use or generate SmartEnum instances.
▪ Serialization integrations – SmartEnum.JsonNet, SmartEnum.SystemTextJson, SmartEnum.Utf8Json, SmartEnum.MessagePack (each providing converters for their corresponding JSON or binary frameworks).
▪ ORM integrations – SmartEnum.EFCore and SmartEnum.Dapper (with DapperSmartEnum variants) for mapping SmartEnum types to database columns.
▪ Model Binding integration – SmartEnum.ModelBinding to facilitate binding in ASP.NET scenarios.
▪ GuardClause support – SmartEnum.GuardClauses for enforcing valid enum transitions.
- Testing & Benchmarking Infrastructure:
▪ Unit Test projects in the “test” folder, each referencing a particular integration package or the core library.
▪ Benchmark projects in the “benchmarks” folder evaluating performance (e.g., on list, lookup, and switch operations).
- Relationships and Interactions:
- External dependencies (e.g., JSON.Net, System.Text.Json, Dapper, EF Core, AutoFixture) as external systems that interact with the respective integration packages.

##### Architectural Patterns & Design Principles
- Modular Design: The project is split into many small, focused NuGet packages, each responsible for a single integration or extension.
- Separation of Concerns: The core logic of SmartEnum is isolated from the specific framework adaptations (e.g., serialization converters for JSON frameworks, or type handlers for Dapper).
- Extensibility: The design supports extension via inheritance (e.g., DapperSmartEnum, SmartFlagEnum variants) and composition.
- Integration Testing & Performance Tuning: Use of dedicated test and benchmark projects helps ensure correctness and performance.

- Clear labels on all components (e.g., “SmartEnum (Core)”, “SmartEnum.Dapper”, “SmartEnum.EFCore”, “Tests”, “Benchmarks”).
- Dependency/invocation (e.g., integration components rely on the core library).
- Data flow (e.g., from client application to ORM layer through the SmartEnum converter).
- Core modules (central block).
- Integration packages (periphery blocks targeting specific external frameworks).
- Supporting projects (tests and benchmarks).
- External dependencies (third-party libraries like AutoFixture, JSON.Net, EF Core, etc.).

## Diagram (Mermaid)

```mermaid
graph TD
    A["Client Application"]:::external
    B["SmartEnum (Core)"]:::core

    subgraph "Integrations"
        B1["SmartEnum AutoFixture"]:::integration
        B2["SmartEnum Dapper"]:::integration
        B3["SmartEnum EFCore"]:::integration
        B4["SmartEnum GuardClauses"]:::integration
        B5["SmartEnum JSON.Net"]:::integration
        B6["SmartEnum MessagePack"]:::integration
        B7["SmartEnum Model Binding"]:::integration
        B8["SmartEnum ProtoBufNet"]:::integration
        B9["SmartEnum System.Text.Json"]:::integration
        B10["SmartEnum Utf8Json"]:::integration
    end

    subgraph "External Dependencies"
        E1["AutoFixture"]:::external
        E2["Dapper"]:::external
        E3["EF Core"]:::external
        E4["JSON.Net"]:::external
        E5["MessagePack"]:::external
        E6["ProtoBufNet"]:::external
        E7["System.Text.Json"]:::external
        E8["Utf8Json"]:::external
        E9["ASP.NET"]:::external
    end

    T["Tests"]:::infrastructure
    BT["Benchmarks"]:::infrastructure
    CI["Continuous Integration"]:::infrastructure

    A -->|"uses"| B

    B1 -->|"extends"| B
    B2 -->|"extends"| B
    B3 -->|"extends"| B
    B4 -->|"extends"| B
    B5 -->|"extends"| B
    B6 -->|"extends"| B
    B7 -->|"extends"| B
    B8 -->|"extends"| B
    B9 -->|"extends"| B
    B10 -->|"extends"| B

    B1 -->|"integrates"| E1
    B2 -->|"integrates"| E2
    B3 -->|"integrates"| E3
    B5 -->|"integrates"| E4
    B6 -->|"integrates"| E5
    B8 -->|"integrates"| E6
    B9 -->|"integrates"| E7
    B10 -->|"integrates"| E8
    B7 -->|"integrates"| E9

    T -->|"tests"| B
    T -->|"tests"| B1
    T -->|"tests"| B2
    T -->|"tests"| B3
    T -->|"tests"| B4
    T -->|"tests"| B5
    T -->|"tests"| B6
    T -->|"tests"| B7
    T -->|"tests"| B8
    T -->|"tests"| B9
    T -->|"tests"| B10

    BT -->|"benchmarks"| B

    CI -->|"builds&tests"| B
    CI -->|"builds&tests"| T
    CI -->|"builds&tests"| BT

    classDef core fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef integration fill:#aed6f1,stroke:#2874a6,stroke-width:2px;
    classDef external fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef infrastructure fill:#f5b7b1,stroke:#943126,stroke-width:2px;

    click B "https://github.com/ardalis/smartenum/tree/main/src/SmartEnum"
    click B1 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.AutoFixture"
    click B2 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.Dapper"
    click B3 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.EFCore"
    click B4 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.GuardClauses"
    click B5 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.JsonNet"
    click B6 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.MessagePack"
    click B7 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.ModelBinding"
    click B8 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.ProtoBufNet"
    click B9 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.SystemTextJson"
    click B10 "https://github.com/ardalis/smartenum/blob/main/src/SmartEnum.Utf8Json"
    click T "https://github.com/ardalis/smartenum/tree/main/test"
    click BT "https://github.com/ardalis/smartenum/tree/main/benchmarks"
    click CI "https://github.com/ardalis/smartenum/tree/main/.github/workflows"
```
