# aristanetworks/anta architecture

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

- Interactive diagram: https://gitdiagram.com/aristanetworks/anta
- Repository: https://github.com/aristanetworks/anta

## Overview

##### Project Type and Purpose
- ANTA is a Python framework for automating tests on Arista devices. It is designed both as a library and as a Command-Line Interface (CLI) tool.
- Key functions include running NRFU tests, validating device configurations, executing EOS commands, and generating reports.
- The presence of separate modules for “check,” “debug,” “exec,” “get,” and “nrfu” within the CLI directory indicates a clear separation of CLI functionalities.

##### File Structure for Architecture Insights
- The primary source code lives under the "anta" directory, which contains modules for:
- Core functionality (e.g., device handling, test catalog, runner, and inventory management).
- CLI commands – organized under anta/cli with subdirectories split by functionality (check, debug, exec, get, nrfu).
- Input models for representing various device configurations and protocols (e.g., BGP, ISIS, SNMP).
- Reporting and result management components (e.g., reporter, result_manager).
- A separate package, “asynceapi”, is bundled beside the main ANTA package and provides asynchronous API communication for device command execution.
- Extensive testing is organized into several directories (anta/tests and tests/units), which further assures you capture components related to test definitions and executions.
- Additional directories such as “docs”, “examples”, and GitHub configuration files support documentation, CI/CD, and community development.

