# linux-mobile-broadband/libqmi architecture

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

- Interactive diagram: https://gitdiagram.com/linux-mobile-broadband/libqmi
- Repository: https://github.com/linux-mobile-broadband/libqmi

## Overview

##### Major Components
- Library Layer:
– libqmi-glib (located in src/libqmi-glib) forms the core library for communication with QMI devices. It provides public APIs for the rest of the tools.
– Common modules (e.g., src/common) with shared QMI functionality.
- Tools / Client Applications:
– qmicli (src/qmicli): a command-line client that uses the libqmi API to send QMI commands.
– qmi-network (found under utils/qmi-network or similar): a tool for network management.
– qmi-firmware-update (src/qmi-firmware-update): which handles firmware updates over QMI.
– qmi-proxy (src/qmi-proxy): for proxying functions if needed.
- Gobi API Integration:
– Directories like gobi-api and its versions indicate application-specific integrations supporting specific modems (e.g., Gobi devices).
- Build and Code Generation Tools:
– The build-aux directory, which contains scripts and code generators (qmi-codegen and mkenums), as well as a set of templates.
- Data Definitions:
– The data directory with various JSON files (e.g., qmi-common.json, qmi-service-*.json), which likely feed into code generators or document supported protocols.
- Documentation and Examples:
– docs, examples, and test directories provide usage examples and verification of functionality.

##### Relationships and Interactions
- The command-line tools (qmicli, qmi-network, etc.) depend on and invoke routines from the library (libqmi-glib).
- The library itself leverages the lower-level common modules and possibly hardware-specific integrations (as seen in the Gobi API directories).
- Build and code generation scripts (in build-aux) are used in creating parts of the library (such as enum and flag definitions) using data from the JSON files in the data directory.
- There is a clear separation between the core protocol handling and the vendor-specific extensions (Gobi API) that abstract hardware-specific communication.
- The meson.build files scattered throughout illustrate the build system dependency: each component is built and linked together during the compilation process.

##### Architectural Patterns and Principles
- Modular Design: Separation between the core library (libqmi-glib) and the tools that use it.
- Layered Architecture: Application layer (command-line tools) above the library layer, which then interfaces with lower-level hardware interfacing.
- Extensibility: The use of code generation and templating (e.g., in build-aux and data directories) suggests that many parts of the API are autogenerated to ease updates and integration.
- Vendor-Specific Extensions: The multiple versions of Gobi API implementations indicate that the project is built to support different vendor devices through modular inclusions.

##### Relevant Technologies
- Glib (since it is glib-based).
- C for the core libraries and tools (as indicated by the .c and .h files).
- Meson build system (meson.build files indicate the chosen build configuration).
- Python (via some scripts in the build-aux/qmi-codegen directory and utilities under utils/qmidb).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data & Build Layer
    subgraph "Data & Build Layer"
        J["Data Definitions"]:::database
        subgraph "Build & Code Generation"
            H["Code Generators"]:::build
            I["Templates"]:::build
        end
    end

    %% Library Layer
    subgraph "Library Layer"
        A["libqmi-glib (Core Library)"]:::library
        B["Common Modules"]:::library
    end

    %% Command-Line Tools
    subgraph "Command-Line Tools"
        C["qmicli"]:::tool
        D["qmi-network"]:::tool
        E["qmi-firmware-update"]:::tool
        F["qmi-proxy"]:::tool
    end

    %% Vendor Extensions
    subgraph "Vendor Extensions"
        G["Gobi API"]:::vendor
    end

    %% Documentation & Examples
    subgraph "Documentation & Examples"
        K["Docs"]:::docs
        L["Examples"]:::docs
    end

    %% Connections from Data to Build
    J --> H
    J --> I

    %% Connections from Build to Library
    H --> A
    I --> A

    %% Library internal connection
    A -->|"uses"| B

    %% Library to Command-Line Tools connections
    A -->|"dependency"| C
    A -->|"dependency"| D
    A -->|"dependency"| E
    A -->|"dependency"| F

    %% Library to Vendor Extensions
    A -->|"integrates"| G

    %% Tools to Documentation connection (usage guidelines)
    C -->|"documented_in"| K
    D -->|"documented_in"| K
    E -->|"documented_in"| K
    F -->|"documented_in"| K

    %% Library also links to Examples
    A -->|"example_usage"| L

    %% Click Events
    click A "https://github.com/linux-mobile-broadband/libqmi/tree/main/src/libqmi-glib"
    click B "https://github.com/linux-mobile-broadband/libqmi/tree/main/src/common"
    click C "https://github.com/linux-mobile-broadband/libqmi/tree/main/src/qmicli"
    click D "https://github.com/linux-mobile-broadband/libqmi/blob/main/utils/qmi-network.in"
    click E "https://github.com/linux-mobile-broadband/libqmi/tree/main/src/qmi-firmware-update"
    click F "https://github.com/linux-mobile-broadband/libqmi/tree/main/src/qmi-proxy"
    click G "https://github.com/linux-mobile-broadband/libqmi/tree/main/gobi-api"
    click H "https://github.com/linux-mobile-broadband/libqmi/tree/main/build-aux/qmi-codegen"
    click I "https://github.com/linux-mobile-broadband/libqmi/tree/main/build-aux/templates"
    click J "https://github.com/linux-mobile-broadband/libqmi/tree/main/data"
    click K "https://github.com/linux-mobile-broadband/libqmi/tree/main/docs"
    click L "https://github.com/linux-mobile-broadband/libqmi/tree/main/examples"

    %% Styles
    classDef library fill:#AEDFF7,stroke:#000,stroke-width:2px;
    classDef tool fill:#C3F7C2,stroke:#000,stroke-width:2px;
    classDef vendor fill:#F7C2C2,stroke:#000,stroke-width:2px;
    classDef build fill:#F7E7C2,stroke:#000,stroke-width:2px;
    classDef database fill:#FFFFCC,stroke:#000,stroke-width:2px;
    classDef docs fill:#E2E2E2,stroke:#000,stroke-width:2px;
```
