MedMatrix (also known as KVISION) is an enterprise-grade clinical MRI volumetric analysis, k-space anomaly detection, digital brain twin simulation, and automated reporting platform. Built inside a modular pnpm monorepo, it seamlessly couples state-of-the-art Deep Learning (Hybrid S4 State-Space Models + Spatial Convolutions) with high-performance native compute engines (C++ ONNX Runtime and Rust FFT reconstruction) and a Syngo-themed clinical desktop console (Electron + React).
MedMatrix operates an automated, two-tier AI cascade to optimize compute budget while ensuring high diagnostic quality on raw multi-coil MRI acquisition streams.
graph TD
A[DICOM / Raw K-Space Upload] --> B[MinIO S3 Storage: 'kspace-raw']
B --> C[BullMQ Enqueue Processing Job]
C --> D[TypeScript Background Worker]
D --> E[Axios AIServiceClient.predict]
E --> F[FastAPI /predict Endpoint]
F --> G[Reconstruct Magnitude Image]
G --> H[CNN Artifact Classifier]
H --> I{"Composite score >= 0.5?"}
I -- Yes: Anomaly Detected --> J[Trigger Image Encoder: Motion Correction & Denoising]
J --> K[Upload reconstructed.npy to 'reconstructed' bucket]
K --> L[Return full classification scores + report metadata]
I -- No: Clean Scan --> M[Bypass secondary image models to save compute]
M --> N[Return gating decision: skip image encoder]
L & N --> O[Persist ModelResult, AnomalyDetection & GatingDecision in PostgreSQL via Prisma]
O --> P[Compile PDF Report draft using Rust Engine]
P --> Q["Mark Study Status: Complete in Electronic Health Record (EHR)"]
- β‘ Two-Tier AI Gating Cascade: Automatically detects hardware artifacts and scan corruption (ghosting, wrap-around, zipper noise) prior to heavy model execution. Clean scans bypass computationally expensive modules to maintain high patient throughput.
- π§ Hybrid Fused S4-CNN Volumetric Classifier: Merges complex-domain frequency sequence analysis (Diagonal State Space Model - S4D) with spatial magnitude slice representations via Slice-Level Cross-Attention. Achieves 88.28% validation accuracy across 11 pathology classes with only ~281k parameters (vs ~67M in traditional 3D CNNs).
- π SSM-Based K-Space Anomaly Estimator: Real-valued diagonal State Space Model reading multi-coil raw complex K-space data row-by-row to predict continuous regression metrics for noise severity, motion blur, and phase corruption.
- π C++ ONNX Runtime Engine: Native C++ executables (
kvision::InferenceEngine&kvision::AnomalyDetectorEngine) compiled with CMake and CUDA GPU support, achieving up to 84.8 inferences/second. - π¦ Native Rust MRI Reconstruction & PDF Engine: Phase-corrected 2D centered IFFT slice reconstruction module coupled with a high-speed, native clinical PDF report generator.
- π» Syngo-Themed Clinical Desktop App: Electron desktop console adhering to modern clinical Syngo UI design guidelines. Includes raw DICOM ingestion, Cornerstone3D multi-planar viewers, frequency domain k-space visualizers, and Digital Brain Twin node graphs.
- 𧬠Synthetic Data & Phantom Generation (
data-gen): Complete Python simulation suite for generating multi-coil k-space arrays, numerical brain phantoms (PhantomNet), and benchmark pathology datasets.
Provides interactive 3D mesh renderings overlaying tumor volumes, hemorrhage regions, and lesion nodes using Three.js and VTK.js.
Multi-planar slice viewer powered by Cornerstone3D, featuring seamless scrolling across axial, sagittal, and coronal slice planes with AI segmentation overlays.
The MedMatrix repository is organized as a workspace monorepo managed with pnpm.
Med_Matrix/
βββ π³ docker-compose.yml <- Infrastructure orchestration (Postgres, Redis, MinIO)
βββ π€ ai-service/ <- Python FastAPI + PyTorch AI microservice
β βββ βοΈ inference/ <- C++ ONNX Runtime Inference Engine (CMake)
βββ π± apps/
β βββ π₯οΈ electron/ <- Electron + React + TypeScript clinical desktop application
β βββ π backend/ <- Node.js Express server + Prisma ORM + BullMQ worker
βββ 𧬠data-gen/ <- Synthetic MRI & PhantomNet data generator
βββ π¦ rust-mri/ <- High-speed Rust reconstruction & PDF compiler
βββ π¦ packages/
βββ βοΈ config/ <- Shared ESLint, Prettier, and TypeScript configurations
βββ π§© shared-types/ <- Shared TypeScript interfaces across client and backend
- ai-service/README.md β Python AI microservice, PyTorch architectures, and FastAPI endpoints.
- ai-service/inference/README.md β High-performance C++ ONNX Runtime engine & builds.
- apps/backend/README.md β Express REST API, Prisma ORM schema, PostgreSQL DB, and BullMQ worker queues.
- apps/electron/README.md β Electron desktop UI client structure, Cornerstone3D, and Digital Brain Twin components.
- data-gen/README.md β Synthetic MRI k-space generation and PhantomNet phantom pipeline.
- rust-mri/README.md β Native Rust FFT slice reconstruction and PDF report compiler.
- packages/README.md β Shared configurations and TypeScript types index.
- Node.js: v20+ and pnpm installed globally (
npm install -g pnpm) - Python: v3.10+ with
pip - Docker & Compose: For running backing database and storage services
- C++ Compiler: GCC / Clang, CMake 3.18+, pkg-config
- Rust: Cargo and rustc (edition 2021)
- ONNX Runtime C++ Shared Libraries: Installed on host system (e.g.
onnxruntime-cuda)
Launch PostgreSQL, Redis, and MinIO storage containers:
docker-compose up -dService ports:
- PostgreSQL:
localhost:5432(database:medmatrix) - Redis:
localhost:6379 - MinIO Console:
localhost:9001(S3 API:localhost:9000)
Copy the root environment template:
cp .env.example .envEnsure DB, Redis, and MinIO credentials align with your local configuration.
Install Node dependencies and synchronize the Prisma database schema:
pnpm install
cd apps/backend
npx prisma db push
cd ../..Create a virtual environment and install requirements:
cd ai-service
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtTo launch the FastAPI service on port 8000:
uvicorn main:app --reload --host 0.0.0.0 --port 8000API Documentation will be accessible at http://localhost:8000/docs.
Build the high-throughput native C++ inference engine:
cd ai-service/inference
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)Run validation unit tests:
./test_inference
./test_anomaly_detector_inferenceCompile the Rust slice reconstruction binary and PDF generator:
cd rust-mri
cargo build --releaseTo synthesize demo patients and phantom previews:
python data-gen/generate_demo_patients.py
python data-gen/generate_phantomnet_demo.pyFrom the monorepo root, start the backend server and BullMQ processing worker:
pnpm --filter backend devLaunch the Electron clinical console:
pnpm --filter electron devThis project is licensed under the Apache License 2.0. See the LICENSE file for details.


