Working in the UI

Developer guide for extending and customizing the Terraform Configuration Web UI.

Architecture Overview

The UI uses a template registry architecture. Templates are registered from external git repositories, cloned on demand, and managed through a SQLite database with drift detection.

ui/
β”œβ”€β”€ backend/                    # FastAPI Python backend
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/                # API routers
β”‚   β”‚   β”‚   β”œβ”€β”€ templates.py    # Template registry CRUD
β”‚   β”‚   β”‚   β”œβ”€β”€ tfvars_ui.py    # Scaffold, export/import, drift
β”‚   β”‚   β”‚   β”œβ”€β”€ template_terraform.py  # Plan/apply/destroy
β”‚   β”‚   β”‚   β”œβ”€β”€ aws.py          # AWS resource discovery
β”‚   β”‚   β”‚   └── gcp.py          # GCP resource discovery
β”‚   β”‚   β”œβ”€β”€ services/           # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ git_service.py         # Git clone/pull
β”‚   β”‚   β”‚   β”œβ”€β”€ drift_service.py       # Drift detection
β”‚   β”‚   β”‚   β”œβ”€β”€ file_hash_service.py   # SHA-256 file scanning
β”‚   β”‚   β”‚   β”œβ”€β”€ scaffold_generator.py  # tfvars.ui generation
β”‚   β”‚   β”‚   β”œβ”€β”€ hcl_parser.py          # variables.tf parser
β”‚   β”‚   β”‚   └── tfvars_example_parser.py  # Annotation parser
β”‚   β”‚   β”œβ”€β”€ db/                 # Database layer (SQLite)
β”‚   β”‚   β”‚   β”œβ”€β”€ crud.py         # TemplateDB, FileHashDB
β”‚   β”‚   β”‚   └── models.py       # Pydantic models
β”‚   β”‚   └── config.py           # App settings
β”‚   └── tests/                  # 250+ pytest tests
β”œβ”€β”€ frontend/                   # React/Vite frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ TerraformConfig.jsx       # Main UI
β”‚   β”‚   β”‚   β”œβ”€β”€ TemplateRegistration.jsx  # Register templates
β”‚   β”‚   β”‚   └── DriftResolution.jsx       # Resolve drift
β”‚   β”‚   └── services/api.js     # API client
β”‚   └── nginx.conf              # Production reverse proxy
└── docker-compose.yml          # Container deployment

Data Flow

  1. User registers a template (git repo URL + path)
  2. Backend clones the repo, scans files, stores hashes in SQLite
  3. Scaffold generator creates tfvars.ui from variables.tf + terraform.tfvars.example
  4. User enriches annotations, imports back
  5. Drift detection compares stored hashes with current repo state
  6. Terraform execution streams plan/apply/destroy output (blocks on hard-stop drift)

Starting the UI

First Time Setup

Install dependencies for both backend and frontend:

cd ui
./SETUP.sh

This script:

  1. Creates a Python virtual environment using uv
  2. Installs Python dependencies (FastAPI, aiosqlite, boto3, etc.)
  3. Installs Node.js dependencies via npm install

Running the UI

Use the restart script to start both services:

cd ui
./RESTART.sh

Services started:

  • Backend (FastAPI): http://127.0.0.1:8000
  • Frontend (Vite): http://localhost:3000
  • API Docs (Swagger): http://127.0.0.1:8000/docs

Manual Startup

For development, you may want to run services separately:

Backend:

cd ui/backend
uv run uvicorn app.main:app --reload --port 8000

Frontend:

cd ui/frontend
npm run dev

Container Deployment

cd ui
docker compose up --build

This starts backend (port 8000) and frontend (port 3000) with a shared registry-data volume for the SQLite database and cloned repositories.


Developer Topics

TopicDescription
Annotation Reference@ui- annotation tags for tfvars.ui and tfvars.example files
Registering TemplatesHow to add templates via the registry
Backend APIsTemplate registry, tfvars.ui, and terraform execution endpoints
Parsers & ServicesHCL parser, annotation parser, scaffold generator, drift detection
Cloud Provider APIsIntegrating AWS, Azure, GCP APIs
Frontend DevelopmentReact components, template selector, drift UI
TestingBackend pytest suite (250+ tests) and frontend builds
TroubleshootingCommon issues and fixes