# pedchenkoroman/aws-kaizen architecture

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

- Interactive diagram: https://gitdiagram.com/pedchenkoroman/aws-kaizen
- Repository: https://github.com/pedchenkoroman/aws-kaizen

## Overview

##### Main Components
- CDK Application Entry Point (bin/aws-kaizen.ts): This is where the app initializes and kicks off the stack deployment.
- AWS CloudFormation Stack Definition (lib/aws-kaizen-stack.ts): This file defines the infrastructure — the “stack” of AWS resources that will be deployed.
- AWS Lambda Function (lambda/turn-on-off-handler.ts): This function acts as the operational logic to start or stop EC2 instances. It is the core “engine” that implements the EC2 control logic.
- Test Suite (test/aws-kaizen.test.ts): While not directly part of runtime architecture, tests ensure that the core functionality and infrastructure definitions work as expected.
- CDK and Build Configurations (cdk.json, tsconfig.json, jest.config.js, etc.): These files/configuration artifacts guide the build, deployment, and test processes.

##### Relationships and Interactions
- The CDK application (initiated in the bin directory) synthesizes a CloudFormation template using the definitions in the lib directory.
- The stack then includes the Lambda function (from the lambda directory) as an AWS resource.
- Although not explicitly in the code, the Lambda will have triggers (which may be defined by events such as CloudWatch Events or scheduled rule, based on the underlying infrastructure setup) to start/stop EC2 instances.
- Upon deployment via the CDK commands (deploy, diff, synth), the CloudFormation stack manages the lifecycle of these resources (Lambda, any associated IAM Roles, and the EC2 instance management hooks).

##### Architectural Patterns & Design Principles
- Infrastructure as Code (IaC): The project leverages AWS CDK to define infrastructure programmatically.
- Separation of Concerns: The project splits infrastructure definitions (lib), operational logic (lambda), and deployment entry logic (bin).
- Test-Driven Development (TDD) for infrastructure: With Jest tests validating functionality.
- Modularity: Each component is clearly isolated (e.g., Lambda logic separated from stack definition), facilitating extensibility.

##### Including Relevant Technologies and Frameworks
- AWS Cloud Development Kit (CDK) for infrastructure definition.
- AWS Lambda for serverless functions executing the start/stop EC2 logic.
- AWS CloudFormation as the underlying deployment mechanism.
- Typescript as the programming language.
- Jest for testing.
- Node.js (implied by npm scripts and package.json).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure Definition
    subgraph "Infrastructure Definition"
        A["CDK App (Entry Point)"]:::entry
        B["AWS Kaizen Stack"]:::stack
        A -->|"synthesizes"| B
    end

    %% Operational Logic
    subgraph "Operational Logic"
        C["Lambda: Turn On/Off Handler"]:::lambda
        B -->|"includes"| C
    end

    %% AWS Resources
    subgraph "AWS Resources"
        D(("AWS EC2 Instance")):::awsresource
        C -->|"controls"| D
    end

    %% Build & Test
    subgraph "Build & Test"
        T["Test Suite"]:::test
        subgraph "Build Configurations"
            F1["CDK Config"]:::config
            F2["TS Config"]:::config
            F3["Jest Config"]:::config
        end
        A --- T
        A --- F1
        A --- F2
        A --- F3
    end

    %% Click Events
    click A "https://github.com/pedchenkoroman/aws-kaizen/blob/master/bin/aws-kaizen.ts"
    click B "https://github.com/pedchenkoroman/aws-kaizen/blob/master/lib/aws-kaizen-stack.ts"
    click C "https://github.com/pedchenkoroman/aws-kaizen/blob/master/lambda/turn-on-off-handler.ts"
    click T "https://github.com/pedchenkoroman/aws-kaizen/blob/master/test/aws-kaizen.test.ts"
    click F1 "https://github.com/pedchenkoroman/aws-kaizen/blob/master/cdk.json"
    click F2 "https://github.com/pedchenkoroman/aws-kaizen/blob/master/tsconfig.json"
    click F3 "https://github.com/pedchenkoroman/aws-kaizen/blob/master/jest.config.js"

    %% Styles
    classDef entry fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef stack fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef lambda fill:#ffffe0,stroke:#000,stroke-width:1px;
    classDef awsresource fill:#ffa500,stroke:#000,stroke-width:1px;
    classDef test fill:#ffc0cb,stroke:#000,stroke-width:1px;
    classDef config fill:#d3d3d3,stroke:#000,stroke-width:1px;
```
