# sfbenitez/openform architecture

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

- Interactive diagram: https://gitdiagram.com/sfbenitez/openform
- Repository: https://github.com/sfbenitez/openform

## Overview

##### Project type and purpose
- This is a full-stack web application built in Django whose purpose is to let users model “infrastructure as code.”
- It exposes a browser-based UI where the user fills in forms (providers, flavors, instances, credentials), then generates Terraform HCL files and invokes Terraform to plan/apply against AWS, OpenStack, etc.

##### File structure
- Top-level:
- manage.py – Django CLI entrypoint
- openform/openform – the Django “project” (settings.py, urls.py, wsgi.py, plus models.py, forms.py, views.py)
- openform/generator – a Django “app” that encapsulates HCL generation logic, with submodules:
– instance (views & URL routes specific to instance generation)
– repository.py (state management / abstraction layer to persist Terraform plans)
– Jinja2 templates (.j2) under templates/plans for code generation
- templates/ – HTML templates for the UI (login, dashboards, plans, forms)
- static/ – front-end assets (Bootstrap, jQuery, DataTables, chart libs)
- db.sqlite3 – development database
- Configuration and deployment artifacts are minimal (no Dockerfile, no separate CI config).

##### README
- Confirms: uses Django + Terraform + HCL
- Primary workflows: form→generate HCL→call Terraform CLI→manage infra
- Mentions extensibility via multiple Terraform providers

##### Elements
- Clear labels for each component (Browser, Django Router, openform app, generator app, DB, FS, Terraform CLI, Cloud Providers)
- Browser → Django
- Django → DB / FS / CLI
- CLI → Cloud Providers → CLI → Django
- Django → Browser
- Front-end (e.g., blue rectangles)
- Back-end services (e.g., green rectangles)

##### Be detailed and capture essential elements
- Separate the two Django apps and show their own URL namespaces
- Template engine as the bridge between data models and UI
- Credentials management as part of the data-flow (from DB to generation)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["Browser / Front-end UI"]:::frontend
        StaticAssets["Static Assets (CSS/JS)"]:::frontend
        StaticDist["Compiled CSS/JS (dist)"]:::frontend
        HTMLTemplates["HTML Templates"]:::frontend
    end

    Browser -->|HTTPS Request| Django["Django Web Server"]:::backend

    %% Django Server
    subgraph "Django Web Server"
        CLI["manage.py"]:::backend
        Router["URL Router (urls.py)"]:::backend
        TemplateEngine["Template Engine (Django + Jinja2)"]:::backend

        subgraph "Core App: openform"
            Models["Models (models.py)"]:::backend
            Forms["Forms (forms.py)"]:::backend
            Views_Core["Views (views.py)"]:::backend
            Admin["Admin (admin.py)"]:::backend
        end

        subgraph "Generator App"
            Repo["Repository (repository.py)"]:::backend
            Views_Gen["Generator Views (views.py)"]:::backend

            subgraph "Instance Sub-App"
                InstRouter["Instance URLs (instance/urls.py)"]:::backend
                InstViews["Instance Views (instance/views.py)"]:::backend
            end
        end
    end

    %% Data Stores and Processes
    Models -->|persist| DB["SQLite DB"]:::datastore
    DB -- read/write --> Views_Core
    Views_Core -->|use| Models
    Views_Core -->|use| Forms
    Views_Core -->|use| Admin

    Router -->|routes to| Views_Core
    Router -->|routes to| Views_Gen
    Views_Gen -->|call| Repo
    Repo -->|render| TemplateEngine
    TemplateEngine -->|use| HCLTemplates["HCL Templates"]:::backend
    HCLTemplates -->|output| FileSystem[".tf Files on FS"]:::datastore

    Django -->|spawn| TerraformCLI["Terraform CLI"]:::process
    TerraformCLI -->|provision| CloudProviders["Cloud Providers"]:::external
    CloudProviders -->|response| TerraformCLI
    TerraformCLI -->|output| Views_Gen
    Views_Gen -->|render| Browser

    StaticAssets -->|served by| Django
    StaticDist -->|served by| Django
    HTMLTemplates -->|served by| Django

    %% Click Events
    click StaticAssets "https://github.com/sfbenitez/openform/tree/master/openform/static/"
    click StaticDist "https://github.com/sfbenitez/openform/tree/master/openform/static/dist/"
    click HTMLTemplates "https://github.com/sfbenitez/openform/tree/master/openform/templates/"
    click CLI "https://github.com/sfbenitez/openform/blob/master/openform/manage.py"
    click Router "https://github.com/sfbenitez/openform/blob/master/openform/openform/urls.py"
    click Models "https://github.com/sfbenitez/openform/blob/master/openform/openform/models.py"
    click Forms "https://github.com/sfbenitez/openform/blob/master/openform/openform/forms.py"
    click Views_Core "https://github.com/sfbenitez/openform/blob/master/openform/openform/views.py"
    click Admin "https://github.com/sfbenitez/openform/blob/master/openform/openform/admin.py"
    click Repo "https://github.com/sfbenitez/openform/blob/master/openform/generator/repository.py"
    click Views_Gen "https://github.com/sfbenitez/openform/blob/master/openform/generator/views.py"
    click InstRouter "https://github.com/sfbenitez/openform/blob/master/openform/generator/instance/urls.py"
    click InstViews "https://github.com/sfbenitez/openform/blob/master/openform/generator/instance/views.py"
    click HCLTemplates "https://github.com/sfbenitez/openform/tree/master/openform/templates/plans/"
    click DB "https://github.com/sfbenitez/openform/blob/master/openform/db.sqlite3"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#0288D1,stroke-width:1px
    classDef backend fill:#C8E6C9,stroke:#388E3C,stroke-width:1px
    classDef datastore fill:#FFE0B2,stroke:#F57C00,stroke-width:1px
    classDef process fill:#F8BBD0,stroke:#C2185B,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#757575,stroke-width:1px
```
