# aws-samples/sample-devgenius-aws-solution-builder architecture

> Architecture diagram of the GitHub repository aws-samples/sample-devgenius-aws-solution-builder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aws-samples/sample-devgenius-aws-solution-builder
- Repository: https://github.com/aws-samples/sample-devgenius-aws-solution-builder

## Overview

##### Project type and purpose
- DevGenius is a full-stack, cloud-native AI application.
- It provides a conversational Streamlit frontend, backed by an Amazon Bedrock AI engine, to generate AWS solution architectures, cost estimates, infrastructure-as-code (CDK/CloudFormation), and documentation.

##### File structure
- Top-level “chatbot/” directory holds the Streamlit UI code (agent.py + widget modules), styles, layout, Dockerfile, and Python utilities.
- “lib/” contains the AWS CDK stack (TypeScript), including:
- edge-lambda/ (Lambda@Edge auth function in Node.js)
- lambda/ (supporting Python Lambdas for vector operations, OSS index lookups, prefix lists)
- layer/ (Python dependencies for the Lambdas)
- Configuration files: cdk.json, tsconfig.json, package.json, requirements.txt.

##### README for additional insights
- Confirms AWS architecture: Streamlit UI on ECS Fargate behind an ALB, CloudFront + Lambda@Edge for auth, Amazon Cognito, Bedrock Agent & Knowledge Base, OpenSearch Serverless, S3, DynamoDB.
- Describes deployment flow: local development vs Docker vs CDK deploy.

a. Main components
- Users & Browser
- CDN & Edge: CloudFront + Lambda@Edge (request validation/auth hook)
- Authentication: Cognito User Pool & Identity Pool
- Frontend container: ECS Fargate running Streamlit app (chatbot/agent.py + widgets) behind an Application Load Balancer
- AI Engine: Amazon Bedrock Agent + Amazon Bedrock Knowledge Base
- Vector Search: Amazon OpenSearch Serverless for embeddings
- Data Stores:
- Amazon DynamoDB for conversations and session tracking
- IaC Generation: CDK (lib/index.ts) producing CloudFormation templates
- Edge Lambdas: Node.js Lambda@Edge (lib/edge-lambda)
- Auxiliary Lambdas: Python Lambdas (lib/lambda) for supporting services

b. Relationships and interactions
1. User’s browser → CloudFront distribution
2. CloudFront → Lambda@Edge (auth/validation) → ALB
3. ALB → ECS Fargate container (Streamlit UI)
4. UI ↔ Cognito for signup/sign-in
6. Bedrock Agent ↔ Bedrock Knowledge Base
7. UI → DynamoDB (session & conversation storage)
8. UI → S3 (store/retrieve generated assets)
9. UI → OpenSearch Serverless (vector search retrieval)
10. UI → CDK (invokes lib/index.ts to synth/deploy infra)

c. Architectural patterns & design principles
- Microservices & serverless: stateless container for UI, serverless lambdas for edge auth and helper logic
- Separation of concerns: UI vs AI engine vs storage vs IaC
- Infrastructure as code: AWS CDK modular stacks
- Event-driven & API-driven interactions between components

d. Key technologies & frameworks
- Frontend: Python 3.12+ with Streamlit
- AI: Amazon Bedrock (Claude models) + custom Knowledge Base
- IaC: AWS CDK (TypeScript) & CloudFormation
- Compute: ECS Fargate, Lambda@Edge, Python Lambdas
- Storage: S3, DynamoDB, OpenSearch Serverless
- Auth & CDN: Amazon Cognito, CloudFront
- Local tooling: Docker, AWS CLI, CDK CLI

##### Elements
- Clear labels on every component (e.g., “ECS Fargate (Streamlit)”, “Amazon Bedrock Agent”).
- Compute (containers/lambdas) in blue
- Data stores in green
- AI services in purple
- Networking (CDN, ALB) in orange
- Auth in yellow

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Zone
    subgraph "User Zone"
        Browser["User Browser"]:::external
    end

    %% Networking & Auth
    subgraph "Networking & Auth"
        CF["Amazon CloudFront"]:::network
        EdgeLambda["Lambda@Edge (Auth/Validation)"]:::compute
        ALB["Application Load Balancer"]:::network
        Cognito["Amazon Cognito"]:::auth
    end

    %% Frontend
    subgraph "Frontend"
        Streamlit["ECS Fargate (Streamlit UI)"]:::compute
    end

    %% AI & Data Services
    subgraph "AI & Data Services"
        BedrockAgent["Amazon Bedrock Agent"]:::ai
        BedrockKB["Bedrock Knowledge Base"]:::ai
        OpenSearch["OpenSearch Serverless"]:::data
        DynamoDB["Amazon DynamoDB"]:::data
        S3["Amazon S3"]:::data
    end

    %% Supporting Lambdas
    subgraph "Supporting Lambdas"
        AuxLambdas["Auxiliary Python Lambdas"]:::compute
        LambdaLayer["Lambda Layer (Python deps)"]:::compute
    end

    %% Deployment (IaC)
    subgraph "Deployment (IaC)"
        IaCGenerator["AWS CDK IaC Generator"]:::deployment
        CFN["CloudFormation / AWS Resources"]:::deployment
    end

    %% Connections
    Browser -->|"HTTPS"| CF
    CF -->|"Viewer Request"| EdgeLambda
    EdgeLambda -->|"Forward"| ALB
    ALB -->|"HTTP"| Streamlit
    Browser -->|"Sign-in/Sign-up"| Cognito
    Streamlit <-->|"Cognito SDK Calls"| Cognito
    Streamlit -->|"Invoke API"| BedrockAgent
    BedrockAgent -->|"Lookup"| BedrockKB
    Streamlit -->|"SDK Call"| DynamoDB
    Streamlit -->|"SDK Call"| S3
    Streamlit -->|"Vector Search"| OpenSearch
    Streamlit -->|"synth & deploy"| IaCGenerator
    IaCGenerator -->|"CloudFormation deploy"| CFN
    Streamlit -->|"Invoke"| AuxLambdas
    AuxLambdas -->|"Uses Layer"| LambdaLayer

    %% Click Events
    click Streamlit "https://github.com/aws-samples/sample-devgenius-aws-solution-builder/tree/main/chatbot/"
    click IaCGenerator "https://github.com/aws-samples/sample-devgenius-aws-solution-builder/blob/main/lib/index.ts"
    click EdgeLambda "https://github.com/aws-samples/sample-devgenius-aws-solution-builder/tree/main/lib/edge-lambda/"
    click AuxLambdas "https://github.com/aws-samples/sample-devgenius-aws-solution-builder/tree/main/lib/lambda/"
    click LambdaLayer "https://github.com/aws-samples/sample-devgenius-aws-solution-builder/blob/main/lib/layer/requirements.txt"

    %% Styles
    classDef compute fill:#D0E6FF,stroke:#1E90FF,stroke-width:1px
    classDef data fill:#E6FFE6,stroke:#2E8B57,stroke-width:1px
    classDef ai fill:#F3E6FF,stroke:#8A2BE2,stroke-width:1px
    classDef network fill:#FFE6CC,stroke:#FF8C00,stroke-width:1px
    classDef auth fill:#FFF5CC,stroke:#DAA520,stroke-width:1px
    classDef deployment fill:#F0F0F0,stroke:#A9A9A9,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#000000,stroke-width:1px,stroke-dasharray: 5 5
```
