# tyrrrz/discordchatexporter architecture

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

- Interactive diagram: https://gitdiagram.com/tyrrrz/discordchatexporter
- Repository: https://github.com/tyrrrz/discordchatexporter

## Overview

##### Project type and purpose
- DiscordChatExporter is a cross-platform client application (desktop GUI and CLI) that exports message history from Discord channels.
- It’s organized as three main deliverables:
- DiscordChatExporter.Gui – the Avalonia-based desktop UI
- DiscordChatExporter.Cli – the command-line interface
- DiscordChatExporter.Core – the shared library containing domain models, Discord API client, exporters, filters, and format writers

##### High-level layers & components
- Presentation Layer
- CLI (Program.cs + Commands/*)
- GUI (App.axaml, ViewModels/*, Views/*, Services/*)
- Application Layer
- Command handlers (ExportCommandBase, DiscordCommandBase)
- DialogManager, ViewManager, SettingsService, UpdateService
- Domain/Core Layer
- DiscordClient (HTTP wrapper over Discord REST API)
- Data models under Discord/Data (Message, Channel, Guild, User, Embeds, etc.)
- Exporting pipeline (ExportContext → MessageExporter → format‐specific writers: CsvMessageWriter, HtmlMessageWriter, JsonMessageWriter, PlainTextMessageWriter)
- Filtering (MessageFilter AST, grammar parser)
- Partitioning (FileSizePartitionLimit, MessageCountPartitionLimit)
- Markdown parsing/rendering (MarkdownParser, MarkdownVisitor, HtmlMarkdownVisitor)
- Infrastructure Layer
- HTTP utilities (in Core/Utils/Http.cs)
- File system & path utilities (PathEx, UrlBuilder)
- Docker support (dockerfile, docker-entrypoint.sh)
- CI/CD (GitHub workflows, Dependabot)

##### External dependencies & services
- Discord’s REST API (HTTPS endpoints) – the data source
- Local file system – export destination
- Docker hub – optional containerized CLI
- GitHub Actions – build/test/release pipeline

##### Diagramming guidance
a. Main components to represent
– User (actor)
– CLI UI & GUI UI
– Command/Controller modules
– Core library (DiscordClient, Export pipeline, Filters, Writers)
– Discord REST API (external service)
– File system (local storage)
– CI/CD pipeline (optional – GitHub Actions, Docker)

b. Relationships & data flows
1. User → CLI or GUI (input triggers)
2. CLI/GUI → Command Handler → Core API
3. Core → DiscordClient → Discord REST API (HTTP request/response)
4. Core → ExportContext → MessageExporter → Writers
5. Writers → File system (writes export files)
6. GUI may invoke UpdateService to check GitHub Releases

c. Architectural patterns & principles
– Layered architecture (Presentation → Application → Domain → Infrastructure)
– Command pattern for CLI commands
– Dependency inversion: Core library does not depend on UI
– Single Responsibility: separate classes for data models, exporting, filtering, rendering

d. Key technologies & frameworks
– C#/.NET 6+
– Avalonia UI (GUI)
– Spectre.Console.CommandLine or similar for CLI binding
– Razor templates (.cshtml) for HTML Preamble/Postamble
– Superpower-based parser for filters & markdown
– GitHub Actions for CI/CD, Docker for containerization

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actors
    User["User"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        CLI["CLI"]:::frontend
        GUI["GUI (Avalonia)"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        CmdHandlers["Command Handlers"]:::app
        DialogMgr["DialogManager"]:::app
        ViewMgr["ViewManager"]:::app
        SettingsSvc["SettingsService"]:::app
        UpdateSvc["UpdateService"]:::app
    end

    %% Core Domain Layer
    subgraph "Core Domain Layer"
        direction TB
        subgraph "Discord API Client & Data"
            direction TB
            DiscordClient["DiscordClient"]:::core
            DataModels["Data Models"]:::core
        end
        subgraph "Exporting Pipeline"
            direction TB
            ExportContext["ExportContext"]:::core
            MessageExporter["MessageExporter"]:::core
            ExportRequest["ExportRequest/ExportFormat"]:::core
        end
        subgraph "Format Writers"
            direction TB
            CsvWriter["CsvMessageWriter"]:::core
            HtmlWriter["HtmlMessageWriter"]:::core
            JsonWriter["JsonMessageWriter"]:::core
            PlainWriter["PlainTextMessageWriter"]:::core
        end
        Filtering["Filtering"]:::core
        Partitioning["Partitioning"]:::core
        Markdown["Markdown Parsing/Rendering"]:::core
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        HttpUtils["HTTP Utils"]:::infra
        FsUtils["File & URL Utils"]:::infra
        DockerSupport["Docker Support"]:::infra
        CICD["CI/CD Pipeline"]:::infra
    end

    %% External Services
    subgraph "External Services"
        direction TB
        DiscordAPI["Discord REST API"]:::external
        FileSystem["Local File System"]:::external
        GitHubActions["GitHub Actions"]:::external
        DockerHub["Docker Hub"]:::external
    end

    %% Dependencies & Flows
    User -->|"commands"| CLI
    User -->|"interacts"| GUI

    CLI -->|"invokes"| CmdHandlers
    GUI -->|"invokes"| CmdHandlers
    GUI -->|"uses"| DialogMgr
    GUI -->|"uses"| ViewMgr
    GUI -->|"uses"| SettingsSvc
    GUI -->|"checks updates via"| UpdateSvc

    CmdHandlers -->|"calls"| DiscordClient
    CmdHandlers -->|"triggers"| ExportContext

    DiscordClient -->|"HTTP"| HTTPFlow[/"HTTP Request"/] --> DiscordAPI
    DiscordAPI -->|"/HTTP Response"/| DiscordClient

    ExportContext --> MessageExporter
    MessageExporter --> CsvWriter
    MessageExporter --> HtmlWriter
    MessageExporter --> JsonWriter
    MessageExporter --> PlainWriter

    CsvWriter -->|"writes"| FileSystem
    HtmlWriter -->|"writes"| FileSystem
    JsonWriter -->|"writes"| FileSystem
    PlainWriter -->|"writes"| FileSystem

    ExportContext --> Filtering
    ExportContext --> Partitioning
    MessageExporter --> Filtering
    MessageExporter --> Partitioning

    Markdown -->|"used by"| HtmlWriter

    HttpUtils --> DiscordClient
    FsUtils --> CsvWriter
    FsUtils --> HtmlWriter
    FsUtils --> JsonWriter
    FsUtils --> PlainWriter

    CICD -->|"build/test/release"| GitHubActions
    CICD -->|"build Docker image"| DockerHub
    DockerSupport --> DockerHub

    %% Click Events
    click CLI "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Cli/Program.cs"
    click CmdHandlers "https://github.com/tyrrrz/discordchatexporter/tree/master/DiscordChatExporter.Cli/Commands/"
    click GUI "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Gui/App.axaml"
    click GUI "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Gui/App.axaml.cs"
    click ViewMgr "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Gui/Framework/ViewManager.cs"
    click DialogMgr "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Gui/Framework/DialogManager.cs"
    click SettingsSvc "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Gui/Services/SettingsService.cs"
    click UpdateSvc "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Gui/Services/UpdateService.cs"
    click DiscordClient "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Discord/DiscordClient.cs"
    click DataModels "https://github.com/tyrrrz/discordchatexporter/tree/master/DiscordChatExporter.Core/Discord/Data/"
    click ExportContext "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/ExportContext.cs"
    click MessageExporter "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/MessageExporter.cs"
    click ExportRequest "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/ExportRequest.cs"
    click ExportRequest "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/ExportFormat.cs"
    click CsvWriter "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/CsvMessageWriter.cs"
    click HtmlWriter "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/HtmlMessageWriter.cs"
    click HtmlWriter "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml"
    click HtmlWriter "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml"
    click HtmlWriter "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/PostambleTemplate.cshtml"
    click JsonWriter "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs"
    click PlainWriter "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Exporting/PlainTextMessageWriter.cs"
    click Filtering "https://github.com/tyrrrz/discordchatexporter/tree/master/DiscordChatExporter.Core/Exporting/Filtering/"
    click Partitioning "https://github.com/tyrrrz/discordchatexporter/tree/master/DiscordChatExporter.Core/Exporting/Partitioning/"
    click Markdown "https://github.com/tyrrrz/discordchatexporter/tree/master/DiscordChatExporter.Core/Markdown/"
    click HttpUtils "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Utils/Http.cs"
    click FsUtils "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Utils/PathEx.cs"
    click FsUtils "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Utils/UrlBuilder.cs"
    click FsUtils "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Core/Utils/Url.cs"
    click DockerSupport "https://github.com/tyrrrz/discordchatexporter/blob/master/DiscordChatExporter.Cli.dockerfile"
    click DockerSupport "https://github.com/tyrrrz/discordchatexporter/blob/master/docker-entrypoint.sh"
    click CICD "https://github.com/tyrrrz/discordchatexporter/blob/master/.github/workflows/docker.yml"
    click CICD "https://github.com/tyrrrz/discordchatexporter/blob/master/.github/workflows/main.yml"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef app fill:#e2e3e5,stroke:#383d41,color:#383d41;
    classDef core fill:#d4edda,stroke:#155724,color:#155724;
    classDef infra fill:#f8f9fa,stroke:#6c757d,color:#6c757d;
    classDef external fill:#fff3cd,stroke:#856404,color:#856404;
```
