# kodemargin/affanet-be architecture

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

- Interactive diagram: https://gitdiagram.com/kodemargin/affanet-be
- Repository: https://github.com/kodemargin/affanet-be

## Overview

AffanetBE is a modular ASP.NET Core commerce backend for multi-tenant storefronts and seller operations. The documented request path runs from HTTP endpoints through commands or queries and handlers to domain rules and module persistence. Checkout quoting is a concrete cross-module workflow: Ordering checks customer eligibility, obtains delivery options and cart pricing, then assembles totals. The host composes identity, tenancy, catalog, inventory, fulfillment, payments, customers, and ordering. Some module internals are represented from the tree and README rather than sampled source, so only documented or excerpt-supported relationships are connected.

Main entry points: [`src/Host/AffanetBE.Api/Program.cs`](https://github.com/kodemargin/affanet-be/blob/main/src/Host/AffanetBE.Api/Program.cs) (API host), [`src/BuildingBlocks/AffanetBE.Presentation`](https://github.com/kodemargin/affanet-be/tree/main/src/BuildingBlocks/AffanetBE.Presentation) (Endpoints and results), [`src/Modules/Ordering/AffanetBE.Ordering/Application/Checkout/QuoteCheckoutQueryHandler.cs`](https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Ordering/AffanetBE.Ordering/Application/Checkout/QuoteCheckoutQueryHandler.cs) (Checkout quote handler), [`src/BuildingBlocks/AffanetBE.Application.Abstractions/Messaging`](https://github.com/kodemargin/affanet-be/tree/main/src/BuildingBlocks/AffanetBE.Application.Abstractions/Messaging) (Command/query handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Host and shared runtime"]
  node_api_host["API host<br/>[Program.cs]"]
  node_presentation["Endpoints and results"]
  node_handler_contracts["Command/query handlers<br/>[Messaging]"]
  node_shared_results["Result types<br/>[Result.cs]"]
  node_tenant_middleware["Tenant resolution"]
  node_route_resolver["Storefront route lookup"]
  node_tenant_db["Tenant transaction context<br/>[TenantDbContext.cs]"]
end

subgraph group_identity_tenancy["Identity and tenancy"]
  node_identity["Authentication and accounts"]
  node_tenancy["Stores and tenant setup<br/>[AffanetBE.Tenancy]"]
  node_media["Store media<br/>[MediaHandlers.cs]"]
  node_blob_storage["Blob media storage"]
end

subgraph group_commerce["Commerce modules"]
  node_catalog["Catalog management<br/>[AffanetBE.Catalog]"]
  node_product_handlers["Product handlers<br/>[ProductHandlers.cs]"]
  node_catalog_store[("Catalog persistence")]
  node_customers["Customer eligibility"]
  node_ordering["Checkout and orders<br/>[AffanetBE.Ordering]"]
  node_quote_handler["Checkout quote handler"]
  node_inventory["Stock management"]
end

subgraph group_fulfillment["Fulfillment and payments"]
  node_fulfillment["Delivery options"]
  node_delivery_handler["Delivery handlers"]
  node_fulfillment_store[("Shipping persistence")]
  node_payments["Payment methods<br/>[AffanetBE.Payments]"]
end

node_caller(("HTTP caller"))

node_caller -->|"sends HTTP"| node_api_host
node_api_host -->|"maps endpoints"| node_presentation
node_api_host -->|"composes modules"| node_identity
node_api_host -->|"composes modules"| node_tenancy
node_api_host -->|"composes modules"| node_catalog
node_api_host -->|"composes modules"| node_inventory
node_api_host -->|"composes modules"| node_fulfillment
node_api_host -->|"composes modules"| node_payments
node_api_host -->|"composes modules"| node_customers
node_api_host -->|"composes modules"| node_ordering
node_presentation -->|"dispatches requests"| node_handler_contracts
node_handler_contracts -->|"returns results"| node_shared_results
node_tenant_middleware -.->|"resolves storefront"| node_route_resolver
node_route_resolver -->|"uses transaction"| node_tenant_db
node_presentation -->|"dispatches requests"| node_product_handlers
node_product_handlers -.->|"persists products"| node_catalog_store
node_presentation -->|"dispatches query"| node_quote_handler
node_quote_handler -->|"checks eligibility"| node_customers
node_quote_handler -->|"requests delivery quote"| node_fulfillment
node_quote_handler -->|"prices cart"| node_catalog
node_presentation -->|"dispatches requests"| node_delivery_handler
node_delivery_handler -.->|"uses module database"| node_fulfillment_store
node_media -->|"stores media"| node_blob_storage

click node_api_host "https://github.com/kodemargin/affanet-be/blob/main/src/Host/AffanetBE.Api/Program.cs"
click node_presentation "https://github.com/kodemargin/affanet-be/tree/main/src/BuildingBlocks/AffanetBE.Presentation"
click node_handler_contracts "https://github.com/kodemargin/affanet-be/tree/main/src/BuildingBlocks/AffanetBE.Application.Abstractions/Messaging"
click node_shared_results "https://github.com/kodemargin/affanet-be/blob/main/src/BuildingBlocks/AffanetBE.SharedKernel/Results/Result.cs"
click node_tenant_middleware "https://github.com/kodemargin/affanet-be/blob/main/src/Host/AffanetBE.Api/Middleware/TenantResolutionMiddleware.cs"
click node_route_resolver "https://github.com/kodemargin/affanet-be/blob/main/src/BuildingBlocks/AffanetBE.Infrastructure/Tenancy/StorefrontRouteResolver.cs"
click node_tenant_db "https://github.com/kodemargin/affanet-be/blob/main/src/BuildingBlocks/AffanetBE.Infrastructure/Tenancy/TenantDbContext.cs"
click node_identity "https://github.com/kodemargin/affanet-be/tree/main/src/Modules/IdentityAccess/AffanetBE.IdentityAccess"
click node_tenancy "https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Tenancy/AffanetBE.Tenancy"
click node_media "https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Tenancy/AffanetBE.Tenancy/Application/Media/MediaHandlers.cs"
click node_blob_storage "https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Tenancy/AffanetBE.Tenancy/Infrastructure/AzureBlobMediaStorage.cs"
click node_catalog "https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Catalog/AffanetBE.Catalog"
click node_product_handlers "https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Catalog/AffanetBE.Catalog/Application/Products/ProductHandlers.cs"
click node_catalog_store "https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Catalog/AffanetBE.Catalog/Infrastructure/CatalogDbContext.cs"
click node_customers "https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Customers/AffanetBE.Customers"
click node_ordering "https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Ordering/AffanetBE.Ordering"
click node_quote_handler "https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Ordering/AffanetBE.Ordering/Application/Checkout/QuoteCheckoutQueryHandler.cs"
click node_inventory "https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Inventory/AffanetBE.Inventory"
click node_fulfillment "https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Fulfillment/AffanetBE.Fulfillment"
click node_delivery_handler "https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Fulfillment/AffanetBE.Fulfillment/Application/Delivery/DeliveryHandlers.cs"
click node_fulfillment_store "https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Fulfillment/AffanetBE.Fulfillment/Infrastructure/FulfillmentDbContext.cs"
click node_payments "https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Payments/AffanetBE.Payments"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_host,node_presentation,node_handler_contracts,node_shared_results,node_tenant_middleware,node_route_resolver,node_tenant_db toneBlue
class node_identity,node_tenancy,node_media,node_blob_storage toneAmber
class node_catalog,node_product_handlers,node_catalog_store,node_customers,node_ordering,node_quote_handler,node_inventory toneMint
class node_fulfillment,node_delivery_handler,node_fulfillment_store,node_payments toneRose
class node_caller toneIndigo
```

## Components

### Host and shared runtime

- [API host](https://github.com/kodemargin/affanet-be/blob/main/src/Host/AffanetBE.Api/Program.cs): `src/Host/AffanetBE.Api/Program.cs`
- [Endpoints and results](https://github.com/kodemargin/affanet-be/tree/main/src/BuildingBlocks/AffanetBE.Presentation): `src/BuildingBlocks/AffanetBE.Presentation`
- [Command/query handlers](https://github.com/kodemargin/affanet-be/tree/main/src/BuildingBlocks/AffanetBE.Application.Abstractions/Messaging): `src/BuildingBlocks/AffanetBE.Application.Abstractions/Messaging`
- [Result types](https://github.com/kodemargin/affanet-be/blob/main/src/BuildingBlocks/AffanetBE.SharedKernel/Results/Result.cs): `src/BuildingBlocks/AffanetBE.SharedKernel/Results/Result.cs`
- [Tenant resolution](https://github.com/kodemargin/affanet-be/blob/main/src/Host/AffanetBE.Api/Middleware/TenantResolutionMiddleware.cs): `src/Host/AffanetBE.Api/Middleware/TenantResolutionMiddleware.cs`
- [Storefront route lookup](https://github.com/kodemargin/affanet-be/blob/main/src/BuildingBlocks/AffanetBE.Infrastructure/Tenancy/StorefrontRouteResolver.cs): `src/BuildingBlocks/AffanetBE.Infrastructure/Tenancy/StorefrontRouteResolver.cs`
- [Tenant transaction context](https://github.com/kodemargin/affanet-be/blob/main/src/BuildingBlocks/AffanetBE.Infrastructure/Tenancy/TenantDbContext.cs): `src/BuildingBlocks/AffanetBE.Infrastructure/Tenancy/TenantDbContext.cs`

### Identity and tenancy

- [Authentication and accounts](https://github.com/kodemargin/affanet-be/tree/main/src/Modules/IdentityAccess/AffanetBE.IdentityAccess): `src/Modules/IdentityAccess/AffanetBE.IdentityAccess`
- [Stores and tenant setup](https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Tenancy/AffanetBE.Tenancy): `src/Modules/Tenancy/AffanetBE.Tenancy`
- [Store media](https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Tenancy/AffanetBE.Tenancy/Application/Media/MediaHandlers.cs): `src/Modules/Tenancy/AffanetBE.Tenancy/Application/Media/MediaHandlers.cs`
- [Blob media storage](https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Tenancy/AffanetBE.Tenancy/Infrastructure/AzureBlobMediaStorage.cs): `src/Modules/Tenancy/AffanetBE.Tenancy/Infrastructure/AzureBlobMediaStorage.cs`

### Commerce modules

- [Catalog management](https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Catalog/AffanetBE.Catalog): `src/Modules/Catalog/AffanetBE.Catalog`
- [Product handlers](https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Catalog/AffanetBE.Catalog/Application/Products/ProductHandlers.cs): `src/Modules/Catalog/AffanetBE.Catalog/Application/Products/ProductHandlers.cs`
- [Catalog persistence](https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Catalog/AffanetBE.Catalog/Infrastructure/CatalogDbContext.cs): `src/Modules/Catalog/AffanetBE.Catalog/Infrastructure/CatalogDbContext.cs`
- [Customer eligibility](https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Customers/AffanetBE.Customers): `src/Modules/Customers/AffanetBE.Customers`
- [Checkout and orders](https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Ordering/AffanetBE.Ordering): `src/Modules/Ordering/AffanetBE.Ordering`
- [Checkout quote handler](https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Ordering/AffanetBE.Ordering/Application/Checkout/QuoteCheckoutQueryHandler.cs): `src/Modules/Ordering/AffanetBE.Ordering/Application/Checkout/QuoteCheckoutQueryHandler.cs`
- [Stock management](https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Inventory/AffanetBE.Inventory): `src/Modules/Inventory/AffanetBE.Inventory`

### Fulfillment and payments

- [Delivery options](https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Fulfillment/AffanetBE.Fulfillment): `src/Modules/Fulfillment/AffanetBE.Fulfillment`
- [Delivery handlers](https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Fulfillment/AffanetBE.Fulfillment/Application/Delivery/DeliveryHandlers.cs): `src/Modules/Fulfillment/AffanetBE.Fulfillment/Application/Delivery/DeliveryHandlers.cs`
- [Shipping persistence](https://github.com/kodemargin/affanet-be/blob/main/src/Modules/Fulfillment/AffanetBE.Fulfillment/Infrastructure/FulfillmentDbContext.cs): `src/Modules/Fulfillment/AffanetBE.Fulfillment/Infrastructure/FulfillmentDbContext.cs`
- [Payment methods](https://github.com/kodemargin/affanet-be/tree/main/src/Modules/Payments/AffanetBE.Payments): `src/Modules/Payments/AffanetBE.Payments`

### Other components

- **HTTP caller**

## Connections

- HTTP caller → API host: sends HTTP (evidence: `README.md`)
- API host → Endpoints and results: maps endpoints (evidence: `README.md`)
- API host → Authentication and accounts: composes modules (evidence: `src/Host/AffanetBE.Api/Program.cs`)
- API host → Stores and tenant setup: composes modules (evidence: `src/Host/AffanetBE.Api/Program.cs`)
- API host → Catalog management: composes modules (evidence: `src/Host/AffanetBE.Api/Program.cs`)
- API host → Stock management: composes modules (evidence: `src/Host/AffanetBE.Api/Program.cs`)
- API host → Delivery options: composes modules (evidence: `src/Host/AffanetBE.Api/Program.cs`)
- API host → Payment methods: composes modules (evidence: `src/Host/AffanetBE.Api/Program.cs`)
- API host → Customer eligibility: composes modules (evidence: `src/Host/AffanetBE.Api/Program.cs`)
- API host → Checkout and orders: composes modules (evidence: `src/Host/AffanetBE.Api/Program.cs`)
- Endpoints and results → Command/query handlers: dispatches requests (evidence: `README.md`)
- Command/query handlers → Result types: returns results (evidence: `src/BuildingBlocks/AffanetBE.Application.Abstractions/Messaging/ICommandHandler.cs`)
- Tenant resolution → Storefront route lookup: resolves storefront (evidence: `src/Host/AffanetBE.Api/Middleware/TenantResolutionMiddleware.cs`)
- Storefront route lookup → Tenant transaction context: uses transaction (evidence: `src/BuildingBlocks/AffanetBE.Infrastructure/Tenancy/StorefrontRouteResolver.cs`)
- Endpoints and results → Product handlers: dispatches requests (evidence: `README.md`)
- Product handlers → Catalog persistence: persists products
- Endpoints and results → Checkout quote handler: dispatches query (evidence: `README.md`)
- Checkout quote handler → Customer eligibility: checks eligibility (evidence: `src/Modules/Ordering/AffanetBE.Ordering/Application/Checkout/QuoteCheckoutQueryHandler.cs`)
- Checkout quote handler → Delivery options: requests delivery quote (evidence: `src/Modules/Ordering/AffanetBE.Ordering/Application/Checkout/QuoteCheckoutQueryHandler.cs`)
- Checkout quote handler → Catalog management: prices cart (evidence: `src/Modules/Ordering/AffanetBE.Ordering/Application/Checkout/QuoteCheckoutQueryHandler.cs`)
- Endpoints and results → Delivery handlers: dispatches requests (evidence: `README.md`)
- Delivery handlers → Shipping persistence: uses module database
- Store media → Blob media storage: stores media (evidence: `src/Modules/Tenancy/AffanetBE.Tenancy/Infrastructure/AzureBlobMediaStorage.cs`)
