# luckypennysoftware/automapper architecture

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

- Interactive diagram: https://gitdiagram.com/luckypennysoftware/automapper
- Repository: https://github.com/luckypennysoftware/automapper

## Overview

##### Project Type and Purpose
- AutoMapper is an open-source .NET library (distributed via NuGet) whose sole purpose is to automate the mapping of properties from one object type to another, eliminating boilerplate code.
- It provides a core mapping engine, extension packages, DI integration, expression‐tree based projection, and extensive test/benchmark suites.

##### File Structure Analysis
- src/AutoMapper: the core library project, containing Configuration, Execution, Mappers, QueryableExtensions, Internal, Licensing, and public entry points (MapperConfiguration, Mapper, IMapper).
- src/AutoMapper.DI.Tests, src/IntegrationTests, src/UnitTests: test projects validating different integration points (DI containers, EF Core mapping, advanced scenarios) and core mapping behavior.
- src/Benchmark: benchmarks comparing different mapping approaches.
- src/TestApp: a sample console app to demonstrate usage.
- docs: Sphinx/ReadTheDocs sources for user documentation.
- GitHub workflows (.github/workflows): CI, release, lockfile maintenance.
- Build scripts (Build.ps1, Setup.ps1, Push.ps1) and solution-wide props/configs (.sln, Directory.Build.props, nuget.config).

##### Key README Insights
- Core concept: configure type maps (cfg.CreateMap<TSource,TDest>()), then resolve at runtime via IMapper.Map<T> or LINQ projections.
- Supports dependency‐injection registration, mapping configuration validation, license key management.
- Mentions related extension repositories.

a. Main Components
- Core Mapping Engine (src/AutoMapper)
- Configuration API (MapperConfiguration + Profiles)
- Mapping Pipeline (IObjectMapper implementations, Convention system, ExpressionBuilder, TypeMapPlanBuilder)
- DI Integration Layer (ServiceCollectionExtensions + AutoMapper.DI.Tests)
- Queryable Extensions (LINQ projection translator)
- Extension Points (Custom Type Converters, Value Resolvers, Conventions)
- External Dependencies: .NET Runtime, Dependency‐Injection Container(s)
- Support Modules: Benchmarking, Test Projects, Documentation site
- Build & Release Pipeline (GitHub Actions, PowerShell scripts)

b. Relationships & Data Flows
- On startup, user code invokes MapperConfiguration → Profiles → builds internal TypeMap graph.
- When Map<TSource,TDest>() is called, the Mapping Pipeline uses ObjectFactory and ExpressionBuilder to generate and cache a delegate or expression tree.
- For IQueryable<T> projection, QueryableExtensions rewrites expression trees from source to destination.
- DI Extension registers MapperConfiguration and IMapper in IServiceCollection to resolve via constructor injection.
- Tests and Benchmarks invoke the public API to validate and measure performance; they depend on the core library assembly.
- Build scripts orchestrate compilation, tests, packaging to NuGet, and publishing via GitHub Actions.

c. Architectural Patterns & Principles
- Pipeline Pattern: IObjectMapper chain for different mapping strategies.
- Convention over Configuration: default member and type matching conventions, override via explicit Profiles.
- Factory Pattern: ObjectFactory for instance creation, ProxyGenerator for dynamic types.
- Dependency Injection: extension methods and tests demonstrating service registration.
- Expression Tree Manipulation: ProjectionBuilder, NullsafeQueryRewriter.
- Modularity: separation of core, DI, projection, tests, benchmarks, documentation.

d. Technologies & Frameworks
- C#/.NET (Core + Framework compatibility)
- Roslyn/expression‐tree API
- GitHub Actions for CI/CD
- Sphinx/ReadTheDocs for documentation
- NuGet packaging

