# khai-pi/dynamodb-lambda-cdk-typescript architecture

> Architecture diagram of the GitHub repository khai-pi/dynamodb-lambda-cdk-typescript, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/khai-pi/dynamodb-lambda-cdk-typescript
- Repository: https://github.com/khai-pi/dynamodb-lambda-cdk-typescript

## Overview

##### Main Components Identification

- AWS Lambda Functions Layer
- DynamoDB Layer
- API Gateway Layer (implied by the Lambda setup)
- Infrastructure as Code Layer (CDK)

##### Component Breakdown

a. Lambda Functions (Group these together):
- Create Operation
- Read Operations (get-all, get-one)
- Update Operation
- Delete Operation

b. Infrastructure Components:
- CDK Stack Definition
- CloudFormation Template (generated)
- DynamoDB Table

**Client Layer**

**API Gateway Layer**

**Lambda Functions Layer**

**Data Layer (DynamoDB)**

##### Specific Elements

a. Client Interaction:
- HTTP endpoints for each operation
- HTTP methods (GET, POST, PUT, DELETE)

b. Lambda Functions:
- Five Lambda functions (create, get-all, get-one, update-one, delete-one)
- Their connection to the API Gateway
- TypeScript runtime

c. Infrastructure:
- CDK stack definition
- CloudFormation template generation
- Resource provisioning flow

##### Additional Details

Annotations for:
- Testing setup (Jest)
- CI/CD pipeline (GitHub Actions)
- Package management separation
- TypeScript compilation flow

##### Relationships to Highlight

- How CDK generates CloudFormation templates
- Demonstrate Lambda function interaction with DynamoDB
- API Gateway routing to specific Lambda functions
- Deployment flow through GitHub Actions

##### Technical Specifications

Notes regarding:
- TypeScript usage
- Separate package.json for Lambda functions
- Testing separation between infrastructure and Lambda functions
- CI pipeline configuration

Remember to:
- Keep the infrastructure provisioning flow separate from the runtime flow
- Separation of concerns between Lambda functions
- Relationship between the CDK code and the resulting AWS resources
- Testing and CI/CD components without overwhelming the main architecture

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Client[Client Application]
    end

    subgraph APIGateway[API Gateway Layer]
        API[API Gateway]
        API --> |POST| CreateAPI["/items (Create)"]:::api
        API --> |GET| ReadAllAPI["/items (Read All)"]:::api
        API --> |GET| ReadOneAPI["/items/{id} (Read One)"]:::api
        API --> |PUT| UpdateAPI["/items/{id} (Update)"]:::api
        API --> |DELETE| DeleteAPI["/items/{id} (Delete)"]:::api
    end

    subgraph LambdaLayer[Lambda Functions Layer]
        CreateLambda[Create Function]:::lambda
        GetAllLambda[Get All Function]:::lambda
        GetOneLambda[Get One Function]:::lambda
        UpdateLambda[Update Function]:::lambda
        DeleteLambda[Delete Function]:::lambda
    end

    subgraph DataLayer[Data Layer]
        DynamoDB[(DynamoDB Table)]:::database
    end

    subgraph InfrastructureLayer[Infrastructure as Code]
        CDKStack[CDK Stack Definition]:::infra
        CDKEntry[CDK Entry Point]:::infra
        CDKConfig[CDK Configuration]:::infra
        CloudFormation[CloudFormation Template]:::infra
    end

    subgraph Testing[Testing Framework]
        LambdaTests[Lambda Tests]:::test
        InfraTests[Infrastructure Tests]:::test
        JestConfig[Jest Configurations]:::test
    end

    subgraph CICD[CI/CD Pipeline]
        GithubActions[GitHub Actions]:::cicd
    end

    %% Connections
    Client --> API
    CreateAPI --> CreateLambda
    ReadAllAPI --> GetAllLambda
    ReadOneAPI --> GetOneLambda
    UpdateAPI --> UpdateLambda
    DeleteAPI --> DeleteLambda

    CreateLambda --> DynamoDB
    GetAllLambda --> DynamoDB
    GetOneLambda --> DynamoDB
    UpdateLambda --> DynamoDB
    DeleteLambda --> DynamoDB

    CDKEntry --> CDKStack
    CDKStack --> CloudFormation
    CDKConfig --> CDKStack
    CloudFormation --> API
    CloudFormation --> DynamoDB
    CloudFormation --> LambdaLayer

    LambdaTests --> LambdaLayer
    InfraTests --> InfrastructureLayer
    GithubActions --> CloudFormation

    %% Click Events
    click CreateLambda "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/lambdas/create.ts"
    click GetAllLambda "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/lambdas/get-all.ts"
    click GetOneLambda "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/lambdas/get-one.ts"
    click UpdateLambda "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/lambdas/update-one.ts"
    click DeleteLambda "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/lambdas/delete-one.ts"
    click CDKStack "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/lib/dynamodb-lambda-cdk-typescript-stack.ts"
    click CDKEntry "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/bin/dynamodb-lambda-cdk-typescript.ts"
    click CDKConfig "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/cdk.json"
    click LambdaTests "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/tree/main/lambdas/test"
    click InfraTests "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/tree/main/test"
    click JestConfig "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/jest.config.cjs"
    click GithubActions "https://github.com/khai-pi/dynamodb-lambda-cdk-typescript/blob/main/.github/workflows/ci.yml"

    %% Styling
    classDef api fill:#9cf,stroke:#333
    classDef lambda fill:#f9f,stroke:#333
    classDef database fill:#fcc,stroke:#333
    classDef infra fill:#fc9,stroke:#333
    classDef test fill:#cfc,stroke:#333
    classDef cicd fill:#ccc,stroke:#333

    %% Legend
    subgraph Legend
        L1[API Gateway]:::api
        L2[Lambda Function]:::lambda
        L3[(Database)]:::database
        L4[Infrastructure]:::infra
        L5[Testing]:::test
        L6[CI/CD]:::cicd
    end
```
