# snatch-dev/convey architecture

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

- Interactive diagram: https://gitdiagram.com/snatch-dev/convey
- Repository: https://github.com/snatch-dev/convey

## Overview

##### Project type and purpose
- This is an open-source .NET Core microservices framework (Convey). It provides a modular “recipe” of libraries and abstractions (CQRS, messaging, persistence, metrics, tracing, service-discovery, security, secrets, WebAPI, etc.) that you plug into your microservice via a fluent ConveyorBuilder pattern.
- The README confirms Convey stands for a set of extension packages to quickly assemble production-ready microservices with integrations for Consul, RabbitMQ, MongoDB, Redis, Vault, Prometheus, Jaeger, Serilog, Swagger, Fabio, OpenStack OCS, etc.

##### File structure analysis
- Top-level “src/Convey.*” folders each map to a NuGet package providing one concern (e.g. Convey.CQRS.Commands, Convey.Persistence.MongoDB, Convey.MessageBrokers.RabbitMQ, Convey.WebApi.CQRS, Convey.Secrets.Vault…)
- There is a “Convey” core package (Convey/src/Convey) that defines the ConveyBuilder and service registration abstractions.
- A “samples” directory illustrates how to assemble these packages into real services: Conveyor.Services.Orders, Conveyor.Services.Deliveries, Conveyor.Services.Pricing, each wired with WebAPI, CQRS, messaging, and persistence.
- “samples/compose” holds Docker-Compose configurations to spin up RabbitMQ, Consul, Fabio, Prometheus, etc.

##### Key architectural insights from README
- Convey is built around a builder pattern (ConveyBuilder) that wires up middleware, dispatchers, registries, and clients for each concern.
- Embraces CQRS, publisher/subscriber message brokers (RabbitMQ), inbox/outbox, service discovery (Consul), load balancing (Fabio), standardized HTTP clients (RestEase), metrics (AppMetrics + Prometheus), tracing (Jaeger), secrets (Vault), logging (Serilog/Seq/ELK/Loki), persistence drivers (MongoDB, Redis, OpenStack OCS), security (JWT, mTLS, certificates), Swagger documentation, and minimal routing-based Web API.

a. Main components (grouped by layer)
- Core ConveyBuilder (entry point)
- Web API layer (Convey.WebApi, Convey.WebApi.CQRS)
- CQRS abstractions (Commands, Queries, Events)
- HTTP clients (Convey.HTTP, Convey.HTTP.RestEase)
- Service Discovery & Load-balancing (Convey.Discovery.Consul, Convey.LoadBalancing.Fabio)
- Messaging (Convey.MessageBrokers, Convey.MessageBrokers.RabbitMQ, Inbox/Outbox packages)
- Persistence drivers (Convey.Persistence.MongoDB, Convey.Persistence.Redis, Convey.Persistence.OpenStack.OCS)
- Secrets & Security (Convey.Secrets.Vault, Convey.Auth, Convey.Security, Convey.Auth.Distributed)
- Observability (Convey.Logging, Convey.Logging.CQRS, Convey.Metrics.AppMetrics, Convey.Metrics.Prometheus, Convey.Tracing.Jaeger, Convey.Tracing.Jaeger.RabbitMQ)
- Samples (Order Service, Delivery Service, Pricing Service)
- External systems: Consul registry, Fabio router, RabbitMQ broker, MongoDB, Redis, OpenStack OCS API, Vault, Prometheus server, Jaeger collector, Seq/ELK/Loki

