# maurictg/mongoodm architecture

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

- Interactive diagram: https://gitdiagram.com/maurictg/mongoodm
- Repository: https://github.com/maurictg/mongoodm

## Overview

##### Project type and purpose
- This is an open-source C# Object-Document-Mapper (ODM) library for MongoDB, packaged as a NuGet component (`MongoODM`).
- Its goal is to let C# developers define domain entities, decorate them with attributes (`[Embed]`, `[Reference]`, `[Index]`), and then use a repository API (`IMongoRepository<T>`, `IAsyncMongoRepository<T>`) to perform CRUD and automatic population of related documents.

##### File structure
- Top-level solution: `MongoODM.sln`.
- Single project folder `MongoODM/` containing:
- Abstractions: interfaces (`IEntity`, `IMongoRepository<T>`, `IAsyncMongoRepository<T>`, `IMongoAttribute`)
- Attributes: decorators (`EmbedAttribute`, `ReferenceAttribute`, `IndexAttribute`)
- Core classes: `Entity` base class, `MongoRepository<T>`, `AsyncMongoRepository<T>`
- Helpers: utility methods (`Tools.cs`)
- Index definitions: `Index.cs`, `IndexType.cs`
- Settings: `AggregateSettings.cs`
- No UI or service-host code—this is purely a class library.

##### Key README insights
- Core components: domain models (inherit from `Entity`), repository API, attributes to drive embedding/referencing, helper tools.
- Depends on external MongoDB.Driver for connectivity and low-level commands.

a. Main components to represent:
- Domain Model Layer (external client code that defines classes inheriting `Entity` and marks fields with `[Embed]`/`[Reference]`)
- MongoODM Library
– Abstractions Sub-module (interfaces)
– Attributes Sub-module (embedding & referencing metadata)
– Repository Implementation Sub-module (`MongoRepository<T>`, `AsyncMongoRepository<T>`)
– Helpers & Settings Sub-module (`Tools`, `AggregateSettings`, `IndexType`)
- External Dependencies
– Official MongoDB.Driver
– MongoDB Server/Cluster (the running database)
- Consumer Application (the calling user code, e.g. a web API or console app that consumes the library)

b. Relationships and interactions:
– Consumer Application defines Domain Models → passes them to → Repository API (`IMongoRepository<T>`)
– Repository Implementation reads metadata from Attributes & Abstractions → uses MongoDB.Driver → communicates with MongoDB Server
– Helpers provide utility functions during runtime (e.g., building filters, mapping Bson representations)
– Index definitions guide creation or enforcement of indexes in MongoDB

c. Architectural patterns & design principles:
– Inversion of Control via interfaces (`IMongoRepository<T>`)
– Attribute-driven metadata for embedding and referencing
– Repository pattern for data access abstraction
– Single Responsibility Principle: separate sub-modules for attributes, abstractions, implementations, helpers

