# olibanjoli/tradesim architecture

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

- Interactive diagram: https://gitdiagram.com/olibanjoli/tradesim
- Repository: https://github.com/olibanjoli/tradesim

## Overview

##### Project type and purpose
- TradeSim is a .NET/C# console-based bot application whose sole purpose is to drive a trade-simulation game via slash-style commands (e.g. “/sim start 1000”) over an external chat platform (Discord, Slack, etc.).
- It encapsulates core simulation logic in a “BotEngine” library and exposes it through an interaction module that listens for and replies to user commands.

##### File structure
Top-level
- TradeSim.sln – Visual Studio solution
- README.md – project overview and command list
“TradeSim” directory
- Program.cs – application entry point and DI/configuration bootstrap
- Settings.cs – configuration holder (API keys, thresholds, tick value)
- TradeSimInteractionModule.cs – adapter translating chat events into engine calls
- BotEngine/
– Engine.cs, EngineManager.cs – orchestrates simulation lifecycle
– User.cs, Order.cs, Scores.cs, ScoreEntry.cs, OrderType.cs – domain entities and value types
- TradeSim.csproj, .gitignore

##### Extract additional insights from README
- No external database: all state (orders, scores, 2× flags) lives in memory for the duration of a simulation.
- The bot lifecycle: Start → Tick → Pause/Close → Score reporting → Reset.

a. Main components
1. Chat Platform (Discord/Slack API)
2. Interaction Module (TradeSimInteractionModule)
3. Application Host (Program + Settings)
4. Core Engine (BotEngine library: EngineManager + Engine)
5. Domain Model (User, Order, Scores, ScoreEntry, OrderType)
6. In-Memory Data Store (transient state container)
7. (Optional) Logging/Monitoring
b. Relationships & data flow
– External users send slash commands → Chat Platform API
– API invokes Interaction Module ←→ parses commands & arguments
– Interaction Module calls EngineManager methods (Start, Tick, Pause, etc.)
– EngineManager updates Domain Model in the In-Memory Data Store
– EngineManager returns results/messages → Interaction Module
– Interaction Module issues chat replies back via Chat Platform API
– Settings.cs provides config values at startup to Program and Interaction Module
c. Architectural patterns & design principles
– Layered (Adapter → Application → Domain)
– Separation of concerns: Interaction (I/O) vs. Business logic vs. Configuration
– Hexagonal/Ports & Adapters style: BotEngine is the core, InteractionModule is a driver adapter
– Single Responsibility: EngineManager only orchestrates; Engine holds simulation rules
d. Key technologies/frameworks
– .NET (Core or Framework) console application
– C# 10+
– Any chat-bot library (Discord.Net, Slack SDK) referenced in Interaction Module
– In-process, in-memory state (no external DB)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    User["User"]:::external
    ChatAPI["Chat Platform API\n(Discord/Slack)"]:::external

    %% Adapter Layer
    subgraph "Chat Integration Layer"
        Interaction["TradeSimInteractionModule"]:::adapter
    end

    subgraph "Application Host"
        Program["Program.cs"]:::host
        Settings["Settings.cs"]:::host
    end

    %% Core Logic
    subgraph "BotEngine Library"
        direction TB
        EngineMgr["EngineManager"]:::core
        Engine["Engine"]:::core
    end

    %% Domain Model
    subgraph "Domain Model"
        direction TB
        UserModel["User.cs"]:::domain
        OrderModel["Order.cs"]:::domain
        OrderTypeModel["OrderType.cs"]:::domain
        ScoresModel["Scores.cs"]:::domain
        ScoreEntryModel["ScoreEntry.cs"]:::domain
    end

    %% In-Memory Storage
    Store[("In-Memory Data Store")]:::storage

    %% Flow
    User -->|"slash command"| ChatAPI
    ChatAPI -->|"receives event"| Interaction
    Interaction -->|"parses & routes"| Program
    Program -->|"loads config"| Settings
    Program -->|"injects into"| Interaction
    Interaction -->|"/sim start, /sim tick, etc."| EngineMgr
    EngineMgr -->|"orchestrates rules"| Engine
    Engine -->|"reads/writes"| Store
    EngineMgr -->|"manages entities"| UserModel
    EngineMgr -->|"manages entities"| OrderModel
    EngineMgr -->|"uses value type"| OrderTypeModel
    EngineMgr -->|"updates scores"| ScoresModel
    EngineMgr -->|"creates entries"| ScoreEntryModel
    EngineMgr -->|"returns results"| Interaction
    Interaction -->|"sends reply"| ChatAPI

    %% Documentation & Project Files
    subgraph "Project Artifacts"
        VS["TradeSim.sln"]:::docs
        README["README.md"]:::docs
        Csproj["TradeSim.csproj"]:::docs
        Gitignore[".gitignore"]:::docs
    end

    %% Legend
    subgraph "Legend"
        direction TB
        ext["External Systems"]:::external
        adp["Adapter / Integration"]:::adapter
        hostL["Application Host"]:::host
        coreL["Core Logic"]:::core
        domL["Domain Model"]:::domain
        stor["Storage"]:::storage
        docL["Docs & Config"]:::docs
    end

    %% Click Events
    click VS "https://github.com/olibanjoli/tradesim/blob/master/TradeSim.sln"
    click README "https://github.com/olibanjoli/tradesim/blob/master/README.md"
    click Program "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/Program.cs"
    click Settings "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/Settings.cs"
    click Interaction "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/TradeSimInteractionModule.cs"
    click BotEngineDir "https://github.com/olibanjoli/tradesim/tree/master/TradeSim/BotEngine/"
    click EngineMgr "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/BotEngine/EngineManager.cs"
    click Engine "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/BotEngine/Engine.cs"
    click UserModel "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/BotEngine/User.cs"
    click OrderModel "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/BotEngine/Order.cs"
    click OrderTypeModel "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/BotEngine/OrderType.cs"
    click ScoresModel "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/BotEngine/Scores.cs"
    click ScoreEntryModel "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/BotEngine/ScoreEntry.cs"
    click Csproj "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/TradeSim.csproj"
    click Gitignore "https://github.com/olibanjoli/tradesim/blob/master/TradeSim/.gitignore"

    %% Styles
    classDef external fill:#a8e6cf,stroke:#379683,color:#05386b,stroke-width:2px;
    classDef adapter fill:#dcedc1,stroke:#8bc34a,color:#33691e,stroke-width:2px;
    classDef host fill:#ffe0b2,stroke:#fb8c00,color:#e65100,stroke-width:2px;
    classDef core fill:#ffd54f,stroke:#ffb300,color:#e65100,stroke-width:2px;
    classDef domain fill:#ffccbc,stroke:#ff5722,color:#bf360c,stroke-width:2px;
    classDef storage fill:#e0e0e0,stroke:#9e9e9e,color:#424242,stroke-width:2px;
    classDef docs fill:#eceff1,stroke:#90a4ae,color:#37474f,stroke-width:2px;
```