b. Relationships & data flow
1. At startup each microservice invokes ConveyBuilder, chaining in modules:
– Register JWT/Certificate authentication (Auth packages)
– Add WebAPI endpoints & CQRS dispatchers
– Connect to Consul & register service
– Configure RestEase HTTP client backed by Consul + Fabio
– Configure messaging: RabbitMQ publisher/subscriber, outbox/inbox
– Configure persistence (Mongo/Redis/OCS)
– Configure secrets (Vault)
– Attach logging, metrics, tracing middleware
2. Incoming HTTP requests → WebAPI layer → CQRS dispatcher → Command/Query handlers → persistence drivers or external HTTP clients or message broker
3. Handlers publish domain events → Convey.CQRS.Events → RabbitMQ via MessageBrokers → other services’ subscribers
4. Outbox processor ensures atomicity with DB → RabbitMQ
5. Services discover one another via Consul; Fabio routes requests to healthy instances
6. Observability: logs emitted by Serilog sinks; metrics exposed on /metrics scraped by Prometheus; traces sent to Jaeger

c. Architectural patterns
- Modular plugin-style architecture: each concern is a replaceable package
- Fluent builder for dependency injection and middleware registration
- CQRS with in-process dispatchers + message brokers for cross-service events
- Outbox pattern for reliable messaging
- Service discovery + client-side load balancing
- Centralized observability (logs, metrics, traces)

d. Key technologies & libraries
- .NET Core + DI
- Convey packages (as above)
- Swagger / Web API minimal routing
- RabbitMQ, EF Core / MongoDB / Redis / OpenStack OCS
- Vault secrets engine
- Consul + Fabio
- RestEase HTTP client
- Serilog + Seq/ELK/Loki
- AppMetrics + Prometheus
- Jaeger tracing

## Diagram (Mermaid)

