# vendenix/brainmetasegmentatorui-front architecture

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

- Interactive diagram: https://gitdiagram.com/vendenix/brainmetasegmentatorui-front
- Repository: https://github.com/vendenix/brainmetasegmentatorui-front

## Overview

The SegmentationUI project is the front-end part of a system designed to empower an OHIF Viewer–based interface to drive a deep learning model (built on UNETR) for the segmentation of brain metastases. The overall architecture enables radiotherapists to interact with DICOM data in a web-based viewer, launch segmentation processes via backend APIs, and then view and manage segmentation outputs and patient tracking results.

##### Main Components
- Client (Web Browser/UI):
– The OHIF Viewer-based interface (the “Viewers-3.7.0” folder contains the editor, extensions, patient tracking and measurement modules).
– Custom extensions such as the MetIA extension, segmentation modules (e.g., for RTStruct creation or modification), patient tracking interface, and deep learning launch control.
- API Integration Layer in Front-end:
– Modules (often under “platform/app” and “extensions”) abstract communication with the back-end REST endpoints.
- Back-end API (external component – note that its repository is linked in the README):
– A REST API (likely built with Flask) to process DICOM data and control the deep learning segmentation.
– A PACS / Orthanc DICOM Web Server backend (possibly deployed via Docker, as described).
- Supporting Infrastructure:
– Node.js server-side code (in server.js) that can serve a production build (from “platform/app/dist”).
– Build and configuration tools (yarn/npm, webpack, Docker configuration files, CI/CD scripts, etc.).

##### Relationships and Interactions
– The Client (browser) interacts with the OHIF Viewer and its embedded custom segmentation modules. When the user initiates segmentation of a study or selects a patient for tracking, the front-end modules make API calls to the back-end.
– The API integration layer in the front-end handles these calls – retrieving DICOM studies, initiating deep learning inference, and receiving segmentation results (such as RTStruct data).
– The back-end completes the heavy lifting by running the UNETR segmentation algorithm on DICOM images. It then returns results that the front-end uses to update the viewer.
– The server.js component acts as the gateway for production deployments to serve static assets and handle any express-based routing for development.
– Additional modules in “platform” and “extensions” likely facilitate configuration management, routing in different “modes” (e.g., segmentation, longitudinal studies, microscopy) and the integration of patient tracking features.

##### Architectural Patterns & Principles
– Modular Design: The project is divided into well-defined directories for “extensions”, “modes”, “platform/core” and “platform/ui”. This suggests a component-based and plugin-oriented architecture where new functionalities (for example deep learning segmentation, patient tracking) are added as extensions.
– Separation of Concerns: The front-end strictly deals with visualization and user interactions while delegating segmentation computations and data persistence to external back-end services.
– API-Driven Integration: Calls from the web client via REST APIs ensure a clean decoupling between the UI and backend services (Orthanc server, Flask API).

##### Technologies & Frameworks
– OHIF Viewer (customized): Built on React, with many components in the “platform/ui” and “extensions”. It is enhanced with extensions to support segmentation, measurement, and patient tracking.
– Node.js with npm/yarn for dependency and build management.
– Docker (in the backend documentation) to deploy Orthanc, nginx, and the Flask API.
– Deep learning model based on UNETR implemented in PyTorch (though that resides on the backend side).

- Clear labels for each major component (Client/UI, API Integration, Back-end API, DICOM Web Server).
– User actions initiating API calls from the viewer.
– API responses updating state and UI components.
– Client-side components (React/JavaScript modules)
– Server-side services (Node.js, Express)
– External services (DICOM Web Server, Dockerized back-end API)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client (Web Browser/UI)"
        A["OHIF Viewer UI"]:::client
        B["Segmentation Mode"]:::client
    end

    subgraph "Custom Extensions"
        C["MetIA Extension"]:::extension
        D["RTStruct Extension"]:::extension
    end

    subgraph "API Integration Layer"
        E["DICOMWeb Module"]:::integration
        F["API Routes"]:::integration
    end

    subgraph "Supporting Infrastructure"
        G["Production Server (Node.js)"]:::server
        H["Build & Config Tools"]:::server
    end

    I["Back-end API"]:::external
    J["DICOM Web Server (Orthanc)"]:::external

    %% Client interactions with custom extensions
    A -.->|"enhancement"| C
    A -.->|"enhancement"| D

    %% Client initiating API calls
    A -->|"apiCall"| E
    B -->|"apiCall"| F

    %% API Integration contacting the back-end API
    E -->|"calls"| I
    F -->|"calls"| I

    %% Back-end API interactions
    I -->|"queries"| J
    I -->|"returns"| E

    %% API Integration Layer updates the Client UI
    E -->|"updates"| A

    %% Production server and build configuration
    H -->|"buildDeploy"| G
    G -->|"servesAssets"| A

    %% Classes
    classDef client fill:#AEDFF7,stroke:#1f78b4,stroke-width:2px;
    classDef extension fill:#FFE599,stroke:#B58900,stroke-width:2px;
    classDef integration fill:#C6EFCE,stroke:#008000,stroke-width:2px;
    classDef server fill:#F4CCCC,stroke:#E06666,stroke-width:2px;
    classDef external fill:#D9D9D9,stroke:#7F7F7F,stroke-width:2px;

    %% Click Events
    click A "https://github.com/vendenix/brainmetasegmentatorui-front/tree/main/Viewers-3.7.0/platform/ui"
    click B "https://github.com/vendenix/brainmetasegmentatorui-front/tree/main/Viewers-3.7.0/modes/segmentation"
    click C "https://github.com/vendenix/brainmetasegmentatorui-front/tree/main/Viewers-3.7.0/extensions/MetIA"
    click D "https://github.com/vendenix/brainmetasegmentatorui-front/tree/main/Viewers-3.7.0/extensions/cornerstone-dicom-seg"
    click E "https://github.com/vendenix/brainmetasegmentatorui-front/tree/main/Viewers-3.7.0/platform/core/src/DICOMWeb"
    click F "https://github.com/vendenix/brainmetasegmentatorui-front/tree/main/Viewers-3.7.0/platform/app/src/routes"
    click G "https://github.com/vendenix/brainmetasegmentatorui-front/blob/main/Viewers-3.7.0/server.js"
    click H "https://github.com/vendenix/brainmetasegmentatorui-front/blob/main/Viewers-3.7.0/package.json"
```
