# viniciusarz/figurefeed-ai architecture

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

- Interactive diagram: https://gitdiagram.com/viniciusarz/figurefeed-ai
- Repository: https://github.com/viniciusarz/figurefeed-ai

## Overview

#### Purpose and execution

`figurefeed-ai` is a Python 3.12 batch automation pipeline that turns unposted anime-figure photos in a Google Photos album into Instagram Business posts. The operational entry point is `post_figurefeed.py`; it delegates orchestration to `workflow.py`. A root `config.json` (runtime secret/config boundary) supplies Google Photos, OpenAI, Meta, and Imgur credentials and identifiers.

#### Workflow orchestration

`workflow.py` is the central control-flow layer. Its intended sequence is: list album photos, exclude already-published items, obtain image bytes, identify the figure, generate a caption, temporarily host the image, create an Instagram post, then remove the temporary image. `post_figurefeed.py` is the executable wrapper for this workflow, suitable for manual or scheduler-driven invocation.

Paths: `post_figurefeed.py`, `workflow.py`.

#### Google Photos ingestion and deduplication

The Google Photos adapter retrieves album media and supports inspection of albums/media identifiers. It forms the source-system boundary and supplies both candidate photo metadata and downloadable content. Deduplication checks whether an album photo has already been processed/published before expensive AI or posting stages; persistent state is not evident in the supplied tree, so this likely depends on remote metadata or workflow logic.

Paths: `google_photos_client/google_photos_client.py`, `google_photos_client/check_album_photos.py`, `google_photos_client/check_folder_ids.py`.

#### AI figure understanding

Figure identification is isolated from caption writing. `agents/identify_figure.py` uses OpenAI models to derive figure information from image input. That result becomes structured/contextual input to caption generation rather than being directly posted, creating a clear AI-enrichment boundary.

Paths: `agents/identify_figure.py`, `agents/get_caption.py`.

#### CrewAI caption generation

Caption generation is implemented as a CrewAI agent/task configuration plus execution code. Agent roles and task prompts are externalized in YAML, allowing editorial behavior to change without reshaping the workflow. `agents/crew.py` assembles/runs the configured CrewAI process and returns post-ready text.

Paths: `agents/crew.py`, `agents/config/agents.yaml`, `agents/config/tasks.yaml`.

#### Publication and temporary media hosting

Instagram Graph publishing requires a publicly reachable image URL, so Imgur is a transient transport/storage boundary between local Google Photos bytes and Meta’s API. The workflow uploads first, invokes the Instagram client to publish, and deletes the Imgur asset afterward. Publishing requires an Instagram Business account linked to a Facebook Page and a Meta long-lived token.

Paths: `meta_client/instagram_client.py`, `workflow.py`, `post_figurefeed.py`.

#### External systems and operational dependencies

Material integrations are Google Photos Library API, OpenAI, CrewAI, Imgur API, and Meta/Instagram Graph API. Poetry manages the Python environment (`pyproject.toml`). Token lifecycle support is separated from publication logic in `meta_client/meta_long_lived_token.py`, enabling renewal of Meta credentials without modifying the posting pipeline.

Paths: `pyproject.toml`, `meta_client/meta_long_lived_token.py`, `agents/crew.py`.

