# nickperugini/ptb-agent-5548 architecture

> Architecture diagram of the GitHub repository nickperugini/ptb-agent-5548, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nickperugini/ptb-agent-5548
- Repository: https://github.com/nickperugini/ptb-agent-5548

## Overview

##### Project Type & Purpose
- This is an AWS Infrastructure-as-Code project using Terraform to deploy a serverless architecture.
- Purpose: Automate the provisioning of four Lambda functions behind HTTP API Gateways, a shared S3 bucket, and a DynamoDB table to accelerate simple doc-generation tasks.

##### File Structure
- Top-level Terraform files: main.tf (resource definitions), variables.tf (input parameters), outputs.tf (deployment outputs).
- lambda/ directory: four subdirectories (lambda1…lambda4), each containing an index.py (Lambda handler).
- Implied architecture: one VPC, subnets, security groups, IAM roles, API Gateway HTTP APIs, S3 bucket, DynamoDB table, and four Lambdas.

##### Extract Key Details from README
- Two API Gateways (api1 routes lambda1 & lambda2; api2 routes lambda3 & lambda4).
- Shared S3 bucket for all Lambdas.
- DynamoDB table used by lambda1.
- VPC encapsulates networking for Lambdas.

##### Main Components
- Subnets (public/private as defined)
- Security Groups
- Lambda1, Lambda2, Lambda3, Lambda4 (all deployed in the VPC)
b. API Gateway HTTP APIs
- API1 → routes to Lambda1 & Lambda2
- API2 → routes to Lambda3 & Lambda4
c. Data Stores (outside VPC)
- S3 bucket (shared by all Lambdas)
- DynamoDB table (used by Lambda1)

##### Relationships & Data Flows
- Calls with “PutObject” or “PutItem” to show the AWS API operations.

##### Architectural Patterns & Design Principles
- Serverless microservices: each Lambda has a single responsibility.
- IaC (Terraform) for reproducible infrastructure.
- Separation of concerns: API layer (Gateway), compute layer (Lambda), data layer (S3/DynamoDB).
- Network boundary: VPC isolates Lambda compute from the public internet (except via API GW).

##### Putting It All Together
- API1 → Lambda1 & Lambda2
- API2 → Lambda3 & Lambda4
- Lambda1,2,3,4 → S3
- Lambda1 → DynamoDB

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "VPC"
        direction TB
        VPCBox["VPC"]:::infra
        L1["Lambda1"]:::lambda
        L2["Lambda2"]:::lambda
        L3["Lambda3"]:::lambda
        L4["Lambda4"]:::lambda
    end

    API1["API Gateway 1"]:::api
    API2["API Gateway 2"]:::api

    S3["S3 Bucket"]:::datastore
    DB["DynamoDB Table"]:::datastore

    IAM["IAM Roles & Policies"]:::infra
    Variables["Terraform Variables"]:::infra
    Outputs["Terraform Outputs"]:::infra

    API1 -->|"Invoke"| L1
    API1 -->|"Invoke"| L2
    API2 -->|"Invoke"| L3
    API2 -->|"Invoke"| L4

    L1 -->|"PutObject"| S3
    L2 -->|"PutObject"| S3
    L3 -->|"PutObject"| S3
    L4 -->|"PutObject"| S3

    L1 -->|"PutItem"| DB

    Variables -.-> IAM
    Outputs -.-> IAM
    IAM -.-> L1
    IAM -.-> L2
    IAM -.-> L3
    IAM -.-> L4

    click VPCBox "https://github.com/nickperugini/ptb-agent-5548/blob/main/main.tf"
    click IAM "https://github.com/nickperugini/ptb-agent-5548/blob/main/main.tf"
    click API1 "https://github.com/nickperugini/ptb-agent-5548/blob/main/main.tf"
    click API2 "https://github.com/nickperugini/ptb-agent-5548/blob/main/main.tf"
    click L1 "https://github.com/nickperugini/ptb-agent-5548/blob/main/lambda/lambda1/index.py"
    click L2 "https://github.com/nickperugini/ptb-agent-5548/blob/main/lambda/lambda2/index.py"
    click L3 "https://github.com/nickperugini/ptb-agent-5548/blob/main/lambda/lambda3/index.py"
    click L4 "https://github.com/nickperugini/ptb-agent-5548/blob/main/lambda/lambda4/index.py"
    click S3 "https://github.com/nickperugini/ptb-agent-5548/blob/main/main.tf"
    click DB "https://github.com/nickperugini/ptb-agent-5548/blob/main/main.tf"
    click Variables "https://github.com/nickperugini/ptb-agent-5548/blob/main/variables.tf"
    click Outputs "https://github.com/nickperugini/ptb-agent-5548/blob/main/outputs.tf"

    classDef api fill:#DDEEFF,stroke:#6699CC;
    classDef lambda fill:#EEFFDD,stroke:#66CC99;
    classDef datastore fill:#FFEEDD,stroke:#CC9966;
    classDef infra fill:#F0F0F0,stroke:#AAAAAA,stroke-dasharray:5 5;
    classDef vpcbox fill:none,stroke:#AAAAAA,stroke-dasharray:5 5;
```