```mermaid
flowchart TD
    ConveyBuilder["ConveyBuilder"]:::core

    subgraph "Web API Layer"
        WebApi["Convey.WebApi"]:::webapi
        WebApiCQRS["Convey.WebApi.CQRS"]:::webapi
        WebApiSec["Convey.WebApi.Security"]:::security
        DocsSwagger["Convey.Docs.Swagger"]:::docs
        WebApiSwagger["Convey.WebApi.Swagger"]:::docs
    end

    subgraph "CQRS Abstractions"
        CQRSCmd["Convey.CQRS.Commands"]:::cqrs
        CQRSQry["Convey.CQRS.Queries"]:::cqrs
        CQRSEvt["Convey.CQRS.Events"]:::cqrs
    end

    subgraph "HTTP Clients"
        HTTPCore["Convey.HTTP"]:::http
        HTTPRest["Convey.HTTP.RestEase"]:::http
    end

    subgraph "Discovery & Load Balancing"
        Consul["Convey.Discovery.Consul"]:::discovery
        Fabio["Convey.LoadBalancing.Fabio"]:::discovery
    end

    subgraph "Messaging"
        MBroker["Convey.MessageBrokers"]:::messaging
        RabbitMQ["Convey.MessageBrokers.RabbitMQ"]:::messaging
        Outbox["Convey.MessageBrokers.Outbox"]:::messaging
        OutboxEF["Convey.MessageBrokers.Outbox.EntityFramework"]:::messaging
        OutboxMongo["Convey.MessageBrokers.Outbox.Mongo"]:::messaging
        MBCQRS["Convey.MessageBrokers.CQRS"]:::messaging
    end

    subgraph "Persistence Drivers"
        MongoDB["Convey.Persistence.MongoDB"]:::persistence
        Redis["Convey.Persistence.Redis"]:::persistence
        OCS["Convey.Persistence.OpenStack.OCS"]:::persistence
    end

    subgraph "Secrets & Security"
        Vault["Convey.Secrets.Vault"]:::security
        Auth["Convey.Auth"]:::security
        AuthDist["Convey.Auth.Distributed"]:::security
        Crypto["Convey.Security"]:::security
    end

    subgraph "Observability"
        Logging["Convey.Logging"]:::obs
        LoggingCQRS["Convey.Logging.CQRS"]:::obs
        MetricsAM["Convey.Metrics.AppMetrics"]:::obs
        MetricsProm["Convey.Metrics.Prometheus"]:::obs
        TraceJaeger["Convey.Tracing.Jaeger"]:::obs
        TraceRabbit["Convey.Tracing.Jaeger.RabbitMQ"]:::obs
    end

    subgraph "Sample Services"
        Orders["Orders Service"]:::service
        Deliveries["Deliveries Service"]:::service
        Pricing["Pricing Service"]:::service
    end

    subgraph "Infrastructure"
        ConsulInfra["Consul (registry)"]:::infra
        FabioInfra["Fabio (router)"]:::infra
        RabbitInfra["RabbitMQ"]:::infra
        MongoInfra["MongoDB"]:::infra
        RedisInfra["Redis"]:::infra
        OCSInfra["OpenStack OCS"]:::infra
        VaultInfra["Vault"]:::infra
        PromInfra["Prometheus"]:::infra
        JaegerInfra["Jaeger"]:::infra
        LogInfra["Seq/ELK/Loki"]:::infra
    end

    %% Initialization flow
    ConveyBuilder --> WebApi
    ConveyBuilder --> WebApiCQRS
    ConveyBuilder --> WebApiSec
    ConveyBuilder --> DocsSwagger
    ConveyBuilder --> WebApiSwagger
    ConveyBuilder --> CQRSCmd
    ConveyBuilder --> CQRSQry
    ConveyBuilder --> CQRSEvt
    ConveyBuilder --> HTTPCore
    ConveyBuilder --> HTTPRest
    ConveyBuilder --> Consul
    ConveyBuilder --> Fabio
    ConveyBuilder --> MBroker
    ConveyBuilder --> RabbitMQ
    ConveyBuilder --> Outbox
    ConveyBuilder --> OutboxEF
    ConveyBuilder --> OutboxMongo
    ConveyBuilder --> MBCQRS
    ConveyBuilder --> MongoDB
    ConveyBuilder --> Redis
    ConveyBuilder --> OCS
    ConveyBuilder --> Vault
    ConveyBuilder --> Auth
    ConveyBuilder --> AuthDist
    ConveyBuilder --> Crypto
    ConveyBuilder --> Logging
    ConveyBuilder --> LoggingCQRS
    ConveyBuilder --> MetricsAM
    ConveyBuilder --> MetricsProm
    ConveyBuilder --> TraceJaeger
    ConveyBuilder --> TraceRabbit

    %% Runtime flows
    Orders -->|"REST"| WebApi
    WebApi -->|"dispatch"| CQRSCmd
    WebApi -->|"dispatch"| CQRSQry
    CQRSCmd -->|"handles"| MongoDB
    CQRSCmd -->|"handles"| Redis
    CQRSCmd -->|"handles"| OCS
    CQRSCmd -->|"publishes"| CQRSEvt
    CQRSEvt -->|"AMQP"| RabbitInfra
    Outbox -->|"ensures atomic"| MongoInfra
    RabbitInfra -->|"delivers"| MBCQRS
    Orders -->|"discover"| ConsulInfra
    ConsulInfra -->|"routes via"| FabioInfra
    FabioInfra --> Orders
    Orders -->|"metrics"| PromInfra
    Orders -->|"traces"| JaegerInfra
    Orders -->|"logs"| LogInfra

    %% Click Events
    click ConveyBuilder "https://github.com/snatch-dev/convey/tree/master/src/Convey/src/Convey"
    click WebApi "https://github.com/snatch-dev/convey/blob/master/src/Convey.WebApi/src/Convey.WebApi"
    click WebApiCQRS "https://github.com/snatch-dev/convey/blob/master/src/Convey.WebApi.CQRS/src/Convey.WebApi.CQRS"
    click WebApiSec "https://github.com/snatch-dev/convey/blob/master/src/Convey.WebApi.Security/src/Convey.WebApi.Security"
    click DocsSwagger "https://github.com/snatch-dev/convey/blob/master/src/Convey.Docs.Swagger/src/Convey.Docs.Swagger"
    click WebApiSwagger "https://github.com/snatch-dev/convey/blob/master/src/Convey.WebApi.Swagger/src/Convey.WebApi.Swagger"
    click CQRSCmd "https://github.com/snatch-dev/convey/blob/master/src/Convey.CQRS.Commands/src/Convey.CQRS.Commands"
    click CQRSQry "https://github.com/snatch-dev/convey/blob/master/src/Convey.CQRS.Queries/src/Convey.CQRS.Queries"
    click CQRSEvt "https://github.com/snatch-dev/convey/blob/master/src/Convey.CQRS.Events/src/Convey.CQRS.Events"
    click HTTPCore "https://github.com/snatch-dev/convey/blob/master/src/Convey.HTTP/src/Convey.HTTP"
    click HTTPRest "https://github.com/snatch-dev/convey/blob/master/src/Convey.HTTP.RestEase/src/Convey.HTTP.RestEase"
    click Consul "https://github.com/snatch-dev/convey/blob/master/src/Convey.Discovery.Consul/src/Convey.Discovery.Consul"
    click Fabio "https://github.com/snatch-dev/convey/blob/master/src/Convey.LoadBalancing.Fabio/src/Convey.LoadBalancing.Fabio"
    click MBroker "https://github.com/snatch-dev/convey/blob/master/src/Convey.MessageBrokers/src/Convey.MessageBrokers"
    click RabbitMQ "https://github.com/snatch-dev/convey/blob/master/src/Convey.MessageBrokers.RabbitMQ/src/Convey.MessageBrokers.RabbitMQ"
    click Outbox "https://github.com/snatch-dev/convey/blob/master/src/Convey.MessageBrokers.Outbox/src/Convey.MessageBrokers.Outbox"
    click OutboxEF "https://github.com/snatch-dev/convey/blob/master/src/Convey.MessageBrokers.Outbox.EntityFramework/src/Convey.MessageBrokers.Outbox.EntityFramework"
    click OutboxMongo "https://github.com/snatch-dev/convey/blob/master/src/Convey.MessageBrokers.Outbox.Mongo/src/Convey.MessageBrokers.Outbox.Mongo"
    click MBCQRS "https://github.com/snatch-dev/convey/blob/master/src/Convey.MessageBrokers.CQRS/src/Convey.MessageBrokers.CQRS"
    click MongoDB "https://github.com/snatch-dev/convey/blob/master/src/Convey.Persistence.MongoDB/src/Convey.Persistence.MongoDB"
    click Redis "https://github.com/snatch-dev/convey/blob/master/src/Convey.Persistence.Redis/src/Convey.Persistence.Redis"
    click OCS "https://github.com/snatch-dev/convey/blob/master/src/Convey.Persistence.OpenStack.OCS/src/Convey.Persistence.OpenStack.OCS"
    click Vault "https://github.com/snatch-dev/convey/blob/master/src/Convey.Secrets.Vault/src/Convey.Secrets.Vault"
    click Auth "https://github.com/snatch-dev/convey/blob/master/src/Convey.Auth/src/Convey.Auth"
    click AuthDist "https://github.com/snatch-dev/convey/blob/master/src/Convey.Auth.Distributed/src/Convey.Auth.Distributed"
    click Crypto "https://github.com/snatch-dev/convey/blob/master/src/Convey.Security/src/Convey.Security"

    classDef core fill:#FFD700,stroke:#333,stroke-width:2px
    classDef webapi fill:#FF7F50,stroke:#333
    classDef cqrs fill:#87CEFA,stroke:#333
    classDef http fill:#ADD8E6,stroke:#333
    classDef discovery fill:#98FB98,stroke:#333
    classDef messaging fill:#DA70D6,stroke:#333
    classDef persistence fill:#FFE4B5,stroke:#333
    classDef security fill:#FFB6C1,stroke:#333
    classDef obs fill:#D3D3D3,stroke:#333
    classDef docs fill:#AFEEEE,stroke:#333
    classDef service fill:#20B2AA,stroke:#333
    classDef infra fill:#778899,stroke:#333,stroke-dasharray: 5 5
```
