# hackmanit/template-injection-playground architecture

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

- Interactive diagram: https://gitdiagram.com/hackmanit/template-injection-playground
- Repository: https://github.com/hackmanit/template-injection-playground

## Overview

The Template Injection Playground is a multi-language web application designed as a test bed for numerous template engines and their injection vulnerabilities. Its primary purpose is to provide isolated, ready-to-run web applications—each built using different template engines across various programming languages (such as .NET, Elixir, Go, Java, JavaScript, PHP, Python, and Ruby)—so that users can experiment with and detect template injection issues. The accompanying README emphasizes features such as optional countermeasures (sandboxing, encoding, denylisting) and provides detailed usage instructions via Docker Compose. This clearly identifies the project as a full-stack, multi-container playground for security testing and research.

##### Main Components
- Docker Compose Orchestrator: At the top level, include the orchestrator that uses docker-compose to build and run the multiple containers.
- Reverse Proxy (nginx): This container receives client requests (on port 13370 by default) and routes them to the appropriate backend services.
- Individual Backend Containers: Represent each language-specific application as separate backend components such as:
- .NET container (hosting the webapp3 application)
- Elixir container (hosting the Phoenix webapp)
- Go container (with main.go)
- Java container (Spring-based application)
- JavaScript container (Express-based demo)
- PHP container (example-app based on Laravel/Blade or similar)
- Python container (Flask webapp)
- Ruby container (running the Ruby webapp)
- Template Engines & Security Options: Optionally, annotate that each backend has different template engine configurations and enhanced settings (e.g., sandboxing, header injection simulation).

##### Relationships and Interactions
- That every backend container encapsulates a specific set of template engines and associated configurations, under the control of Docker.

##### Architectural Patterns
- Microservices/Containerized Architecture: Emphasize that the backend services are isolated microservices each dedicated to one technology stack.
- Docker-based Deployment: Indicate that all components are containerized and orchestrated using Docker Compose and include configuration files (like docker-compose.yml and Dockerfiles).

##### Relevant Technologies, Frameworks, and Libraries
- .NET: Uses ASP.NET Core with Razor, DotLiquid, Fluid, and Scriban.
- Elixir: Deploys a Phoenix application.
- Go: Uses the standard html/text/template package.
- Java: Incorporates frameworks like Spring, with template engines including Freemarker, Thymeleaf, Velocity, etc.
- JavaScript: Implements an Express server using multiple JavaScript template engines.
- PHP: Uses Laravel-like structure with Blade and other PHP template engines.
- Python: Demonstrates usage of Flask along with engines like Jinja2, Django templates, etc.
- Ruby: Implements a lightweight Ruby webapp using ERB, Haml, and others.
- Docker & Nginx: The infrastructure is managed via Docker Compose with each service container linked to the nginx reverse proxy.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraph for the Client Layer
    subgraph "Client Layer"
        Client["External Client/Browser"]:::client
    end

    %% Subgraph for the Orchestration Layer
    subgraph "Orchestration Layer"
        Orchestrator["Docker Compose Orchestrator"]:::orchestrator
    end

    %% Subgraph for the Proxy Layer
    subgraph "Proxy Layer"
        Nginx["nginx Reverse Proxy"]:::proxy
    end

    %% Subgraph for the Backend Services
    subgraph "Backend Services"
        DotNet[".NET (webapp3)"]:::backend
        Elixir["Elixir (Phoenix)"]:::backend
        Go["Go (main.go)"]:::backend
        Java["Java (Spring)"]:::backend
        JavaScript["JavaScript (Express)"]:::backend
        PHP["PHP (example-app)"]:::backend
        Python["Python (Flask)"]:::backend
        Ruby["Ruby (webapp)"]:::backend
    end

    %% Flow connections
    Client -->|"HTTP_Request"| Nginx
    Nginx -->|"Routes_to"| DotNet
    Nginx -->|"Routes_to"| Elixir
    Nginx -->|"Routes_to"| Go
    Nginx -->|"Routes_to"| Java
    Nginx -->|"Routes_to"| JavaScript
    Nginx -->|"Routes_to"| PHP
    Nginx -->|"Routes_to"| Python
    Nginx -->|"Routes_to"| Ruby

    %% Orchestration connections showing container management
    Orchestrator -->|"Manages"| Nginx
    Orchestrator -->|"Manages"| DotNet
    Orchestrator -->|"Manages"| Elixir
    Orchestrator -->|"Manages"| Go
    Orchestrator -->|"Manages"| Java
    Orchestrator -->|"Manages"| JavaScript
    Orchestrator -->|"Manages"| PHP
    Orchestrator -->|"Manages"| Python
    Orchestrator -->|"Manages"| Ruby

    %% Click Events for Component Mappings
    click Orchestrator "https://github.com/hackmanit/template-injection-playground/blob/main/docker-compose.yml"
    click Nginx "https://github.com/hackmanit/template-injection-playground/blob/main/nginx/nginx.conf"
    click Nginx "https://github.com/hackmanit/template-injection-playground/tree/main/nginx/Dockerfile"
    click DotNet "https://github.com/hackmanit/template-injection-playground/tree/main/dotnet/webapp3"
    click Elixir "https://github.com/hackmanit/template-injection-playground/tree/main/elixir/phoenix_webapp"
    click Go "https://github.com/hackmanit/template-injection-playground/blob/main/golang/src/main.go"
    click Go "https://github.com/hackmanit/template-injection-playground/tree/main/golang/Dockerfile"
    click Java "https://github.com/hackmanit/template-injection-playground/tree/main/java/spring"
    click JavaScript "https://github.com/hackmanit/template-injection-playground/tree/main/javascript/express"
    click PHP "https://github.com/hackmanit/template-injection-playground/tree/main/php/example-app"
    click Python "https://github.com/hackmanit/template-injection-playground/blob/main/python/src/flask_webapp.py"
    click Ruby "https://github.com/hackmanit/template-injection-playground/blob/main/ruby/src/webapp.rb"

    %% Class Styles
    classDef orchestrator fill:#b3d9ff,stroke:#1976d2,stroke-width:2px;
    classDef proxy fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef backend fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;
    classDef client fill:#ffcdd2,stroke:#d32f2f,stroke-width:2px;
```
