# muhammadabyaz/go-cdk architecture

> Architecture diagram of the GitHub repository muhammadabyaz/go-cdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/muhammadabyaz/go-cdk
- Repository: https://github.com/muhammadabyaz/go-cdk

## Overview

##### Main Components

A. AWS Infrastructure Layer:
- AWS CloudFormation (as the underlying deployment mechanism)
- AWS CDK (as the IaC framework)
- AWS Lambda (as the compute service)
- API Gateway (implied by the api.go file)

B. Application Components:
- API Layer (represented by /lambda/api)
- Application Logic (represented by /lambda/app)
- Database Layer (represented by /lambda/database)
- Middleware (represented by /lambda/middleware)
- Types/Models (represented by /lambda/types)

**Top Tier: Infrastructure Layer**
**┌─────────────────────────────────────────┐**
- AWS Cloud                  │
- ┌──────────┐        ┌──────────┐     │
- CDK    │───────>│CloudForm.│     │
- ┘        └──────────┘     │
- ┘

**Middle Tier: AWS Services**
**┌─────────────────────────────────────────┐**
- ┌──────────┐        ┌──────────┐     │
- API    │───────>│ Lambda   │     │
- Gateway  │        │Function  │     │
- ┘        └──────────┘     │
- ┘

**Bottom Tier: Application Components**
**┌─────────────────────────────────────────┐**
- ┌────────┐  ┌────────┐  ┌───────────┐  │
- API   │─>│  App   │─>│ Database  │  │
- ┘  └────────┘  └───────────┘  │
- ▲                       │

- ┌────────┐  ┌────────┐                 │
- Types  │  │Middle- │                 │
- ware    │                 │
- ┘  └────────┘                 │
- ┘

##### Important Elements to Highlight

a. Infrastructure Flow:
- How the CDK code generates CloudFormation templates
- Deployment flow from CDK to AWS services

b. Runtime Flow:
- Request path from API Gateway through the Lambda function
- Internal application flow through the different components

c. Component Relationships:
- How middleware intercepts requests
- Demonstrate how types are shared across components
- Database interactions

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Infrastructure
        CDK[CDK Infrastructure Stack]
        CF[CloudFormation Template]
        APIG[API Gateway]
        LAMBDA[AWS Lambda Function]
    end

    subgraph "Lambda Application"
        HANDLER[Lambda Handler]
        subgraph "Application Components"
            MIDDLEWARE[Middleware Layer]
            API[API Router/Handler]
            APP[Application Logic]
            DB[(Database Layer)]
            TYPES[Types/Models]
        end
    end

    CDK --> CF
    CF --> APIG
    APIG --> LAMBDA
    LAMBDA --> HANDLER
    HANDLER --> MIDDLEWARE
    MIDDLEWARE --> API
    API --> APP
    APP --> DB
    API --> TYPES
    APP --> TYPES
    DB --> TYPES

    %% Component Mappings
    click CDK "https://github.com/MuhammadAbyaz/go-cdk/blob/main/go-cdk.go"
    click HANDLER "https://github.com/MuhammadAbyaz/go-cdk/blob/main/lambda/main.go"
    click API "https://github.com/MuhammadAbyaz/go-cdk/blob/main/lambda/api/api.go"
    click APP "https://github.com/MuhammadAbyaz/go-cdk/blob/main/lambda/app/app.go"
    click DB "https://github.com/MuhammadAbyaz/go-cdk/blob/main/lambda/database/database.go"
    click MIDDLEWARE "https://github.com/MuhammadAbyaz/go-cdk/blob/main/lambda/middleware/middleware.go"
    click TYPES "https://github.com/MuhammadAbyaz/go-cdk/blob/main/lambda/types/types.go"

    %% Styling
    classDef aws fill:#FF9900,stroke:#232F3E,color:white
    classDef app fill:#1E88E5,stroke:#0D47A1,color:white
    classDef data fill:#4CAF50,stroke:#1B5E20,color:white
    classDef infra fill:#9E9E9E,stroke:#424242,color:white

    class APIG,LAMBDA aws
    class API,APP,MIDDLEWARE,HANDLER app
    class DB,TYPES data
    class CDK,CF infra

    %% Legend
    subgraph Legend
        L1[AWS Services]:::aws
        L2[Application Components]:::app
        L3[(Data Components)]:::data
        L4[Infrastructure]:::infra
    end
```
