# nasa/cumulus-orca architecture

> Architecture diagram of the GitHub repository nasa/cumulus-orca, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nasa/cumulus-orca
- Repository: https://github.com/nasa/cumulus-orca

## Overview

##### Project type and purpose
- ORCA is a **full‐stack cloud backup and recovery solution** built on AWS.
- It combines **infrastructure-as-code (Terraform)**, **containerized services (GraphQL API on ECS)**, **serverless Step Functions & Lambdas**, **databases (Postgres)**, **object storage (S3)**, and **CI/CD (Bamboo, Docker)**.
- Primary use cases:
- Copy data to deep-archive buckets
- Request and restore backups
- Perform and report internal reconciliation
- Execute recovery workflows

##### Top-level architectural components
- **Terraform modules** (in `modules/…`, `main.tf`, `variables.tf`, `outputs.tf`): define VPC, IAM roles, S3 buckets, API Gateway, ECS cluster, Lambda functions, SQS queues, CloudWatch Events, Step Functions workflows.
- **GraphQL service** (in `graphql/`): FastAPI + Ariadne-style GraphQL server packaged in Docker, deployed to ECS behind API Gateway.
- **ECS tasks** (in `ecs_tasks/internal_reconcile_report_generate/`): containerized batch jobs for internal reporting.
- **Serverless tasks** (in `tasks/…`): dozens of individual Lambda handlers for single‐purpose functions (copy_to_archive, request_from_archive, post_to_catalog, etc.), triggered via Step Functions, SQS, or API Gateway.
- **Shared libraries** (in `shared_libraries/`): common code (database connection, reconciliation & recovery helpers) imported by multiple tasks.
- **State machines / workflows** (in `modules/workflows/…`): Step Functions definitions for high-level workflows (OrcaCopyToArchive, OrcaInternalReconciliation, OrcaRecoveryWorkflow).
- **Database**: Amazon Aurora Serverless (Postgres) accessed by GraphQL and Lambdas.
- **Object storage**: multiple S3 buckets (archive, DR buckets), defined in Terraform.
- **CI/CD**: Bamboo specs under `bamboo-specs/`, plus Dockerfiles in `base_images/`, `graphql/`, and build scripts in `bin/` and `lambda scripts/`.

##### Relationships and dataflow
a. **API Layer**
- **API Gateway** (Terraform) → **GraphQL ECS service** → invokes use‐case code → queries Postgres or fetches metadata from S3 → returns GraphQL responses.
b. **Orchestration Layer**
- **Step Functions** definitions (State Machines) orchestrate multiple **Lambda tasks** from `tasks/…`.
- Each Step Function state (Task) invokes a Lambda ► reads/writes to S3 & Postgres ► passes output to next state.
c. **Batch / Scheduled Jobs**
- **ECS Tasks** (`internal_reconcile_report_generate`) run on CloudWatch schedule (or ECS scheduled tasks) to produce reports, storing results back to S3 / Postgres.
d. **Event & Queueing**
- Some flows use **SQS** (modules/sqs/) to buffer or fan-out copy requests or reconciliation notifications to Lambdas.
e. **Shared code**
- All Lambdas and containers import common logic from `shared_libraries/orca_shared` and `shared_libraries/orca_shared/database`.

