# vfansss/comfucius-instagram architecture

> Architecture diagram of the GitHub repository vfansss/comfucius-instagram, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vfansss/comfucius-instagram
- Repository: https://github.com/vfansss/comfucius-instagram

## Overview

##### Core Components
- Image Generation Service
- Instagram Posting Service
- Database Layer
- Authentication Handler
- External Services Integration

##### Main Flow Components (Top to Bottom)
- To the "Image Generator" component
- Flow into the "Instagram Poster" component
- End with "Instagram API" (external service)

##### Supporting Components (Left Side)
- SQLite Database (for hashtags)
- Session Manager
- Environment Configuration
- File Storage (temporary images)

Use these specific visual elements:

##### Connection Types

Detailed Component Breakdown:

##### Image Generation Service
- Input: Quotes from Comfucius API
- Components: Font handling, background image selection
- Output: Generated motivational image

##### Instagram Posting Service
- Input: Generated image
- Components: Authentication, session management
- Output: Posted content on Instagram

##### Database Layer
- SQLite database for hashtags
- Flat file storage for temporary images

##### Configuration Management
- Environment variables
- Session storage (session.json)
- Credentials management

Specific notes:

##### Temporary Storage Flow
- Image creation path
- Temporary storage location
- Deletion flow after posting

##### Authentication Flow
- Session dumping process
- Cookie management
- Instagram API interaction

##### Error Handling
- Retry mechanisms
- Fallback paths

Important Considerations:

##### Automation aspect
- Cron job integration points (mentioned as not included but relevant)
- Scheduling components

##### Security Aspects
- Credential storage
- Session management
- Cookie handling

##### Configuration Options
- DRY_RUN mode paths
- Different authentication methods

## Diagram (Mermaid)

```mermaid
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#007bff', 'primaryTextColor': '#fff', 'primaryBorderColor': '#007bff', 'lineColor': '#F8B229', 'secondaryColor': '#006100', 'tertiaryColor': '#fff'}}}%%

flowchart TB
    subgraph External["External Services"]
        direction TB
        ComfAPI[("Comfucius API")]:::external
        InstaAPI[("Instagram API")]:::external
    end

    subgraph Core["Core Processing"]
        direction TB
        MainExec["Main Execution Service"]:::core
        ImgGen["Image Generation Service"]:::core
        TextProc["Text Processing"]:::core
        InstaPoster["Instagram Poster"]:::core
    end

    subgraph Storage["Storage Layer"]
        direction TB
        DB[(Database)]:::storage
        TempStore[("Temporary Storage")]:::storage
        Fonts["Font Management"]:::storage
        BGImages["Background Images"]:::storage
    end

    subgraph Config["Configuration & Auth"]
        direction TB
        EnvConfig["Environment Config"]:::config
        AuthHandler["Authentication Handler"]:::config
        SessionMgr["Session Manager"]:::config
    end

    ComfAPI --> MainExec
    MainExec --> TextProc
    TextProc --> ImgGen
    ImgGen --> TempStore
    TempStore --> InstaPoster
    InstaPoster --> InstaAPI

    Fonts --> ImgGen
    BGImages --> ImgGen
    DB --> InstaPoster
    
    EnvConfig -.-> MainExec
    AuthHandler -.-> InstaPoster
    SessionMgr -.-> InstaPoster

    %% Click Events
    click ImgGen "https://github.com/VFansss/comfucius-instagram/blob/master/image_generator/generate_image.py"
    click Fonts "https://github.com/VFansss/comfucius-instagram/tree/master/image_generator/fonts/"
    click BGImages "https://github.com/VFansss/comfucius-instagram/tree/master/folder_base_images/"
    click DB "https://github.com/VFansss/comfucius-instagram/blob/master/flat_file_database.csv"
    click AuthHandler "https://github.com/VFansss/comfucius-instagram/blob/master/dump_session.py"
    click EnvConfig "https://github.com/VFansss/comfucius-instagram/blob/master/.env"
    click MainExec "https://github.com/VFansss/comfucius-instagram/blob/master/do_damage.py"
    click TextProc "https://github.com/VFansss/comfucius-instagram/blob/master/phrase_word_scoring/score_phrase_words.py"

    %% Styling
    classDef core fill:#007bff,stroke:#0056b3,color:#fff
    classDef storage fill:#6c757d,stroke:#495057,color:#fff
    classDef config fill:#ffc107,stroke:#d39e00,color:#000
    classDef external fill:#28a745,stroke:#1e7e34,color:#fff

    %% Legend
    subgraph Legend
        direction TB
        CoreService["Core Service"]:::core
        StorageComp["Storage Component"]:::storage
        ConfigComp["Configuration Component"]:::config
        ExtService["External Service"]:::external
    end
```
