# toshihitokon/slack-archive architecture

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

- Interactive diagram: https://gitdiagram.com/toshihitokon/slack-archive
- Repository: https://github.com/toshihitokon/slack-archive

## Overview

- A CLI mode that can be launched via the “cmd/slack-archive/main.go” entrypoint.
- A Lambda web endpoint mode, built from “cmd/slack-archive-lambda”, which is deployed to AWS and accepts POST requests with the necessary Slack, export, and time-bound information.

- CLI and Lambda Entry Points – Represent the two “frontends” of the application. The CLI entry point (from “cmd/slack-archive”) and the Lambda endpoint (from “cmd/slack-archive-lambda”) are the user-facing parts that trigger the archiving process.
- Core Archiving Engine – This contains the main logic to execute the archive process. From the root files (e.g., “archive.go”, “slack.go”, “exporter.go”, “formatter.go”) and “interface.go”, we see that the engine integrates Slack calls, data formatting, and flexible export via multiple interfaces.
- Custom Formatter & Exporter Interfaces – As described in the README, “interface.go” defines contracts for formatters and exporters, and users can add new implementations. Highlight these as extension points supporting various output formats (Text, file directory, Amazon S3, Amazon SES, etc.).
- AWS Integration Components – Files such as “aws.go” suggest integration with Amazon S3 and SES. These should be shown as external service blocks, with clearly marked interactions.
- Slack API Module – The “slack.go” file indicates that interactions with Slack’s API (using provided tokens and channel IDs) are modularized.
- Utility and Supporting Functions – Additional utility logic (from “utils.go”) and type definitions (e.g., “type.go”) support the overall architecture.

##### Out interactions and data flows between components
- The archiving engine should interact with Slack API to fetch logs and files.
- Once data is retrieved, the process passes through the formatter module that reformats the data based on the provided environment settings (e.g., SA_TEXT_FORMATTER_REPLY_INDENT_BASE64).
- After formatting, the data is sent to the various exporter modules (text exporter, file exporter, S3 exporter, and SES exporter) – each represented as separate blocks. Emphasize that these follow a common interface pattern, allowing easy extension (as described in the README).
- For the Lambda endpoint, include a batch that represents the HTTP payload processing (parsing JSON input) before handing over processing to the core engine.

##### Architectural design details
- Extensibility with Interfaces – Show that the Formatter and Exporter components are built around interfaces (see “interface.go”), which allows for plugging in custom implementations without altering core logic.
- External Service Integration – Mark AWS (S3, SES) and Slack as external systems with clear boundaries, making it evident that they are integrated via well-defined modules (e.g., aws.go for AWS, slack.go for Slack).

##### Presenting details about technology and design patterns
- That the project adheres to a modular and extensible design, where adding a new formatter or exporter only requires implementing the corresponding interface.
- Think of the project as following a layered architecture: User Input (CLI / Lambda) → Business Logic (archiving and processing) → Interface Abstractions (formatters/exporters) → External Services Integration.

- Clearly identifies all system components (CLI, Lambda, Core Archiver, Formatter, Exporters, Slack API, AWS services, Utilities).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend: User Entry Points
    CLI["\"CLI Entry Point\""]:::frontend
    Lambda["\"Lambda Endpoint\""]:::frontend
    LH["\"Lambda Handler\""]:::frontend

    %% Internal processing for Lambda
    HTTP["\"HTTP Payload Processor\""]:::internal

    %% Core Processing and Modules
    CA["\"Core Archiving Engine\""]:::internal
    SA["\"Slack API Connector\""]:::external
    FM["\"Formatter Module\""]:::internal
    EM["\"Exporter Modules\""]:::internal
    UT["\"Utility Functions\""]:::internal
    EC["\"Environment Configuration\""]:::config

    %% External Integrations
    AW["\"AWS Integration\""]:::external

    %% Connections from entry points to core engine
    CLI -->|"triggers"| CA
    Lambda -->|"receives POST"| LH
    LH -->|"processes payload"| HTTP
    HTTP -->|"invokes"| CA

    %% Core Archiving Engine interactions
    CA -->|"fetches logs"| SA
    CA -->|"formats data"| FM
    CA -->|"utilizes"| UT

    %% Formatter to Exporter flow
    FM -->|"passes formatted data"| EM

    %% Exporters to AWS
    EM -->|"exports data"| AW

    %% Environment configurations feeding components (dashed lines)
    EC -.-> CA
    EC -.-> EM
    EC -.-> AW

    %% Click Events
    click CLI "https://github.com/toshihitokon/slack-archive/blob/main/cmd/slack-archive/main.go"
    click Lambda "https://github.com/toshihitokon/slack-archive/blob/main/cmd/slack-archive-lambda/main.go"
    click LH "https://github.com/toshihitokon/slack-archive/blob/main/cmd/slack-archive-lambda/handler.go"
    click CA "https://github.com/toshihitokon/slack-archive/blob/main/archive.go"
    click SA "https://github.com/toshihitokon/slack-archive/blob/main/slack.go"
    click FM "https://github.com/toshihitokon/slack-archive/blob/main/formatter.go"
    click EM "https://github.com/toshihitokon/slack-archive/blob/main/exporter.go"
    click AW "https://github.com/toshihitokon/slack-archive/blob/main/aws.go"
    click UT "https://github.com/toshihitokon/slack-archive/blob/main/utils.go"

    %% Styles
    classDef frontend fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef internal fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef config fill:#E1BEE7,stroke:#6A1B9A,stroke-width:2px;
```
