# sethsec/cloudfox architecture

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

- Interactive diagram: https://gitdiagram.com/sethsec/cloudfox
- Repository: https://github.com/sethsec/cloudfox

## Overview

##### Main Components
- Entry Point & CLI Layer: Represent the main.go file as the entry point. This is where the tool is initiated. The “cli” directory further encapsulates the command line interface logic for each provider (aws.go, azure.go, gcp.go).
- Provider Modules: Show distinct modules for each cloud provider:
– Azure Module: Represent the “azure” directory that contains inventory, RBAC, storage, vms, and test-data.
– GCP Module: Illustrate the “gcp” directory which is split into “commands” and “services” subfolders handling operations like instances, IAM, buckets, and more.
- Shared/Global Libraries: Include components like the “globals” and “internal” directories. These hold shared utility functions (e.g., logging, common types, output handling, array utilities) and domain-specific logic such as AWS policy evaluation.
- Configuration & CI/CD: Optionally note the GitHub workflows and configuration files (e.g., .github/workflows, Makefile, go.mod, go.sum) as supporting infrastructure for build, testing, and deployment.

##### Relationships and Interactions
- Provider Internals: Within each provider module:
- For AWS, illustrate further splitting into submodules for graphing, SDK wrappers (mock and real), and helper files that perform service-specific enumerations (for instance, “iam-simulator”, “resource-trusts”, “pmapper”).
- Testing Support: Note that each provider has associated test files (named *_test.go) grouped alongside the implementation components. This shows a layer of validation and quality assurance without cluttering the high-level architecture.

##### Architectural Patterns & Design Principles
- Command Pattern: The numerous commands (listed in the README) and individual command files indicate a design where each command is implemented as a separate module or function – represent these as smaller blocks within each provider container.
- Abstraction & Wrapping: The use of an “sdk” directory (with production and mock files) suggests that CloudFox wraps standard cloud SDKs with its own abstractions. Show this as a subsystem inside the AWS (and analogous in other providers) module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLIEntry["CLI Entry (main.go)"]:::cli
        CLIInterface["CLI Interfaces (cli/aws.go, cli/azure.go, cli/gcp.go)"]:::cli
    end

    %% Cloud Provider Modules
    subgraph "Cloud Provider Modules"
        subgraph "AWS Module"
            AWSCommands["AWS Commands (access-keys.go, buckets.go, cloudformation.go)"]:::provider
            AWSSDK["AWS SDK Wrappers (aws/sdk/)"]:::provider
            AWSGraph["AWS Graph Engine (aws/graph/)"]:::provider
        end
        subgraph "Azure Module"
            AZCommands["Azure Commands (inventory.go, rbac.go, storage.go, vms.go, whoami.go)"]:::provider
        end
        subgraph "GCP Module"
            GCPCommands["GCP Commands (gcp/commands/)"]:::provider
            GCPServices["GCP Services (gcp/services/)"]:::provider
        end
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        Globals["Globals (globals/)"]:::shared
        Internal["Internal Logic (internal/)"]:::shared
    end

    %% External Cloud APIs
    subgraph "External Cloud APIs"
        AWSAPI["AWS API"]:::external
        AZAPI["Azure API"]:::external
        GCPAPI["GCP API"]:::external
    end

    %% Configuration & CI/CD
    subgraph "Configuration & CI/CD"
        GitHub["GitHub Workflows (.github/)"]:::config
        Makefile["Makefile"]:::config
        GoMod["go.mod"]:::config
        GoSum["go.sum"]:::config
    end

    %% Relationships
    CLIEntry -->|"initiates"| CLIInterface
    CLIInterface -->|"sends_command_to"| AWSCommands
    CLIInterface -->|"sends_command_to"| AZCommands
    CLIInterface -->|"sends_command_to"| GCPCommands

    AWSCommands -->|"utilizes"| AWSSDK
    AWSCommands -->|"feeds_data_to"| AWSGraph

    %% Provider Modules utilize Shared Libraries
    AWSCommands -->|"uses"| Globals
    AWSSDK -->|"uses"| Internal
    AWSGraph -->|"uses"| Internal
    AZCommands -->|"uses"| Globals
    AZCommands -->|"uses"| Internal
    GCPCommands -->|"uses"| Globals
    GCPServices -->|"uses"| Internal

    %% Modules call External APIs
    AWSSDK -->|"calls"| AWSAPI
    AZCommands -->|"calls"| AZAPI
    GCPCommands -->|"calls"| GCPAPI
    GCPServices -->|"calls"| GCPAPI

    %% CLI Layer configuration associations
    CLIEntry -->|"configured_by"| Makefile
    CLIEntry -->|"configured_by"| GoMod
    CLIEntry -->|"configured_by"| GoSum
    AWSCommands -->|"configured_by"| Makefile
    AZCommands -->|"configured_by"| GoMod
    GCPCommands -->|"configured_by"| GoSum
    GitHub --- Makefile
    GitHub --- GoMod
    GitHub --- GoSum

    %% Click Events
    click CLIEntry "https://github.com/sethsec/cloudfox/blob/main/main.go"
    click CLIInterface "https://github.com/sethsec/cloudfox/tree/main/cli/"
    click AWSCommands "https://github.com/sethsec/cloudfox/tree/main/aws/"
    click AWSSDK "https://github.com/sethsec/cloudfox/tree/main/aws/sdk/"
    click AWSGraph "https://github.com/sethsec/cloudfox/tree/main/aws/graph/"
    click AZCommands "https://github.com/sethsec/cloudfox/tree/main/azure/"
    click GCPCommands "https://github.com/sethsec/cloudfox/tree/main/gcp/commands/"
    click GCPServices "https://github.com/sethsec/cloudfox/tree/main/gcp/services/"
    click Globals "https://github.com/sethsec/cloudfox/tree/main/globals/"
    click Internal "https://github.com/sethsec/cloudfox/tree/main/internal/"
    click GitHub "https://github.com/sethsec/cloudfox/tree/main/.github/"
    click Makefile "https://github.com/sethsec/cloudfox/tree/main/Makefile"
    click GoMod "https://github.com/sethsec/cloudfox/blob/main/go.mod"
    click GoSum "https://github.com/sethsec/cloudfox/blob/main/go.sum"

    %% Styles
    classDef cli fill:#b3cde0,stroke:#333,stroke-width:2px;
    classDef provider fill:#ccebc5,stroke:#333,stroke-width:2px;
    classDef shared fill:#fddb92,stroke:#333,stroke-width:2px;
    classDef external fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef config fill:#e5d8bd,stroke:#333,stroke-width:2px;
```
