# nogibjj/coursera-mlops-foundations-lab-1-cicd architecture

> Architecture diagram of the GitHub repository nogibjj/coursera-mlops-foundations-lab-1-cicd, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nogibjj/coursera-mlops-foundations-lab-1-cicd
- Repository: https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd

## Overview

##### Project type and purpose
- This is a Python-based command‐line tool lab project whose primary goal is to teach CI/CD principles (lint, format, refactor, test, container build, and deployment) via a Makefile, GitHub Actions workflows, and a devcontainer.

##### File structure
- .devcontainer/: Dockerfile + VS Code devcontainer.json → defines a reproducible development environment.
- .github/workflows/: cicd.yml + docker-image.yml → two GitHub Actions pipelines (CI and CD).
- Makefile + requirements.txt → defines automated tasks (lint, format, refactor, test) and dependencies.
- main.py (Click CLI) + mylib/calculator.py → core application code.
- test_main.py → CLI unit tests using Click’s test runner.

##### Pull insights from the README
- The README describes lab objectives: automated lint/format/refactor/test via Makefile, writing tests for the Click CLI, and building/deploying via GitHub Actions and Docker.

a. Main components:
- Developer workstation (VS Code + devcontainer)
- Git source repository (GitHub)
- GitHub Actions – CI pipeline (lint, format, refactor, test)
- GitHub Actions – CD pipeline (build Docker image, push to registry)
- Docker registry (Docker Hub or GitHub Container Registry)
- End‐users invoking the CLI (optional)

b. Relationships & interactions:
1. Developer writes code in devcontainer → commits & pushes to GitHub.
2. Push triggers CI workflow (cicd.yml): runs Makefile targets in order (lint → format → refactor → test).
3. On successful CI, push also triggers CD workflow (docker-image.yml): builds Docker image (using .devcontainer/Dockerfile), tags it, and pushes to a registry.
4. Consumers can pull the Docker image or run the standalone CLI after checkout.

c. Architectural patterns & principles:
- Pipeline-as-code: all build/test/deploy steps are defined in Makefile + GitHub Actions YAML.
- Infrastructure-as-code: devcontainer + Dockerfile define a consistent environment.
- Single‐responsibility: separate workflows for CI vs. CD; separate Makefile tasks.

d. Key technologies/frameworks/libraries:
- Python + Click (CLI framework)
- pytest/Click test runner
- Makefile (task runner)
- Docker (containerization)
- GitHub Actions (cicd.yml, docker-image.yml)
- devcontainer (VS Code remote development)

## Diagram (Mermaid)

```mermaid
graph TD
    %% Developer Environment
    subgraph "Developer Workstation" 
        direction TB
        VSCode["VS Code IDE"]:::environments
        DevContainer["Devcontainer Environment"]:::environments
        Dockerfile["Dockerfile"]:::environments
        DevContainerJSON["devcontainer.json"]:::environments
    end

    %% GitHub Repository
    subgraph "GitHub Repository" 
        direction TB
        Repo["Repository"]:::code_artifacts
        README["README.md"]:::code_artifacts
        Gitignore[".gitignore"]:::code_artifacts
        Requirements["requirements.txt"]:::code_artifacts
        MainPy["main.py (CLI Entry)"]:::code_artifacts
        CalcPy["mylib/calculator.py"]:::code_artifacts
        TestMain["test_main.py"]:::code_artifacts
        MakefileNode["Makefile"]:::processes
        CI_YML["cicd.yml"]:::processes
        CD_YML["docker-image.yml"]:::processes
    end

    %% CI Workflow
    subgraph "CI Workflow (cicd.yml)" 
        direction TB
        Lint["Lint"]:::processes
        Format["Format"]:::processes
        Refactor["Refactor"]:::processes
        Test["Test"]:::processes
    end

    %% CD Workflow
    subgraph "CD Workflow (docker-image.yml)"
        direction TB
        DockerBuild["Docker Build"]:::processes
        PushImage["Push Image"]:::processes
    end

    %% Docker Registry
    Registry["Docker Registry"]:::external

    %% End User
    EndUser["End User"]:::external

    %% Flows
    VSCode -->|edits code| Repo
    DevContainer -->|mirrors CI env| Repo

    Repo -->|triggers| CI_YML
    CI_YML -->|runs| Lint
    CI_YML -->|runs| Format
    CI_YML -->|runs| Refactor
    CI_YML -->|runs| Test

    Repo -->|triggers| CD_YML
    CD_YML -->|uses Dockerfile| DockerBuild
    DockerBuild -->|pushes| PushImage
    PushImage -->|push to| Registry

    Registry -->|pull image| EndUser
    EndUser -->|runs CLI| MainPy

    %% Internal orchestration
    Test -->|executes| TestMain
    Lint -->|via| MakefileNode
    Format -->|via| MakefileNode
    Refactor -->|via| MakefileNode
    Test -->|via| MakefileNode

    DockerBuild -->|reads| Dockerfile
    DockerBuild -->|uses| DevContainer

    %% Code artifacts locations
    Repo --> README
    Repo --> Gitignore
    Repo --> Requirements
    Repo --> MainPy
    Repo --> CalcPy
    Repo --> TestMain
    Repo --> MakefileNode

    Repo --> CI_YML
    Repo --> CD_YML

    %% Click Events
    click Dockerfile "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/tree/main/.devcontainer/Dockerfile"
    click DevContainerJSON "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/blob/main/.devcontainer/devcontainer.json"
    click CI_YML "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/blob/main/.github/workflows/cicd.yml"
    click CD_YML "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/blob/main/.github/workflows/docker-image.yml"
    click MakefileNode "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/tree/main/Makefile"
    click MainPy "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/blob/main/main.py"
    click CalcPy "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/blob/main/mylib/calculator.py"
    click TestMain "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/blob/main/test_main.py"
    click Requirements "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/blob/main/requirements.txt"
    click README "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/blob/main/README.md"
    click Gitignore "https://github.com/nogibjj/coursera-mlops-foundations-lab-1-cicd/blob/main/.gitignore"

    %% Styles
    classDef code_artifacts fill:#ADD8E6,stroke:#000
    classDef processes fill:#90EE90,stroke:#000
    classDef environments fill:#FFA500,stroke:#000
    classDef external fill:#DDA0DD,stroke:#000
```