##### Architectural patterns & principles
- **Clean Architecture** in Python services: clear separation of
- Entities (business objects)
- Use Cases (application logic)
- Adapters (API, storage, logger)
- **Infrastructure-as-Code (IaC)** using Terraform modules for repeatability and environment isolation.
- **Microservices & Serverless**: single-purpose Lambda functions combined into Step Functions workflows.
- **Containerized API**: GraphQL service in Docker/ECS for a persistent API endpoint.
- **CI/CD Pipelines** with Bamboo and Docker images to build, test, and deploy artifacts.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure as Code
    subgraph "Infrastructure (Terraform)" 
        style Infrastructure fill:#FFE5B4,stroke:#E69A00
        TFMain["main.tf / variables.tf / outputs.tf"]:::iac
        Modules["modules/"]:::iac
        subgraph "Terraform Modules"
            style TerraformModules fill:#FFE5B4,stroke:#E69A00
            APIGW["modules/api-gateway"]:::iac
            IAM["modules/iam"]:::iac
            DRBuckets["modules/dr_buckets"]:::iac
            ECSMod["modules/ecs"]:::iac
            LambdasMod["modules/lambdas"]:::iac
            SQSMod["modules/sqs"]:::iac
            WorkflowsMod["modules/workflows"]:::iac
        end
    end

    %% API Layer
    subgraph "Container / ECS Service"
        style ECSService fill:#D0E7FF,stroke:#1A73E8
        GraphQLService["GraphQL Service (FastAPI/Ariadne)"]:::compute
    end

    %% Serverless Tasks
    subgraph "Serverless Tasks (Lambdas)"
        style Serverless fill:#D0E7FF,stroke:#1A73E8
        subgraph "Copy Domain"
            style CopyDomain fill:#D0E7FF,stroke:#1A73E8
            CopyToArchive["copy_to_archive Lambda"]:::compute
            CopyFromArchive["copy_from_archive Lambda"]:::compute
        end
        subgraph "Request Domain"
            style RequestDomain fill:#D0E7FF,stroke:#1A73E8
            RequestFromArchive["request_from_archive Lambda"]:::compute
        end
        subgraph "Queue Trigger"
            style QueueDomain fill:#D0E7FF,stroke:#1A73E8
            PostToQueue["post_to_queue_and_trigger_step_function Lambda"]:::compute
        end
    end

    %% Step Functions
    subgraph "Step Functions Workflows"
        style SFN fill:#F3D1FF,stroke:#A33EA1
        CopyWorkflow["OrcaCopyToArchiveWorkflow SFN"]:::state
        ReconcileWorkflow["OrcaInternalReconciliationWorkflow SFN"]:::state
        RecoverWorkflow["OrcaRecoveryWorkflow SFN"]:::state
    end

    %% ECS Batch Jobs
    subgraph "ECS Batch Jobs"
        style ECSBatch fill:#D0E7FF,stroke:#1A73E8
        InternalReport["internal_reconcile_report_generate ECS Task"]:::compute
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        style SharedLibs fill:#E8FFE5,stroke:#2E8B57
        SharedRecon["shared_reconciliation.py"]:::shared
        SharedRecov["shared_recovery.py"]:::shared
        SharedDBURI["create_postgres_connection_uri.py"]:::shared
        SharedDBAWS["database/adapters/api/aws.py"]:::shared
    end

    %% Storage
    Postgres["Amazon Aurora Serverless (Postgres)"]:::storage
    S3Archive["OrcaArchiveBucket (S3)"]:::storage
    S3DR["DR Buckets (S3)"]:::storage

    %% CI/CD
    subgraph "CI/CD & Builds"
        style CICD fill:#FFF2CC,stroke:#D9B21C
        BambooSpecs["bamboo-specs/"]:::cicd
        BaseImages["base_images/"]:::cicd
        LambdaScripts["lambda scripts/"]:::cicd
    end

    %% SQS
    SQSQueue["SQS Queues"]:::storage

    %% Connections
    APIGW -->|"Invokes"| GraphQLService
    GraphQLService -->|Queries| Postgres
    GraphQLService -->|Fetches Metadata| S3Archive
    GraphQLService -->|Fetches Metadata| S3DR

    CopyWorkflow -->|Tasks| CopyToArchive
    CopyWorkflow -->|Tasks| CopyFromArchive
    ReconcileWorkflow -->|Tasks| InternalReport
    RecoverWorkflow -->|Tasks| RequestFromArchive

    CopyToArchive -->|Reads/Writes| S3Archive
    CopyToArchive -->|Uses| Postgres
    CopyFromArchive -->|Reads/Writes| S3Archive
    RequestFromArchive -->|Reads/Writes| S3Archive
    PostToQueue -->|Triggers| CopyWorkflow

    SQSQueue -->|Messages| PostToQueue
    SQSMod -->|Defines| SQSQueue

    InternalReport -->|Writes Report| S3Archive
    InternalReport -->|Logs to| Postgres

    WorkflowsMod -->|Contains Definitions| CopyWorkflow
    WorkflowsMod -->|Contains Definitions| ReconcileWorkflow
    WorkflowsMod -->|Contains Definitions| RecoverWorkflow

    LambdasMod -->|Contains| CopyToArchive
    LambdasMod -->|Contains| CopyFromArchive
    LambdasMod -->|Contains| RequestFromArchive
    LambdasMod -->|Contains| PostToQueue

    SharedRecon --- CopyToArchive
    SharedRecov --- RequestFromArchive
    SharedDBURI --- GraphQLService
    SharedDBAWS --- GraphQLService

    BambooSpecs -->|Triggers Builds| TFMain
    BambooSpecs -->|Triggers| BaseImages
    BaseImages -->|Docker Builds| GraphQLService
    LambdaScripts -->|Builds| LambdasMod

    %% Click Events
    click TFMain "https://github.com/nasa/cumulus-orca/blob/master/main.tf"
    click Modules "https://github.com/nasa/cumulus-orca/tree/master/modules/"
    click APIGW "https://github.com/nasa/cumulus-orca/tree/master/modules/api-gateway/"
    click IAM "https://github.com/nasa/cumulus-orca/tree/master/modules/iam/"
    click DRBuckets "https://github.com/nasa/cumulus-orca/tree/master/modules/dr_buckets/"
    click ECSMod "https://github.com/nasa/cumulus-orca/tree/master/modules/ecs/"
    click LambdasMod "https://github.com/nasa/cumulus-orca/tree/master/modules/lambdas/"
    click SQSMod "https://github.com/nasa/cumulus-orca/tree/master/modules/sqs/"
    click WorkflowsMod "https://github.com/nasa/cumulus-orca/tree/master/modules/workflows/"
    click GraphQLService "https://github.com/nasa/cumulus-orca/tree/master/graphql/"
    click CopyToArchive "https://github.com/nasa/cumulus-orca/blob/master/tasks/copy_to_archive/copy_to_archive.py"
    click CopyFromArchive "https://github.com/nasa/cumulus-orca/blob/master/tasks/copy_from_archive/copy_from_archive.py"
    click RequestFromArchive "https://github.com/nasa/cumulus-orca/blob/master/tasks/request_from_archive/request_from_archive.py"
    click PostToQueue "https://github.com/nasa/cumulus-orca/blob/master/tasks/post_to_queue_and_trigger_step_function/post_to_queue_and_trigger_step_function.py"
    click InternalReport "https://github.com/nasa/cumulus-orca/blob/master/ecs_tasks/internal_reconcile_report_generate/src/use_cases/internal_reconcile_report_generate.py"
    click CopyWorkflow "https://github.com/nasa/cumulus-orca/blob/master/modules/workflows/OrcaCopyToArchiveWorkflow/orca_copy_to_archive_workflow.asl.json"
    click ReconcileWorkflow "https://github.com/nasa/cumulus-orca/blob/master/modules/workflows/OrcaInternalReconciliationWorkflow/orca_internal_reconciliation_workflow.asl.json"
    click RecoverWorkflow "https://github.com/nasa/cumulus-orca/blob/master/modules/workflows/OrcaRecoveryWorkflow/orca_recover_workflow.asl.json"
    click BambooSpecs "https://github.com/nasa/cumulus-orca/tree/master/bamboo-specs/"
    click BaseImages "https://github.com/nasa/cumulus-orca/tree/master/base_images/"
    click LambdaScripts "https://github.com/nasa/cumulus-orca/tree/master/lambda scripts/"

    %% Styles
    classDef compute fill:#D0E7FF,stroke:#1A73E8
    classDef storage fill:#D0FFCE,stroke:#28A745,stroke-width:2px
    classDef iac fill:#FFE5B4,stroke:#E69A00
    classDef state fill:#F3D1FF,stroke:#A33EA1
    classDef shared fill:#E8FFE5,stroke:#2E8B57
    classDef cicd fill:#FFF2CC,stroke:#D9B21C
```
