# raksit31667/learn-aws-voice-calling-chatbot architecture

> Architecture diagram of the GitHub repository raksit31667/learn-aws-voice-calling-chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raksit31667/learn-aws-voice-calling-chatbot
- Repository: https://github.com/raksit31667/learn-aws-voice-calling-chatbot

## Overview

##### Project type and purpose
- This is an AWS-based, Infrastructure-as-Code (IaC) project that provisions and wires together an automated voice-calling chatbot.
- It uses Terraform to spin up Amazon Lex bots/intents, an Amazon Connect contact flow, and a Lambda function to handle business logic.

##### File structure
- providers.tf: AWS provider configuration
- lex_bot.tf / lex_intents.tf: Terraform resources for the Lex bot and its intents
- contact_flow.json: Amazon Connect contact flow definition (JSON)
- lambda_function.py: AWS Lambda handler implementing intent fulfillment and business logic
- lex_bot.tf, lex_intents.tf, contact_flow.json and lambda_function.py together define the runtime pieces

##### README for insights
- Describes a serverless, event-driven workflow:
- Amazon Connect initiates and drives the call (outbound)
- Amazon Polly for Text-to-Speech (TTS)
- Amazon Lex for Automatic Speech Recognition (ASR) and Natural Language Understanding (NLU)
- AWS Lambda for intent fulfillment and session logic
- Terraform is used to provision Lex, Lex Intents, and Connect contact flows

##### Main components and interactions
a. Components
- End user (phone)
- Amazon Connect (Contact Flow)
- Amazon Polly (TTS)
- Amazon Lex (ASR & NLU)
- AWS Lambda (business logic)
- Terraform (IaC)
b. Relationships & data flow
1. Terraform provisions: Lex Bot & Intents, Contact Flow, Lambda function
2. Initiates outbound call → user’s phone
3. User answers → Connect invokes “Get customer input” (Lex)
4. Lex ASR & NLU → returns intent + slots to Lambda
5. Lambda processes context & returns response payload
6. Polly TTS converts response text → Connect plays audio to user
7. Loop back to step 3 until session ends
c. Architectural patterns
- Serverless / event-driven
- Separation of concerns: ASR (Lex), TTS (Polly), business logic (Lambda), orchestration (Connect)
- IaC provisioning with Terraform
d. Key technologies
- Terraform (HCL)
- AWS Connect, Lex, Polly, Lambda
- JSON for contact flows

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Infrastructure as Code (Terraform)"
        TFProv["providers.tf"]:::iac
        TFLexBot["lex_bot.tf"]:::iac
        TFLexInt["lex_intents.tf"]:::iac
        TFContactFlow["contact_flow.json"]:::iac
    end

    subgraph "Custom Code"
        LambdaCode["lambda_function.py"]:::code
    end

    DocNode["README.md"]:::doc

    User["End User (Phone)"]:::external
    Connect["Amazon Connect"]:::aws
    Lex["Amazon Lex"]:::aws
    Polly["Amazon Polly"]:::aws
    LambdaSvc["AWS Lambda"]:::aws

    %% Provisioning
    TFProv --> Connect
    TFProv --> Lex
    TFProv --> LambdaSvc
    TFLexBot --> Lex
    TFLexInt --> Lex
    TFContactFlow --> Connect

    %% Runtime flow
    User -->|"Answer call"| Connect
    Connect -->|"Get customer input (audio)"| Lex
    Lex -->|"Intent + slots"| LambdaSvc
    LambdaSvc -->|"Response text payload"| Polly
    Polly -->|"Audio stream"| Connect
    Connect -->|"Play audio"| User
    Connect -->|"Next prompt"| Lex

    %% Click Events
    click TFProv "https://github.com/raksit31667/learn-aws-voice-calling-chatbot/blob/master/providers.tf"
    click TFLexBot "https://github.com/raksit31667/learn-aws-voice-calling-chatbot/blob/master/lex_bot.tf"
    click TFLexInt "https://github.com/raksit31667/learn-aws-voice-calling-chatbot/blob/master/lex_intents.tf"
    click TFContactFlow "https://github.com/raksit31667/learn-aws-voice-calling-chatbot/blob/master/contact_flow.json"
    click LambdaCode "https://github.com/raksit31667/learn-aws-voice-calling-chatbot/blob/master/lambda_function.py"
    click DocNode "https://github.com/raksit31667/learn-aws-voice-calling-chatbot/blob/master/README.md"

    %% Styles
    classDef iac fill:#FFA500,stroke:#333,stroke-width:2px
    classDef aws fill:#2E8B57,stroke:#fff,stroke-width:2px
    classDef code fill:#1E90FF,stroke:#fff,stroke-width:2px
    classDef doc fill:#808080,stroke:#fff,stroke-width:2px
    classDef external fill:#EEEEEE,stroke:#000,stroke-width:1px
```
