# imrooteodoro/trace-vision-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/imrooteodoro/trace-vision-chatbot
- Repository: https://github.com/imrooteodoro/trace-vision-chatbot

## Overview

This is a WhatsApp chatbot for reporting missing and found people, checking report status, and delivering tailored guidance. A message enters through Twilio and the main handler uses Lex conversation state to decide when to collect a photo or protocol. Trigger handling dispatches photo, record-management, and instruction-generation work; face processing validates and matches images, while record management and guidance use AWS services. The map follows the README and shown call sites; some subsystem details are documented but their full source was not sampled.

Main entry points: [`backend/functions/main/main.py`](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/main.py) (Webhook handler), [`backend/functions/store_face/store_face.py`](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/store_face.py) (Face intake), [`backend/functions/main/triggers.py`](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/triggers.py) (Workflow triggers), [`backend/functions/main/aws_lambda.py`](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/aws_lambda.py) (Lambda dispatcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_conversation["Conversation"]
  node_handler["Webhook handler<br/>[main.py]"]
  node_lex["Lex conversation<br/>[amazon_lex.py]"]
  node_twilio_client["Twilio client<br/>[twilio.py]"]
end

subgraph group_workflow["Report workflows"]
  node_triggers["Workflow triggers<br/>[triggers.py]"]
  node_lambda_dispatch["Lambda dispatcher<br/>[aws_lambda.py]"]
end

subgraph group_identity["Face processing"]
  node_face_flow["Face intake<br/>[store_face.py]"]
  node_face_match["Face matching<br/>[match_face.py]"]
  node_rekognition["Rekognition"]
  node_image_download["Image download<br/>[twilio.py]"]
  node_face_crop["Face cropping<br/>[crop.py]"]
  node_face_storage["Face image storage<br/>[amazon_s3.py]"]
end

subgraph group_records["Record management"]
  node_record_flow["Record operations<br/>[manage_records.py]"]
  node_record_store[("DynamoDB access<br/>[amazon_dynamodb.py]")]
end

subgraph group_guidance["Guidance"]
  node_instruction_flow["Instruction generation"]
  node_bedrock["Bedrock text generation<br/>[amazon_bedrock.py]"]
  node_polly["Polly audio conversion<br/>[amazon_polly.py]"]
  node_audio_storage["Audio storage<br/>[amazon_s3.py]"]
end

node_user(("WhatsApp user"))
node_twilio{{"Twilio WhatsApp"}}

node_user -->|"sends message"| node_twilio
node_twilio -->|"posts webhook"| node_handler
node_handler -->|"validates request"| node_twilio_client
node_handler -->|"reads and forwards session"| node_lex
node_handler -->|"checks workflow"| node_triggers
node_handler -->|"sends replies"| node_twilio_client
node_triggers -->|"invokes functions"| node_lambda_dispatch
node_lambda_dispatch -->|"dispatches photo work"| node_face_flow
node_lambda_dispatch -->|"dispatches record work"| node_record_flow
node_lambda_dispatch -->|"dispatches guidance work"| node_instruction_flow
node_triggers -->|"converts instructions"| node_polly
node_triggers -->|"stores audio"| node_audio_storage
node_face_flow -->|"checks existing matches"| node_face_match
node_face_flow -->|"detects and indexes face"| node_rekognition
node_face_flow -->|"crops detected face"| node_face_crop
node_face_flow -->|"stores face image"| node_face_storage
node_face_match -->|"searches collections"| node_rekognition
node_face_match -->|"downloads image"| node_image_download
node_rekognition -->|"downloads image"| node_image_download
node_face_crop -->|"downloads image"| node_image_download
node_record_flow -->|"reads and writes records"| node_record_store
node_instruction_flow -->|"generates guidance text"| node_bedrock
node_twilio_client -->|"sends WhatsApp replies"| node_twilio

click node_handler "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/main.py"
click node_lex "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/amazon_lex.py"
click node_twilio_client "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/twilio.py"
click node_triggers "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/triggers.py"
click node_lambda_dispatch "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/aws_lambda.py"
click node_face_flow "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/store_face.py"
click node_face_match "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/match_face.py"
click node_rekognition "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/amazon_rekognition.py"
click node_image_download "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/twilio.py"
click node_face_crop "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/crop.py"
click node_face_storage "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/amazon_s3.py"
click node_record_flow "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/manage_records/manage_records.py"
click node_record_store "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/manage_records/amazon_dynamodb.py"
click node_instruction_flow "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/generate_instructions/generate_instructions.py"
click node_bedrock "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/generate_instructions/amazon_bedrock.py"
click node_polly "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/amazon_polly.py"
click node_audio_storage "https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/amazon_s3.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_handler,node_lex,node_twilio_client,node_user toneBlue
class node_triggers,node_lambda_dispatch toneAmber
class node_face_flow,node_face_match,node_rekognition,node_image_download,node_face_crop,node_face_storage toneMint
class node_record_flow,node_record_store toneRose
class node_instruction_flow,node_bedrock,node_polly,node_audio_storage,node_twilio toneIndigo
```

## Components

### Conversation

- [Webhook handler](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/main.py): `backend/functions/main/main.py`
- [Lex conversation](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/amazon_lex.py): `backend/functions/main/amazon_lex.py`
- [Twilio client](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/twilio.py): `backend/functions/main/twilio.py`

### Report workflows

- [Workflow triggers](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/triggers.py): `backend/functions/main/triggers.py`
- [Lambda dispatcher](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/aws_lambda.py): `backend/functions/main/aws_lambda.py`

### Face processing

- [Face intake](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/store_face.py): `backend/functions/store_face/store_face.py`
- [Face matching](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/match_face.py): `backend/functions/store_face/match_face.py`
- [Rekognition](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/amazon_rekognition.py): `backend/functions/store_face/amazon_rekognition.py`
- [Image download](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/twilio.py): `backend/functions/store_face/twilio.py`
- [Face cropping](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/crop.py): `backend/functions/store_face/crop.py`
- [Face image storage](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/store_face/amazon_s3.py): `backend/functions/store_face/amazon_s3.py`

### Record management

- [Record operations](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/manage_records/manage_records.py): `backend/functions/manage_records/manage_records.py`
- [DynamoDB access](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/manage_records/amazon_dynamodb.py): `backend/functions/manage_records/amazon_dynamodb.py`

### Guidance

- [Instruction generation](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/generate_instructions/generate_instructions.py): `backend/functions/generate_instructions/generate_instructions.py`
- [Bedrock text generation](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/generate_instructions/amazon_bedrock.py): `backend/functions/generate_instructions/amazon_bedrock.py`
- [Polly audio conversion](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/amazon_polly.py): `backend/functions/main/amazon_polly.py`
- [Audio storage](https://github.com/imrooteodoro/trace-vision-chatbot/blob/main/backend/functions/main/amazon_s3.py): `backend/functions/main/amazon_s3.py`

### Other components

- **WhatsApp user**
- **Twilio WhatsApp**

## Connections

- WhatsApp user → Twilio WhatsApp: sends message (evidence: `README.md`)
- Twilio WhatsApp → Webhook handler: posts webhook (evidence: `README.md`)
- Webhook handler → Twilio client: validates request (evidence: `backend/functions/main/main.py`)
- Webhook handler → Lex conversation: reads and forwards session (evidence: `backend/functions/main/main.py`)
- Webhook handler → Workflow triggers: checks workflow (evidence: `backend/functions/main/main.py`)
- Webhook handler → Twilio client: sends replies (evidence: `backend/functions/main/main.py`)
- Workflow triggers → Lambda dispatcher: invokes functions (evidence: `backend/functions/main/triggers.py`)
- Lambda dispatcher → Face intake: dispatches photo work
- Lambda dispatcher → Record operations: dispatches record work
- Lambda dispatcher → Instruction generation: dispatches guidance work
- Workflow triggers → Polly audio conversion: converts instructions (evidence: `backend/functions/main/triggers.py`)
- Workflow triggers → Audio storage: stores audio (evidence: `backend/functions/main/triggers.py`)
- Face intake → Face matching: checks existing matches (evidence: `backend/functions/store_face/store_face.py`)
- Face intake → Rekognition: detects and indexes face (evidence: `backend/functions/store_face/store_face.py`)
- Face intake → Face cropping: crops detected face (evidence: `backend/functions/store_face/store_face.py`)
- Face intake → Face image storage: stores face image (evidence: `backend/functions/store_face/store_face.py`)
- Face matching → Rekognition: searches collections (evidence: `backend/functions/store_face/match_face.py`)
- Face matching → Image download: downloads image (evidence: `backend/functions/store_face/match_face.py`)
- Rekognition → Image download: downloads image (evidence: `backend/functions/store_face/amazon_rekognition.py`)
- Face cropping → Image download: downloads image (evidence: `backend/functions/store_face/crop.py`)
- Record operations → DynamoDB access: reads and writes records (evidence: `backend/functions/manage_records/manage_records.py`)
- Instruction generation → Bedrock text generation: generates guidance text (evidence: `backend/functions/generate_instructions/generate_instructions.py`)
- Twilio client → Twilio WhatsApp: sends WhatsApp replies (evidence: `README.md`)
