# tspeterkim/insta-chat architecture

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

- Interactive diagram: https://gitdiagram.com/tspeterkim/insta-chat
- Repository: https://github.com/tspeterkim/insta-chat

## Overview

insta-chat lets a user configure keyword-based Instagram comment replies through a Google Sheets-backed web app. The documented workflow is to log in, view Instagram posts, create automation rows, then have a periodically polling Python bot read those rows, find matching comments, and send replies. The bot’s source supports its Sheets and Graph API interactions; frontend details and the UI-to-Sheets wiring are documented in the README, not shown in source excerpts.

Main entry points: [`bot.py`](https://github.com/tspeterkim/insta-chat/blob/main/bot.py) (Polling bot), [`index.html`](https://github.com/tspeterkim/insta-chat/blob/main/index.html) (Automation web app), [`Code.gs`](https://github.com/tspeterkim/insta-chat/blob/main/Code.gs) (Apps Script), [`Sidebar.html`](https://github.com/tspeterkim/insta-chat/blob/main/Sidebar.html) (Posts sidebar)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Automation setup"]
  node_webapp["Automation web app<br/>[index.html]"]
  node_login["Facebook Login button<br/>[index.html]"]
  node_sidebar["Posts sidebar<br/>[Sidebar.html]"]
  node_apps_script["Apps Script<br/>[Code.gs]"]
  node_sheet[("Automation spreadsheet")]
end

subgraph group_runtime["Reply automation"]
  node_poller["Polling bot<br/>[bot.py]"]
  node_token["Token exchange<br/>[bot.py]"]
  node_comment_scan["Comment scanning<br/>[bot.py]"]
  node_matcher["Keyword matching<br/>[bot.py]"]
  node_reply["Reply sending<br/>[bot.py]"]
end

subgraph group_services["External services"]
  node_facebook["Facebook / Instagram Graph API"]
  node_google_sheets["Google Sheets service"]
end

node_user(("Account owner"))

node_user -->|"uses"| node_webapp
node_webapp -->|"embeds"| node_login
node_webapp -->|"uses"| node_apps_script
node_apps_script -->|"populates"| node_sidebar
node_sidebar -->|"loads posts"| node_facebook
node_user -->|"creates rules"| node_sheet
node_apps_script -->|"backs app"| node_sheet
node_poller -->|"reads config"| node_google_sheets
node_poller -->|"gets token"| node_token
node_poller -->|"scans rules"| node_comment_scan
node_token -->|"exchanges token"| node_facebook
node_comment_scan -->|"fetches comments"| node_facebook
node_comment_scan -->|"checks comments"| node_matcher
node_matcher -->|"sends matches"| node_reply
node_reply -->|"posts replies"| node_facebook

click node_webapp "https://github.com/tspeterkim/insta-chat/blob/main/index.html"
click node_login "https://github.com/tspeterkim/insta-chat/blob/main/index.html"
click node_sidebar "https://github.com/tspeterkim/insta-chat/blob/main/Sidebar.html"
click node_apps_script "https://github.com/tspeterkim/insta-chat/blob/main/Code.gs"
click node_poller "https://github.com/tspeterkim/insta-chat/blob/main/bot.py"
click node_token "https://github.com/tspeterkim/insta-chat/blob/main/bot.py"
click node_comment_scan "https://github.com/tspeterkim/insta-chat/blob/main/bot.py"
click node_matcher "https://github.com/tspeterkim/insta-chat/blob/main/bot.py"
click node_reply "https://github.com/tspeterkim/insta-chat/blob/main/bot.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_webapp,node_login,node_sidebar,node_apps_script,node_sheet toneBlue
class node_poller,node_token,node_comment_scan,node_matcher,node_reply toneAmber
class node_facebook,node_google_sheets toneMint
class node_user toneIndigo
```

## Components

### Automation setup

- [Automation web app](https://github.com/tspeterkim/insta-chat/blob/main/index.html): `index.html`
- [Facebook Login button](https://github.com/tspeterkim/insta-chat/blob/main/index.html): `index.html`
- [Posts sidebar](https://github.com/tspeterkim/insta-chat/blob/main/Sidebar.html): `Sidebar.html`
- [Apps Script](https://github.com/tspeterkim/insta-chat/blob/main/Code.gs): `Code.gs`
- **Automation spreadsheet**

### Reply automation

- [Polling bot](https://github.com/tspeterkim/insta-chat/blob/main/bot.py): `bot.py`
- [Token exchange](https://github.com/tspeterkim/insta-chat/blob/main/bot.py): `bot.py`
- [Comment scanning](https://github.com/tspeterkim/insta-chat/blob/main/bot.py): `bot.py`
- [Keyword matching](https://github.com/tspeterkim/insta-chat/blob/main/bot.py): `bot.py`
- [Reply sending](https://github.com/tspeterkim/insta-chat/blob/main/bot.py): `bot.py`

### External services

- **Facebook / Instagram Graph API**
- **Google Sheets service**

### Other components

- **Account owner**

## Connections

- Account owner → Automation web app: uses (evidence: `README.md`)
- Automation web app → Facebook Login button: embeds (evidence: `README.md`)
- Automation web app → Apps Script: uses (evidence: `README.md`)
- Apps Script → Posts sidebar: populates (evidence: `README.md`)
- Posts sidebar → Facebook / Instagram Graph API: loads posts (evidence: `README.md`)
- Account owner → Automation spreadsheet: creates rules (evidence: `README.md`)
- Apps Script → Automation spreadsheet: backs app (evidence: `README.md`)
- Polling bot → Google Sheets service: reads config (evidence: `bot.py`)
- Polling bot → Token exchange: gets token (evidence: `bot.py`)
- Polling bot → Comment scanning: scans rules (evidence: `bot.py`)
- Token exchange → Facebook / Instagram Graph API: exchanges token (evidence: `bot.py`)
- Comment scanning → Facebook / Instagram Graph API: fetches comments (evidence: `bot.py`)
- Comment scanning → Keyword matching: checks comments (evidence: `bot.py`)
- Keyword matching → Reply sending: sends matches (evidence: `bot.py`)
- Reply sending → Facebook / Instagram Graph API: posts replies (evidence: `bot.py`)
