# splunk/contentctl architecture

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

- Interactive diagram: https://gitdiagram.com/splunk/contentctl
- Repository: https://github.com/splunk/contentctl

## Overview

##### Main Components
- CLI/Application Entrypoint: The primary command-line interface (evidenced by files like contentctl/contentctl.py and contentctl/api.py) acts as the user’s entrypoint.
- Actions/Commands: The “actions” folder contains various modules (build, deploy, inspect, test, new_content, etc.) that define core functionalities.
- Input Processing: Under “contentctl/input” you find modules that read YAML and ask questions (e.g., director.py, new_content_questions.py, yml_reader.py) to process and validate user-supplied content.
- Content Objects & Domain Models: The “contentctl/objects” directory houses domain models such as detections, dashboards, alerts, tests, etc. These represent the different types of security content.
- Enrichments & External Data: The “contentctl/enrichments” directory enriches content with additional data from sources such as CVEs, MITRE ATT&CK, or Splunk-specific enhancements.
- Output Generation: The “contentctl/output” modules and Jinja2 templates (under “contentctl/output/templates”) are responsible for generating the final app configuration (YAML, JSON, Splunk configuration files) that will be deployed.
- Testing and Validation: Files under “contentctl/actions/detection_testing” and the “tests” directory focus on validating the content within a live Splunk or simulated environment.
- Templates and Deployment: The “contentctl/templates” directory organizes application default YAML and Splunk configuration templates, while the “docs” folder provides guides and migration instructions.

##### Relationships and Interactions Among Components
- The CLI application (contentctl.py) will trigger various “actions” based on user input. Each action (e.g., build, test, deploy) invokes routines in the input layer to parse YAML, instantiate domain models (in the objects module), and then call the appropriate enrichment and output generators.
- The domain objects form the backbone of the processing: they encapsulate security content that gets validated, enriched, and eventually rendered into output.
- Outgoing data flows from input → processing (objects and enrichments) → actions → templating/output. In addition, separate testing commands are available to validate both the correctness of the YAML and the generation of the Splunk app configurations.
- There is clearly a separation between the ‘action’ layer (command functions that users trigger), the ‘core logic’ (domain models and enrichments), and the ‘output’ layer (templating and file generation).

##### Architectural Patterns and Design Principles
- Layered/Modular Architecture: Each directory corresponds to a specific layer (actions, input, objects, enrichment, output), facilitating separation of concerns.
- Command Pattern: The individual action modules act as distinct commands triggered by the CLI.
- Template-Based Generation: The use of Jinja2 templates in the “output/templates” and the “templates” directory shows how the tool abstracts configuration file generation.
- Test-Driven and Configured CI/CD: The presence of numerous GitHub workflows, tests, and pre-commit configurations indicates an emphasis on continuous testing and quality assurance.

##### Relevant Technologies and Frameworks
- Python is the core language, along with its extensive use of modules.
- Jinja2 templating is employed in the output generation.
- YAML is used heavily for configuration, as evidenced by the numerous YAML reader modules and sample detection YAML files.
- GitHub Actions (workflows in the .github directory) for CI/CD.
- Possibly external services or APIs for enrichment (e.g., CVE lookups, Splunk integrations).

##### Elements
- CLI → Action Modules → Input Parsing → Domain Object Instantiation → Enrichment → Output Generation.
- Additional Flows: Show feedback loops where data might be validated/tested and potentially sent back for re-processing.
- CI/CD Integration: Optionally, include a side panel that shows the integration of GitHub workflows (CI tests, deployments) which ensure that the outputs and tests are continuously being run.

##### Final Detailed Steps
- Sub-modules or annotate blocks with lists of key files (e.g., “actions” module includes build, deploy, test, etc.).
- Ancillary components like “Templates,” “Tests,” and “CI/CD Workflows” as separate entities linked to the appropriate components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Entrypoint
    subgraph "CLI Entrypoint"
        CLI1["contentctl.py"]:::entry
        CLI2["api.py"]:::entry
    end

    %% Action Modules
    ACTIONS["Actions: build, deploy, inspect, new_content, test"]:::actions

    %% Input Processing
    INPUT["Input Processing: director, new_content_questions, yml_reader"]:::input

    %% Domain Models
    DOMAIN["Domain Models: detection, dashboard, correlation_search, etc."]:::domain

    %% Enrichments
    ENRICH["Enrichments: attack_enrichment, cve_enrichment, splunk_app_enrichment"]:::enrichment

    %% Output Generation
    OUTPUT["Output Generation: output modules & Jinja2 templates"]:::output

    %% Deployment & Templates
    subgraph "Deployment & Templates"
        TEMPLATES["Templates: app_default.yml, app_template, etc."]:::templates
        DOCS["Docs: user guides & migration"]:::templates
    end

    %% Testing & Validation
    subgraph "Testing & Validation"
        TESTS["General Tests"]:::testing
        DETECT_TEST["Detection Testing"]:::testing
    end

    %% CI/CD Workflows
    CI["CI/CD Workflows"]:::ci

    %% Flow Connections
    CLI1 -->|"triggers"| ACTIONS
    CLI2 -->|"triggers"| ACTIONS
    ACTIONS -->|"parses"| INPUT
    INPUT -->|"instantiates"| DOMAIN
    DOMAIN -->|"applies"| ENRICH
    ENRICH -->|"generates"| OUTPUT
    OUTPUT -->|"renders"| TEMPLATES
    OUTPUT -->|"uses"| DOCS
    ACTIONS -->|"validates"| TESTS
    ACTIONS -->|"validates"| DETECT_TEST
    TESTS -->|"runs"| CI
    DETECT_TEST -->|"runs"| CI

    %% Click Events
    click CLI1 "https://github.com/splunk/contentctl/blob/main/contentctl/contentctl.py"
    click CLI2 "https://github.com/splunk/contentctl/blob/main/contentctl/api.py"
    click ACTIONS "https://github.com/splunk/contentctl/tree/main/contentctl/actions"
    click INPUT "https://github.com/splunk/contentctl/tree/main/contentctl/input"
    click DOMAIN "https://github.com/splunk/contentctl/tree/main/contentctl/objects"
    click ENRICH "https://github.com/splunk/contentctl/tree/main/contentctl/enrichments"
    click OUTPUT "https://github.com/splunk/contentctl/tree/main/contentctl/output"
    click TEMPLATES "https://github.com/splunk/contentctl/tree/main/contentctl/templates"
    click DOCS "https://github.com/splunk/contentctl/tree/main/docs"
    click TESTS "https://github.com/splunk/contentctl/tree/main/tests"
    click DETECT_TEST "https://github.com/splunk/contentctl/tree/main/contentctl/actions/detection_testing"

    %% Styles
    classDef entry fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef actions fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef input fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef domain fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef enrichment fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef output fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef templates fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef testing fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef ci fill:#D3D3D3,stroke:#333,stroke-width:2px;
```
