# nesi/training-environment architecture

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

- Interactive diagram: https://gitdiagram.com/nesi/training-environment
- Repository: https://github.com/nesi/training-environment

## Overview

##### Project Type and Purpose
- This is an infrastructure and configuration management project that deploys a full training environment.
- It uses Terraform to provision infrastructure resources (e.g., VMs, Kubernetes clusters, network/DNS setups) in a cloud environment (NeSI RDC and OpenStack) and Ansible for post-provisioning configuration (setting up Open OnDemand, key services like LDAP and Keycloak, user management, and supporting components).
- The README makes it clear that the environment supports training scenarios with pre-created user accounts and specialized trainer accounts, and that the end-user accesses the environment via a web interface (e.g., https://ood.flexi.nesi).

##### Analyzing the File Structure
- Top-level files include README.md, deployment scripts (deployment.sh), and configuration files (e.g., configure-route53.yml, setup files).
- There is a dedicated Terraform directory containing main.tf, provider.tf, templates, and variables files. This block represents the Infrastructure-as-Code part.
- A major “roles” directory contains many subdirectories. Each subdirectory is an Ansible role corresponding to various components (e.g., keycloak, cluster-ctl, container-apps, monitoring, pre-checks). These roles modularize the configuration for different services and system components.
- Supporting directories like “docs” (with tutorials, images, stylesheets), “pubkeys”, “host_vars”, and “vars” provide additional data and documentation that guide setup.
- Presence of GitHub workflows and CI/CD related files also suggests deployment automation that ties into real infrastructure updates and management.

##### Key Architectural Components
a. Infrastructure Provisioning (Terraform):
- Responsible for setting up cloud resources (VMs, network, and Kubernetes clusters).
- Uses external authentication (clouds.yaml, environment variables for EC2 and Route 53) to manage platforms like OpenStack and AWS.

b. Configuration Management (Ansible):
- Leverages a rich “roles” directory to configure and install numerous services: Open OnDemand, Keycloak (for OIDC), LDAP services, monitoring (Grafana, Prometheus, node exporters), NFS servers, and additional container-related functionalities.
- The host_vars, users, and vars directories indicate that dynamic inventory and user-meta configurations are managed here.

c. Deployment Orchestration:
- Scripts such as deployment.sh, along with several GitHub workflow files, orchestrate the creation and destruction of environments.
- Role-specific scripts (e.g., tasks for pre-checks, kubectl management, etc.) ensure a layered approach in applying infrastructure and then configuring the software environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CP["Cloud Providers & External Services"]:::cloud
    TF["Terraform – Infrastructure Provisioning"]:::terraform
    DO["Deployment Orchestration"]:::orchestration
    DOC["Documentation & CI/CD"]:::docs
    Client["Training Users / Trainers"]:::client

    subgraph "Ansible – Configuration & Deployment"
        A_OD["Open OnDemand Setup"]:::ansible
        A_AI["Authentication & Identity"]:::ansible
        A_K["Kubernetes Cluster Management"]:::ansible
        A_MP["Monitoring & Pre-Checks"]:::ansible
        A_UT["User & Training Environment Setup"]:::ansible
    end

    CP -->|"ProvisionResources"| TF
    TF -->|"ConfigureInfra"| DO
    DO -->|"DeployConfiguration"| A_OD
    DO -->|"DeployConfiguration"| A_AI
    DO -->|"DeployConfiguration"| A_K
    DO -->|"DeployConfiguration"| A_MP
    DO -->|"DeployConfiguration"| A_UT
    A_MP -->|"PreChecksBefore"| A_OD
    A_OD -->|"AccessWeb"| Client
    DO ---|"TriggerPipeline"| DOC

    click TF "https://github.com/nesi/training-environment/tree/main/terraform/"
    click A_OD "https://github.com/nesi/training-environment/tree/main/roles/container-apps/webnode"
    click A_OD "https://github.com/nesi/training-environment/tree/main/roles/openondemand-webnode-config"
    click A_AI "https://github.com/nesi/training-environment/tree/main/roles/keycloak"
    click A_AI "https://github.com/nesi/training-environment/tree/main/roles/ldap_server"
    click A_AI "https://github.com/nesi/training-environment/tree/main/roles/ldap_client"
    click A_AI "https://github.com/nesi/training-environment/tree/main/roles/ldap_add_users"
    click A_K "https://github.com/nesi/training-environment/tree/main/roles/capi-cluster"
    click A_K "https://github.com/nesi/training-environment/tree/main/roles/cluster-ctl"
    click A_K "https://github.com/nesi/training-environment/tree/main/roles/kubectl"
    click A_MP "https://github.com/nesi/training-environment/tree/main/roles/monitoring"
    click A_MP "https://github.com/nesi/training-environment/tree/main/roles/pre-checks"
    click A_MP "https://github.com/nesi/training-environment/tree/main/roles/upgrade_system"
    click A_UT "https://github.com/nesi/training-environment/tree/main/users/"
    click A_UT "https://github.com/nesi/training-environment/tree/main/roles/app-data"
    click A_UT "https://github.com/nesi/training-environment/tree/main/roles/ml102_workshop"
    click DO "https://github.com/nesi/training-environment/blob/main/deployment.sh"
    click DO "https://github.com/nesi/training-environment/tree/main/.github/workflows/"
    click DOC "https://github.com/nesi/training-environment/tree/main/docs/"
    click DOC "https://github.com/nesi/training-environment/tree/main/.github/workflows/"

    classDef terraform fill:#FDEBD0,stroke:#D35400,stroke-width:2px;
    classDef ansible fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef cloud fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef client fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef orchestration fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef docs fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
```
