# rusq/slackdump architecture

> Architecture diagram of the GitHub repository rusq/slackdump, 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/rusq/slackdump
- Repository: https://github.com/rusq/slackdump

## Overview

##### Main Components
- Command-Line Interface (CLI):
- Located primarily in the “cmd/slackdump” directory.
- Handles parsing command-line arguments, routing to different commands (dumping, listing, archiving, exporting, viewing, etc.), and interfacing with the user.
- Authentication & Authorization:
- The “auth” package (along with subdirectories like auth_ui and browser/…) manages token-based authentication, EZ-Login 3000, and, when needed, browser-based login.
- This component interfaces with Slack’s API by handling token retrieval (using methods like obtaining tokens and cookies).
- Core Processing Modules:
- The “internal” directory (including subfolders such as “chunk”, “convert”, “edge”, “network”, “cache”, “source”, “structures”, etc.) contains the bulk of the application’s business logic.
- Modules here are responsible for ingesting Slack data (from export files or live sessions), processing it (chunking, conversion between formats, data transformations), and orchestrating the data flow.
- User Interface / Viewer:
- Found in “internal/viewer” and in “auth/auth_ui”, this module provides the built-in viewer functionality, which allows for previewing archives, exports, or dumps.
- Additional submodules in “internal/ui” and its bubbles (for menus, input, datepicker, etc.) add to an interactive user interface.
- File and Data Management:
- The project deals extensively with file I/O and data conversion. The “internal/source” package and several “internal/chunk” subpackages manage reading, writing, conversion, and even temporary file storage.
- Supporting Utilities & Helpers:
- Packages such as “internal/fasttime”, “utils”, “contrib”, and others provide scripts, extra functionalities (for incremental backups, testing scripts, etc.) and integrations.

##### Relationships and Data Flow
- The CLI (front façade) accepts user commands (like dump, list, export, archive, view). These commands are then routed to the core processing modules.
- The Authentication module is used early on (or on-demand) to initialize a session and secure the necessary tokens that will be passed to the processing layers.
- The processing layer interacts with the data access layer (“internal/source” and file management) to ingest the Slack data, then uses conversion and chunking modules (in “internal/chunk” and “internal/convert”) to transform the data into various supported formats.
- For generating output (in export, archive, or dump formats), the system relies on conversion controllers that interconnect with utility modules. Finally, the Viewer module can be invoked to display the result.
- The network boundaries and external endpoints (Slack’s API, user’s browser authentication, etc.) are abstracted within the “auth” and “edge” packages.

##### Architectural Patterns and Principles
- Modular Monolith: Although the application is a single program, its functionalities are clearly modularized by domain (authentication, processing, viewing, conversion) with well-defined package boundaries.
- Separation of Concerns: UI/CLI, authentication, domain logic, and file/ data management remain separated making maintenance and potential future refactoring easier.
- Layered Architecture: There is a clear flow between presentation (CLI/UI), application logic (commands/logics) and infrastructure (file system, network, database mocks) layers.
- Testability: The inclusion of “_test.go” files across many directories (auth, cache, chunk, convert, etc.) shows a heavy emphasis on ensuring that each module is independently testable.

##### Additional Detail
- Within the processing layer, you might further decompose into sub-components such as “Chunking & Archive Creation”, “Conversion and Export Formatting”, and “Cache & Data Structures”.
- Optionally, highlight the integration of logging (using Go’s slog) and note how the logger can be replaced/customized.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        CLI["CLI Interface"]:::presentation
        Viewer["Viewer/UI Module (internal/viewer, auth/auth_ui)"]:::presentation
    end

    %% Application Services
    subgraph "Application Services"
        Auth["Authentication Module (auth, auth_ui, browser)"]:::application
        Processing["Core Processing Modules (chunk, convert, edge, cache, source, structures)"]:::application
    end

    %% Data Management Layer
    subgraph "Data Management"
        DataMgmt["File and Data Management (source, chunk)"]:::data
    end

    %% Supporting Utilities
    subgraph "Supporting Utilities"
        Utils["Supporting Utilities & Helpers (fasttime, utils)"]:::utilities
    end

    %% External Endpoint
    SlackAPI["Slack API Endpoint"]:::external

    %% Relationships
    CLI -->|"initCommand"| Auth
    CLI -->|"routeCommand"| Processing
    Auth -->|"token_request"| SlackAPI
    Processing -->|"data_io"| DataMgmt
    DataMgmt -->|"file_transfer"| Processing
    Processing -->|"view_export"| Viewer
    Processing -->|"utilize"| Utils
    CLI -->|"display_output"| Viewer

    %% Click Events
    click CLI "https://github.com/rusq/slackdump/tree/master/cmd/slackdump/"
    click Auth "https://github.com/rusq/slackdump/tree/master/auth/"
    click Processing "https://github.com/rusq/slackdump/tree/master/internal/"
    click Viewer "https://github.com/rusq/slackdump/tree/master/internal/viewer/"
    click DataMgmt "https://github.com/rusq/slackdump/tree/master/internal/source/"
    click Utils "https://github.com/rusq/slackdump/tree/master/utils/"

    %% Styles
    classDef presentation fill:#fefbd8,stroke:#333,stroke-width:2px;
    classDef application fill:#c8e6c9,stroke:#333,stroke-width:2px;
    classDef data fill:#bbdefb,stroke:#333,stroke-width:2px;
    classDef utilities fill:#d1c4e9,stroke:#333,stroke-width:2px;
    classDef external fill:#ffccbc,stroke:#333,stroke-width:2px;
```
