# ln0330/ai-chat-demo architecture

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

- Interactive diagram: https://gitdiagram.com/ln0330/ai-chat-demo
- Repository: https://github.com/ln0330/ai-chat-demo

## Overview

##### Project type and purpose
- This is a full-stack desktop + web solution (“AI-Chat-Demo”) built in C#.
- Purpose: A WPF client that communicates via REST to an ASP.NET Core Web API which powers an AI Q&A interface using a local Llama model and persists chat history in MySQL.

##### File structure
- Top-level solution: WpfAIGreeting.sln
- Two main projects/directories:
- GreetingAPI – ASP.NET Core REST API
· Controllers (GreetingController.cs)
· Models (AskAIRequest, HistoryItem)
· Program.cs, appsettings.json (incl. MySQL connection), launch settings
· .http test file for endpoints
- WpfClient – WPF desktop application
· App.xaml / MainWindow.xaml (UI)
· Models (HistoryItem)
- Configuration and deployment artifacts (.config, .gitignore, .gitattributes)

##### Key insights from the README
- Frontend (WPF) and backend (ASP.NET Core) are separated.
- Uses MVC concept, RESTful API, MySQL datastore, local Llama AI model.
- Demo shows UI exchanging messages with API, which calls AI engine and logs history.

##### Main components and their interactions
a. Components:
1) WPF Client (Desktop UI)
2) ASP.NET Core Web API
– Presentation Layer (Controllers)
– Business Logic Layer (AI service integration)
– Data Access Layer (MySQL repository)
3) MySQL Database
4) Local Llama AI Engine (model inference)
5) External HTTP testing tool (.http file)
b. Relationships / Data flow:
- WPF Client → HTTP (REST) → GreetingAPI Controller
- Controller → invokes AI service → Llama Engine → returns answer
- Controller → writes/reads chat HistoryItem → MySQL DB
- API → HTTP response → WPF Client updates UI
c. Architectural patterns and principles:
- Separation of concerns: UI, API, AI logic, persistence
- MVC in API (Controllers + Models)
- RESTful communications
- Dependency Injection in ASP.NET Core
d. Key technologies:
- WPF (.NET desktop)
- ASP.NET Core Web API
- MySQL (Connector in appsettings.json)
- Local Llama model library (in Business Logic)
- Visual Studio 2022

##### Final advice
- Keep labels concise but descriptive.
- This level of detail captures the essential architecture without overcomplicating.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Wpf Client"
        direction TB
        WPFUI["WpfClient UI"]:::client
        HistoryModelClient["HistoryItem Model"]:::model
    end

    %% API Layer
    subgraph "GreetingAPI"
        direction TB
        Controller["GreetingController"]:::controller
        Service["AI Service"]:::service
        Repo["History Repository"]:::repository
        subgraph "Models"
            direction TB
            ModelAsk["AskAIRequest Model"]:::model
            ModelHist["HistoryItem Model"]:::model
        end
        Config["Program.cs & Config"]:::config
    end

    %% External Components
    AI["Local Llama AI Engine"]:::ai
    DB["MySQL Database"]:::db
    TestTool["HTTP Test File"]:::test
    Solution["Solution & Config Files"]:::config

    %% Connections
    WPFUI -->|"POST /api/greeting\n(JSON AskAIRequest)"| Controller
    TestTool -->|"HTTP Request\n(JSON AskAIRequest)"| Controller
    Controller -->|"invokes"| Service
    Service -->|"infer"| AI
    AI -->|"response"| Service
    Controller -->|"reads/writes"| Repo
    Repo -->|"SQL Queries"| DB
    Controller -->|"returns JSON\n(HistoryItem)"| WPFUI

    %% Click Events
    click WPFUI "https://github.com/ln0330/ai-chat-demo/tree/master/WpfClient"
    click HistoryModelClient "https://github.com/ln0330/ai-chat-demo/blob/master/WpfClient/Models/HistoryItem.cs"
    click Controller "https://github.com/ln0330/ai-chat-demo/blob/master/GreetingAPI/Controllers/GreetingController.cs"
    click ModelAsk "https://github.com/ln0330/ai-chat-demo/blob/master/GreetingAPI/Models/AskAIRequest.cs"
    click ModelHist "https://github.com/ln0330/ai-chat-demo/blob/master/GreetingAPI/Models/HistoryItem.cs"
    click TestTool "https://github.com/ln0330/ai-chat-demo/blob/master/GreetingAPI/GreetingAPI.http"
    click Config "https://github.com/ln0330/ai-chat-demo/blob/master/GreetingAPI/Program.cs"
    click Solution "https://github.com/ln0330/ai-chat-demo/blob/master/WpfAIGreeting.sln"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#024;
    classDef controller fill:#DFFFD0,stroke:#292;
    classDef service fill:#D0FFD0,stroke:#292;
    classDef repository fill:#C0FFC0,stroke:#292;
    classDef model fill:#FFFFD0,stroke:#992;
    classDef db fill:#FFF0B3,stroke:#997,stroke-width:2px;
    classDef ai fill:#FFD0A0,stroke:#DA7000;
    classDef test fill:#FFE0FF,stroke:#D070A0;
    classDef config fill:#F0F0F0,stroke:#888;
```