Main entry points: [`workflow.py`](https://github.com/viniciusarz/figurefeed-ai/blob/main/workflow.py) (Posting workflow), [`agents/crew.py`](https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/crew.py) (Caption generation), [`google_photos_client/google_photos_client.py`](https://github.com/viniciusarz/figurefeed-ai/blob/main/google_photos_client/google_photos_client.py) (Google Photos client), [`agents/identify_figure.py`](https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/identify_figure.py) (Figure identification)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Batch Runtime"]
  node_entrypoint["Post command<br/>Python executable<br/>[post_figurefeed.py]"]
  node_workflow{{"Posting workflow<br/>orchestrator<br/>[workflow.py]"}}
  node_config["Runtime config<br/>secret boundary"]
  node_environment["Poetry environment<br/>Python dependencies<br/>[pyproject.toml]"]
end

subgraph group_photos["Photo Ingestion"]
  node_photos_client["Google Photos client<br/>source adapter"]
  node_album_inspection["Album inspection<br/>operations helper"]
  node_folder_inspection["Folder ID inspection<br/>operations helper"]
  node_google_photos_api(("Google Photos API<br/>external API"))
  node_deduplication["Published-item filter<br/>workflow stage<br/>[workflow.py]"]
end

subgraph group_ai["AI Enrichment"]
  node_identifier["Figure identification<br/>OpenAI image analysis<br/>[identify_figure.py]"]
  node_caption_agent["Caption generation<br/>CrewAI execution<br/>[crew.py]"]
  node_agent_prompts["Agent roles<br/>CrewAI config<br/>[agents.yaml]"]
  node_task_prompts["Caption tasks<br/>CrewAI config<br/>[tasks.yaml]"]
  node_openai(("OpenAI<br/>external AI API"))
end

subgraph group_publish["Publication"]
  node_imgur(("Imgur API<br/>temporary media host"))
  node_instagram_client["Instagram publisher<br/>Meta API adapter"]
  node_instagram_api(("Instagram Graph API<br/>external publishing API"))
  node_token_renewal["Meta token renewal<br/>credential utility"]
end

node_entrypoint -->|"invokes"| node_workflow
node_config -.->|"runtime settings"| node_workflow
node_environment -.->|"defines dependencies"| node_entrypoint
node_workflow -->|"lists and downloads"| node_photos_client
node_photos_client -->|"album media requests"| node_google_photos_api
node_album_inspection -.->|"inspects media"| node_google_photos_api
node_folder_inspection -.->|"inspects identifiers"| node_google_photos_api
node_photos_client -->|"candidate metadata"| node_deduplication
node_deduplication -->|"unposted photos"| node_workflow
node_workflow -->|"image bytes"| node_identifier
node_identifier -->|"vision request"| node_openai
node_identifier -->|"figure context"| node_caption_agent
node_agent_prompts -.->|"defines roles"| node_caption_agent
node_task_prompts -.->|"defines prompts"| node_caption_agent
node_caption_agent -->|"generation request"| node_openai
node_caption_agent -->|"caption text"| node_workflow
node_workflow -->|"uploads image bytes"| node_imgur
node_imgur -->|"public image URL"| node_instagram_client
node_workflow -->|"publishes caption and media"| node_instagram_client
node_instagram_client -->|"creates post"| node_instagram_api
node_workflow -.->|"deletes temporary asset"| node_imgur
node_token_renewal -->|"renews long-lived token"| node_instagram_api

click node_entrypoint "https://github.com/viniciusarz/figurefeed-ai/blob/main/post_figurefeed.py"
click node_workflow "https://github.com/viniciusarz/figurefeed-ai/blob/main/workflow.py"
click node_environment "https://github.com/viniciusarz/figurefeed-ai/blob/main/pyproject.toml"
click node_photos_client "https://github.com/viniciusarz/figurefeed-ai/blob/main/google_photos_client/google_photos_client.py"
click node_album_inspection "https://github.com/viniciusarz/figurefeed-ai/blob/main/google_photos_client/check_album_photos.py"
click node_folder_inspection "https://github.com/viniciusarz/figurefeed-ai/blob/main/google_photos_client/check_folder_ids.py"
click node_deduplication "https://github.com/viniciusarz/figurefeed-ai/blob/main/workflow.py"
click node_identifier "https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/identify_figure.py"
click node_caption_agent "https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/crew.py"
click node_agent_prompts "https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/config/agents.yaml"
click node_task_prompts "https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/config/tasks.yaml"
click node_instagram_client "https://github.com/viniciusarz/figurefeed-ai/blob/main/meta_client/instagram_client.py"
click node_token_renewal "https://github.com/viniciusarz/figurefeed-ai/blob/main/meta_client/meta_long_lived_token.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entrypoint,node_workflow,node_config,node_environment toneBlue
class node_photos_client,node_album_inspection,node_folder_inspection,node_google_photos_api,node_deduplication toneAmber
class node_identifier,node_caption_agent,node_agent_prompts,node_task_prompts,node_openai toneMint
class node_imgur,node_instagram_client,node_instagram_api,node_token_renewal toneRose
```

## Components

### Batch Runtime

- [Post command](https://github.com/viniciusarz/figurefeed-ai/blob/main/post_figurefeed.py): Python executable · Manual or scheduler-driven entry point. · `post_figurefeed.py`
- [Posting workflow](https://github.com/viniciusarz/figurefeed-ai/blob/main/workflow.py): orchestrator · Coordinates the end-to-end posting sequence. · `workflow.py`
- **Runtime config**: secret boundary · Supplies integration credentials and identifiers.
- [Poetry environment](https://github.com/viniciusarz/figurefeed-ai/blob/main/pyproject.toml): Python dependencies · `pyproject.toml`

### Photo Ingestion

- [Google Photos client](https://github.com/viniciusarz/figurefeed-ai/blob/main/google_photos_client/google_photos_client.py): source adapter · Lists album media and downloads image content. · `google_photos_client/google_photos_client.py`
- [Album inspection](https://github.com/viniciusarz/figurefeed-ai/blob/main/google_photos_client/check_album_photos.py): operations helper · Inspects album and media identifiers. · `google_photos_client/check_album_photos.py`
- [Folder ID inspection](https://github.com/viniciusarz/figurefeed-ai/blob/main/google_photos_client/check_folder_ids.py): operations helper · `google_photos_client/check_folder_ids.py`
- **Google Photos API**: external API
- [Published-item filter](https://github.com/viniciusarz/figurefeed-ai/blob/main/workflow.py): workflow stage · Excludes already processed album photos. · `workflow.py`

### AI Enrichment

- [Figure identification](https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/identify_figure.py): OpenAI image analysis · Derives figure information from image input. · `agents/identify_figure.py`
- [Caption generation](https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/crew.py): CrewAI execution · Produces post-ready caption text. · `agents/crew.py`
- [Agent roles](https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/config/agents.yaml): CrewAI config · `agents/config/agents.yaml`
- [Caption tasks](https://github.com/viniciusarz/figurefeed-ai/blob/main/agents/config/tasks.yaml): CrewAI config · `agents/config/tasks.yaml`
- **OpenAI**: external AI API

### Publication

- **Imgur API**: temporary media host · Provides a public image URL for publishing.
- [Instagram publisher](https://github.com/viniciusarz/figurefeed-ai/blob/main/meta_client/instagram_client.py): Meta API adapter · Creates Instagram Business posts. · `meta_client/instagram_client.py`
- **Instagram Graph API**: external publishing API
- [Meta token renewal](https://github.com/viniciusarz/figurefeed-ai/blob/main/meta_client/meta_long_lived_token.py): credential utility · Renews Meta long-lived credentials separately from publishing. · `meta_client/meta_long_lived_token.py`

## Connections

- Post command → Posting workflow: invokes
- Runtime config → Posting workflow: runtime settings
- Poetry environment → Post command: defines dependencies
- Posting workflow → Google Photos client: lists and downloads
- Google Photos client → Google Photos API: album media requests
- Album inspection → Google Photos API: inspects media
- Folder ID inspection → Google Photos API: inspects identifiers
- Google Photos client → Published-item filter: candidate metadata
- Published-item filter → Posting workflow: unposted photos
- Posting workflow → Figure identification: image bytes
- Figure identification → OpenAI: vision request
- Figure identification → Caption generation: figure context
- Agent roles → Caption generation: defines roles
- Caption tasks → Caption generation: defines prompts
- Caption generation → OpenAI: generation request
- Caption generation → Posting workflow: caption text
- Posting workflow → Imgur API: uploads image bytes
- Imgur API → Instagram publisher: public image URL
- Posting workflow → Instagram publisher: publishes caption and media
- Instagram publisher → Instagram Graph API: creates post
- Posting workflow → Imgur API: deletes temporary asset
- Meta token renewal → Instagram Graph API: renews long-lived token
