How meyer1994/wa works
Project type and purpose
• This is a serverless WhatsApp Bot built in Python using FastAPI (app.py, routes.py) and deployed as an AWS Lambda function (handler.py).
• It ingests incoming WhatsApp messages, persists them in DynamoDB, calls OpenAI to generate a response, persists chat records, and replies via the WhatsApp API.
File structure
• Top-level:
• handler.py – AWS Lambda entry point
• infra.py – CDK infra definition (ignored per instructions)
• docker-compose.yml, Dockerfile – local dev environment
• pyproject.toml – Python project config
• wa/ package:
• app.py – FastAPI application instance
• routes.py – HTTP endpoint definitions
• deps.py, config.py – dependency injection and configuration
• agents/ – business-logic modules for different bot skills (math, todos, log)
• dynamo/ – DynamoDB wrappers for events, messages, and WhatsApp raw events
• blob.py – S3 (RAG bucket) interactions
• whats/ – WhatsApp API client and models
• logs.py, lifespan.py – application logging and startup/shutdown hooks
README insights
• Uses AWS Lambda behind API Gateway to expose a POST webhook for WhatsApp events
• Two DynamoDB tables (EVENTS_TABLE, MESSAGES_TABLE)
• One S3 bucket for RAG artifacts
• External dependency: OpenAI API
Main components
a. External WhatsApp service (Meta/Twilio WhatsApp API)
b. AWS API Gateway (webhook endpoint)
c. AWS Lambda function running FastAPI (handler.py → wa/app.py)
d. DynamoDB:
• EVENTS_TABLE – raw inbound events
• MESSAGES_TABLE – chat history
e. S3 bucket – RAG storage (blob.py)
f. OpenAI API – model inference
g. Logging/Monitoring – CloudWatch (implied by AWS Lambda)
Relationships and data flows
• WhatsApp → API Gateway: inbound webhook POST
• API Gateway → Lambda: invoke FastAPI endpoint
• Lambda → DynamoDB (events): store raw event
• Lambda → OpenAI API: request response
• OpenAI → Lambda: return generated text
• Lambda → DynamoDB (messages): store chat message
• Lambda → WhatsApp API client: send reply
• Lambda → S3 bucket: read/write RAG artifacts (optional, when needed)
Architectural patterns and design principles
• Serverless single-function pattern: one Lambda hosts the FastAPI app
• Layered application structure:
• API layer (routes.py)
• Business-logic layer (agents/)
• Persistence layer (dynamo/, blob.py)
• Integration layer (whats/, OpenAI client)
• Dependency injection via deps.py for easier testing and swapping implementations
Detail level
• You show both DynamoDB tables separately
• OpenAI call as a distinct step
• That S3 is used for RAG artifacts (optional path)
• Do not include CDK code; represent only logical AWS services