# facebookarchive/pcicrawler architecture

> Architecture diagram of the GitHub repository facebookarchive/pcicrawler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/facebookarchive/pcicrawler
- Repository: https://github.com/facebookarchive/pcicrawler

## Overview

##### Main Components

a. Core Components:
- CLI Interface Layer
- PCI Device Crawler Engine
- Data Processing Layer
- Output Formatters
- System Interface Layer (sysfs interaction)

b. Supporting Libraries:
- pci_lib (PCI operations library)
- pci_vpd_lib (PCI Vital Product Data library)

**User Interface Layer**

**Processing Layer**

**System Interface Layer**

##### Specific Component Details

a. User Interface Layer:
- CLI component (pcicrawler/cli.py)
- Command parsing and option handling
- Various output formats (Tree, JSON, Plain text)

b. Processing Layer:
- PCI Device Crawler Engine (core logic)
- Device Filtering System (class, device, address filters)
- Data Aggregation Component
- Two supporting libraries:
- pci_lib (general PCI operations)
- pci_vpd_lib (VPD data handling)

c. System Interface Layer:
- sysfs Interface (for reading PCI device information)
- Device Tree Parser
- Error Handling Component

##### Data Flow Representation

- User input → CLI Parser
- CLI Parser → Device Crawler
- Device Crawler ↔ System Interface
- Device Crawler → Output Formatters
- Output Formatters → User Display

##### Component Interactions

Specific interactions for key features:
- Tree view generation path
- JSON output path
- VPD data retrieval flow
- Device filtering process

##### Technical Details

- Python3 requirement
- Root privilege requirement
- Sysfs dependency
- Optional features (VPD, AER)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef cli fill:#f9f,stroke:#333,stroke-width:2px
    classDef core fill:#9cf,stroke:#333,stroke-width:2px
    classDef lib fill:#fcf,stroke:#333,stroke-width:2px
    classDef sys fill:#cfc,stroke:#333,stroke-width:2px
    classDef output fill:#ffc,stroke:#333,stroke-width:2px
    
    subgraph User_Interface
        CLI["CLI Interface"]:::cli
        Parser["Command Parser"]:::cli
    end
    
    subgraph Processing_Layer
        Core["Core Package"]:::core
        PCICrawler["PCI Device Crawler"]:::core
        FilterSystem["Device Filtering"]:::core
        DataAggregator["Data Aggregator"]:::core
        Constants["System Constants"]:::core
        Version["Version Manager"]:::core
    end
    
    subgraph Libraries
        PCILib["PCI Operations Library"]:::lib
        VPDLib["PCI VPD Library"]:::lib
    end
    
    subgraph System_Interface
        SysFS["sysfs Interface"]:::sys
        DTParser["Device Tree Parser"]:::sys
        ErrorHandler["Error Handler"]:::sys
    end
    
    subgraph Output_Formatters
        TreeView["Tree View"]:::output
        JSONOut["JSON Output"]:::output
        PlainText["Plain Text"]:::output
    end
    
    %% Connections
    CLI --> Parser
    Parser --> PCICrawler
    PCICrawler --> FilterSystem
    PCICrawler --> DataAggregator
    DataAggregator --> |Tree Format| TreeView
    DataAggregator --> |JSON Format| JSONOut
    DataAggregator --> |Plain Format| PlainText
    PCICrawler --> PCILib
    PCICrawler --> VPDLib
    PCILib --> SysFS
    VPDLib --> SysFS
    SysFS --> DTParser
    DTParser --> ErrorHandler
    
    %% Click events for component mapping
    click CLI "https://github.com/facebookarchive/pcicrawler/blob/main/pcicrawler/cli.py"
    click PCILib "https://github.com/facebookarchive/pcicrawler/blob/main/pci_lib/pci_lib.py"
    click VPDLib "https://github.com/facebookarchive/pcicrawler/blob/main/pci_vpd_lib/pci_vpd_lib.py"
    click Constants "https://github.com/facebookarchive/pcicrawler/blob/main/pcicrawler/lib/constants.py"
    click Version "https://github.com/facebookarchive/pcicrawler/blob/main/pcicrawler/__version__.py"
    click Core "https://github.com/facebookarchive/pcicrawler/blob/main/pcicrawler/__init__.py"
    
    %% Legend
    subgraph Legend
        L1["CLI Components"]:::cli
        L2["Core Components"]:::core
        L3["Libraries"]:::lib
        L4["System Interface"]:::sys
        L5["Output Formats"]:::output
    end
```
