# iesgn/hosting-proyecto architecture

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

- Interactive diagram: https://gitdiagram.com/iesgn/hosting-proyecto
- Repository: https://github.com/iesgn/hosting-proyecto

## Overview

##### Project type and purpose
- This is an automated hosting platform (“AutoHosting”) that provisions and configures servers for Drupal, MediaWiki, PrestaShop and a custom management panel.
- It leverages Terraform (0.12.0) for infrastructure provisioning and Ansible (2.2.1.0) for configuration management.
- It also includes two Python WSGI web applications (“hosting” and “panel”) that provide user-facing interfaces to trigger and monitor the automation.

##### High-level architecture components
a. Terraform layer
- Responsible for creating cloud resources (VM instances, network, security groups).
b. Ansible controller
- Executes playbooks and roles against the freshly provisioned servers.
- Roles are split into “install_*” (installing software: Apache, PHP, CMS prerequisites) and “hosting_*” (configuring virtual hosts, templates, site files).
- A “common” role manages baseline tasks (user accounts, firewall).
c. Cloud provider
- Hosts the VMs for:
– CMS servers (Drupal, MediaWiki, PrestaShop)
– Panel application server
– (Optional) Database server (“database_hosting”)
d. Web applications
- hosting.py WSGI app – allows users to request new CMS hosting, which under the hood invokes Terraform & Ansible.
- panel.py WSGI app – management panel to view logs, software lists, CMS status.
e. Data stores / external services
- Underlying database for user accounts and server metadata.
- File system storage for CMS assets and logs.

##### Component interactions and data flows
1. User → hosting.py (WSGI)
- Initiates a “create server” request.
2. hosting.py → Terraform CLI
- Calls Terraform to provision a new VM.
3. Terraform → Cloud API
- Creates the VM and returns its IP.
4. hosting.py (or orchestrator) → Ansible Controller
- Invokes Ansible playbook (e.g., site_drupal.yml) against the new VM.
5. Ansible Controller → VM via SSH
- Runs “common”, “install_drupal”, and “hosting_drupal” roles in sequence.
6. CMS server → Database server
- CMS connects to its database backend.
7. User → panel.py (WSGI)
- Retrieves logs/status by Ansible ad-hoc commands or by reading log files directly on CMS servers.

