# lenardmagat/chatengine architecture

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

- Interactive diagram: https://gitdiagram.com/lenardmagat/chatengine
- Repository: https://github.com/lenardmagat/chatengine

## Overview

ChatEngine is a SignalR chat backend for a peer-to-peer bartering platform. Its main workflow authenticates a user, initializes or loads a room, and sends messages that are persisted and broadcast; trade negotiations are represented as chat events and offer records. REST account, inventory, and search capabilities form related branches, while background workers synchronize documents and process offer lifecycles. The README documents chat and trade capabilities beyond the sampled handlers; their exact wiring is not fully verifiable, so uncertain links are omitted.

Main entry points: [`Infrastructure/DataBase/DataBaseContext.cs`](https://github.com/lenardmagat/chatengine/blob/main/Infrastructure/DataBase/DataBaseContext.cs) (Application database), [`Services/EventHandlers/InventoryEventHandler`](https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/InventoryEventHandler) (Inventory handlers), [`EndPoints/Hub/AppHub.cs`](https://github.com/lenardmagat/chatengine/blob/main/EndPoints/Hub/AppHub.cs) (SignalR hub), [`Services/EventHandlers/ChatEventHandler`](https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/ChatEventHandler) (Chat handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_rest["REST routers<br/>[FeatureRouters.cs]"]
  node_hub["SignalR hub<br/>[AppHub.cs]"]
end

subgraph group_domain["Chat and trades"]
  node_chatcommands["Chat commands<br/>[ChatEvents.cs]"]
  node_chatlogic["Chat handlers"]
  node_chatmodels["Rooms and messages<br/>[ChatRoomModel.cs]"]
  node_tradecommands["Offer commands"]
  node_tradelogic["Offer handlers"]
  node_trademodels["Trade and sale offers<br/>[TradeOfferModel.cs]"]
end

subgraph group_accounts["Accounts and inventory"]
  node_accountapi["Account routers"]
  node_accountlogic["Account handlers"]
  node_authlogic["Authentication handlers"]
  node_inventoryapi["Inventory routers"]
  node_inventorylogic["Inventory handlers"]
  node_products["Products<br/>[ProductModel.cs]"]
end

subgraph group_search["Search indexing"]
  node_searchapi["Search endpoint<br/>[SearchRouter.cs]"]
  node_searchlogic["Search strategies"]
  node_searchservice["MeiliSearch service"]
  node_syncworker["Index sync worker<br/>[MeiliSyncWorker.cs]"]
  node_documentation["Document handlers"]
end

subgraph group_platform["Persistence and security"]
  node_database[("Application database<br/>[DataBaseContext.cs]")]
  node_authservice["JWT services<br/>[JwtAuthServices.cs]"]
  node_tokenservice["Token creation"]
end

node_client(("User client"))
node_meili[("MeiliSearch")]

node_client -->|"connects and sends"| node_hub
node_client -->|"calls REST"| node_rest
node_hub -->|"dispatches"| node_chatcommands
node_chatcommands -->|"handled by"| node_chatlogic
node_chatlogic -->|"reads and writes"| node_database
node_chatlogic -->|"creates chat data"| node_chatmodels
node_hub -.->|"offer actions"| node_tradelogic
node_tradelogic -->|"reads and writes"| node_database
node_tradelogic -->|"updates offers"| node_trademodels
node_accountapi -->|"dispatches"| node_accountlogic
node_accountapi -->|"dispatches"| node_authlogic
node_accountlogic -->|"reads and writes"| node_database
node_authlogic -->|"issues tokens"| node_authservice
node_authservice -->|"creates tokens"| node_tokenservice
node_authservice -->|"stores refresh tokens"| node_database
node_inventoryapi -->|"dispatches"| node_inventorylogic
node_inventorylogic -->|"reads and writes"| node_database
node_inventorylogic -->|"manages products"| node_products
node_searchapi -->|"dispatches query"| node_searchlogic
node_searchlogic -->|"searches index"| node_searchservice
node_searchservice -->|"queries and indexes"| node_meili
node_syncworker -->|"reads outbox"| node_database
node_syncworker -->|"dispatches documents"| node_documentation
node_documentation -->|"indexes documents"| node_searchservice
node_inventorylogic -->|"records outbox entries"| node_database

click node_rest "https://github.com/lenardmagat/chatengine/tree/main/EndPoints/Routers/FeatureRouters.cs"
click node_hub "https://github.com/lenardmagat/chatengine/blob/main/EndPoints/Hub/AppHub.cs"
click node_chatcommands "https://github.com/lenardmagat/chatengine/blob/main/Services/SystemEvents/ChatEvents.cs"
click node_chatlogic "https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/ChatEventHandler"
click node_chatmodels "https://github.com/lenardmagat/chatengine/blob/main/Datas/Models/ChatRoomModel.cs"
click node_tradecommands "https://github.com/lenardmagat/chatengine/blob/main/Services/SystemEvents/UnifiedProposedOffer.cs"
click node_tradelogic "https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/OfferingMechanismsHandler"
click node_trademodels "https://github.com/lenardmagat/chatengine/blob/main/Datas/Models/TradeOfferModel.cs"
click node_accountapi "https://github.com/lenardmagat/chatengine/tree/main/EndPoints/Routers/AccountRouters"
click node_accountlogic "https://github.com/lenardmagat/chatengine/blob/main/Services/EventHandlers/AccountEventHandler/CreateAccountHandler.cs"
click node_authlogic "https://github.com/lenardmagat/chatengine/blob/main/Services/EventHandlers/AuthEventHandler/LoginCommandHandler.cs"
click node_inventoryapi "https://github.com/lenardmagat/chatengine/tree/main/EndPoints/Routers/InventoryRouter"
click node_inventorylogic "https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/InventoryEventHandler"
click node_products "https://github.com/lenardmagat/chatengine/blob/main/Datas/Models/ProductModel.cs"
click node_searchapi "https://github.com/lenardmagat/chatengine/blob/main/EndPoints/Routers/FeatureRouters.cs/SearchRouter.cs"
click node_searchlogic "https://github.com/lenardmagat/chatengine/blob/main/Services/EventHandlers/SearchEventHandler.cs/ProductSearchHandler.cs"
click node_searchservice "https://github.com/lenardmagat/chatengine/blob/main/Services/EventsServices/MeiliSearchServices.cs"
click node_syncworker "https://github.com/lenardmagat/chatengine/blob/main/BackGroundWorkers/MeiliSyncWorker.cs"
click node_documentation "https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/BackgroundWorkerHandler/DocumentationEventHandler"
click node_database "https://github.com/lenardmagat/chatengine/blob/main/Infrastructure/DataBase/DataBaseContext.cs"
click node_authservice "https://github.com/lenardmagat/chatengine/blob/main/Services/EventsServices/JwtAuthServices.cs"
click node_tokenservice "https://github.com/lenardmagat/chatengine/blob/main/Infrastructure/Security/JwtTokenServices.cs"

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_rest,node_hub,node_client toneBlue
class node_chatcommands,node_chatlogic,node_chatmodels,node_tradecommands,node_tradelogic,node_trademodels,node_meili toneAmber
class node_accountapi,node_accountlogic,node_authlogic,node_inventoryapi,node_inventorylogic,node_products toneMint
class node_searchapi,node_searchlogic,node_searchservice,node_syncworker,node_documentation toneRose
class node_database,node_authservice,node_tokenservice toneIndigo
```

## Components

### API entry

- [REST routers](https://github.com/lenardmagat/chatengine/tree/main/EndPoints/Routers/FeatureRouters.cs): `EndPoints/Routers/FeatureRouters.cs`
- [SignalR hub](https://github.com/lenardmagat/chatengine/blob/main/EndPoints/Hub/AppHub.cs): `EndPoints/Hub/AppHub.cs`

### Chat and trades

- [Chat commands](https://github.com/lenardmagat/chatengine/blob/main/Services/SystemEvents/ChatEvents.cs): `Services/SystemEvents/ChatEvents.cs`
- [Chat handlers](https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/ChatEventHandler): `Services/EventHandlers/ChatEventHandler`
- [Rooms and messages](https://github.com/lenardmagat/chatengine/blob/main/Datas/Models/ChatRoomModel.cs): `Datas/Models/ChatRoomModel.cs`
- [Offer commands](https://github.com/lenardmagat/chatengine/blob/main/Services/SystemEvents/UnifiedProposedOffer.cs): `Services/SystemEvents/UnifiedProposedOffer.cs`
- [Offer handlers](https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/OfferingMechanismsHandler): `Services/EventHandlers/OfferingMechanismsHandler`
- [Trade and sale offers](https://github.com/lenardmagat/chatengine/blob/main/Datas/Models/TradeOfferModel.cs): `Datas/Models/TradeOfferModel.cs`

### Accounts and inventory

- [Account routers](https://github.com/lenardmagat/chatengine/tree/main/EndPoints/Routers/AccountRouters): `EndPoints/Routers/AccountRouters`
- [Account handlers](https://github.com/lenardmagat/chatengine/blob/main/Services/EventHandlers/AccountEventHandler/CreateAccountHandler.cs): `Services/EventHandlers/AccountEventHandler/CreateAccountHandler.cs`
- [Authentication handlers](https://github.com/lenardmagat/chatengine/blob/main/Services/EventHandlers/AuthEventHandler/LoginCommandHandler.cs): `Services/EventHandlers/AuthEventHandler/LoginCommandHandler.cs`
- [Inventory routers](https://github.com/lenardmagat/chatengine/tree/main/EndPoints/Routers/InventoryRouter): `EndPoints/Routers/InventoryRouter`
- [Inventory handlers](https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/InventoryEventHandler): `Services/EventHandlers/InventoryEventHandler`
- [Products](https://github.com/lenardmagat/chatengine/blob/main/Datas/Models/ProductModel.cs): `Datas/Models/ProductModel.cs`

### Search indexing

- [Search endpoint](https://github.com/lenardmagat/chatengine/blob/main/EndPoints/Routers/FeatureRouters.cs/SearchRouter.cs): `EndPoints/Routers/FeatureRouters.cs/SearchRouter.cs`
- [Search strategies](https://github.com/lenardmagat/chatengine/blob/main/Services/EventHandlers/SearchEventHandler.cs/ProductSearchHandler.cs): `Services/EventHandlers/SearchEventHandler.cs/ProductSearchHandler.cs`
- [MeiliSearch service](https://github.com/lenardmagat/chatengine/blob/main/Services/EventsServices/MeiliSearchServices.cs): `Services/EventsServices/MeiliSearchServices.cs`
- [Index sync worker](https://github.com/lenardmagat/chatengine/blob/main/BackGroundWorkers/MeiliSyncWorker.cs): `BackGroundWorkers/MeiliSyncWorker.cs`
- [Document handlers](https://github.com/lenardmagat/chatengine/tree/main/Services/EventHandlers/BackgroundWorkerHandler/DocumentationEventHandler): `Services/EventHandlers/BackgroundWorkerHandler/DocumentationEventHandler`

### Persistence and security

- [Application database](https://github.com/lenardmagat/chatengine/blob/main/Infrastructure/DataBase/DataBaseContext.cs): `Infrastructure/DataBase/DataBaseContext.cs`
- [JWT services](https://github.com/lenardmagat/chatengine/blob/main/Services/EventsServices/JwtAuthServices.cs): `Services/EventsServices/JwtAuthServices.cs`
- [Token creation](https://github.com/lenardmagat/chatengine/blob/main/Infrastructure/Security/JwtTokenServices.cs): `Infrastructure/Security/JwtTokenServices.cs`

### Other components

- **User client**
- **MeiliSearch**

## Connections

- User client → SignalR hub: connects and sends
- User client → REST routers: calls REST
- SignalR hub → Chat commands: dispatches
- Chat commands → Chat handlers: handled by
- Chat handlers → Application database: reads and writes
- Chat handlers → Rooms and messages: creates chat data
- SignalR hub → Offer handlers: offer actions
- Offer handlers → Application database: reads and writes
- Offer handlers → Trade and sale offers: updates offers
- Account routers → Account handlers: dispatches
- Account routers → Authentication handlers: dispatches
- Account handlers → Application database: reads and writes
- Authentication handlers → JWT services: issues tokens
- JWT services → Token creation: creates tokens
- JWT services → Application database: stores refresh tokens
- Inventory routers → Inventory handlers: dispatches
- Inventory handlers → Application database: reads and writes
- Inventory handlers → Products: manages products
- Search endpoint → Search strategies: dispatches query
- Search strategies → MeiliSearch service: searches index
- MeiliSearch service → MeiliSearch: queries and indexes
- Index sync worker → Application database: reads outbox
- Index sync worker → Document handlers: dispatches documents
- Document handlers → MeiliSearch service: indexes documents
- Inventory handlers → Application database: records outbox entries
