# thestrugglingblack/the-docker-playbook architecture

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

- Interactive diagram: https://gitdiagram.com/thestrugglingblack/the-docker-playbook
- Repository: https://github.com/thestrugglingblack/the-docker-playbook

## Overview

##### Project Overview & Purpose
- This project, dubbed the “Docker Playbook,” is designed as a workshop or seminar tool. It focuses on demonstrating how to efficiently containerize Python models (in the “model” directory) and deploy these containers using Docker, AWS ECR, and Terraform-managed AWS resources (primarily Lambda functions). The project emphasizes building scalable, portable pipelines for model deployment.

##### Analyzing the Project Structure
- Top-Level Directories:
- The “model” directory contains the Dockerfile, Python model code, and requirements – this is your core application that gets containerized.
- The “terraform” directory, specifically under “terraform/lambda,” holds multiple Terraform scripts (e.g., lambda.tf, iam_ecr.tf, s3.tf, sns.tf) that set up AWS infrastructure such as Lambda, ECR, IAM roles, and other supporting AWS services.
- The “scripts” directory includes auxiliary scripts (e.g., ecr-login.sh) used for handling container registry authentication.
- The “.github” folder includes workflows which likely automate Docker builds and deployments via GitHub Actions.
- Architectural Implication:
- The structure suggests a clear separation between the model application, containerization, and cloud deployment. This is indicative of a layered architecture where local development, container image creation, and cloud infrastructure management are decoupled.

##### Main Components
a. Local Development Environment:
- Developer’s workstation where the Python model is built and a Docker image is created.
b. Containerization Process:
- The “model” component – show the Docker build process (using the Dockerfile in the model directory).
- Mention the Docker runtime and dependency management (via requirements.txt).
c. Container Registry:
- The Docker Hub or AWS ECR where built images are pushed. Include the “scripts/ecr-login.sh” as a support for authenticating with ECR.
d. CI/CD Pipeline:
- GitHub Actions from the “.github/workflows” directory – highlight the automated steps for building images and possibly running tests.
e. Cloud Deployment (AWS):
- AWS Lambda: Represent this as the component where the containerized application is deployed.
- Supporting AWS Services: Include ECR, S3, SNS, and IAM roles/resources as defined in the Terraform scripts.
- Terraform: Illustrate the infrastructure as code process that provisions and manages these AWS resources.

##### Relationships and Data Flow
- GitHub Actions as automating the build and deployment pipeline by connecting to both the Container Registry and Terraform.
- Terraform’s role in provisioning the AWS infrastructure, connecting it with both the Container Registry and AWS Lambda.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The model’s business logic is separated from its deployment (Docker) and infrastructure provisioning (Terraform).
- Infrastructure as Code: Terraform scripts are used to self-manage AWS resources ensuring consistency in deployments.
- CI/CD Automation: GitHub Actions streamline the build and deployment processes.

- Pipeline steps: building, pushing to a library (Docker Hub/ECR), and then provisioning infrastructure to run the image.
- Terraform-managed AWS layer showing Lambda functions, IAM roles, and additional services (S3, SNS) clearly.

Happy Diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Local Environment
    subgraph "Local Environment"
        A["Local Dev Environment"]:::local
    end

    %% Containerization and Registry
    subgraph "Containerization & Registry"
        B["Docker Build"]:::container
        C["Container Registry (ECR)"]:::container
        G["ECR Login Script"]:::support
    end

    %% Automation and Provisioning
    subgraph "Automation & Provisioning"
        D["CI/CD Pipeline (GitHub Actions)"]:::automation
        E["Terraform Provisioning (AWS Infra)"]:::automation
    end

    %% Cloud Deployment
    subgraph "Cloud Deployment"
        F["AWS Lambda & Services"]:::cloud
    end

    %% Connections
    A -->|"docker_build"| B
    B -->|"push_image"| C
    G -->|"authenticates"| C
    D -->|"triggers_build"| B
    D -->|"triggers_provisioning"| E
    C -->|"deploy_image"| F
    E -->|"provisions_infra"| F

    %% Click Events
    click A "https://github.com/thestrugglingblack/the-docker-playbook/blob/main/model/model.py"
    click B "https://github.com/thestrugglingblack/the-docker-playbook/tree/main/model/Dockerfile"
    click G "https://github.com/thestrugglingblack/the-docker-playbook/blob/main/scripts/ecr-login.sh"
    click D "https://github.com/thestrugglingblack/the-docker-playbook/blob/main/.github/workflows/model_docker.yml"
    click E "https://github.com/thestrugglingblack/the-docker-playbook/tree/main/terraform/lambda"

    %% Styles
    classDef local fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef container fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef automation fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef cloud fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef support fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
```