##### Architectural patterns and design principles
- Infrastructure as Code (Terraform)
- Configuration as Code (Ansible roles/playbooks)
- Modular roles: “install_*” vs “hosting_*” to separate software installation from host-specific configuration
- Micro-services style separation: dedicated VMs for different CMS types + management panel
- MVC for Python WSGI apps (templates under Aplicaciones/*/html, logic in .py)

##### Relevant technologies and frameworks
- Terraform 0.12.0
- Ansible 2.2.1.0 with:
- group_vars/all for global variables
- roles/common, roles/install_*, roles/hosting_*
- Python (WSGI apps)
- Jinja2 templating (Ansible + web apps)
- HTML/CSS for frontend templates
- Optional DB (MySQL/PostgreSQL) for CMS and user metadata

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User(("User")):::user

    %% Application Layer
    subgraph "Application Layer"
        HostingPy["hosting.py WSGI"]:::application
        PanelPy["panel.py WSGI"]:::application
    end

    %% Provisioning Layer
    subgraph "Provisioning Layer"
        Terraform["Terraform 0.12.0"]:::provisioning
        Cloud["Cloud Provider"]:::cloud
    end

    %% Configuration Layer
    subgraph "Configuration Layer"
        AnsibleController["Ansible Controller"]:::configuration
        GroupVars["group_vars/all"]:::configuration

        subgraph "Playbooks"
            SiteDrupal["site_drupal.yml"]:::configuration
            SiteMediawiki["site_mediawiki.yml"]:::configuration
            SitePrestashop["site_prestashop.yml"]:::configuration
            PanelPlaybook["panel.yml"]:::configuration
        end

        subgraph "Roles"
            CommonRole["common"]:::configuration
            InstallDrupal["install_drupal"]:::configuration
            InstallMediawiki["install_mediawiki"]:::configuration
            InstallPrestashop["install_prestashop"]:::configuration
            InstallPanel["install_panel"]:::configuration
            HostingDrupal["hosting_drupal"]:::configuration
            HostingMediawiki["hosting_mediawiki"]:::configuration
            HostingPrestashop["hosting_prestashop"]:::configuration
        end
    end

    %% VM Instances
    subgraph "VM Instances (Cloud)"
        DrupalVM["Drupal Server"]:::server
        MediaWikiVM["MediaWiki Server"]:::server
        PrestaVM["PrestaShop Server"]:::server
        PanelVM["Panel Server"]:::server
        DBVM["Database Server"]:::server
    end

    %% Data Layer
    subgraph "Data Layer"
        Database["DB (MySQL/PostgreSQL)"]:::datastore
        FileStorage["FS Storage (assets, logs)"]:::datastore
    end

    %% Connections: User to Apps
    User -->|"create request"| HostingPy
    User -->|"view logs/status"| PanelPy

    %% Hosting flow: provisioning
    HostingPy -->|"invoke Terraform"| Terraform
    Terraform -->|"calls Cloud API"| Cloud
    Cloud --> DrupalVM
    Cloud --> MediaWikiVM
    Cloud --> PrestaVM
    Cloud --> PanelVM
    Cloud --> DBVM

    %% Configuration flow: orchestration
    HostingPy -->|"invoke Ansible"| AnsibleController
    AnsibleController --> GroupVars
    AnsibleController --> SiteDrupal
    AnsibleController --> SiteMediawiki
    AnsibleController --> SitePrestashop
    AnsibleController --> PanelPlaybook

    SiteDrupal --> InstallDrupal
    SiteDrupal --> HostingDrupal
    SiteMediawiki --> InstallMediawiki
    SiteMediawiki --> HostingMediawiki
    SitePrestashop --> InstallPrestashop
    SitePrestashop --> HostingPrestashop
    PanelPlaybook --> InstallPanel

    InstallDrupal --> DrupalVM
    HostingDrupal --> DrupalVM
    InstallMediawiki --> MediaWikiVM
    HostingMediawiki --> MediaWikiVM
    InstallPrestashop --> PrestaVM
    HostingPrestashop --> PrestaVM
    InstallPanel --> PanelVM

    %% CMS to Database and storage
    DrupalVM -->|"connect"| Database
    MediaWikiVM -->|"connect"| Database
    PrestaVM -->|"connect"| Database
    DrupalVM --> FileStorage
    MediaWikiVM --> FileStorage
    PrestaVM --> FileStorage

    %% Panel interactions
    PanelPy --> PanelVM
    PanelPy --> DrupalVM
    PanelPy --> MediaWikiVM
    PanelPy --> PrestaVM

    %% Click Events
    click AnsibleController "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/"
    click GroupVars "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/group_vars/all"
    click CommonRole "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/roles/common"
    click InstallDrupal "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/roles/install_drupal"
    click InstallMediawiki "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/roles/install_mediawiki"
    click InstallPrestashop "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/roles/install_prestashop"
    click InstallPanel "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/roles/install_panel"
    click HostingDrupal "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/roles/hosting_drupal"
    click HostingMediawiki "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/roles/hosting_mediawiki"
    click HostingPrestashop "https://github.com/iesgn/hosting-proyecto/tree/master/Ansible/roles/hosting_prestashop"
    click SiteDrupal "https://github.com/iesgn/hosting-proyecto/blob/master/Ansible/site_drupal.yml"
    click SiteMediawiki "https://github.com/iesgn/hosting-proyecto/blob/master/Ansible/site_mediawiki.yml"
    click SitePrestashop "https://github.com/iesgn/hosting-proyecto/blob/master/Ansible/site_prestashop.yml"
    click PanelPlaybook "https://github.com/iesgn/hosting-proyecto/blob/master/Ansible/panel.yml"
    click HostingPy "https://github.com/iesgn/hosting-proyecto/blob/master/Aplicaciones/hosting/hosting.py"
    click Aplicaciones/hosting/hosting.wsgi "https://github.com/iesgn/hosting-proyecto/blob/master/Aplicaciones/hosting/hosting.wsgi"
    click Aplicaciones/hosting/ansible.cfg "https://github.com/iesgn/hosting-proyecto/blob/master/Aplicaciones/hosting/ansible.cfg"
    click Aplicaciones/hosting/hosting.conf "https://github.com/iesgn/hosting-proyecto/blob/master/Aplicaciones/hosting/hosting.conf"
    click Aplicaciones/hosting/html/ "https://github.com/iesgn/hosting-proyecto/tree/master/Aplicaciones/hosting/html/"
    click Aplicaciones/hosting/requeriments.txt "https://github.com/iesgn/hosting-proyecto/blob/master/Aplicaciones/hosting/requeriments.txt"
    click Aplicaciones/hosting/database_hosting "https://github.com/iesgn/hosting-proyecto/tree/master/Aplicaciones/hosting/database_hosting"
    click PanelPy "https://github.com/iesgn/hosting-proyecto/blob/master/Aplicaciones/panel/panel.py"
    click Aplicaciones/panel/panel.wsgi "https://github.com/iesgn/hosting-proyecto/blob/master/Aplicaciones/panel/panel.wsgi"
    click Aplicaciones/panel/html/ "https://github.com/iesgn/hosting-proyecto/tree/master/Aplicaciones/panel/html/"
    click Aplicaciones/panel/requeriments.txt "https://github.com/iesgn/hosting-proyecto/blob/master/Aplicaciones/panel/requeriments.txt"

    %% Styles
    classDef provisioning fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef configuration fill:#90EE90,stroke:#000,stroke-width:1px
    classDef application fill:#FFA500,stroke:#000,stroke-width:1px
    classDef datastore fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef server fill:#FAFAD2,stroke:#000,stroke-width:1px
    classDef cloud fill:#87CEEB,stroke:#000,stroke-width:1px
    classDef user fill:#FFFFFF,stroke:#000,stroke-width:1px
```
