# mitodl/ol-infrastructure architecture

> Architecture diagram of the GitHub repository mitodl/ol-infrastructure, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mitodl/ol-infrastructure
- Repository: https://github.com/mitodl/ol-infrastructure

## Overview

##### Project Type and Purpose
- This is a monorepo “DevOps platform” for MIT Open Learning that combines:
- Infrastructure-as-Code (IaC) via Pulumi (Python) under src/ol_infrastructure
- Configuration management via PyInfra under src/bilder
- CI/CD automation via Concourse pipelines (pipelines/ & .github/workflows)
- Image-building via Packer, Dockerfiles, and Cloud Custodian policies
- Goal: Enable engineers to define, test, and deploy cloud infra and server configuration in pure Python.

##### File-Structure Analysis
- Top-level directories:
- src/ol_infrastructure – Pulumi “Projects” (components/, infrastructure/, applications/, substructure/)
- src/bilder – PyInfra component modules (models, steps, templates) for each service
- pipelines/ & .github – CI pipelines definitions (Concourse, GitHub Actions)
- dockerfiles/, cloud_custodian/ – Docker builds and resource-cleanup policies
- copier_templates/ – Scaffolding for new Pulumi or PyInfra projects
- scripts/ – Utility helpers (eks.sh, security-report)
- Key patterns:
- Mono-repo grouping IaC and config code
- Pulumi projects organized by domain (network, eks, applications) and environment via stack YAMLs
- PyInfra components decoupled per technology (caddy, docker, traefik, vault, etc.)

##### README Insights
- Two “runtimes”: Pulumi Python (state backend S3) and PyInfra (pure Python, Pydantic models)
- Pulumi: Projects = deployable units; Stacks = envs (QA, Production) with dot-notation
- PyInfra: Components = reusable config units; Pydantic BaseSettings for environment overrides
- Conventions: FHS paths (/opt, /etc, /var/lib), consistent naming.

