# zafinamn/blackbox architecture

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

- Interactive diagram: https://gitdiagram.com/zafinamn/blackbox
- Repository: https://github.com/zafinamn/blackbox

## Overview

This is a small Express-based Facebook Messenger bot for BlackBox Garage MN. Its main workflow accepts webhook events, handles menu and camera-model selections, and collects phone and delivery address for an order before replying through the Messenger Send API. The tree also includes standalone scripts that configure Messenger’s Get Started action and persistent menu. The available excerpts show the webhook and outbound API behavior; connections from the setup scripts to the Facebook service are explicit, but their relationship to the running bot is not shown.

Main entry points: [`index.js`](https://github.com/zafinamn/blackbox/blob/main/index.js) (Webhook handler), [`setupGetStarted.js`](https://github.com/zafinamn/blackbox/blob/main/setupGetStarted.js) (Get Started setup), [`setupPersistentMenu.js`](https://github.com/zafinamn/blackbox/blob/main/setupPersistentMenu.js) (Persistent menu setup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_webhook["Webhook handler<br/>[index.js]"]
  node_event_state[("Event and order state<br/>[index.js]")]
  node_menu_flow["Menu and welcome<br/>[index.js]"]
  node_camera_info["Camera catalog<br/>[index.js]"]
  node_order_flow["Delivery order flow<br/>[index.js]"]
  node_send_api["Messenger replies<br/>[index.js]"]
end

subgraph group_messenger_setup["Messenger setup"]
  node_get_started_setup["Get Started setup<br/>[setupGetStarted.js]"]
  node_persistent_menu_setup["Persistent menu setup"]
end

node_customer(("Messenger user"))
node_facebook{{"Facebook Messenger"}}

node_customer -->|"sends events"| node_facebook
node_facebook -->|"posts events"| node_webhook
node_webhook -->|"checks and updates"| node_event_state
node_webhook -->|"handles selections"| node_menu_flow
node_webhook -->|"dispatches catalog"| node_camera_info
node_webhook -->|"collects order details"| node_order_flow
node_menu_flow -->|"sends menu replies"| node_send_api
node_camera_info -->|"sends carousel"| node_send_api
node_order_flow -->|"sends order prompts"| node_send_api
node_send_api -->|"posts messages"| node_facebook
node_get_started_setup -->|"configures action"| node_facebook
node_persistent_menu_setup -->|"configures menu"| node_facebook

click node_webhook "https://github.com/zafinamn/blackbox/blob/main/index.js"
click node_event_state "https://github.com/zafinamn/blackbox/blob/main/index.js"
click node_menu_flow "https://github.com/zafinamn/blackbox/blob/main/index.js"
click node_camera_info "https://github.com/zafinamn/blackbox/blob/main/index.js"
click node_order_flow "https://github.com/zafinamn/blackbox/blob/main/index.js"
click node_send_api "https://github.com/zafinamn/blackbox/blob/main/index.js"
click node_get_started_setup "https://github.com/zafinamn/blackbox/blob/main/setupGetStarted.js"
click node_persistent_menu_setup "https://github.com/zafinamn/blackbox/blob/main/setupPersistentMenu.js"

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_webhook,node_event_state,node_menu_flow,node_camera_info,node_order_flow,node_send_api,node_customer toneBlue
class node_get_started_setup,node_persistent_menu_setup toneAmber
class node_facebook toneIndigo
```

## Components

### Bot runtime

- [Webhook handler](https://github.com/zafinamn/blackbox/blob/main/index.js): `index.js`
- [Event and order state](https://github.com/zafinamn/blackbox/blob/main/index.js): `index.js`
- [Menu and welcome](https://github.com/zafinamn/blackbox/blob/main/index.js): `index.js`
- [Camera catalog](https://github.com/zafinamn/blackbox/blob/main/index.js): `index.js`
- [Delivery order flow](https://github.com/zafinamn/blackbox/blob/main/index.js): `index.js`
- [Messenger replies](https://github.com/zafinamn/blackbox/blob/main/index.js): `index.js`

### Messenger setup

- [Get Started setup](https://github.com/zafinamn/blackbox/blob/main/setupGetStarted.js): `setupGetStarted.js`
- [Persistent menu setup](https://github.com/zafinamn/blackbox/blob/main/setupPersistentMenu.js): `setupPersistentMenu.js`

### Other components

- **Messenger user**
- **Facebook Messenger**

## Connections

- Messenger user → Facebook Messenger: sends events
- Facebook Messenger → Webhook handler: posts events (evidence: `index.js`)
- Webhook handler → Event and order state: checks and updates (evidence: `index.js`)
- Webhook handler → Menu and welcome: handles selections (evidence: `index.js`)
- Webhook handler → Camera catalog: dispatches catalog (evidence: `index.js`)
- Webhook handler → Delivery order flow: collects order details (evidence: `index.js`)
- Menu and welcome → Messenger replies: sends menu replies (evidence: `index.js`)
- Camera catalog → Messenger replies: sends carousel (evidence: `index.js`)
- Delivery order flow → Messenger replies: sends order prompts (evidence: `index.js`)
- Messenger replies → Facebook Messenger: posts messages (evidence: `index.js`)
- Get Started setup → Facebook Messenger: configures action (evidence: `setupGetStarted.js`)
- Persistent menu setup → Facebook Messenger: configures menu (evidence: `setupPersistentMenu.js`)
