# nationalarchives/ds-infrastructure-web architecture

> Architecture diagram of the GitHub repository nationalarchives/ds-infrastructure-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nationalarchives/ds-infrastructure-web
- Repository: https://github.com/nationalarchives/ds-infrastructure-web

## Overview

#### Purpose and scope
This is AWS infrastructure-as-code for www.nationalarchives.gov.uk and its supporting web applications. Terraform manages web-platform resources; the VPC and general database infrastructure are explicitly owned elsewhere. The repository also defines EC2/AMI provisioning and GitHub Actions deployment automation.

#### Operational entry points
Primary infrastructure execution paths are Terraform workflows and wrapper scripts: `.github/workflows/terraform-plan.yml`, `.github/workflows/terraform-apply.yml`, and `components/scripts/terraform.sh`. Environment-specific deployment workflows route changes to develop, staging, or production: `.github/workflows/deploy-develop.yml`, `.github/workflows/deploy-staging.yml`, `.github/workflows/deploy-production.yml`.

#### Terraform composition and environments
`components/terraform/` is the root infrastructure composition layer: top-level `.tf` files assemble reusable service modules for networking-adjacent web resources, identity, delivery, storage, and compute. Environment values are separated into dev, staging, and live variable/backend sets, e.g. `components/terraform/_vars/dev/backend.tf`, `components/terraform/_vars/staging/environment.auto.tfvars`, and `components/terraform/_vars/live/global.auto.tfvars`. This boundary allows a common topology with environment-specific capacity, names, and service settings.

#### Web workload fleet
Each web application has a dedicated Terraform module defining an EC2 launch template, Auto Scaling Group, and load-balancer target group. Representative modules are `components/terraform/web-frontend/launch-template.tf`, `components/terraform/web-frontend/auto-scaling-group.tf`, and `components/terraform/web-frontend/target-group.tf`; equivalent modules exist for catalogue, forms, search, Wagtail, and other named services. Instances bootstrap from user-data/startup scripts and receive constrained IAM/S3/SSM permissions via module templates.

#### Request delivery and edge security
Internet traffic is handled through CloudFront, load balancers, a reverse-proxy workload, Route 53, and AWS WAF. Key boundaries are `components/terraform/cloudfront/cloudfront.tf`, `components/terraform/load-balancer/lb.tf`, and `components/terraform/web-reverse-proxy/load-balancer.tf`. WAF composes custom and AWS-managed rules, including rate limiting and known-IP controls, from `components/terraform/waf/waf.tf`, `components/terraform/waf-rule-groups/web-rate-limiting/main.tf`, and `components/terraform/waf-rules/aws-managed/BotControlRuleSet/main.tf`.

#### Stateful and asynchronous services
The platform provisions Redis as an EC2 autoscaled service, EFS-backed media storage, PostgreSQL source/replica resources, SES, Cognito, and Lambda/EventBridge automation. Core paths include `components/terraform/redis/auto-scaling-group.tf`, `components/terraform/media-efs/efs.tf`, and `components/terraform/postgres/replica_instance.tf`. Event-driven processing includes submitted-file handling and scheduled application triggers in `components/terraform/lambda/process-submitted-files/source/process-submitted-files.py`, `components/terraform/lambda/wagtail-cron-trigger/source/wagtail-cron-trigger.py`, and `components/terraform/eventbridge/main.tf`.

#### Build, provisioning, and deployment flow
Per-application AMI workflows build machine images, then Ansible configures Docker/Traefik-hosted workloads and blue-green deployment scripts. Examples are `.github/workflows/web-wagtail-ami-build.yml`, `.github/ansible-playbooks/wagtail/web-wagtail-playbook.yml`, and `.github/ansible-playbooks/wagtail/files/website-blue-green-deploy.sh`. GitHub composite actions centralize runtime setup, Terraform planning, deployment, and environment-variable updates: `.github/actions/setup-runtime/action.yml`, `.github/actions/terraform-plan/action.yml`, and `.github/actions/deploy/action.yml`. Runtime configuration is supplied per application and environment under `config/parameters/`, such as `config/parameters/wagtail/production.json`.

