Integration Document

REST API specification, external dependencies, data formats, and inter-module communication for the MICRO platform.

1. Overview

MICRO follows a monolithic-with-clean-boundaries architecture. A single Flask process serves the web UI, REST API, and simulation engines. All data is stored in JSON files on disk — no external database is required.

The platform exposes a RESTful API for programmatic access to instruments, specimens, phantoms, and rendering endpoints. All responses are JSON-encoded.

2. REST API Specification

Base URL

http://localhost:5001 (development)  |  Configure port in run.py

Instrument Endpoints

MethodEndpointDescription
GET/api/instrumentsList all instruments. Filter with ?category= and ?manufacturer=
GET/api/search?q=Full-text search across instrument names and manufacturers
GET/api/statsAggregate statistics (counts by category, manufacturer totals)

Specimen & Phantom Endpoints

MethodEndpointDescription
GET/api/specimensList all specimen types with stains and categories
GET/api/phantomsList all anatomical phantoms with tissue layers

Rendering Endpoints

MethodEndpointBody Fields
POST /api/render/microscope manufacturer_key, model_key, specimen_id, magnification, illumination, stain, focus, pan_x, pan_y, brightness, contrast
POST /api/render/imaging manufacturer_key, model_key, phantom_id, modality_params, pan_x, pan_y, brightness, contrast

Response Format

Render endpoints return:

{
  "image": "<base64-encoded PNG>",
  "info": {
    "model": "...",
    "manufacturer": "...",
    ...modality-specific metadata
  }
}
3. External Dependencies

Python Packages

PackageVersionPurpose
flask3.1.3Web server framework and routing
numpy2.4.3Array operations, image pixel manipulation
scipy1.17.1Gaussian filtering, signal processing
Pillow12.1.1Image encoding (array → PNG bytes)
openai2.28.0AI image generation API client (backlogged)

Client-Side CDN Libraries

LibraryPurpose
Font Awesome 6.5.1Icon set for UI elements

Browser APIs

  • Fetch API — AJAX calls to REST endpoints
  • Canvas 2D — Image display in viewers (via <img> elements)
  • LocalStorage — Bug tracker persistence, user preferences
4. Data Formats

Instrument JSON Schema

{
  "manufacturer": "string",
  "model": "string",
  "category": "microscope|ct|mri|ultrasound|...",
  "type": "string (subtype)",
  "specifications": { ... category-specific },
  "imaging_modes": ["string"],
  "product_url": "string (URL)"
}

Specimen JSON Schema

{
  "id": "string",
  "name": "string",
  "category": "hematology|histology|microbiology|...",
  "stains": ["unstained", "h_and_e", "gram", ...],
  "features": { ... specimen characteristics }
}

Phantom JSON Schema

{
  "id": "string",
  "name": "string",
  "description": "string",
  "tissue_layers": [
    { "name": "string", "density": float, ... }
  ]
}
5. Deployment

Local Development Setup

  1. python -m venv .venv — Create virtual environment
  2. .venv\Scripts\activate — Activate (Windows)
  3. pip install flask numpy scipy Pillow openai — Install dependencies
  4. python run.py — Start server on port 5001
  5. Open http://localhost:5001 in browser

Environment Variables

VariablePurposeRequired
OPENAI_API_KEYAPI key for AI image generationOptional (for image generation only)

File Structure

MICRO/
├── data/
│   ├── instruments/       # 16 manufacturer JSON files
│   ├── specimens/         # 15 specimen type JSONs
│   ├── phantoms/          # 8 anatomical phantom JSONs
│   ├── image_prompts/     # AI prompt catalog
│   └── generated_images/  # AI-generated images (output)
├── micro/
│   ├── instruments/       # Registry, simulators
│   ├── specimens/         # Specimen registry
│   ├── phantoms/          # Phantom registry
│   ├── images/            # Image library
│   └── web/               # Flask server, templates, static
├── generate_images.py     # AI image generation script
└── run.py                 # Application entry point
6. Inter-Module Communication

Data Flow

  1. Browser → Flask — HTTP request (page route or API call)
  2. Flask → Registry — Query instruments/specimens/phantoms from in-memory index
  3. Flask → Simulator — Pass instrument + specimen/phantom + parameters
  4. Simulator → ImageLibrary — Check for AI-generated image (optional)
  5. Simulator → NumPy — Procedural rendering fallback (array operations)
  6. NumPy → Pillow — Encode array as PNG bytes
  7. Flask → Browser — Return base64-encoded PNG in JSON response

Dependency Graph

server.py
  ├── InstrumentRegistry  ← data/instruments/*.json
  ├── SpecimenRegistry    ← data/specimens/*.json
  ├── PhantomRegistry     ← data/phantoms/*.json
  ├── MicroscopeSimulator ← ImageLibrary
  └── ImagingSimulator    ← ImageLibrary