# diogofeld/mensagerylib architecture

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

- Interactive diagram: https://gitdiagram.com/diogofeld/mensagerylib
- Repository: https://github.com/diogofeld/mensagerylib

## Overview

##### Project Type and Purpose
- This is a messaging library project with an accompanying ASP.NET Core Web API that demonstrates publishing and consuming messages via RabbitMQ.
- It is organized as:
- A library (MensageryLib) that wraps RabbitMQ operations
- An API project (ApiMensagery) exposing REST endpoints to drive messaging
- A unit‐test project (MensageryLibTests)
- Docker assets for spinning up RabbitMQ and optionally containerizing the API
- Packaging via NuGet

##### File‐Structure Analysis
- Top‐level solution file: MensageryLib.sln
- MensageryLib (class library)
- /Services contains Mensagery interface and implementation
- ApiMensagery (ASP.NET Core Web API)
- /Controllers holds MensageryController and request/response models
- appsettings.json for RabbitMQ connection settings
- Dockerfile to containerize the API
- MensageryLibTests: xUnit test project targeting the library
- docker-compose.yml at root brings up a RabbitMQ container

##### Key README Insights
- Core feature: send/receive messages over RabbitMQ
- API endpoints map to RabbitMQ operations
- Unit tests validate library behavior
- Docker Compose template for RabbitMQ
- Packaging to NuGet for reuse

a. Main Components
- API Layer (ASP.NET Core Web API – ApiMensagery)
- Messaging Library (MensageryLib)
- RabbitMQ Broker (containerized via Docker Compose)
- External REST Clients (e.g. Postman, frontend apps)
- Unit Test Runner (MensageryLibTests)
- NuGet Gallery (for library distribution)
b. Relationships & Interactions
- REST Clients → HTTP POST/GET → API Controller
- Controller → calls → MensageryLib service methods
- Library → connects → RabbitMQ Broker (Publish/Consume)
- Unit Test Runner ↔ calls library methods directly (no broker or with test‐broker stub)
- CI/CD → builds, runs tests, packages library to NuGet
c. Architectural Patterns & Principles
- Layered architecture: Presentation (Controller) → Service (Library) → Infrastructure (RabbitMQ)
- Dependency inversion: Controllers depend on IMensagery interface
- Single responsibility: Controller only handles HTTP, Library encapsulates messaging logic
d. Technologies, Frameworks, Libraries
- ASP.NET Core Web API
- RabbitMQ (.NET client)
- Docker & Docker Compose
- xUnit or NUnit for unit tests
- NuGet packaging

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    subgraph "External Systems"
        RESTClient["REST Client"]:::external
        NuGetGallery["NuGet Gallery"]:::external
    end

    %% API Layer
    subgraph "ApiMensagery (ASP.NET Core)" 
        Controllers["MensageryController"]:::api
        Models["Request/Response Models"]:::api
        Startup["Program & Startup"]:::api
        Config["appsettings.json"]:::api
        DockerfileAPI["Dockerfile"]:::api
    end

    %% Library Layer
    subgraph "MensageryLib Service"
        Interface["IMensagery Interface"]:::lib
        Implementation["MensageryImp Implementation"]:::lib
    end

    %% Infrastructure
    subgraph "Infrastructure"
        RabbitMQ["RabbitMQ Broker"]:::infra
        DockerCompose["Docker Compose"]:::infra
    end

    %% Test Runner
    subgraph "MensageryLibTests (xUnit)"
        TestProject["Test Project File"]:::infra
        TestCases["Test Cases"]:::infra
    end

    %% CI/CD Pipeline
    subgraph "CI/CD & Packaging"
        CI["CI/CD Pipeline"]:::infra
        PublishProfiles["Publish Profiles"]:::infra
    end

    %% Connections
    RESTClient -->|"HTTP POST/GET"| Controllers
    Controllers -->|"calls"| Interface
    Interface -->|"publishes/consumes"| RabbitMQ
    RabbitMQ -->|"delivers messages"| Implementation
    TestCases -->|"invoke"| Interface
    TestProject -->|"contains tests for"| Interface
    DockerCompose -->|"orchestrates"| RabbitMQ
    DockerCompose -->|"orchestrates"| Controllers
    CI -->|"builds & tests"| TestProject
    CI -->|"packages"| PublishProfiles
    PublishProfiles -->|"push to"| NuGetGallery

    %% Click Events
    click Controllers "https://github.com/diogofeld/mensagerylib/blob/main/MensageryLib/ApiMensagery/Controllers/MensageryController.cs"
    click Models "https://github.com/diogofeld/mensagerylib/tree/main/MensageryLib/ApiMensagery/Controllers/Models/Request"
    click Startup "https://github.com/diogofeld/mensagerylib/blob/main/MensageryLib/ApiMensagery/Program.cs"
    click Config "https://github.com/diogofeld/mensagerylib/blob/main/MensageryLib/ApiMensagery/appsettings.json"
    click DockerfileAPI "https://github.com/diogofeld/mensagerylib/tree/main/MensageryLib/ApiMensagery/Dockerfile"
    click Interface "https://github.com/diogofeld/mensagerylib/blob/main/MensageryLib/MensageryLib/Services/Mensagery.cs"
    click Implementation "https://github.com/diogofeld/mensagerylib/blob/main/MensageryLib/MensageryLib/Services/MensageryImp.cs"
    click TestProject "https://github.com/diogofeld/mensagerylib/blob/main/MensageryLib/MensageryLibTests/MensageryLibTests.csproj"
    click TestCases "https://github.com/diogofeld/mensagerylib/blob/main/MensageryLib/MensageryLibTests/MensageryTest.cs"
    click DockerCompose "https://github.com/diogofeld/mensagerylib/blob/main/MensageryLib/docker-compose.yml"
    click PublishProfiles "https://github.com/diogofeld/mensagerylib/tree/main/MensageryLib/MensageryLib/Properties/PublishProfiles"

    %% Styles
    classDef api fill:#D6EAF8,stroke:#1F618D,stroke-width:1px
    classDef lib fill:#D5F5E3,stroke:#27AE60,stroke-width:1px
    classDef infra fill:#FCF3CF,stroke:#F4D03F,stroke-width:1px
    classDef external fill:#F2F3F4,stroke:#7F8C8D,stroke-width:1px
```
