# cubyverse/ig2hugo architecture

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

- Interactive diagram: https://gitdiagram.com/cubyverse/ig2hugo
- Repository: https://github.com/cubyverse/ig2hugo

## Overview

##### Project Components
- Command‑Line Interface (CLI): This is the entry point (main.go) that parses command‑line parameters (token, user, output directory) and orchestrates the workflow.
- Instagram API Client: A module or function responsible for constructing and sending requests to the Instagram Graph API with the provided Access Token, and retrieving the post data.
- Data Converter/Processor: The component that takes the raw Instagram post data and extracts the Instagram shortcode (from the permalink) along with necessary metadata (date, tags, etc.) to format the Markdown file.
- Markdown File Generator: A component that writes out the converted content as a Markdown file in a specific output directory, following Hugo’s expected format.
- CI/CD Pipeline (GitHub Actions): The .github/workflows/release.yml file indicates there’s an automated build/release process. This represents an external automation component of the system.
- External Dependencies:
◦ Instagram Graph API: An external service that provides data.
◦ Hugo Website: While not directly part of the conversion tool, the output is intended for integration with a Hugo-based website.

##### Relationships & Data Flow
- The CLI component accepts user parameters and passes them to the Instagram API Client.
- The API Client communicates with the Instagram Graph API, receiving data back.
- The converter takes the API data, processes and extracts the necessary shortcode and metadata.
- The Markdown Generator then writes out the structured Markdown files in the destination folder (default "content/instagram").
- Optionally, a user would integrate these Markdown files into their Hugo site.
- The CI/CD pipeline automates build and release processes, ensuring that the latest version of the tool is distributed.

##### Architectural Patterns and Design
- The project follows a modular design even though it’s contained within a single source file. Each “phase” (input parsing, API communication, conversion, and file output) can be viewed as discrete layers.
- The system emphasizes separation of concerns: the input (CLI) is decoupled from processing (converter) and output (file writing).
- Use of external environment configurations (API tokens and user IDs) makes it flexible and integrates with an external API, following best practices for external service integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Processing Flow
    subgraph "Processing Flow"
        A["CLI Interface (main.go)"]:::internal
        B["Instagram API Client (main.go)"]:::internal
        C["Data Converter/Processor (main.go)"]:::internal
        D["Markdown File Generator (main.go)"]:::internal
    end

    %% External Components
    subgraph "External Systems"
        E["Instagram Graph API"]:::external
        F["Hugo Website"]:::external
    end

    %% CI/CD Components
    subgraph "CI/CD Automation"
        H["Main Repository"]:::internal
        G["CI/CD Pipeline (GitHub Actions)"]:::ci
        I["Distributed Binary"]:::ci
    end

    %% Data Flow
    A -->|"sends_parameters"| B
    B -->|"FetchPosts"| E
    E -->|"return_response"| B
    B -->|"returns_data"| C
    C -->|"Convert_Post"| D
    D -->|"Write_Markdown"| F

    %% CI/CD Flow
    H -->|"Trigger_Build"| G
    G -->|"Release"| I

    %% Click Events
    click A "https://github.com/cubyverse/ig2hugo/blob/main/main.go"
    click B "https://github.com/cubyverse/ig2hugo/blob/main/main.go"
    click C "https://github.com/cubyverse/ig2hugo/blob/main/main.go"
    click D "https://github.com/cubyverse/ig2hugo/blob/main/main.go"
    click G "https://github.com/cubyverse/ig2hugo/blob/main/.github/workflows/release.yml"

    %% Styles
    classDef internal fill:#CAF7E3,stroke:#333,stroke-width:2px;
    classDef external fill:#FFD6A5,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef ci fill:#A5D8A5,stroke:#333,stroke-width:2px;
```