d. Technologies & frameworks:
– .NET / C#, NuGet packaging
– MongoDB.Driver (official C# driver)
– BSON serialization via attributes
– LINQ support for filters

##### Essential elements
- Arrowheads indicating call/invoke directions and data flow
- Annotations for key patterns (e.g., “Repository Pattern”, “Attribute-driven mapping”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumer Layer
    subgraph "Consumer Application / Domain Models"
        direction TB
        DomainModels["Domain Models\n(classes inherit Entity)"]:::consumer
    end

    %% MongoODM Library
    subgraph "MongoODM Library"
        direction TB

        subgraph "Abstractions"
            direction TB
            IEntity["IEntity"]:::interface
            IMongoAttribute["IMongoAttribute"]:::interface
            IMongoRepository["IMongoRepository<T>"]:::interface
            IAsyncMongoRepository["IAsyncMongoRepository<T>"]:::interface
        end

        subgraph "Attributes"
            direction TB
            EmbedAttribute["EmbedAttribute"]:::attribute
            ReferenceAttribute["ReferenceAttribute"]:::attribute
            IndexAttribute["IndexAttribute"]:::attribute
        end

        subgraph "Implementation"
            direction TB
            EntityClass["Entity (base class)"]:::implementation
            MongoRepository["MongoRepository<T>"]:::implementation
            AsyncMongoRepository["AsyncMongoRepository<T>"]:::implementation
        end

        subgraph "Helpers & Settings"
            direction TB
            Tools["Tools"]:::helper
            AggregateSettings["AggregateSettings"]:::helper
            IndexDef["Index"]:::helper
            IndexTypeDef["IndexType"]:::helper
        end
    end

    %% External Dependencies
    subgraph "External Libraries"
        direction TB
        MongoDriver["MongoDB.Driver"]:::external
    end

    subgraph "External Systems"
        direction TB
        MongoDBServer["MongoDB Server/Cluster"]:::external
    end

    %% Connections
    DomainModels -->|"defines entities & calls"| IMongoRepository
    IMongoRepository -->|"implemented by"| MongoRepository
    IAsyncMongoRepository -->|"implemented by"| AsyncMongoRepository
    MongoRepository -->|"uses metadata from"| EmbedAttribute
    MongoRepository -->|"uses metadata from"| ReferenceAttribute
    MongoRepository -->|"uses metadata from"| IndexAttribute
    AsyncMongoRepository -->|"uses metadata from"| EmbedAttribute
    AsyncMongoRepository -->|"uses metadata from"| ReferenceAttribute
    AsyncMongoRepository -->|"uses metadata from"| IndexAttribute
    MongoRepository -->|"utilizes"| Tools
    MongoRepository -->|"utilizes"| AggregateSettings
    MongoRepository -->|"utilizes"| IndexDef
    MongoRepository -->|"utilizes"| IndexTypeDef
    AsyncMongoRepository -->|"utilizes"| Tools
    AsyncMongoRepository -->|"utilizes"| AggregateSettings
    AsyncMongoRepository -->|"utilizes"| IndexDef
    AsyncMongoRepository -->|"utilizes"| IndexTypeDef
    MongoRepository -->|"calls"| MongoDriver
    AsyncMongoRepository -->|"calls"| MongoDriver
    MongoDriver -->|"connects to"| MongoDBServer

    %% Click Events
    click IMongoRepository "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Abstractions/IMongoRepository.cs"
    click IAsyncMongoRepository "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Abstractions/IAsyncMongoRepository.cs"
    click IEntity "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Abstractions/IEntity.cs"
    click IMongoAttribute "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Abstractions/IMongoAttribute.cs"
    click EmbedAttribute "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Attributes/EmbedAttribute.cs"
    click ReferenceAttribute "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Attributes/ReferenceAttribute.cs"
    click IndexAttribute "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Attributes/IndexAttribute.cs"
    click MongoRepository "https://github.com/maurictg/mongoodm/blob/master/MongoODM/MongoRepository.cs"
    click AsyncMongoRepository "https://github.com/maurictg/mongoodm/blob/master/MongoODM/AsyncMongoRepository.cs"
    click EntityClass "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Entity.cs"
    click Tools "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Helpers/Tools.cs"
    click AggregateSettings "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Properties/AggregateSettings.cs"
    click IndexDef "https://github.com/maurictg/mongoodm/blob/master/MongoODM/Index.cs"
    click IndexTypeDef "https://github.com/maurictg/mongoodm/blob/master/MongoODM/IndexType.cs"

    %% Styles
    classDef interface fill:#CCE5FF,stroke:#0366d6,stroke-width:1px
    classDef attribute fill:#E2F0D9,stroke:#2e7d32,stroke-width:1px
    classDef implementation fill:#D9E5FF,stroke:#4a148c,stroke-width:1px
    classDef helper fill:#FFF2CC,stroke:#f9a825,stroke-width:1px
    classDef external fill:#F2F2F2,stroke:#616161,stroke-width:1px
    classDef consumer fill:#FFFFFF,stroke:#000000,stroke-width:1px
```
