# ch1nch4ch4/az-endpoint-discovery architecture

> Architecture diagram of the GitHub repository ch1nch4ch4/az-endpoint-discovery, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ch1nch4ch4/az-endpoint-discovery
- Repository: https://github.com/ch1nch4ch4/az-endpoint-discovery

## Overview

##### Project type and purpose
- This is an open-source, modular PowerShell CLI tool whose sole responsibility is to discover and report on internet-exposed Azure endpoints across one or many subscriptions/tenants.
- It connects to Azure via PowerShell, iterates subscriptions, invokes a set of discovery modules (one per Azure service or resource category), aggregates the results, and writes a Markdown and CSV report.

##### Main components
a. **CLI Entry Point (Get-AzureEndpointDiscovery.ps1)**
- Orchestrates the run: parses parameters, bootstraps module loader, iterates subscriptions, invokes discovery modules, and hands off to the report generator.
b. **Module Loader / Manager**
- Dynamically imports / installs required Azure PowerShell Az.* modules and our custom `.psm1` files from the `Modules/` directory.
- Provides a plugin boundary for each resource-type discovery function.
c. **Discovery Modules** (one per `.psm1` under `Modules/`)
- VirtualMachines.psm1, WebApps.psm1, StorageAccounts.psm1, etc.
- Each exposes a standardized function (e.g., `Get-XyzEndpoints`) returning objects with ResourceName, Endpoint, Type, SubscriptionId, ResourceGroup.
d. **Azure Control Plane**
- The underlying Az PowerShell modules talk to Azure Resource Manager (ARM) REST APIs or Resource Graph.
e. **Aggregation & Reporting Engine**
- Takes module outputs, groups by subscription and resource type, formats into Markdown and CSV.
- Writes files under the selected `OutputPath` (default: current directory), under `Reports/`.
f. **File System / Reports Store**
- Directory structure under `Reports/`, including example CSV/MD, and per-tenant subdirectories.
g. **User / Operator**
- Launches the script, supplies optional parameters (SubscriptionIds, TenantId, SkipResourceTypes, OutputPath).

##### Relationships and data flow
- User → CLI Entry Point
- CLI Entry Point → Module Loader
- Module Loader → Discovery Modules (loops over each .psm1)
- Discovery Modules → Azure Control Plane (API calls)
- Azure Control Plane → Discovery Modules (returns resource data)
- Discovery Modules → Aggregation & Reporting Engine (raw findings)
- Reporting Engine → File System (Markdown + CSV files under Reports/)
- User → Views Reports

##### Architectural patterns & design principles
- **Plugin/Module Pattern**: Each resource type is a self-contained PowerShell module. Adding a new resource involves dropping a new `.psm1` in `Modules/`.
- **Single Responsibility**: Entry point only orchestrates; modules only discover; reporting engine only formats.
- **Dependency Injection** (implicit): Modules assume a standard input/output contract, injected by the orchestrator.
- **Separation of Concerns**: Clear divide between discovery, Azure interactions, and reporting.

- Components listed above.
- Plugin architecture and reporting pipeline are both obvious.
- Don’t overcrowd: cluster similar modules together but call out the loader’s discovery loop.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User / Operator"]:::user

    %% Entry Point
    CLI["Get-AzureEndpointDiscovery.ps1\n(CLI Entry Point)"]:::script

    %% Module Loader
    Loader["Module Loader\n(dynamically imports Modules/*.psm1)"]:::script

    %% Discovery Modules Cluster
    subgraph "Discovery Modules (Plugins)" 
        style DiscoveryModules fill:#e0f7ff,stroke:#0288d1
        DM["Modules/*.psm1\n(AKS, APIManagement, AnalyticsServices,\nCDNEndpoints, DatabaseServices, DevOpsServices,\nFrontDoor, IoTServices, MessagingServices,\nNetworkConnectivity, NetworkResources,\nSQLDatabases, SecurityServices,\nStorageAccounts, VirtualMachines, WebApps, WebServices)"]:::script
    end

    %% Azure Control Plane
    AzureCloud["Azure Resource Manager /\nResource Graph"]:::azure

    %% Reporting Engine
    ReportEngine["Aggregation & Reporting Engine\n(Formats Markdown & CSV)"]:::script

    %% File System / Reports
    Reports["Reports/\n(Consolidated CSV & MD per tenant)"]:::file

    %% Documentation
    Docs["README.md"]:::file

    %% Data Flow
    User -->|"Launch script\nwith parameters"| CLI
    CLI -->|"Invoke Module Loader"| Loader
    Loader -->|"Import & Invoke each\nGet-<Resource>Endpoints"| DM
    DM -->|"ARM REST API calls"| AzureCloud
    AzureCloud -->|"Returns resource data"| DM
    DM -->|"Raw findings"| ReportEngine
    ReportEngine -->|"Write CSV & MD"| Reports
    User -->|"View reports"| Reports

    %% Click Events
    click CLI "https://github.com/ch1nch4ch4/az-endpoint-discovery/blob/main/Get-AzureEndpointDiscovery.ps1"
    click DM "https://github.com/ch1nch4ch4/az-endpoint-discovery/tree/main/Modules/"
    click Reports "https://github.com/ch1nch4ch4/az-endpoint-discovery/tree/main/Reports/"
    click Docs "https://github.com/ch1nch4ch4/az-endpoint-discovery/blob/main/README.md"

    %% Styles
    classDef script fill:#e3f2fd,stroke:#1565c0,color:#000;
    classDef azure fill:#e8f5e9,stroke:#2e7d32,color:#000;
    classDef file fill:#fff3e0,stroke:#ef6c00,color:#000;
    classDef user fill:#eceff1,stroke:#607d8b,color:#000;
```
