Modular fluorescence-imaging analysis stack combining a Next.js TypeScript frontend/API with a Python worker that runs watershed-based segmentation, Frangi filtering, and dendrite skeleton metrics.
.
├── analysis/ # Runtime storage for uploads/results (gitignored)
├── components/ # UI components shared across pages
├── lib/ # Node/Next helpers (paths, OpenAI client, schemas)
├── pages/ # Next.js routes and API endpoints
├── public/ # Static assets placeholder
├── scripts/ # Environment bootstrap helpers
└── worker/ # Python analysis package
- Upload & job orchestration happens in
pages/api/upload.ts. Multipart uploads are written toanalysis/uploads/<jobId>and a detached Python worker process (python -m worker.cli) runs asynchronously so API requests remain responsive. - Result retrieval lives in
pages/api/results/[jobId].ts, using Zod validation to enforce schema integrity. File passthrough is exposed at/results/:jobId/*via a Next.js rewrite topages/api/results/[jobId]/files/[...path].ts. - Observations are generated in
pages/api/observations/[jobId].tsthrough OpenAI Responses, turning metric payloads into narrative lab notes. - Python worker modules under
worker/load TIFF/JPEG stacks, perform watershed segmentation and Frangi-based skeleton analysis, and emit JSON + CSV summaries together with mask/overlay artifacts.
- Node.js 18+
- Python 3.10+
- OpenAI API key (for AI observations)
npm installUse the provided helper for your shell:
bash scripts/bootstrap_worker.sh
# or on Windows PowerShell
pwsh scripts/bootstrap_worker.ps1This creates worker/.venv and installs the required scientific stack (numpy, pandas, scikit-image, opencv-python-headless).
Copy the example file and add your OpenAI key:
cp .env.local.example .env.local
# Edit .env.local to add OPENAI_API_KEYIn one terminal start Next.js:
npm run devIn another terminal activate the worker virtualenv if needed for manual debugging (the API spawns it automatically for jobs):
source worker/.venv/bin/activate
python -m worker.cli --job-id demo --input analysis/uploads/demo --output analysis/results/demo- Visit
http://localhost:3000and upload a folder of TIFF/JPEG images. - The API stores files, spawns the worker, and immediately returns a
jobId. - Open
http://localhost:3000/jobs/<jobId>to monitor. Oncesummary.jsonis produced, the UI shows metrics, download links, and an AI observation button.
| Command | Description |
|---|---|
npm run dev |
Start Next.js dev server |
npm run build |
Build the production bundle |
npm run start |
Run the compiled Next.js server |
npm run worker |
Execute the Python worker module manually |
bash scripts/bootstrap_worker.sh |
Bootstrap Python virtual environment |
pwsh scripts/bootstrap_worker.ps1 |
Windows PowerShell equivalent |
- The
analysis/uploadsandanalysis/resultsdirectories are ignored by git to prevent leaking user data. - Long-running processing is isolated in a detached worker so that API routes remain non-blocking.
- Zod schemas enforce the structure of
summary.jsonbefore results are surfaced to the UI.