Main entry points: [`components/terraform`](https://github.com/nationalarchives/ds-infrastructure-web/tree/main/components/terraform) (Platform composition), [`components/terraform/web-frontend/auto-scaling-group.tf`](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/web-frontend/auto-scaling-group.tf) (Web application fleets), [`.github/workflows/deploy-production.yml`](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/.github/workflows/deploy-production.yml) (Environment deploy workflows), [`components/terraform/cloudfront/cloudfront.tf`](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/cloudfront/cloudfront.tf) (CloudFront and WAF)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_automation["CI/CD automation"]
  node_deploy_workflows["Environment deploy workflows<br/>GitHub Actions"]
  node_terraform_workflows["Terraform plan and apply<br/>GitHub Actions<br/>[terraform-plan.yml]"]
  node_terraform_wrapper["Terraform wrapper<br/>shell script<br/>[terraform.sh]"]
  node_composite_actions["Shared CI actions<br/>GitHub composite actions<br/>[action.yml]"]
  node_ami_pipeline["AMI build and provisioning<br/>image pipeline"]
  node_runtime_parameters["Runtime parameters<br/>environment config<br/>[production.json]"]
end

subgraph group_terraform["Terraform platform"]
  node_terraform_root["Platform composition<br/>Terraform root"]
  node_environment_vars["Environment variables and backends<br/>Terraform environment sets<br/>[backend.tf]"]
end

subgraph group_delivery["Request delivery"]
  node_edge_security{{"CloudFront and WAF<br/>edge security<br/>[cloudfront.tf]"}}
  node_dns["Route 53<br/>DNS"]
  node_load_balancer["Load balancer<br/>[lb.tf]"]
  node_reverse_proxy["Reverse-proxy fleet<br/>EC2 workload<br/>[load-balancer.tf]"]
end

subgraph group_workloads["Application workloads"]
  node_web_fleet["Web application fleets<br/>EC2 Auto Scaling modules"]
  node_iam_access["IAM, S3, and SSM access<br/>workload permissions"]
end

subgraph group_state["State and events"]
  node_redis[("Redis fleet<br/>EC2 autoscaled cache")]
  node_media_efs[("Media EFS<br/>shared file storage<br/>[efs.tf]")]
  node_postgres[("PostgreSQL replica resources<br/>database resources")]
  node_event_automation["Lambda and EventBridge<br/>event automation<br/>[main.tf]"]
  node_identity_messaging["Cognito and SES<br/>identity and email"]
end

node_deploy_workflows -->|"uses"| node_composite_actions
node_deploy_workflows -->|"builds images"| node_ami_pipeline
node_deploy_workflows -->|"loads"| node_runtime_parameters
node_terraform_workflows -->|"uses"| node_composite_actions
node_terraform_workflows -->|"runs"| node_terraform_wrapper
node_terraform_wrapper -->|"applies"| node_terraform_root
node_terraform_root -->|"selects"| node_environment_vars
node_terraform_root -->|"provisions"| node_edge_security
node_terraform_root -->|"provisions"| node_load_balancer
node_terraform_root -->|"provisions"| node_web_fleet
node_terraform_root -->|"provisions"| node_redis
node_terraform_root -->|"provisions"| node_media_efs
node_terraform_root -.->|"manages replica resources"| node_postgres
node_terraform_root -->|"provisions"| node_event_automation
node_terraform_root -->|"provisions"| node_identity_messaging
node_dns -->|"resolves to"| node_edge_security
node_edge_security -->|"forwards requests"| node_load_balancer
node_load_balancer -->|"targets"| node_reverse_proxy
node_reverse_proxy -->|"routes to"| node_web_fleet
node_ami_pipeline -->|"publishes AMIs for"| node_web_fleet
node_web_fleet -->|"receives"| node_iam_access
node_web_fleet -->|"uses"| node_redis
node_web_fleet -->|"mounts"| node_media_efs
node_web_fleet -->|"connects to"| node_postgres
node_web_fleet -->|"uses"| node_identity_messaging
node_event_automation -->|"triggers scheduled tasks"| node_web_fleet

click node_deploy_workflows "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/.github/workflows/deploy-production.yml"
click node_terraform_workflows "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/.github/workflows/terraform-plan.yml"
click node_terraform_wrapper "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/scripts/terraform.sh"
click node_composite_actions "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/.github/actions/terraform-plan/action.yml"
click node_ami_pipeline "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/.github/workflows/web-wagtail-ami-build.yml"
click node_runtime_parameters "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/config/parameters/wagtail/production.json"
click node_terraform_root "https://github.com/nationalarchives/ds-infrastructure-web/tree/main/components/terraform"
click node_environment_vars "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/_vars/dev/backend.tf"
click node_edge_security "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/cloudfront/cloudfront.tf"
click node_load_balancer "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/load-balancer/lb.tf"
click node_reverse_proxy "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/web-reverse-proxy/load-balancer.tf"
click node_web_fleet "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/web-frontend/auto-scaling-group.tf"
click node_redis "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/redis/auto-scaling-group.tf"
click node_media_efs "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/media-efs/efs.tf"
click node_postgres "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/postgres/replica_instance.tf"
click node_event_automation "https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/eventbridge/main.tf"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_deploy_workflows,node_terraform_workflows,node_terraform_wrapper,node_composite_actions,node_ami_pipeline,node_runtime_parameters toneBlue
class node_terraform_root,node_environment_vars toneAmber
class node_edge_security,node_dns,node_load_balancer,node_reverse_proxy toneMint
class node_web_fleet,node_iam_access toneRose
class node_redis,node_media_efs,node_postgres,node_event_automation,node_identity_messaging toneIndigo
```

## Components

### CI/CD automation

- [Environment deploy workflows](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/.github/workflows/deploy-production.yml): GitHub Actions · Routes deployments to develop, staging, and production. · `.github/workflows/deploy-production.yml`
- [Terraform plan and apply](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/.github/workflows/terraform-plan.yml): GitHub Actions · `.github/workflows/terraform-plan.yml`
- [Terraform wrapper](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/scripts/terraform.sh): shell script · `components/scripts/terraform.sh`
- [Shared CI actions](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/.github/actions/terraform-plan/action.yml): GitHub composite actions · Sets up runtime and standardizes planning and deployment. · `.github/actions/terraform-plan/action.yml`
- [AMI build and provisioning](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/.github/workflows/web-wagtail-ami-build.yml): image pipeline · Builds application images and configures Docker/Traefik workloads. · `.github/workflows/web-wagtail-ami-build.yml`
- [Runtime parameters](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/config/parameters/wagtail/production.json): environment config · `config/parameters/wagtail/production.json`

### Terraform platform

- [Platform composition](https://github.com/nationalarchives/ds-infrastructure-web/tree/main/components/terraform): Terraform root · Assembles reusable web-platform infrastructure modules. · `components/terraform`
- [Environment variables and backends](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/_vars/dev/backend.tf): Terraform environment sets · Dev, staging, and live settings select shared topology variants. · `components/terraform/_vars/dev/backend.tf`

### Request delivery

- [CloudFront and WAF](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/cloudfront/cloudfront.tf): edge security · Applies CDN delivery, managed/custom rules, rate limits, and IP controls. · `components/terraform/cloudfront/cloudfront.tf`
- **Route 53**: DNS
- [Load balancer](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/load-balancer/lb.tf): AWS load balancer · `components/terraform/load-balancer/lb.tf`
- [Reverse-proxy fleet](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/web-reverse-proxy/load-balancer.tf): EC2 workload · Routes load-balancer traffic to application services. · `components/terraform/web-reverse-proxy/load-balancer.tf`

### Application workloads

- [Web application fleets](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/web-frontend/auto-scaling-group.tf): EC2 Auto Scaling modules · Dedicated launch template, ASG, and target group per application. · `components/terraform/web-frontend/auto-scaling-group.tf`
- **IAM, S3, and SSM access**: workload permissions · Constrained instance access is attached through module templates.

### State and events

- [Redis fleet](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/redis/auto-scaling-group.tf): EC2 autoscaled cache · `components/terraform/redis/auto-scaling-group.tf`
- [Media EFS](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/media-efs/efs.tf): shared file storage · `components/terraform/media-efs/efs.tf`
- [PostgreSQL replica resources](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/postgres/replica_instance.tf): database resources · Database infrastructure is generally owned outside this repository. · `components/terraform/postgres/replica_instance.tf`
- [Lambda and EventBridge](https://github.com/nationalarchives/ds-infrastructure-web/blob/main/components/terraform/eventbridge/main.tf): event automation · Processes submitted files and invokes scheduled application tasks. · `components/terraform/eventbridge/main.tf`
- **Cognito and SES**: identity and email

## Connections

- Environment deploy workflows → Shared CI actions: uses
- Environment deploy workflows → AMI build and provisioning: builds images
- Environment deploy workflows → Runtime parameters: loads
- Terraform plan and apply → Shared CI actions: uses
- Terraform plan and apply → Terraform wrapper: runs
- Terraform wrapper → Platform composition: applies
- Platform composition → Environment variables and backends: selects
- Platform composition → CloudFront and WAF: provisions
- Platform composition → Load balancer: provisions
- Platform composition → Web application fleets: provisions
- Platform composition → Redis fleet: provisions
- Platform composition → Media EFS: provisions
- Platform composition → PostgreSQL replica resources: manages replica resources
- Platform composition → Lambda and EventBridge: provisions
- Platform composition → Cognito and SES: provisions
- Route 53 → CloudFront and WAF: resolves to
- CloudFront and WAF → Load balancer: forwards requests
- Load balancer → Reverse-proxy fleet: targets
- Reverse-proxy fleet → Web application fleets: routes to
- AMI build and provisioning → Web application fleets: publishes AMIs for
- Web application fleets → IAM, S3, and SSM access: receives
- Web application fleets → Redis fleet: uses
- Web application fleets → Media EFS: mounts
- Web application fleets → PostgreSQL replica resources: connects to
- Web application fleets → Cognito and SES: uses
- Lambda and EventBridge → Web application fleets: triggers scheduled tasks
