# 0xroco/ludereai architecture

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

- Interactive diagram: https://gitdiagram.com/0xroco/ludereai
- Repository: https://github.com/0xroco/ludereai

## Overview

##### Main Components
- Frontend Client (LudereAI.WPF): A WPF desktop application that provides the interactive chat interface, game state visualization, voice synthesis feedback, and user interactions.
- Backend API (LudereAI.API): A .NET-based web API hosting various controllers (for Accounts, Assistant functionality, Authentication, Conversations, Health checks) that serve as the entry point for client requests.
- Application and Domain Layers:
- Application Layer (LudereAI.Application): Defines interfaces for services (authentication, accounts, conversations, messages, etc.) and factories used to abstract business logic.
- Domain Layer (LudereAI.Domain): Contains the core domain models, mappers, and business entities representing accounts, chats, messages, configuration, and feature flags.
- Infrastructure Layer (LudereAI.Infrastructure): Implements the interfaces defined in the Application Layer, including concrete services like AccountService, AuthService, ConversationsService, repositories accessing the MySQL database via DatabaseContext, and factories for accounts and chat clients. Note also the addition of middleware like CloudflareMiddleware and additional functionality like screenshot processing.
- Shared Components (LudereAI.Shared): Offers common data transfer objects (DTOs), enums, result classes, and other utilities that are used throughout the system.
- External Services Integration:
- Integration with the OpenAI API (or Gemini via OpenAI-compatible endpoints) for AI responses.
- Integration with ElevenLabs and/or Piper for voice synthesis.
- A MySQL database is used for conversation history, user preferences, and authentication.

##### Relationships and Data Flow
- The WPF client communicates with the backend API by consuming endpoints exposed through controllers.
- The API routes client requests to the appropriate application services.
- Application services act as an intermediary between the API’s controllers and the underlying infrastructure (repositories, external integrations).
- The Infrastructure layer handles direct interactions with:
- The MySQL database (via DatabaseContext and repositories),
- External APIs such as OpenAI for AI responses and ElevenLabs/Piper for text-to-speech.
- Shared components (DTOs, enums, etc.) are used across layers to standardize communication.

##### Incorporate Architectural Patterns & Design Principles
- Clear separation of concerns: Each project (API, Application, Domain, Infrastructure, Shared) and each folder (e.g., Controllers, Services, Repositories) represents a specific responsibility.
- Use of Factory and Repository patterns: Factories in Infrastructure and Repository interfaces in Application indicate a design focused on loose coupling and extensibility.

##### Technological Details
- Technologies and frameworks should be labeled:
- Backend: .NET 9 (C#)
- Frontend: WPF
- AI integration: OpenAI API (or Gemini)
- Voice Synthesis: ElevenLabs API or self-hosted Piper
- Storage: MySQL for persistent data
- That custom middleware (e.g., CloudflareMiddleware) and additional services (instruction loader, timestamp interceptor) support extended functionality.

##### Final Touches
- Keep it detailed enough so that the core architectural flows and integration points (such as screenshot analysis for computer vision and consequent textual/audio responses) are well-illustrated.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        WPF["WPF Client"]:::frontend
    end

    subgraph "Backend Layer"
        API["LudereAI API – Controllers"]:::backend
    end

    subgraph "Application & Domain Layers"
        App["Application Layer"]:::application
        Domain["Domain Layer"]:::domain
    end

    subgraph "Infrastructure & External Services"
        Infra["Infrastructure Layer"]:::infrastructure
        DB["MySQL Database"]:::database
        AI["OpenAI/Gemini Integration"]:::external
        Voice["ElevenLabs/Piper Integration"]:::external
    end

    subgraph "Shared Components"
        Shared["DTOs, Enums, Utilities"]:::shared
    end

    %% Connections
    WPF -->|"ClientRequest"| API
    API -->|"Routes"| App
    App -->|"BusinessLogic"| Domain
    App -->|"CallsInfra"| Infra
    Infra -->|"DataAccess"| DB
    Infra -->|"AIIntegration"| AI
    Infra -->|"VoiceSynthesis"| Voice

    %% Shared components usage (dashed lines)
    App -- "UsesDTOs"--> Shared
    Domain -- "UsesDTOs"--> Shared
    Infra -- "UsesDTOs"--> Shared

    %% Click Events
    click WPF "https://github.com/0xroco/ludereai/blob/master/LudereAI.WPF"
    click API "https://github.com/0xroco/ludereai/blob/master/LudereAI.API"
    click App "https://github.com/0xroco/ludereai/blob/master/LudereAI.Application"
    click Domain "https://github.com/0xroco/ludereai/blob/master/LudereAI.Domain"
    click Infra "https://github.com/0xroco/ludereai/blob/master/LudereAI.Infrastructure"
    click Shared "https://github.com/0xroco/ludereai/blob/master/LudereAI.Shared"

    %% Styles
    classDef frontend fill:#e3f2fd,stroke:#0d47a1,stroke-width:2px;
    classDef backend fill:#e8f5e9,stroke:#1b5e20,stroke-width:2px;
    classDef application fill:#fff3e0,stroke:#e65100,stroke-width:2px;
    classDef domain fill:#fce4ec,stroke:#880e4f,stroke-width:2px;
    classDef infrastructure fill:#f3e5f5,stroke:#4a148c,stroke-width:2px;
    classDef external fill:#eceff1,stroke:#37474f,stroke-width:2px;
    classDef shared fill:#ffebee,stroke:#b71c1c,stroke-width:2px;
    classDef database fill:#e0f7fa,stroke:#006064,stroke-width:2px;
```
