# rebarfw/arabic-meme-autoposter architecture

> Architecture diagram of the GitHub repository rebarfw/arabic-meme-autoposter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rebarfw/arabic-meme-autoposter
- Repository: https://github.com/rebarfw/arabic-meme-autoposter

## Overview

Arabic Meme Autoposter turns approved Instagram DM shares into deduplicated Reel jobs, downloads and validates the original media, then publishes it to the configured Instagram and TikTok Buffer channels. Polling is the configured ingestion route; webhook validation remains a capability, not the active ingestion path. Separate branches cover sender enrollment, cost controls, diagnostics, and cleanup. The excerpts and README support the main workflow; some unsampled internals are represented only at their documented subsystem paths.

Main entry points: [`src/jobs.ts`](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/jobs.ts) (Job orchestration), [`src/index.ts`](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/index.ts) (Worker routes), [`src/downloaders.ts`](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/downloaders.ts) (Provider selection), [`src/instagram-polling.ts`](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/instagram-polling.ts) (DM polling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingestion and authorization"]
  node_worker["Worker routes<br/>[index.ts]"]
  node_polling["DM polling"]
  node_igapi["Instagram API<br/>[instagram-api.ts]"]
  node_enrollment["Sender enrollment<br/>[owner-setup.ts]"]
  node_senders["Sender allowlist<br/>[senders.ts]"]
end

subgraph group_pipeline["Publishing pipeline"]
  node_jobs["Job orchestration<br/>[jobs.ts]"]
  node_d1[("Job state")]
  node_media["Media storage<br/>[media.ts]"]
  node_r2[("Private media")]
  node_buffer["Buffer publishing<br/>[buffer.ts]"]
end

subgraph group_downloads["Media acquisition"]
  node_downloaders["Provider selection<br/>[downloaders.ts]"]
  node_apify["Apify downloads<br/>[apify-download.ts]"]
  node_providers["Website providers"]
  node_video["MP4 validation"]
end

subgraph group_controls["Safety and operations"]
  node_apifybudget["Apify budget guard<br/>[apify-budget.ts]"]
  node_cloudguard["Cloudflare usage guard"]
  node_privacy["Privacy cleanup<br/>[privacy.ts]"]
  node_diagnostics["Meta diagnostics"]
  node_cloudprobe["Usage probe"]
end

subgraph group_external["External services"]
  node_meta["Meta messages"]
  node_bufferapi["Buffer API"]
  node_analytics["Cloudflare analytics"]
end

node_person(("Approved sender"))
node_operator(("Administrator"))

node_person -->|"shares Reel"| node_polling
node_polling -->|"reads conversations"| node_igapi
node_igapi -->|"requests messages"| node_meta
node_polling -->|"enqueues source"| node_jobs
node_worker -->|"dispatches polling"| node_polling
node_operator -->|"calls admin routes"| node_worker
node_worker -->|"routes setup"| node_enrollment
node_enrollment -->|"verifies identity"| node_meta
node_enrollment -->|"installs sender IDs"| node_senders
node_jobs -->|"checks authorization"| node_senders
node_jobs -->|"stores job state"| node_d1
node_jobs -->|"requests download"| node_downloaders
node_downloaders -->|"uses Apify"| node_apify
node_downloaders -->|"tries providers"| node_providers
node_downloaders -->|"validates media"| node_video
node_apify -->|"reserves runs"| node_apifybudget
node_jobs -->|"stores video"| node_media
node_media -->|"writes object"| node_r2
node_jobs -->|"requests posts"| node_buffer
node_buffer -->|"creates posts"| node_bufferapi
node_jobs -->|"checks capacity"| node_cloudguard
node_cloudguard -->|"reads usage"| node_analytics
node_worker -->|"guards routes"| node_cloudguard
node_worker -->|"dispatches probe"| node_cloudprobe
node_cloudprobe -->|"checks usage"| node_cloudguard
node_worker -->|"dispatches diagnosis"| node_diagnostics
node_worker -.->|"serves privacy routes"| node_privacy
node_jobs -->|"deletes after delivery"| node_r2

click node_worker "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/index.ts"
click node_polling "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/instagram-polling.ts"
click node_igapi "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/instagram-api.ts"
click node_enrollment "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/owner-setup.ts"
click node_senders "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/senders.ts"
click node_jobs "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/jobs.ts"
click node_downloaders "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/downloaders.ts"
click node_apify "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/apify-download.ts"
click node_apifybudget "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/apify-budget.ts"
click node_providers "https://github.com/rebarfw/arabic-meme-autoposter/tree/main/src/downloader-providers"
click node_video "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/video-downloader.ts"
click node_media "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/media.ts"
click node_buffer "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/buffer.ts"
click node_cloudguard "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/cloudflare-usage.ts"
click node_privacy "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/privacy.ts"
click node_diagnostics "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/meta-diagnostics.ts"
click node_cloudprobe "https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/cloudflare-probe.ts"

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_worker,node_polling,node_igapi,node_enrollment,node_senders toneBlue
class node_jobs,node_d1,node_media,node_r2,node_buffer toneAmber
class node_downloaders,node_apify,node_providers,node_video toneMint
class node_apifybudget,node_cloudguard,node_privacy,node_diagnostics,node_cloudprobe toneRose
class node_meta,node_bufferapi,node_analytics,node_person,node_operator toneIndigo
```

## Components

### Ingestion and authorization

- [Worker routes](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/index.ts): `src/index.ts`
- [DM polling](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/instagram-polling.ts): `src/instagram-polling.ts`
- [Instagram API](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/instagram-api.ts): `src/instagram-api.ts`
- [Sender enrollment](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/owner-setup.ts): `src/owner-setup.ts`
- [Sender allowlist](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/senders.ts): `src/senders.ts`

### Publishing pipeline

- [Job orchestration](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/jobs.ts): `src/jobs.ts`
- **Job state**
- [Media storage](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/media.ts): `src/media.ts`
- **Private media**
- [Buffer publishing](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/buffer.ts): `src/buffer.ts`

### Media acquisition

- [Provider selection](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/downloaders.ts): `src/downloaders.ts`
- [Apify downloads](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/apify-download.ts): `src/apify-download.ts`
- [Website providers](https://github.com/rebarfw/arabic-meme-autoposter/tree/main/src/downloader-providers): `src/downloader-providers`
- [MP4 validation](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/video-downloader.ts): `src/video-downloader.ts`

### Safety and operations

- [Apify budget guard](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/apify-budget.ts): `src/apify-budget.ts`
- [Cloudflare usage guard](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/cloudflare-usage.ts): `src/cloudflare-usage.ts`
- [Privacy cleanup](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/privacy.ts): `src/privacy.ts`
- [Meta diagnostics](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/meta-diagnostics.ts): `src/meta-diagnostics.ts`
- [Usage probe](https://github.com/rebarfw/arabic-meme-autoposter/blob/main/src/cloudflare-probe.ts): `src/cloudflare-probe.ts`

### External services

- **Meta messages**
- **Buffer API**
- **Cloudflare analytics**

### Other components

- **Approved sender**
- **Administrator**

## Connections

- Approved sender → DM polling: shares Reel
- DM polling → Instagram API: reads conversations (evidence: `src/instagram-polling.ts`)
- Instagram API → Meta messages: requests messages
- DM polling → Job orchestration: enqueues source (evidence: `src/instagram-polling.ts`)
- Worker routes → DM polling: dispatches polling (evidence: `src/index.ts`)
- Administrator → Worker routes: calls admin routes (evidence: `src/index.ts`)
- Worker routes → Sender enrollment: routes setup (evidence: `src/index.ts`)
- Sender enrollment → Meta messages: verifies identity
- Sender enrollment → Sender allowlist: installs sender IDs (evidence: `src/owner-setup.ts`)
- Job orchestration → Sender allowlist: checks authorization (evidence: `src/jobs.ts`)
- Job orchestration → Job state: stores job state
- Job orchestration → Provider selection: requests download (evidence: `src/jobs.ts`)
- Provider selection → Apify downloads: uses Apify (evidence: `src/downloaders.ts`)
- Provider selection → Website providers: tries providers (evidence: `src/downloaders.ts`)
- Provider selection → MP4 validation: validates media (evidence: `src/downloaders.ts`)
- Apify downloads → Apify budget guard: reserves runs (evidence: `src/apify-download.ts`)
- Job orchestration → Media storage: stores video (evidence: `src/jobs.ts`)
- Media storage → Private media: writes object
- Job orchestration → Buffer publishing: requests posts (evidence: `src/jobs.ts`)
- Buffer publishing → Buffer API: creates posts
- Job orchestration → Cloudflare usage guard: checks capacity (evidence: `src/jobs.ts`)
- Cloudflare usage guard → Cloudflare analytics: reads usage
- Worker routes → Cloudflare usage guard: guards routes (evidence: `src/index.ts`)
- Worker routes → Usage probe: dispatches probe (evidence: `src/index.ts`)
- Usage probe → Cloudflare usage guard: checks usage (evidence: `src/cloudflare-probe.ts`)
- Worker routes → Meta diagnostics: dispatches diagnosis (evidence: `src/index.ts`)
- Worker routes → Privacy cleanup: serves privacy routes (evidence: `src/index.ts`)
- Job orchestration → Private media: deletes after delivery
