# aws-samples/amazon-connect-contact-lens-rules-library architecture

> Architecture diagram of the GitHub repository aws-samples/amazon-connect-contact-lens-rules-library, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aws-samples/amazon-connect-contact-lens-rules-library
- Repository: https://github.com/aws-samples/amazon-connect-contact-lens-rules-library

## Overview

##### Project Type & Purpose
- This is an **AWS CLI / PowerShell–based deployment tool** that bundles JSON rule templates for Amazon Connect Contact Lens.
- It provides categorized rule definitions (Airline, Financial Services, General, Insurance, Telecommunications) in JSON, plus a PowerShell script (`Install-CLRuleLibrary.ps1`) to batch-install them.
- Users (contact-center managers, DevOps engineers) run commands or the script to push rules via the Connect Rules API.

##### File Structure
- Top-level directories:
- **Airline**, **Financial Services**, **General**, **Insurance**, **Telecommunications** – each contains `Voice/Post-Call` and/or `Voice/Real-Time` subfolders with JSON files.
- **Install-CLRuleLibrary** – holds the deployment script.
- Root files: `README.md`, `LICENSE`, `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`, `.gitignore`.
- **Patterns**:
- Hierarchical categorization by business domain → voice context → timing (post-call vs real-time) → individual rule JSON.
- **Deployment artifacts**:
- JSON rule definitions (inputs to AWS Connect APIs).
- PowerShell script orchestrates AWS CLI calls.

##### README for Architecture Hints
- The README outlines two installation methods: direct `aws connect create-rule` CLI commands, or via the PowerShell script in CloudShell.
- It references AWS services: Amazon Connect, Contact Lens Rules API, IAM for authentication.

##### Main Components & Their Interactions
a. **Local Developer/Operator** (user)
– Runs commands locally or in AWS CloudShell.
b. **Rule Library Directory**
– File system with categorized JSON files.
c. **Installer Script** (`Install-CLRuleLibrary.ps1`)
– PowerShell wrapper; lists directories → prompts user → invokes AWS CLI.
d. **AWS CLI / AWS SDK**
– Authenticated calls to `CreateRule` API against the Amazon Connect instance.
e. **Amazon Connect Service**
– Contact Lens Rules engine stores and enforces rules.
f. **AWS Account & IAM**
– Permission boundary; credentials used by CLI/Script.

##### Architectural Patterns & Principles
- **Separation of Concerns**:
- Rule definitions (data) are decoupled from deployment logic (script).
- **Extensibility**:
- New business domains or rule types simply add JSON under a new folder.
- **Infrastructure as Code (IaC) Lite**:
- JSON files act as declarative inputs to an AWS API.
- **Interactive Deployment**:
- Script prompts for folder selection, enabling selective installs.

##### Elements
- **Labels**: e.g., “Rule Library (JSON)”, “Install-CLRuleLibrary.ps1”, “AWS CLI”, “Amazon Connect CreateRule API”.
- **Annotations**: note folder hierarchy for clarity (e.g., Airline → Voice → Post-Call → `create-*.json`).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Local User
    User["Local Developer/Operator"]:::local

    %% Rule Library
    subgraph "Rule Library (JSON Templates)"
        direction TB
        Airline["Airline"]:::local
        Airline_PC["Voice/Post-Call"]:::local
        Airline_RT["Voice/Real-Time"]:::local
        Financial["Financial Services"]:::local
        Fin_PC["Voice/Post-Call"]:::local
        General["General"]:::local
        Gen_PC["Voice/Post-Call"]:::local
        Gen_RT["Voice/Real-Time"]:::local
        Insurance["Insurance"]:::local
        Ins_PC["Voice/Post-Call"]:::local
        Telecom["Telecommunications"]:::local
        Tel_PC["Voice/Post-Call"]:::local
    end

    %% Deployment Container
    subgraph "Deployment"
        direction TB
        Script["Install-CLRuleLibrary.ps1"]:::local
        AWSCLI["AWS CLI / SDK"]:::client
    end

    %% AWS Cloud
    subgraph "AWS Cloud"
        direction TB
        IAM["IAM (Authentication)"]:::aws
        Connect["Amazon Connect\n(Contact Lens Rules API)"]:::aws
    end

    %% Documentation
    subgraph "Project Documentation & Config"
        direction TB
        README["README.md"]:::local
        LICENSE["LICENSE"]:::local
        CONTRIB["CONTRIBUTING.md"]:::local
        CODEC["CODE_OF_CONDUCT.md"]:::local
        GITIGNORE[".gitignore"]:::local
    end

    %% Flows
    User -->|"runs script"| Script
    Script -->|"reads JSON"| Airline_PC
    Script --> Airline_RT
    Script --> Fin_PC
    Script --> Gen_PC
    Script --> Gen_RT
    Script --> Ins_PC
    Script --> Tel_PC
    Script -->|"invokes"| AWSCLI
    AWSCLI -->|"aws connect create-rule"| Connect
    AWSCLI -->|"uses credentials"| IAM
    AWSCLI --> IAM
    User -->|"can run direct CLI"| AWSCLI

    %% Click Events
    click Airline_PC "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/Airline/Voice/Post-Call/create-baggage-inquiry-voice-postcall.json"
    click Airline_RT "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/Airline/Voice/Real-Time/create-wheelchair-access-voice-realtime.json"
    click Fin_PC "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/Financial Services/Voice/Post-Call/create-failure-demand-voice-postcall.json"
    click Gen_PC "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/General/Voice/Post-Call/create-apology-voice-postcall.json"
    click Gen_RT "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/General/Voice/Real-Time/create-priorityAssistance-voice-realtime.json"
    click Ins_PC "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/Insurance/Voice/Post-Call/create-claims-voice-postcall.json"
    click Tel_PC "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/Telecommunications/Voice/Post-Call/create-mobile-data-voice-postcall.json"
    click Script "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/Install-CLRuleLibrary/Install-CLRuleLibrary.ps1"
    click README "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/README.md"
    click LICENSE "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/tree/main/LICENSE"
    click CONTRIB "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/CONTRIBUTING.md"
    click CODEC "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/CODE_OF_CONDUCT.md"
    click GITIGNORE "https://github.com/aws-samples/amazon-connect-contact-lens-rules-library/blob/main/.gitignore"

    %% Styles
    classDef local fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef client fill:#ccf,stroke:#333,stroke-width:1px
    classDef aws fill:#ffcc99,stroke:#333,stroke-width:1px
```
