# fvckgrimm/discord-fansly-notify architecture

> Architecture diagram of the GitHub repository fvckgrimm/discord-fansly-notify, 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/fvckgrimm/discord-fansly-notify
- Repository: https://github.com/fvckgrimm/discord-fansly-notify

## Overview

##### Main Components
- Bot Executable & Entry Point – Represented by the file in cmd/fansly-notify/main.go, this is where the application starts.
- API Layer – The “api” directory contains Go files (get_account_info.go, get_post_media.go, etc.) that interact with Fansly. This component holds responsibilities for contacting external Fansly services and retrieving the needed data.
- Business Logic/Discord Bot Module – The “internal/bot” directory (with bot.go, commands.go, and handlers.go) encapsulates the core functionality of the Discord bot. It manages events, commands, and processing of notifications.
- Configuration Module – Under “internal/config/config.go” the project handles configuration settings, including loading environment variables (from the .env file).
- Database Layer – Inside “internal/database/databse.go”, this component (even if basic) is responsible for persistence, such as storing subscription state or other runtime data.
- Embed Factory – The “internal/embed/embed.go” builds the rich embed messages dispatched to Discord.
- CI/CD and Deployment – The .github/workflows and related config files (like .goreleaser.yml) handle automated building and releasing of the bot. Though peripheral to runtime architecture, they are key aspects of the project’s overall lifecycle.

##### External Services and Data Sources
- Discord API – Where the bot connects to send messages (embed notifications) and potentially receive commands.
- Fansly API – External service from which the bot fetches live/update information about posts and streaming status.
- (Optional) Hosting Environment – If self-hosted, consider representing the deployment environment that runs the binary.

##### Relationships and Data Flow
- The entry point (fansly-notify executable) initializes the application by loading configuration (from internal/config) which uses the .env file.
- Once running, the bot (internal/bot) uses its command handlers to either poll or subscribe to changes. When an event occurs (a new Fansly post or live notification), the corresponding method in the API layer is called.
- Data retrieved by the API layer (from Fansly) is then processed; any associated media or details are formatted using the embed module.
- If needed, the processed data may be stored or referenced via the database layer.
- Finally, the processed notification is dispatched to Discord through the Discord API.

##### Architectural Patterns and Principles
- Separation of Concerns: Distinct layers for configuration, business logic (bot/handlers), API interactions, data persistence, and message formatting.
- Modularity: Components mostly reside in different directories (api, internal/bot, internal/config) to enforce a clean layered approach.

##### Detailed Elements
- .env file as the external configuration input feeding into the Configuration module.
- A separate note for automated workflows indicating that after code pushes, the CI/CD pipeline builds and releases the binary.
- If desired, represent the “migrate.py” script near the database layer as part of the migration/setup process.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Internal Components Subgraph
    subgraph "Internal System Components"
        A["Bot Entry Point (cmd/fansly-notify/main.go)"]:::internal
        B["Configuration Module (internal/config/config.go)"]:::internal
        C["Discord Bot Handlers (internal/bot)"]:::internal
        D["API Handlers (api)"]:::internal
        E["Embed Factory (internal/embed)"]:::internal
        F["Database Layer (internal/database/databse.go)"]:::database
    end

    %% External Services Subgraph
    subgraph "External Services"
        G["Environment (.env)"]:::external
        H["Discord API"]:::external
        I["Fansly API"]:::external
    end

    %% CI/CD Pipeline Subgraph
    subgraph "CI/CD Pipeline"
        J["CI/CD Workflow (.github/workflows)"]:::cicd
        K["CI/CD Config (.goreleaser.yml)"]:::cicd
    end

    %% Connections between External and Internal components
    G -->|"loadSettings"| B
    B -->|"initialize"| A
    A -->|"startBot"| C
    C -->|"fetchData"| D
    D -->|"requestData"| I
    I -->|"returnData"| D
    D -->|"passData"| C
    C -->|"formatEmbed"| E
    E -->|"embedReady"| C
    C -->|"sendNotification"| H
    C -->|"storeState"| F

    %% CI/CD Connections
    K -->|"deployBinary"| A
    J --> K

    %% Styles
    classDef internal fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef external fill:#e6ffe6,stroke:#008000,stroke-width:2px;
    classDef database fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef cicd fill:#ffe0cc,stroke:#cc6600,stroke-width:2px;

    %% Click Events
    click A "https://github.com/fvckgrimm/discord-fansly-notify/blob/main/cmd/fansly-notify/main.go"
    click B "https://github.com/fvckgrimm/discord-fansly-notify/blob/main/internal/config/config.go"
    click C "https://github.com/fvckgrimm/discord-fansly-notify/tree/main/internal/bot"
    click D "https://github.com/fvckgrimm/discord-fansly-notify/tree/main/api/"
    click E "https://github.com/fvckgrimm/discord-fansly-notify/blob/main/internal/embed/embed.go"
    click F "https://github.com/fvckgrimm/discord-fansly-notify/blob/main/internal/database/databse.go"
    click J "https://github.com/fvckgrimm/discord-fansly-notify/tree/main/.github/workflows"
    click K "https://github.com/fvckgrimm/discord-fansly-notify/blob/main/.goreleaser.yml"
```
