# mrmoneyc/slack-exporter architecture

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

- Interactive diagram: https://gitdiagram.com/mrmoneyc/slack-exporter
- Repository: https://github.com/mrmoneyc/slack-exporter

## Overview

##### Main Components
- Command-Line Interface (CLI) and Entry Point:
- Main binary (located in cmd/slack-exporter/main.go) as the starting point of the application.
- This component is responsible for bootstrapping the application, handling user-supplied command options (like configuration paths and verbosity), and triggering the export process.

- Configuration Management:
- Configuration module (pkg/config/config.go) which reads and parses the config.yaml file.
- That configuration details (API tokens, request delay, export base path, etc.) are provided either via the default file or via command-line parameters.

- Exporter Logic:
▪ Channel Exporter (pkg/exporter/channel.go) – handles exporting channels and their metadata.
▪ File Exporter (pkg/exporter/file.go) – manages downloading and saving files linked in messages.
▪ Message Exporter (pkg/exporter/message.go) – processes the conversation history, including threaded replies.
▪ User Exporter (pkg/exporter/user.go) – exports user profiles and participation information.
- Modules as part of the overall export pipeline.

- Archival Module:
- Archiver component (pkg/archiver/zip.go) which packages exported data into a ZIP archive if enabled in the configuration.

- Command Routing & Utility Functions:
- Package structure inside pkg/cmd (including modules like root.go and version.go) which likely supports CLI command parsing, global flags, and version management.

- External Dependencies and Integrations:
- Slack API as an external service/component.

##### Relationships and Interactions
- Next, represent a flow from the CLI to the command routing/logic component (pkg/cmd) which directs application behavior based on input options.
- Exporter components side by side and show how each specific exporter (channel, file, message, user) is invoked as part of the export process.
- Exporter components to the external Slack API (illustrating API calls and data retrieval).
- If the ArchiveData option is enabled, show a subsequent step routing data into the Archiver module (pkg/archiver) that prepares a ZIP file of the export.

##### Architectural Patterns and Design Principles
- Modular Design: The project is structured into distinct modules (configuration, exporter, archiver, command routing) which are cleanly separated and interoperate through well-defined interfaces.
- Single Binary / CLI Tool: Highlight that all components are packaged into one CLI application, with command-line arguments determining operational modes (e.g., specifying alternate configuration files or log verbosity).

##### Relevant Technologies/Frameworks
- Mention that continuous integration is set up through GitHub Workflows (.github/workflows/release.yml) though this does not directly affect runtime architecture.
- The Makefile and scripts (like scripts/run.bat) are used for building and running the tool in different environments.

##### Emphasize
- Each component’s role and its dependencies should be clearly marked.
- The overall workflow—from reading config and accepting CLI commands, interfacing with Slack, processing data, to final archiving—should be sequentially represented.
- Use additional annotations (such as notes or legends) for any conditional flows like using an alternative config file or changing logging verbosity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CLI & Bootstrapping"
        Main["Main (cmd/slack-exporter/main.go)"]:::internal
        click Main "https://github.com/mrmoneyc/slack-exporter/blob/master/cmd/slack-exporter/main.go"
        ConfigLoader["Configuration Loader (pkg/config/config.go)"]:::internal
        click ConfigLoader "https://github.com/mrmoneyc/slack-exporter/blob/master/pkg/config/config.go"
        ConfigFile["Config File (config/config.yaml)"]:::internal
        click ConfigFile "https://github.com/mrmoneyc/slack-exporter/blob/master/config/config.yaml"
        CmdRouter["Command Router (pkg/cmd)"]:::internal
        click CmdRouter "https://github.com/mrmoneyc/slack-exporter/tree/master/pkg/cmd"
        
        Main -->|"loads_config"| ConfigLoader
        ConfigLoader -->|"reads"| ConfigFile
        Main -->|"parses_commands"| CmdRouter
        Main -->|"triggers_export"| ExpPipeline
    end

    subgraph "Export Pipeline"
        ExpPipeline["Export Pipeline"]:::internal
        ExpChannel["Channel Exporter (pkg/exporter/channel.go)"]:::internal
        click ExpChannel "https://github.com/mrmoneyc/slack-exporter/blob/master/pkg/exporter/channel.go"
        ExpFile["File Exporter (pkg/exporter/file.go)"]:::internal
        click ExpFile "https://github.com/mrmoneyc/slack-exporter/blob/master/pkg/exporter/file.go"
        ExpMessage["Message Exporter (pkg/exporter/message.go)"]:::internal
        click ExpMessage "https://github.com/mrmoneyc/slack-exporter/blob/master/pkg/exporter/message.go"
        ExpUser["User Exporter (pkg/exporter/user.go)"]:::internal
        click ExpUser "https://github.com/mrmoneyc/slack-exporter/blob/master/pkg/exporter/user.go"
        
        ConfigLoader -->|"provides_settings"| ExpChannel
        ConfigLoader -->|"provides_settings"| ExpFile
        ConfigLoader -->|"provides_settings"| ExpMessage
        ConfigLoader -->|"provides_settings"| ExpUser
        
        ExpChannel -->|"calls_API"| SlackAPI
        ExpFile -->|"calls_API"| SlackAPI
        ExpMessage -->|"calls_API"| SlackAPI
        ExpUser -->|"calls_API"| SlackAPI
        
        ExpChannel -->|"routes_to"| Archiver
        ExpFile -->|"routes_to"| Archiver
        ExpMessage -->|"routes_to"| Archiver
        ExpUser -->|"routes_to"| Archiver
    end

    SlackAPI["Slack API"]:::external
    Archiver["Archiver (pkg/archiver/zip.go)"]:::internal
    click Archiver "https://github.com/mrmoneyc/slack-exporter/blob/master/pkg/archiver/zip.go"

    subgraph "Support & CI/CD"
        CI["GitHub Workflows (.github/workflows/release.yml)"]:::external
        click CI "https://github.com/mrmoneyc/slack-exporter/blob/master/.github/workflows/release.yml"
        Build["Build & Run Scripts (Makefile, scripts/run.bat)"]:::external
        click Build "https://github.com/mrmoneyc/slack-exporter/tree/master/Makefile"
        click Build "https://github.com/mrmoneyc/slack-exporter/blob/master/scripts/run.bat"
    end

    classDef internal fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
```