##### Details to Capture
- Layered arrangement: Public API at top, internal pipeline components in the middle, infrastructure (ReflectionHelper, Licensing) at bottom.
- Configuration flow (Profiles → TypeMapConfiguration → MemberConfigurationExpression).
- Build & release process separately, showing source repos → GitHub Actions → NuGet.org.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Public API Layer
    subgraph "Public API" 
        direction TB
        API["MapperConfiguration\nIMapper"]:::public
    end

    %% Core Mapping Engine
    subgraph "Core Mapping Engine" 
        direction TB
        Core["src/AutoMapper"]:::core
    end

    %% Configuration API
    subgraph "Configuration API" 
        direction TB
        MapperConfig["MapperConfiguration.cs"]:::core
        Profile["Profile.cs"]:::core
    end

    %% Mapping Pipeline
    subgraph "Mapping Pipeline" 
        direction TB
        subgraph "Expression & Plan Builder"
            ExpressionBuilder["ExpressionBuilder.cs"]:::core
            TypeMapPlanBuilder["TypeMapPlanBuilder.cs"]:::core
        end
        subgraph "Object Factory & Proxies"
            ObjectFactory["ObjectFactory.cs"]:::core
            ProxyGenerator["ProxyGenerator.cs"]:::core
        end
        subgraph "IObjectMapper Implementations"
            Mappers["src/AutoMapper/Mappers"]:::core
        end
    end

    %% Helpers & Conventions
    subgraph "Internal Helpers & Conventions"
        direction TB
        InternalHelpers["src/AutoMapper/Internal"]:::core
        Conventions["Conventions.cs"]:::core
    end

    %% Extension Points
    subgraph "Extension Points"
        direction TB
        Annotations["src/AutoMapper/Configuration/Annotations"]:::extension
    end

    %% DI Integration
    subgraph "DI Integration Layer"
        direction TB
        ServiceExtensions["ServiceCollectionExtensions.cs"]:::extension
        DITests["src/AutoMapper.DI.Tests"]:::test
    end

    %% Queryable Extensions
    subgraph "Queryable Extensions"
        direction TB
        QE_Extensions["Extensions.cs"]:::extension
        NullsafeRewriter["NullsafeQueryRewriter.cs"]:::extension
        ProjectionBuilder["ProjectionBuilder.cs"]:::extension
        ProjectionMappers["ProjectionMappers"]:::extension
    end

    %% Licensing Module
    subgraph "Licensing Module"
        direction TB
        Licensing["src/AutoMapper/Licensing"]:::core
    end

    %% Support Modules
    subgraph "Support & Documentation"
        direction TB
        Benchmarks["src/Benchmark"]:::test
        UnitTests["src/UnitTests"]:::test
        IntegrationTests["src/IntegrationTests"]:::test
        SampleApp["src/TestApp"]:::test
        Docs["docs/source"]:::test
    end

    %% Build & Release Pipeline
    subgraph "Build & Release Pipeline"
        direction TB
        CI[".github/workflows"]:::ci
        BuildScripts["Build.ps1\nSetup.ps1\nPush.ps1\nDirectory.Build.props\nnuget.config"]:::ci
    end

    %% Relationships
    API -->|uses| MapperConfig
    API -->|uses| Profile
    MapperConfig --> Core
    Profile --> Core
    Core --> ExpressionBuilder
    Core --> TypeMapPlanBuilder
    Core --> ObjectFactory
    Core --> ProxyGenerator
    Core --> Mappers
    Core --> InternalHelpers
    Core --> Conventions
    Core --> Licensing
    Core --> Annotations
    API -->|DI registration| ServiceExtensions
    ServiceExtensions --> Core
    API -->|LINQ projection| QE_Extensions
    QE_Extensions --> NullsafeRewriter
    QE_Extensions --> ProjectionBuilder
    ProjectionBuilder --> ProjectionMappers
    Benchmarks --> Core
    UnitTests --> Core
    IntegrationTests --> Core
    DITests --> ServiceExtensions
    SampleApp --> API
    Docs --> API
    CI --> Core
    CI --> Benchmarks
    CI --> UnitTests
    CI --> IntegrationTests
    CI --> SampleApp
    CI --> Publish["NuGet.org"]:::external
    BuildScripts --> CI

    Publish:::external

    %% Click Events
    click Core "https://github.com/luckypennysoftware/automapper/tree/master/src/AutoMapper"
    click MapperConfig "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/Configuration/MapperConfiguration.cs"
    click Profile "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/Configuration/Profile.cs"
    click ExpressionBuilder "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/Execution/ExpressionBuilder.cs"
    click TypeMapPlanBuilder "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/Execution/TypeMapPlanBuilder.cs"
    click ObjectFactory "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/Execution/ObjectFactory.cs"
    click ProxyGenerator "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/Execution/ProxyGenerator.cs"
    click Mappers "https://github.com/luckypennysoftware/automapper/tree/master/src/AutoMapper/Mappers"
    click InternalHelpers "https://github.com/luckypennysoftware/automapper/tree/master/src/AutoMapper/Internal"
    click Conventions "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/Configuration/Conventions.cs"
    click Annotations "https://github.com/luckypennysoftware/automapper/tree/master/src/AutoMapper/Configuration/Annotations"
    click ServiceExtensions "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/ServiceCollectionExtensions.cs"
    click DITests "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper.DI.Tests"
    click QE_Extensions "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/QueryableExtensions/Extensions.cs"
    click NullsafeRewriter "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/QueryableExtensions/NullsafeQueryRewriter.cs"
    click ProjectionBuilder "https://github.com/luckypennysoftware/automapper/blob/master/src/AutoMapper/QueryableExtensions/ProjectionBuilder.cs"
    click ProjectionMappers "https://github.com/luckypennysoftware/automapper/tree/master/src/AutoMapper/QueryableExtensions/ProjectionMappers"
    click Licensing "https://github.com/luckypennysoftware/automapper/tree/master/src/AutoMapper/Licensing"
    click Benchmarks "https://github.com/luckypennysoftware/automapper/tree/master/src/Benchmark"
    click UnitTests "https://github.com/luckypennysoftware/automapper/tree/master/src/UnitTests"
    click IntegrationTests "https://github.com/luckypennysoftware/automapper/tree/master/src/IntegrationTests"
    click SampleApp "https://github.com/luckypennysoftware/automapper/tree/master/src/TestApp"
    click Docs "https://github.com/luckypennysoftware/automapper/tree/master/docs/source"
    click CI "https://github.com/luckypennysoftware/automapper/blob/master/.github/workflows/ci.yml"
    click BuildScripts "https://github.com/luckypennysoftware/automapper/blob/master/Build.ps1"

    %% Styles
    classDef public fill:#D6EAF8,stroke:#1B4F72,color:#1B4F72,stroke-width:1px;
    classDef core fill:#D1F2EB,stroke:#117A65,color:#117A65,stroke-width:1px;
    classDef extension fill:#D5F5E3,stroke:#27AE60,color:#196F3D,stroke-width:1px;
    classDef test fill:#F2F3F4,stroke:#ABB2B9,color:#424949,stroke-width:1px,stroke-dasharray: 5 5;
    classDef ci fill:#FCF3CF,stroke:#B7950B,color:#7D6608,stroke-width:1px;
    classDef external fill:#E8DAEF,stroke:#6C3483,color:#512E5F,stroke-width:1px;
```