##### Main Components and Their Interactions
- Core Library: Contains business logic (anta/catalog.py, anta/device.py, anta/models.py, etc.) and utility functions (tools, decorators).
- CLI: Contains command entry points and subcommands (anta/cli/*). This layer interfaces user commands with appropriate library functions.
- Input Models: Encapsulates various data models that represent device states and test definitions (anta/input_models/*).
- Inventory and Catalog: Manages device inventory, configuration details, and the organization of test catalogs (anta/inventory, docs/examples/inventory.yaml).
- Test Runner: Manages the execution of tests with results aggregation (anta/runner.py, anta/result_manager).
- Reporter: Formats and outputs results in different formats, such as CSV and Markdown (anta/reporter).
- Asynchronous API (asynceapi): Provides asynchronous operations for device communication (aio_portcheck, device communication).
- External Integration: Although not explicitly shown in the file tree, the README mentions integration with production network devices and references to dependencies (e.g., aio-eapi).

##### Architectural Patterns and Design Principles
- Modular Design: Clear separation of concerns is evident by splitting CLI, core test logic, reporting, and data modeling into separate components.
- Extensibility: With dedicated directories for input models and tests, the project supports adding new types of tests and device protocols.
- Test-Driven Development: A very extensive suite of unit, integration, and benchmark tests underscores the focus on quality and reliability.
- Use of asynchronous programming (via asynceapi) for non-blocking operations on network devices.

##### Technology, Frameworks, and Libraries
- Python forms the base language.
- The project leverages asynchronous programming (asynceapi) to interact with Arista devices.
- It uses external libraries for command-line interfaces and possibly Pytest for testing.
- Documentation tools (such as MkDocs) are suggested by the mkdocs.yml and docs folder.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI Interface"]:::cli
    end

    %% Core Business Logic Layer with submodules
    subgraph "Core Business Logic"
        CORE["Core Business Logic"]:::core
        CATALOG["Catalog Module"]:::core
        DEVICE["Device Module"]:::core
        MODELS["Models Module"]:::core
        DECORATORS["Decorators Module"]:::core
        TOOLS["Tools Module"]:::core
        CORE --> CATALOG
        CORE --> DEVICE
        CORE --> MODELS
        CORE --> DECORATORS
        CORE --> TOOLS
    end

    %% Input Models Layer
    subgraph "Input Models"
        INPUT_MODELS["Input Models"]:::input
    end

    %% Inventory & Catalog Management Layer
    subgraph "Inventory & Catalog Management"
        INVENTORY["Inventory Management"]:::inv
        INV_YAML["Catalog Inventory YAML"]:::inv
    end

    %% Test Execution Layer
    subgraph "Test Execution"
        RUNNER["Test Runner"]:::run
        RESULT_MANAGER["Result Manager"]:::run
        RUNNER --> RESULT_MANAGER
    end

    %% Reporting Layer
    subgraph "Reporting"
        REPORTER["Reporter"]:::rep
        CSV_REPORTER["CSV Reporter"]:::rep
        MD_REPORTER["Markdown Reporter"]:::rep
        REPORTER --> CSV_REPORTER
        REPORTER --> MD_REPORTER
    end

    %% Asynchronous API Layer
    subgraph "Asynchronous API"
        ASYNC_API["Asynchronous API"]:::async
        AIO_PORTCHECK["AIO Portcheck Module"]:::async
        ASYNC_DEVICE["Async Device Module"]:::async
        ASYNC_API --> AIO_PORTCHECK
        ASYNC_API --> ASYNC_DEVICE
    end

    %% External Systems Layer
    subgraph "External Systems"
        EXTERNAL["External Systems"]:::ext
    end

    %% Testing Suite Layer
    subgraph "Testing"
        TESTING["Testing Suite"]:::test
    end

    %% Connections between layers
    CLI -->|"sends_commands"| CORE
    CORE -->|"uses"| INPUT_MODELS
    CORE -->|"manages"| INVENTORY
    CORE -->|"manages"| INV_YAML
    CORE -->|"triggers"| RUNNER
    RUNNER -->|"aggregates"| RESULT_MANAGER
    RESULT_MANAGER -->|"feeds"| REPORTER
    CORE -->|"calls_async"| ASYNC_API
    ASYNC_API -->|"communicates_with"| EXTERNAL
    TESTING -->|"validates"| CORE

    %% Click Events for CLI Layer
    click CLI "https://github.com/aristanetworks/anta/tree/main/anta/cli"

    %% Click Events for Core Business Logic submodules
    click CATALOG "https://github.com/aristanetworks/anta/blob/main/anta/catalog.py"
    click DEVICE "https://github.com/aristanetworks/anta/blob/main/anta/device.py"
    click MODELS "https://github.com/aristanetworks/anta/blob/main/anta/models.py"
    click DECORATORS "https://github.com/aristanetworks/anta/blob/main/anta/decorators.py"
    click TOOLS "https://github.com/aristanetworks/anta/blob/main/anta/tools.py"

    %% Click Event for Input Models
    click INPUT_MODELS "https://github.com/aristanetworks/anta/tree/main/anta/input_models"

    %% Click Events for Inventory & Catalog Management
    click INVENTORY "https://github.com/aristanetworks/anta/tree/main/anta/inventory"
    click INV_YAML "https://github.com/aristanetworks/anta/blob/main/examples/inventory.yaml"

    %% Click Events for Test Runner and Result Manager
    click RUNNER "https://github.com/aristanetworks/anta/blob/main/anta/runner.py"
    click RESULT_MANAGER "https://github.com/aristanetworks/anta/tree/main/anta/result_manager"

    %% Click Events for Reporter and its submodules
    click REPORTER "https://github.com/aristanetworks/anta/tree/main/anta/reporter"
    click CSV_REPORTER "https://github.com/aristanetworks/anta/blob/main/anta/reporter/csv_reporter.py"
    click MD_REPORTER "https://github.com/aristanetworks/anta/blob/main/anta/reporter/md_reporter.py"

    %% Click Events for Asynchronous API Layer
    click ASYNC_API "https://github.com/aristanetworks/anta/tree/main/asynceapi"
    click AIO_PORTCHECK "https://github.com/aristanetworks/anta/blob/main/asynceapi/aio_portcheck.py"
    click ASYNC_DEVICE "https://github.com/aristanetworks/anta/blob/main/asynceapi/device.py"

    %% Class Definitions with Colors
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef core fill:#98FB98,stroke:#000,stroke-width:1px;
    classDef input fill:#FFE4B5,stroke:#000,stroke-width:1px;
    classDef inv fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef run fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef rep fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef async fill:#AFEEEE,stroke:#000,stroke-width:1px;
    classDef ext fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef test fill:#FFA07A,stroke:#000,stroke-width:1px;
```
