# google-ai-edge/model-explorer architecture

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

- Interactive diagram: https://gitdiagram.com/google-ai-edge/model-explorer
- Repository: https://github.com/google-ai-edge/model-explorer

## Overview

##### Project Type and Purpose
- Model Explorer is a visualization and debugging tool for deep learning model graphs. Its purpose is to allow users to explore, debug, and analyze models (supporting formats such as TFLite, TF, TFJS, MLIR, and PyTorch Exported Program) by converting them into hierarchical JSON graphs.
- It comes in two primary distributions: a Python package (installed via pip) that runs a CLI/server and a separate UI component (available as an npm package).
- The project also supports an extension framework for developing additional adapters, which are implemented both as built-in adapters (in C++ and Python under src/builtin-adapter) and as separate example adapters (under src/example_adapters).

##### Analyzing the File Structure – Key Components
- CI/CD Setup:
- Core Backend/Server:
- Under src/server, you have the backend portion with a “package” that includes a “model_explorer” module. It contains key components such as server.py, API endpoints (apis.py), adapter orchestrators (adapter_runner.py), and extension managers.
- This layer is responsible for processing model data, running adapter conversions, and exposing the results.
- Adapters:
- The src/builtin-adapter directory holds conversion tools (in both C++ and Python) that convert several model graph formats into a common JSON representation.
- The extensions and source-level tools (like translate_helpers.cc, graphnode_builder.h, etc.) indicate a modular design where each adapter implements a specific conversion pipeline.
- Example adapters (src/example_adapters) demonstrate how third-party or experimental adapters can be plugged in.
- Frontend/UI:
- The src/ui directory is dedicated to the visual component, built with Angular (as indicated by angular.json, TypeScript files, and numerous Angular template files). This UI interacts with the backend and renders the visualization of model graphs.
- Additionally, there is a custom element package (src/ui/custom_element_npm) that showcases how the core visualizer is provided as an npm package.
- There are demo pages in various formats (in src/custom_element_demos: Angular, Next.js, Vanilla JS/TS) which illustrate how the visualization component can be integrated into different web applications.
- Testing and Examples:
- The test directory includes models and screenshot “golden” files used for regression testing, indicating that the system’s visual output is also part of its quality assurance.
- Example notebooks (in example_colabs) present quick-start demos for users in interactive environments (like Colab).

##### Relationships and Interactions
- The Backend layer acts as a coordinator:
– It receives model files/input through a CLI or API.
– It then utilizes the built-in adapters (and can dynamically integrate external adapters) to convert model files into JSON graphs.
– The converted data is then served to the UI.
- CI/CD Components: show a background “DevOps” layer that continuously tests, builds, and deploys both the backend and the UI using GitHub workflows, bash helpers, etc.

##### Architectural Patterns and Design Principles
- Layered architecture: You have a clear separation between the presentation layer (UI), the business logic processing layer (server and adapters), and the development/operations layer (CI/CD scripts).
- Modular design: The adapters are developed as discrete modules, which facilitates extension (e.g., “Develop Adapter Extension” guide in the README) and testing.
- Micro-frontend potential: The multiple demo approaches (Angular, Next.js, Vanilla JS/TS) suggest that the UI part is built to provide flexible integration with various front-end technologies.
- Use of build systems: Presence of Bazel (BUILD files) in various directories indicates that some components are built and managed using Bazel which might influence component interdependencies.

##### Elements
- Clear labels for each major component (Frontend/UI, Backend/Server, Builtin/Example Adapters, CI/CD Pipelines).
– Model ingestion / conversion pipeline (model file to JSON graph).
– API communication between the server and UI.
– Use another for frontend components (e.g., rounded rectangles or components with Angular logos).

##### Final Suggestions
- Be as detailed as possible—include every component that impacts the end-to-end flow of model visualization.
- Do not shy away from compartmentalizing elements further (for instance, split the adapter subsystem into conversion utilities, extension management, and example implementations).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% DevOps / CI/CD Layer
    subgraph "DevOps / CI/CD Layer"
        DEVOPS["CI/CD Pipelines"]:::devops
        TESTING["Testing and Regression"]:::test
    end

    %% Service / Logic Layer
    subgraph "Service / Logic Layer"
        MODEL_INPUT["Model Input"]:::backend
        SERVER["Model Explorer Server"]:::backend
        BUILTIN["Builtin Adapters"]:::adapter
        EXAMPLE["Example/Custom Adapters"]:::adapter
    end

    %% Presentation / UI Layer
    subgraph "Presentation / UI Layer"
        UI["Angular UI (Model Graph Visualizer) & Custom Element NPM"]:::frontend
        UIDEMO["UI Demos (Additional Frontend Integrations)"]:::frontend
        COLABS["Demo Notebooks/Examples"]:::frontend
    end

    %% Data Flow Connections
    MODEL_INPUT -->|"input"| SERVER
    SERVER -->|"runs_conversion"| BUILTIN
    SERVER -->|"runs_conversion"| EXAMPLE
    BUILTIN -->|"returns_JSON"| SERVER
    EXAMPLE -->|"returns_JSON"| SERVER
    SERVER -->|"API_data"| UI
    UI -->|"integrates"| UIDEMO
    UI -->|"demo_usage"| COLABS

    %% DevOps Interactions
    DEVOPS -->|"build_deploy"| SERVER
    DEVOPS -->|"build_deploy"| UI
    TESTING -->|"regression"| SERVER
    TESTING -->|"regression"| UI

    %% Click Events
    click DEVOPS "https://github.com/google-ai-edge/model-explorer/tree/main/.github/workflows"
    click SERVER "https://github.com/google-ai-edge/model-explorer/tree/main/src/server/package/src/model_explorer/"
    click BUILTIN "https://github.com/google-ai-edge/model-explorer/tree/main/src/builtin-adapter"
    click EXAMPLE "https://github.com/google-ai-edge/model-explorer/tree/main/src/example_adapters"
    click UI "https://github.com/google-ai-edge/model-explorer/tree/main/src/ui"
    click COLABS "https://github.com/google-ai-edge/model-explorer/tree/main/example_colabs"
    click UIDEMO "https://github.com/google-ai-edge/model-explorer/tree/main/src/custom_element_demos"
    click TESTING "https://github.com/google-ai-edge/model-explorer/tree/main/test"

    %% Styles
    classDef devops fill:#FFCC80,stroke:#666,stroke-width:1px;
    classDef backend fill:#BBDEFB,stroke:#666,stroke-width:1px;
    classDef adapter fill:#FFF9C4,stroke:#666,stroke-width:1px;
    classDef frontend fill:#C8E6C9,stroke:#666,stroke-width:1px;
    classDef test fill:#E1BEE7,stroke:#666,stroke-width:1px;
```
