# infinigate-techservices/demo-hub-fastapi architecture

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

- Interactive diagram: https://gitdiagram.com/infinigate-techservices/demo-hub-fastapi
- Repository: https://github.com/infinigate-techservices/demo-hub-fastapi

## Overview

##### Main Components
- API / Backend: Highlight the FastAPI application (main.py) as the core of the system that runs the REST API and serves the web interface.
- Web Interface: Include the PyWebIO-based modules (e.g., pywebio_app.py, pywebio_dns.py, pywebio_guacamole.py, etc.) which create the user interface for different management tasks.
- External Integration Modules:
- Proxmox VE (pve.py & pywebio_pve.py) for VM lifecycle management.
- Guacamole (guacamole.py & pywebio_guacamole.py) for remote access.
- NGINX Proxy Manager (nginx_proxy_manager.py & pywebio_nginx.py) for reverse proxy configurations.
- Authentik (authentik.py) for identity management.
- FortiGate (fortigate.py) for DHCP/reservation and firewall management.
- Cloudflare (cf.py) for DNS management.
- LLDAP (lldap.py & pywebio_lldap.py) for LDAP user management.
- Models: The models.py file that defines the data models used across the system.
- Background Task Schedulers: Although not a separate file, the README details background tasks (e.g., VM scheduling, start/stop checks) that should be represented as part of asynchronous processes or scheduled jobs within the API.

##### Relationships and Interactions
- The FastAPI backend serves as the central hub. It exposes APIs (with Swagger and ReDoc UI) and triggers background tasks that manage the lifecycle of the training lab VMs.
- The web interface (via PyWebIO components) is the user-facing layer that interacts with the backend to trigger actions like “create training seats” or setting up configurations.
- Data flowing from the backend to these modules.
- Requests that handle VM creation, user provisioning, network configurations, etc.
- Background tasks (schedulers) periodically trigger calls to these integration modules for VM updates and cleanup.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly illustrate different layers (API/backend, UI layer, and external integrations) to emphasize modularity.
- Service Integration Pattern: Show how each external system is abstracted into its own module, allowing independent evolution and testing.

##### Relevant Technologies and Frameworks
- FastAPI: As the API framework powering the REST endpoints.
- PyWebIO: For constructing the interactive web interfaces.
- Python Environment: The system’s core is built in Python, featuring libraries like secrets for secure token/password generation.

- Web Interface to the API Backend that houses your main application logic.
- Branch out from the API Backend to multiple modules that interface with external systems:
- One branch for VM Management (linking to Proxmox VE module).
- Another for User Management (linking to Authentik, Guacamole, LLDAP modules).
- Yet another for Network Management (linking to FortiGate, Cloudflare, NGINX Proxy Manager modules).
- A background process block linked to the API Backend for periodic tasks like VM scheduling.
- Configuration details (load from .env, settings) where applicable.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    Client["Client/User"]:::frontend

    %% Web Interface Subgraph
    subgraph "Web Interface"
        UI1["App Interface"]:::frontend
        UI2["DNS Interface"]:::frontend
        UI3["Guacamole Interface"]:::frontend
        UI4["LDAP Interface"]:::frontend
        UI5["NGINX Interface"]:::frontend
        UI6["Proxmox VE Interface"]:::frontend
        UI7["Trainings Management"]:::frontend
    end

    %% API Backend Subgraph
    subgraph "API Backend"
        BE["FastAPI Backend"]:::backend
        Models["Models"]:::backend
        Scheduler["Background Scheduler"]:::scheduler
    end

    %% External Integrations Subgraph
    subgraph "External Integrations"
        EXT1["Proxmox VE Integration"]:::integration
        EXT2["Guacamole Integration"]:::integration
        EXT3["NGINX Proxy Manager Integration"]:::integration
        EXT4["Authentik Integration"]:::integration
        EXT5["FortiGate Integration"]:::integration
        EXT6["Cloudflare Integration"]:::integration
        EXT7["LLDAP Integration"]:::integration
    end

    %% Relationships
    Client -->|"HTTP_request"| UI1
    Client -->|"HTTP_request"| UI2
    Client -->|"HTTP_request"| UI3
    Client -->|"HTTP_request"| UI4
    Client -->|"HTTP_request"| UI5
    Client -->|"HTTP_request"| UI6
    Client -->|"HTTP_request"| UI7

    UI1 -->|"calls"| BE
    UI2 -->|"calls"| BE
    UI3 -->|"calls"| BE
    UI4 -->|"calls"| BE
    UI5 -->|"calls"| BE
    UI6 -->|"calls"| BE
    UI7 -->|"calls"| BE

    BE -->|"uses"| Models

    BE -->|"triggers"| EXT1
    BE -->|"triggers"| EXT2
    BE -->|"triggers"| EXT3
    BE -->|"triggers"| EXT4
    BE -->|"triggers"| EXT5
    BE -->|"triggers"| EXT6
    BE -->|"triggers"| EXT7

    Scheduler -->|"periodically calls"| BE
    Scheduler -->|"updates"| EXT1
    Scheduler -->|"updates"| EXT2
    Scheduler -->|"updates"| EXT3
    Scheduler -->|"updates"| EXT4
    Scheduler -->|"updates"| EXT5
    Scheduler -->|"updates"| EXT6
    Scheduler -->|"updates"| EXT7

    %% Click Events for API Backend and Models
    click BE "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/main.py"
    click Models "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/models.py"

    %% Click Events for Web Interface Components
    click UI1 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/pywebio_app.py"
    click UI2 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/pywebio_dns.py"
    click UI3 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/pywebio_guacamole.py"
    click UI4 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/pywebio_lldap.py"
    click UI5 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/pywebio_nginx.py"
    click UI6 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/pywebio_pve.py"
    click UI7 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/pywebio_trainings.py"

    %% Click Events for External Integration Modules
    click EXT1 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/pve.py"
    click EXT2 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/guacamole.py"
    click EXT3 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/nginx_proxy_manager.py"
    click EXT4 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/authentik.py"
    click EXT5 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/fortigate.py"
    click EXT6 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/cf.py"
    click EXT7 "https://github.com/infinigate-techservices/demo-hub-fastapi/blob/main/lldap.py"

    %% Styles
    classDef backend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef frontend fill:#A9DFBF,stroke:#239B56,stroke-width:2px;
    classDef integration fill:#F9E79F,stroke:#D4AC0D,stroke-width:2px;
    classDef scheduler fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
