Skip to content

Repository files navigation

Medical Platform Backend

An AI-powered healthcare platform that connects patients with doctors, supports medical-image analysis (brain & bone scans), insurance eligibility via Zero-Knowledge Proofs, and immutable audit trails on Hyperledger Fabric.

This repository contains the backend API — the central orchestration layer that ties together AI services, blockchain, and the frontend.


Architecture

┌──────────────────────────────────────────────────────────────────────┐
│                         SYSTEM ARCHITECTURE                          │
├──────────────────────────────────────────────────────────────────────┤
│                                                                      │
│  ┌─────────────┐     ┌──────────────────────────────────────────┐   │
│  │   Frontend   │────▶│           Backend API (Express)          │   │
│  │  React+Vite  │◀────│   Port 9000 │ Swagger Docs :8082        │   │
│  └─────────────┘     └──────────┬───────┬───────┬───────────────┘   │
│                                 │       │       │                    │
│                    ┌────────────┘       │       └────────────┐      │
│                    ▼                    ▼                    ▼      │
│           ┌──────────────┐    ┌──────────────┐    ┌──────────────┐  │
│           │  AI Brain    │    │   AI Bone    │    │  AI Chatbot  │  │
│           │  FastAPI     │    │   FastAPI    │    │  FastAPI     │  │
│           │  YOLOv8      │    │   Bone       │    │  Groq LLM    │  │
│           │  :8000       │    │   :5001      │    │  :9090       │  │
│           └──────────────┘    └──────────────┘    └──────────────┘  │
│                                                                      │
│           ┌──────────────┐    ┌──────────────────────────────────┐  │
│           │  MySQL 9.0   │    │   Hyperledger Fabric 2.5         │  │
│           │  Prisma ORM  │    │   3 Orgs │ 4 Peers │ 3 Channels  │  │
│           │  :3307       │    │   Raft Consensus │ CouchDB       │  │
│           └──────────────┘    └──────────────────────────────────┘  │
│                                                                      │
│           ┌──────────────────────────────────────────────────────┐  │
│           │              Zero-Knowledge Layer                    │  │
│           │   circom Circuits │ snarkjs Groth16 Prover/Verifier  │  │
│           └──────────────────────────────────────────────────────┘  │
└──────────────────────────────────────────────────────────────────────┘

Tech Stack

Layer Technology
Runtime Node.js 18 + TypeScript
Framework Express.js
ORM Prisma
Database MySQL 9.0
Auth JWT + bcrypt
AI Services FastAPI (Python 3.9)
AI Models YOLOv8 (brain/bone scans)
LLM Groq API (chatbot)
Blockchain Hyperledger Fabric 2.5
ZKP circom + snarkjs (Groth16)
Containerization Docker + Docker Compose
Frontend React + Vite (TypeScript)
API Docs Swagger UI

Services

Backend API (:9000)

The central orchestration service. Handles authentication, user management, appointments, messaging, reports, and bridges all external services.

Module Description
Auth JWT authentication, email verification, bcrypt password hashing
Users Multi-role management (Patient, Doctor, Admin, Hospital, Insurance)
Appointments Scheduling and tracking doctor-patient appointments
Chat Real-time messaging between doctors and patients
Reports Medical scan report management with AI integration
Blockchain Fabric SDK integration for on-chain operations
Consent Patient-controlled data access granting/revoking
ZKP Zero-Knowledge Proof generation and verification

AI Brain (:8000)

Brain scan analysis service built with FastAPI and YOLOv8.

  • Accepts brain scan images (MRI/CT)
  • Runs YOLOv8 object detection for anomaly detection
  • Returns detection results with bounding boxes and confidence scores
  • Generates annotated images and heatmaps
  • Produces PDF reports with preliminary diagnosis

AI Bone (:5001)

Bone scan analysis service built with FastAPI.

  • Accepts bone X-ray/scan images
  • Analyzes fractures, abnormalities, and conditions
  • Returns diagnosis text and detection data
  • Generates result images with annotations

AI Chatbot (:9090)

Medical consultation chatbot powered by Groq LLM.

  • Accepts patient medical questions
  • Uses Groq API for fast LLM inference
  • Provides medical information and guidance
  • Maintains chat history per session
  • Built on top of AI Brain base image for shared dependencies

Hyperledger Fabric Network

Private blockchain network for immutable medical record audit trails.

Component Count Purpose
Organizations 3 Hospital, Insurance, Regulator
Peers 4 2 Hospital + 1 Insurance + 1 Regulator
Channels 3 medical, insurance, regulator
Smart Contracts 4 medical, insurance, consent, audit
Orderer 1 Raft consensus
CouchDB 4 State database (1 per peer)

Key Features:

  • Report hash storage and integrity verification
  • Insurance eligibility verification on-chain
  • Patient consent management (grant/revoke)
  • Full audit trail for every report access
  • Read-only regulator peer for compliance oversight

Zero-Knowledge Layer

Privacy-preserving verification using ZKPs.

Circuit Purpose
diagnosis-exists Prove a diagnosis exists without revealing it
report-valid Prove a report is valid without showing contents
insurance-eligible Prove insurance eligibility without sharing medical data
consent-prove Prove consent was granted without revealing details

Flow: circom circuit → snarkjs Groth16 prover → on-chain verification via Fabric


Docker Setup

Services

Service Container Port Description
backend medical_backend 9000, 5555 Node.js Express API
db medical_db 3307 MySQL 9.0 database
ai-brain ai_brain 8000 Brain scan analysis
ai-bone ai_bone 5001 Bone scan analysis
ai-chatbot ai_chatbot 9090 Medical chatbot
frontend medical_frontend 5173 React web app
docs medical_docs 8082 Swagger UI
zkp-setup medical_zkp_setup Circuit compilation

