# imr/ngspice architecture

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

- Interactive diagram: https://gitdiagram.com/imr/ngspice
- Repository: https://github.com/imr/ngspice

## Overview

##### Main Components
The system should be divided into these major components:

a. Frontend Layer
- Command Line Interface (src/frontend)
- Parser System (src/spicelib/parser)
- Plot/Visualization Components (src/frontend/plotting)
- Help System (src/frontend/help)

b. Core Simulation Layer
- Circuit Analysis Engine (src/spicelib/analysis)
- Device Models (src/spicelib/devices)
- Mathematics Library (src/maths)
- XSPICE Integration (src/xspice)

c. Device Layer
- Standard Devices (BJT, MOSFET, etc.)
- CIDER Device Simulator Integration
- XSPICE Digital Components
- Custom Device Models

d. External Interfaces
- Shared Library Interface
- OSDI Interface
- TCL/TK Interface
- File I/O System

##### Relationships and Data Flow
Key interactions:

a. Input Flow:
- Circuit Description → Parser → Internal Circuit Representation
- Commands → Command Processor → Simulation Control

b. Simulation Flow:
- Circuit Setup → Analysis Engine → Device Models → Math Solvers
- Mixed-Signal Integration between Analog and Digital Components

c. Output Flow:
- Results → Plot System/File Output
- Error Handling → User Interface

##### Layering

- Top: User Interface Layer
- Middle: Simulation Control Layer
- Lower: Device and Math Layer
- Bottom: External Interface Layer

##### Additional Details
- Version information
- Configuration options
- Extension points
- Major file formats supported

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#f9d71c
    classDef core fill:#3498db
    classDef device fill:#2ecc71
    classDef external fill:#9b59b6
    classDef interface fill:#e74c3c

    %% Frontend Layer
    subgraph Frontend
        CLI["Command Line Interface"]
        Parser["Parser System"]
        Plot["Plot/Visualization"]
        Help["Help System"]
        FileIO["File I/O System"]
    end
    
    %% Core Simulation Layer
    subgraph CoreSim
        Analysis["Circuit Analysis Engine"]
        Math["Mathematics Library"]
        XSPICE["XSPICE Integration"]
    end
    
    %% Device Layer
    subgraph Devices
        StandardDev["Standard Devices"]
        CIDER["CIDER Device Simulator"]
        XSPICEDig["XSPICE Digital Components"]
        CustomDev["Custom Device Models"]
    end
    
    %% External Interfaces
    subgraph Interfaces
        SharedLib["Shared Library Interface"]
        OSDI["OSDI Interface"]
        TCLTK["TCL/TK Interface"]
    end

    %% Relationships
    CLI --> Parser
    Parser --> Analysis
    Analysis --> Math
    Analysis --> StandardDev
    Analysis --> CIDER
    Analysis --> XSPICE
    XSPICE --> XSPICEDig
    Analysis --> Plot
    Analysis --> FileIO
    CLI --> Help
    StandardDev --> OSDI
    StandardDev --> CustomDev
    Plot --> TCLTK
    
    %% Component Mappings
    click CLI "https://github.com/imr/ngspice/tree/master/src/frontend/"
    click Parser "https://github.com/imr/ngspice/tree/master/src/spicelib/parser/"
    click Plot "https://github.com/imr/ngspice/tree/master/src/frontend/plotting/"
    click Help "https://github.com/imr/ngspice/tree/master/src/frontend/help/"
    click Analysis "https://github.com/imr/ngspice/tree/master/src/spicelib/analysis/"
    click StandardDev "https://github.com/imr/ngspice/tree/master/src/spicelib/devices/"
    click Math "https://github.com/imr/ngspice/tree/master/src/maths/"
    click XSPICE "https://github.com/imr/ngspice/tree/master/src/xspice/"
    click CIDER "https://github.com/imr/ngspice/tree/master/src/ciderlib/"
    click OSDI "https://github.com/imr/ngspice/tree/master/src/osdi/"
    click TCLTK "https://github.com/imr/ngspice/tree/master/src/frontend/wdisp/"
    click FileIO "https://github.com/imr/ngspice/blob/master/src/frontend/com_fileio.c"
    click XSPICEDig "https://github.com/imr/ngspice/tree/master/src/xspice/icm/digital/"
    click CustomDev "https://github.com/imr/ngspice/tree/master/src/spicelib/devices/adms/"

    %% Style Applications
    class CLI,Parser,Plot,Help,FileIO frontend
    class Analysis,Math,XSPICE core
    class StandardDev,CIDER,XSPICEDig,CustomDev device
    class SharedLib,OSDI,TCLTK external

    %% Legend
    subgraph Legend
        Frontend["Frontend Components"]:::frontend
        Core["Core Components"]:::core
        DeviceComp["Device Components"]:::device
        ExtInt["External Interfaces"]:::external
    end
```