a. Main Components
- Developer Workstation: Poetry, Pulumi CLI, PyInfra CLI
- Version Control (GitHub) with mono-repo
- CI/CD Engines:
– GitHub Actions (.github/workflows/project_automation.yaml)
– Concourse (pipelines/*)
- Code Subsystems:
– IaC (src/ol_infrastructure):
· Components library
· Infrastructure projects
· Application projects
· Substructure (shared infra patterns like Consul, Vault)
– Config Management (src/bilder):
· PyInfra components (caddy, traefik, vault, etc.)
· Packer image definitions (src/bilder/images…)
- Artifact & State Backends:
– Docker registries (for built images)
– S3 bucket (Pulumi state)
– Packer AMI output
- Cloud Environment (AWS):
– Networking (VPC, subnets, security groups)
– Compute (EKS clusters, EC2 ASGs, Fargate)
– Data (RDS, OpenSearch, MongoDB Atlas)
– Services (Consul, Vault, Traefik, Caddy)
- External Tools: Cloud Custodian, BotKube, Fastly, Heroku CLI, etc.

b. Relationships & Interactions
1. Developer commits → GitHub triggers CI/CD
2. CI pipelines:
- Lint & unit-test PyInfra & Pulumi code
- Build Docker images (dockerfiles/) & push to registry
- Invoke Packer to produce AMIs per component
- Run Pulumi up –C src/ol_infrastructure/... on selected stack
- Execute PyInfra deploy: configure provisioned servers
3. Pulumi modules reflect components → create AWS resources
4. PyInfra components apply service setups on machines
5. Cloud Custodian policies run periodically against AWS to enforce cleanup
c. Architectural Patterns
- Mono-repo with per-module Pulumi projects & PyInfra components
- Separation of concerns: Infrastructure provisioning vs. Machine configuration
- Environment-specific stacks via dot-notation + shared component libraries
- Declarative state (Pulumi) + imperative config (PyInfra)
- CI/CD as code (Concourse & GitHub Actions pipelines versioned alongside infra)
d. Key Technologies
- Pulumi (Python), PyInfra
- Packer, Docker
- Poetry, Pydantic
- AWS (EKS, S3, RDS, OpenSearch, IAM)
- Concourse, GitHub Actions
- Cloud Custodian, Fastly, Heroku CLI

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: Developer & VCS
    Dev["Developer Workstation<br/>(Poetry, Pulumi CLI, PyInfra CLI)"]:::dev
    GitHub["GitHub Repository<br/>(Monorepo)"]:::dev

    Dev -->|"git commit / push"| GitHub

    %% Layer 2: CI/CD
    subgraph "CI/CD Engines"
        GitHubActions["GitHub Actions<br/>(project_automation.yaml)"]:::ci
        Concourse["Concourse<br/>(pipelines/* & teams)"]:::ci
    end

    GitHub -->|"trigger workflow"| GitHubActions
    GitHub -->|"trigger pipelines"| Concourse

    %% Layer 3: Code Modules
    subgraph "Infrastructure-as-Code (Pulumi)" 
        direction TB
        PulumiComponents["Pulumi: Components Library"]:::code
        PulumiInfra["Pulumi: Infrastructure Projects"]:::code
        PulumiApps["Pulumi: Application Projects"]:::code
        PulumiSub["Pulumi: Shared Substructure"]:::code
    end

    subgraph "Configuration Management (PyInfra)"
        direction TB
        PyInfraComponents["PyInfra Components Modules"]:::code
        PyInfraImages["PyInfra Packer Image Definitions"]:::code
    end

    GitHubActions -->|"lint & test code"| PulumiComponents
    GitHubActions --> PulumiInfra
    GitHubActions --> PulumiApps
    GitHubActions --> PulumiSub
    GitHubActions --> PyInfraComponents
    GitHubActions --> PyInfraImages

    Concourse -->|"lint & test code"| PulumiComponents
    Concourse --> PulumiInfra
    Concourse --> PulumiApps
    Concourse --> PulumiSub
    Concourse --> PyInfraComponents
    Concourse --> PyInfraImages

    %% Layer 4: Artifact & State Backends
    subgraph "Artifact Stores"
        direction TB
        DockerRegistry["Docker Registry"]:::store
        S3State["S3 Backend<br/>(Pulumi State)"]:::store
        PackerAMIs["Packer AMI Outputs"]:::store
    end

    GitHubActions -->|"docker build"| DockerRegistry
    GitHubActions -->|"packer build"| PackerAMIs
    GitHubActions -->|"pulumi up"| S3State

    Concourse -->|"docker build"| DockerRegistry
    Concourse -->|"packer build"| PackerAMIs
    Concourse -->|"pulumi up"| S3State

    %% Layer 5: Cloud Environment (AWS)
    subgraph "AWS Cloud Resources"
        direction TB
        VPC["VPC, Subnets, SGs"]:::cloud
        Compute["Compute:<br/>EKS, EC2 ASG, Fargate"]:::cloud
        Data["Data:<br/>RDS, OpenSearch, MongoDB Atlas"]:::cloud
        Services["Services:<br/>Consul, Vault, Traefik, Caddy"]:::cloud
    end

    S3State -->|"state store for pulumi"| VPC
    DockerRegistry -->|"deploy images"| Compute
    PackerAMIs -->|"launch AMIs"| Compute
    PulumiInfra -->|"provision infra"| VPC
    PulumiApps -->|"provision apps"| Services
    PulumiComponents -->|"shared components"| VPC
    PulumiSub -->|"apply patterns"| Services
    PyInfraComponents -->|"configure services via SSH"| Compute
    PyInfraImages -->|"image definitions"| Compute

    %% External Tools
    CloudCustodian["Cloud Custodian Policies"]:::ext
    CloudCustodian -->|"periodic cleanup"| VPC

    %% Utility & Scaffolding
    CopierTemplates["Copier Templates"]:::util
    Dockerfiles["Dockerfiles"]:::util

    %% Connections
    Concourse --> CopierTemplates
    GitHubActions --> CopierTemplates
    GitHubActions --> Dockerfiles
    Concourse --> Dockerfiles

    %% Click Events
    click PulumiComponents "https://github.com/mitodl/ol-infrastructure/tree/main/src/ol_infrastructure/components"
    click PulumiInfra "https://github.com/mitodl/ol-infrastructure/tree/main/src/ol_infrastructure/infrastructure"
    click PulumiApps "https://github.com/mitodl/ol-infrastructure/tree/main/src/ol_infrastructure/applications"
    click PulumiSub "https://github.com/mitodl/ol-infrastructure/tree/main/src/ol_infrastructure/substructure"
    click PyInfraComponents "https://github.com/mitodl/ol-infrastructure/tree/main/src/bilder/components"
    click PyInfraImages "https://github.com/mitodl/ol-infrastructure/tree/main/src/bilder/images"
    click Concourse "https://github.com/mitodl/ol-infrastructure/tree/main/concourse/teams"
    click Concourse "https://github.com/mitodl/ol-infrastructure/tree/main/pipelines/"
    click GitHubActions "https://github.com/mitodl/ol-infrastructure/blob/main/.github/workflows/project_automation.yaml"
    click Dockerfiles "https://github.com/mitodl/ol-infrastructure/tree/main/dockerfiles/"
    click CloudCustodian "https://github.com/mitodl/ol-infrastructure/tree/main/cloud_custodian/"
    click CopierTemplates "https://github.com/mitodl/ol-infrastructure/tree/main/copier_templates/"

    %% Styles
    classDef dev fill:#cce5ff,stroke:#3399ff,color:#000000;
    classDef ci fill:#d4edda,stroke:#28a745,color:#000000;
    classDef code fill:#ffe5b4,stroke:#ff8c00,color:#000000;
    classDef store fill:#e2e3e5,stroke:#6c757d,color:#000000;
    classDef cloud fill:#f0f8ff,stroke:#1e90ff,color:#000000;
    classDef ext fill:#f8d7da,stroke:#dc3545,color:#000000;
    classDef util fill:#e2e3e5,stroke:#6c757d,color:#000000;
```