Volumes

Volume Purpose
mysql_data Persistent MySQL data
ai_brain_data AI Brain model/database cache
ai_bone_data AI Bone results storage
ai_chatbot_data Chatbot session data

Network

  • Backend connects to fablo_network_202607012331_basic (external) for Fabric communication
  • Fabric crypto material mounted read-only at /crypto

Getting Started

Prerequisites

  • Node.js 18+
  • Docker & Docker Compose
  • Hyperledger Fabric network running (cd fabric && ./fablo.sh up)

Environment Variables

Create .env file in the medical/ directory:

# Server
NODE_ENV=development
PORT=9000

# Database
MYSQL_ROOT_PASSWORD=your_root_password
MYSQL_DATABASE=medical_db
MYSQL_USER=your_user
MYSQL_PASSWORD=your_password
DATABASE_URL=mysql://root:your_root_password@db:3306/medical_db

# JWT
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=7d

# Email
SMTP_HOST=your_smtp_host
SMTP_PORT=587
SMTP_USER=your_smtp_user
SMTP_PASS=your_smtp_password

# AI Chatbot
GROQ_API_KEY=your_groq_api_key
CHATBOT_URL=http://ai-chatbot:9090

# Fabric
FABRIC_NETWORK_NAME=fablo_network_202607012331_basic
FABRIC_ORDERER_URL=grpcs://orderer0.orderergroup.atlas.com:7030
FABRIC_PEER_HOSPITAL_URL=grpcs://peer0.hospital.atlas.com:7041
FABRIC_PEER_INSURANCE_URL=grpcs://peer0.insurance.atlas.com:7061
FABRIC_PEER_REGULATOR_URL=grpcs://peer0.regulator.atlas.com:7081
FABRIC_CRYPTO_PATH=/crypto

Run with Docker

# Start all services
docker compose up -d --build

# Check status
docker compose ps

# View logs
docker compose logs -f backend

Run Locally (Development)

# Install dependencies
npm install

# Generate Prisma client
npx prisma generate

# Run database migrations
npx prisma db push

# Start dev server
npm run dev

Server starts at http://localhost:9000

Swagger UI available at http://localhost:8082


API Endpoints

Auth

Method Endpoint Description
POST /api/auth/signup Register new user
POST /api/auth/login Login and get JWT
POST /api/auth/verify-email Verify email address
POST /api/auth/forgot-password Request password reset
POST /api/auth/reset-password Reset password with token

Users

Method Endpoint Description
GET /api/users/me Get current user profile
PUT /api/users/me Update current user profile
GET /api/users/:id Get user by ID
GET /api/users/doctors List all doctors
GET /api/users/patients List assigned patients (doctor)

Appointments

Method Endpoint Description
POST /api/appointments Create appointment
GET /api/appointments List user appointments
GET /api/appointments/:id Get appointment details
PUT /api/appointments/:id Update appointment status
DELETE /api/appointments/:id Cancel appointment

Chat & Messaging

Method Endpoint Description
POST /api/messages Send message
GET /api/messages/:userId Get conversation with user
POST /api/chat Create AI chat session
POST /api/chat/:id/message Send message to AI chatbot

Reports

Method Endpoint Description
POST /api/reports Upload scan & create report
GET /api/reports List patient reports
GET /api/reports/:id Get report details
POST /api/reports/:id/analyze Trigger AI analysis

Blockchain

Method Endpoint Description
GET /api/blockchain/health Check Fabric gateway
POST /api/blockchain/medical/store-report Store report hash on-chain
GET /api/blockchain/medical/verify-report/:hash Verify report integrity
GET /api/blockchain/medical/report/:hash Get report from blockchain
POST /api/blockchain/medical/log-access Log report access event
POST /api/blockchain/insurance/register Register insurance company
POST /api/blockchain/insurance/verify-eligibility Check insurance eligibility
POST /api/blockchain/consent/grant Grant patient consent
POST /api/blockchain/consent/revoke Revoke patient consent
GET /api/blockchain/consent/check Check consent status
POST /api/blockchain/audit/log Log audit entry
GET /api/blockchain/audit/trail/:hash Get full audit trail
GET /api/blockchain/provenance/:hash Get complete provenance

ZKP

Method Endpoint Description
POST /api/zkp/generate-proof Generate ZK proof
POST /api/zkp/verify-proof Verify ZK proof
GET /api/zkp/proofs List user proofs

Project Structure

medical/
├── prisma/
│   └── schema.prisma          # Database schema (15+ models)
├── src/
│   ├── app.ts                 # Express app config
│   ├── server.ts              # Server bootstrap
│   ├── routes/                # API route definitions
│   ├── controllers/           # Request handlers
│   ├── middleware/             # Auth, validation, error handling
│   ├── services/              # Business logic
│   └── zkp/                   # ZKP integration (snarkjs)
├── circuits/                  # circom ZK circuits
├── scripts/                   # Circuit compilation scripts
├── docs/                      # API documentation
│   ├── api/                   # Swagger specs per module
│   └── *.md                   # Feature documentation
├── docker-compose.yml         # Multi-service orchestration
├── Dockerfile                 # Backend container
├── Dockerfile.zkp             # ZKP setup container
└── package.json

Documentation

Document Description
Overview Project goals and current status
Roles User role definitions and permissions
Services Platform service descriptions
AI & Reports AI pipeline integration details
Consultation Q&A workflow between patients and doctors
Admin Panel Admin panel features and plans
Blockchain Testing Postman testing guide for blockchain endpoints

License

This project is part of a graduation thesis — Atlas 2 Apex.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages