# bluedoors/ecr-metrics architecture

> Architecture diagram of the GitHub repository bluedoors/ecr-metrics, 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/bluedoors/ecr-metrics
- Repository: https://github.com/bluedoors/ecr-metrics

## Overview

##### Main Components
- Command-Line Tool / Script: The core logic lives in src/ecr_metrics/main.py.
- AWS Lambda Deployment: The README provides instructions for deploying the script as a Lambda function (with a note on setting the handler and customizing memory/timeout settings).
- AWS CloudWatch Events: To automate execution on a schedule (e.g., every 30 minutes).
- External AWS Services: Specifically, the AWS ECR API that the script queries.
- Supporting Files: These include configuration (pyproject.toml, .editorconfig, .gitignore), deployment configuration (Dockerfile and template.yml), and tests (in the tests directory), which overall support developing, building, testing, and deploying the project.

##### Relationships and Interactions
- The core script acts as the bridge between the AWS API and the end user by collecting metrics on repository count, image count per repository, and total image size.
- In an automated setup, the AWS Lambda function executes the script. CloudWatch Events trigger the Lambda function on a predefined schedule.
- Data flows from the AWS ECR service (queried via the AWS API) into the script, which then produces the metrics desired by the user/administrator.
- The Dockerfile and template.yml indicate that there is an option for container-based deployment or infrastructure-as-code deployment, reinforcing the idea of a flexible deployment model.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Business logic (retrieving and computing metrics) is decoupled from deployment concerns (Lambda/CloudWatch):
- The src directory clearly isolates the application code.
- Deployment-specific details reside in Dockerfile and template.yml.
- Modularity and Testability: The presence of a tests directory with dedicated test files shows the importance placed on verifying functionality independently from the deployment target.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Manual Workflow"
        CLI["CLI Executor (Manual)"]:::cli
        SCRIPT["Python Script (src/ecr_metrics/main.py)"]:::script
        CLI -->|"invokes"| SCRIPT
    end

    subgraph "Automated Workflow"
        CW["CloudWatch Events (Scheduler)"]:::cloudwatch
        LAMBDA["AWS Lambda Function"]:::lambda
        CW -->|"triggers"| LAMBDA
        LAMBDA -->|"executes"| SCRIPT
    end

    SCRIPT -->|"queries"| ECR["AWS ECR API"]:::aws
    ECR -->|"returns"| SCRIPT

    subgraph "Deployment Configuration"
        DOCKER["Dockerfile"]:::deployment
        TEMPLATE["template.yml"]:::deployment
    end

    subgraph "Supporting Files"
        CONFIG["Configuration Files"]:::config
        TOML["pyproject.toml"]:::config
        EDITOR[".editorconfig"]:::config
        GITIGNORE[".gitignore"]:::config
        CONFIG -->|"includes"| TOML
        CONFIG -->|"includes"| EDITOR
        CONFIG -->|"includes"| GITIGNORE
    end

    subgraph "Testing Suite"
        TESTS["tests directory"]:::testing
        TESTMAIN["tests/test_main.py"]:::testing
        RESPONSES["tests/responses.md"]:::testing
        TESTS -->|"contains"| TESTMAIN
        TESTS -->|"contains"| RESPONSES
    end

    %% Click Events
    click SCRIPT "https://github.com/bluedoors/ecr-metrics/blob/main/src/ecr_metrics/main.py"
    click DOCKER "https://github.com/bluedoors/ecr-metrics/tree/main/Dockerfile"
    click TEMPLATE "https://github.com/bluedoors/ecr-metrics/blob/main/template.yml"
    click TOML "https://github.com/bluedoors/ecr-metrics/blob/main/pyproject.toml"
    click EDITOR "https://github.com/bluedoors/ecr-metrics/blob/main/.editorconfig"
    click GITIGNORE "https://github.com/bluedoors/ecr-metrics/blob/main/.gitignore"
    click TESTS "https://github.com/bluedoors/ecr-metrics/tree/main/tests"
    click TESTMAIN "https://github.com/bluedoors/ecr-metrics/blob/main/tests/test_main.py"
    click RESPONSES "https://github.com/bluedoors/ecr-metrics/blob/main/tests/responses.md"

    %% Styles
    classDef cli fill:#a8dadc,stroke:#1d3557,stroke-width:2px;
    classDef script fill:#f1faee,stroke:#457b9d,stroke-width:2px;
    classDef cloudwatch fill:#ffb703,stroke:#fb8500,stroke-width:2px;
    classDef lambda fill:#83c5be,stroke:#006d77,stroke-width:2px;
    classDef aws fill:#e9c46a,stroke:#f4a261,stroke-width:2px;
    classDef deployment fill:#e76f51,stroke:#d62828,stroke-width:2px;
    classDef config fill:#2a9d8f,stroke:#264653,stroke-width:2px;
    classDef testing fill:#8ecae6,stroke:#219ebc,stroke-width:2px;
```
