# ecsdeployer/ecsdeployer architecture

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

- Interactive diagram: https://gitdiagram.com/ecsdeployer/ecsdeployer
- Repository: https://github.com/ecsdeployer/ecsdeployer

## Overview

##### Main Components

a. Core Components:
- CLI Interface (cmd/ directory)
- Configuration Parser (pkg/config/)
- Deployment Pipeline (internal/pipeline/)
- AWS Service Clients (internal/awsclients/)
- Resource Builders (internal/builders/)

b. Resource Management Components:
- Task Definition Builder
- Service Builder
- Cron Job Builder
- Network Configuration
- IAM Role Management

c. External Systems:
- AWS ECS/Fargate
- AWS CloudWatch
- AWS IAM
- AWS EventBridge (for cron jobs)
- Docker Registry

**[CLI Commands] --> [Configuration Parser]**

**[Pipeline Orchestrator] --> [Resource Builders] --> [AWS Clients]**

**[ECS/Fargate] <--> [CloudWatch] <--> [EventBridge] <--> [IAM]**

##### Key Relationships to Highlight

- Flow from configuration input through the pipeline steps
- Relationship between builders and AWS services
- Demonstrate the interaction between different AWS services

##### Specific Implementation Details

**[CLI Interface]**
- Command handling (cmd/)
- Configuration validation
- Error handling

**[Configuration Parser]**
- YAML parsing
- Schema validation
- Template processing

**[Resource Builders]**
- Task Definitions
- Services
- Cron Jobs
- Network Configuration

**[AWS Clients]**
- ECS
- CloudWatch
- IAM
- EventBridge

**[Pipeline Orchestrator]**
- Step sequencing
- Error management
- State tracking

##### Data Flow Indicators

- Configuration flow (→)
- API calls (⇄)
- Resource creation/updates (⇢)
- Event triggers (⇡)

##### Important Notes

- Version compatibility information
- Error handling paths
- Async vs sync operations
- Optional components (like cron jobs)

##### Implementation Details to Highlight

- Middleware chain (internal/middleware/)
- Builder pattern implementation
- Demonstrate the step execution flow
- Validation and error handling paths

##### Architectural Patterns to Emphasize

- Builder Pattern (for resource construction)
- Pipeline Pattern (for deployment flow)
- Middleware Chain (for cross-cutting concerns)
- Factory Pattern (for AWS client creation)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph CLI
        CLI_CMD["CLI Commands"]:::cli
        CLI_DEPLOY["Deploy Command"]:::cli
        CLI_CHECK["Check Command"]:::cli
        CLI_CLEAN["Clean Command"]:::cli
        
        CLI_CMD --> CLI_DEPLOY
        CLI_CMD --> CLI_CHECK
        CLI_CMD --> CLI_CLEAN
    end

    subgraph Configuration
        CONFIG_PARSER["Configuration Parser"]:::config
        SCHEMA["Schema Validation"]:::config
        TMPL["Template Processing"]:::config
        
        CONFIG_PARSER --> SCHEMA
        CONFIG_PARSER --> TMPL
    end

    subgraph Pipeline
        PIPELINE["Pipeline Orchestrator"]:::pipeline
        MIDDLEWARE["Middleware Chain"]:::pipeline
        
        STEPS["Deployment Steps"]:::pipeline
        PRE_DEPLOY["Pre-deployment"]:::pipeline
        SERVICE_DEPLOY["Service Deployment"]:::pipeline
        CRON_DEPLOY["Cron Deployment"]:::pipeline
        
        PIPELINE --> MIDDLEWARE
        PIPELINE --> STEPS
        STEPS --> PRE_DEPLOY
        STEPS --> SERVICE_DEPLOY
        STEPS --> CRON_DEPLOY
    end

    subgraph Builders
        BUILDERS["Resource Builders"]:::builder
        TASK_DEF["Task Definition Builder"]:::builder
        SERVICE_BUILD["Service Builder"]:::builder
        CRON_BUILD["Cron Job Builder"]:::builder
        RUN_TASK["Run Task Builder"]:::builder
        
        BUILDERS --> TASK_DEF
        BUILDERS --> SERVICE_BUILD
        BUILDERS --> CRON_BUILD
        BUILDERS --> RUN_TASK
    end

    subgraph "AWS Integration"
        AWS_CLIENTS["AWS Service Clients"]:::aws
        FARGATE_RES["Fargate Resources"]:::aws
        IAM_PERMS["IAM Permissions"]:::aws
        
        AWS_CLIENTS --> FARGATE_RES
        AWS_CLIENTS --> IAM_PERMS
    end

    subgraph "AWS Services"
        ECS["ECS/Fargate"]:::external
        CLOUDWATCH["CloudWatch"]:::external
        EVENTBRIDGE["EventBridge"]:::external
        IAM["IAM"]:::external
        
        ECS <--> CLOUDWATCH
        CLOUDWATCH <--> EVENTBRIDGE
        EVENTBRIDGE <--> IAM
    end

    CLI_CMD --> CONFIG_PARSER
    CONFIG_PARSER --> PIPELINE
    PIPELINE --> BUILDERS
    BUILDERS --> AWS_CLIENTS
    AWS_CLIENTS --> ECS

    %% Click Events
    click CLI_CMD "https://github.com/ecsdeployer/ecsdeployer/tree/main/cmd/"
    click CLI_DEPLOY "https://github.com/ecsdeployer/ecsdeployer/blob/main/cmd/deploy.go"
    click CLI_CHECK "https://github.com/ecsdeployer/ecsdeployer/blob/main/cmd/check.go"
    click CLI_CLEAN "https://github.com/ecsdeployer/ecsdeployer/blob/main/cmd/clean.go"
    click CONFIG_PARSER "https://github.com/ecsdeployer/ecsdeployer/tree/main/pkg/config/"
    click AWS_CLIENTS "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/awsclients/"
    click PIPELINE "https://github.com/ecsdeployer/ecsdeployer/blob/main/internal/pipeline/pipeline.go"
    click MIDDLEWARE "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/middleware/"
    click TASK_DEF "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/builders/taskdefinition/"
    click SERVICE_BUILD "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/builders/service/"
    click CRON_BUILD "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/builders/cron/"
    click RUN_TASK "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/builders/runtask/"
    click SCHEMA "https://github.com/ecsdeployer/ecsdeployer/blob/main/internal/configschema/schema.go"
    click TMPL "https://github.com/ecsdeployer/ecsdeployer/blob/main/internal/tmpl/tmpl.go"
    click SERVICE_DEPLOY "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/step/servicedeployment/"
    click CRON_DEPLOY "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/step/crondeployment/"
    click PRE_DEPLOY "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/step/predeployment/"
    click FARGATE_RES "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/fargate/"
    click IAM_PERMS "https://github.com/ecsdeployer/ecsdeployer/tree/main/internal/generate/iamperms/"

    %% Styles
    classDef cli fill:#2374ab
    classDef config fill:#ff8c42
    classDef pipeline fill:#7bc950
    classDef builder fill:#845ec2
    classDef aws fill:#00c2a8
    classDef external fill:#cccccc
    
    %% Legend
    subgraph Legend
        L1["CLI Components"]:::cli
        L2["Configuration Components"]:::config
        L3["Pipeline Components"]:::pipeline
        L4["Builder Components"]:::builder
        L5["AWS Integration"]:::aws
        L6["External Services"]:::external
    end
```
