# Project export: Trialytics

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: Cal Hacks 12.0
- Tagline: Turning tangled, time-consuming clinical trial data chaos into seamless, protocol-compliant automated workflows
- Devpost: https://devpost.com/software/trialytics
- GitHub: https://github.com/ShauryaJ1/medical
- Demo: http://medical-app-omega-five.vercel.app/
- Video: https://www.youtube.com/embed/mKz1m1JFRIQ?enablejsapi=1&hl=en_US&rel=0&start=&version=3&wmode=transparent
- Result: winner (Regeneron: Runner-Up)
- Team: 3 GitHub contributor(s) — ShauryaJ1 (31 commits), avni (1 commits), BhavnaMalladi (1 commits)

## Devpost submission (written by the team)

### Inspiration

The regulatory pathway for clinical trials is no joke. For example, wordy filings such as FDA Form 1571, FDA Form 1572 and FDA Form 3674 are required for an Investigational New Drug application, on top of dozens of others. With so many forms, protocols and standardizations piling up, clinicians spend far too much time on paperwork and far too little time on what really matters: advancing healthcare. We live in a fast world. Nobody has time for that. We believe nobody should be stuck in data-cleanup purgatory.

### What it does

Enter Trialytics: a purpose-built solution to take the mountain of raw trial data and transform it into a fully protocol-compliant workflow. Our system: Accepts just three core data documents from a clinician (clinical trial protocol, raw data, SAP) Condenses their workflow by tens to hundreds of documents and countless hours Ensures compliance with regulatory requirements. It's the difference between approval and starting over completely.

### How we built it

We didn’t just wrap a generic GPT model and call it a day. Our team is comprised of scientists with deep regulatory and clinical trial domain expertise. We built everything from the ground up. Tech stack includes: Frontend NextJS Tailwind ShadCN ChartJS Backend Fast API VLLM tRPC Supabase S3 Modal We implemented: Automated ingestion of freely-formatted clinician data Mapping to standard formats (e.g., SDTM, ADAM, ICH-E3) Rule-based compliance checks (for forms like 1571/1572/3674 and CSRs) A user interface built for fast turnaround and minimal training.

### Challenges we ran into

Maintaining regulatory precision at scale was our biggest hurdle. Compliance isn’t just conceptually important. It’s mandatory when human lives are at stake. Adapting freeform clinician data into structured, regulatory-ready formats required solving edge cases, format variability, and mapping ambiguity, all while making the tool friendly and usable was our largest hurdle.

### Accomplishments we're proud of

End-to-end working prototype from protocol upload → SDTM → ADaM → AI analysis Real streaming responses that feel as responsive as ChatGPT CDISC-compliant pipeline using industry-standard pharmaverse R packages Self-hosted LLM on AWS GPU infrastructure (no API dependencies) Type-safe architecture across the entire stack Integrated complex technologies (Next.js + tRPC + Python + R + vLLM) in 36 hours Production-ready infrastructure with CloudFormation automation

### What we learned

We learned that rules matter, not just for safety or approval, but for enabling innovation by removing friction. Regulatory compliance is hard to master, but when done right, it becomes a feature, not a blocker. We also discovered that treating data formats, protocol mapping, and submission compliance as engineering problems (not just administrative burdens) unlocked major operational improvements.

### What's next

We’re planning to broaden Trialytics’ capabilities: Expand data-cleaning modules (handling more formats, more document types) Build the LLM-to-SDTM conversion as a packaged integration (rather than ad-hoc LLM calls) for predictability and auditability Add advanced compliance analytics (real-time monitoring of submission integrity) Extend into new regulatory domains (e.g., device trials, global submissions)

## README (from the GitHub repository)

## Calhacks 12.0 Regeneron Track Runner Up
## Inspiration
The regulatory pathway for clinical trials is no joke. For example, wordy filings such as FDA Form 1571, FDA Form 1572 and FDA Form 3674 are required for an Investigational New Drug application, on top of dozens of others.
With so many forms, protocols and standardizations piling up, clinicians spend far too much time on paperwork and far too little time on what really matters: advancing healthcare. We live in a fast world. Nobody has time for that. We believe nobody **should** be stuck in data-cleanup purgatory.

## What it does
Enter **Trialytics**: a purpose-built solution to take the mountain of raw trial data and transform it into a **fully protocol-compliant workflow**.  
Our system:
- Accepts just **three core data documents** from a clinician (clinical trial protocol, raw data, SAP)  
- Condenses their workflow by **tens to hundreds of documents** and **countless hours** 
- Ensures compliance with regulatory requirements. It's the difference between approval and starting over completely.
- Watch a demo here: https://www.youtube.com/watch?v=mKz1m1JFRIQ&feature=youtu.be
## How we built it
We didn’t just wrap a generic GPT model and call it a day. Our team is comprised of scientists with deep regulatory and clinical trial domain expertise. We built everything from the ground up.  
**Tech stack includes:**

Frontend
- NextJS
- Tailwind
- ShadCN
- ChartJS

Backend
- Fast API
- VLLM
- tRPC
- Supabase
- S3
- Modal
 
We implemented:  
- Automated ingestion of freely-formatted clinician data  
- Mapping to standard formats (e.g., SDTM, ADAM, ICH-E3)  
- Rule-based compliance checks (for forms like 1571/1572/3674 and CSRs)  
- A user interface built for fast turnaround and minimal training.

## Challenges we ran into
Maintaining regulatory precision at scale was our biggest hurdle. Compliance isn’t just conceptually important. It’s **mandatory** when human lives are at stake.  Adapting freeform clinician data into structured, regulatory-ready formats required solving edge cases, format variability, and mapping ambiguity, all while making the tool friendly and usable was our largest hurdle.

## Accomplishments that we're proud of
- **End-to-end working prototype** from protocol upload → SDTM → ADaM → AI analysis
- **Real streaming responses** that feel as responsive as ChatGPT
- **CDISC-compliant pipeline** using industry-standard pharmaverse R packages
- **Self-hosted LLM** on AWS GPU infrastructure (no API dependencies)
- **Type-safe architecture** across the entire stack
- **Integrated complex technologies** (Next.js + tRPC + Python + R + vLLM) in 36 hours
- **Production-ready infrastructure** with CloudFormation automation

## What we learned
We learned that **rules matter**, not just for safety or approval, but for enabling innovation by removing friction. Regulatory compliance is hard to master, but when done right, it becomes a **feature**, not a blocker.  
We also discovered that treating data formats, protocol mapping, and submission compliance as engineering problems (not just administrative burdens) unlocked major operational improvements.

## What's next for Trialytics
We’re planning to broaden **Trialytics**’ capabilities:  
- Expand data-cleaning modules (handling more formats, more document types)  
- Build the LLM-to-SDTM conversion as a **packaged integration** (rather than ad-hoc LLM calls) for predictability and auditability  
- Add advanced compliance analytics (real-time monitoring of submission integrity)  
- Extend into new regulatory domains (e.g., device trials, global submissions)  


## Detected evidence (automated analysis)

Indexed codebase: 133 recognized source files, 797 KB.
- CSS (language) — detected in the code
- FastAPI (technology) — detected in the code
- JavaScript (language) — detected in the code
- Next.js (technology) — detected in the code
- Python (language) — detected in the code
- React (technology) — detected in the code
- SQL (language) — detected in the code
- Supabase (technology) — detected in the code
- Tailwind CSS (technology) — detected in the code
- TypeScript (language) — detected in the code
- Vercel AI SDK (technology) — detected in the code
- AWS (technology) — claimed on Devpost, not found in the code
- Docker (technology) — claimed on Devpost, not found in the code
- PostgreSQL (technology) — claimed on Devpost, not found in the code
- AI coding agent: Cursor — evidence: config files committed to the repository

## Codebase structure (from repository index)

### Files (120 of 158)

```
.cursor/rules/context.mdc
.gitignore
backend-services/modal_quick_sandbox.py
backend-services/modal_sandbox_test.py
backend-services/modal_server/.gitignore
backend-services/modal_server/app.py
backend-services/modal_server/csr format_extracted.txt
backend-services/modal_server/deploy/cloudformation.yaml
backend-services/modal_server/deploy/deploy.sh
backend-services/modal_server/docker-entrypoint.sh
backend-services/modal_server/Dockerfile
backend-services/modal_server/example_client.py
backend-services/modal_server/example_s3_usage.py
backend-services/modal_server/local_s3_test.py
backend-services/modal_server/medical.csv
backend-services/modal_server/modal_executor.py
backend-services/modal_server/pdf_test.py
backend-services/modal_server/pdfplumber_advanced_local.py
backend-services/modal_server/pdfplumber_local_test.py
backend-services/modal_server/pdfplumber_test.py
backend-services/modal_server/quick_s3_test.sh
backend-services/modal_server/README.md
backend-services/modal_server/requirements.txt
backend-services/modal_server/setup_s3_bucket.sh
backend-services/modal_server/test_api.py
backend-services/modal_server/test_s3_bucket.py
backend-services/modal_server/test_s3_integration.py
backend-services/modal_server/test.csv
backend-services/modal_test.py
DEEP_LEARNING_AMI_INFO.md
demo-vid
deploy-g6e-instance.sh
g6e-instance-vpc-stack.yaml
g6e-launch-template.json
medical-ai/.gitignore
medical-ai/app/api/chat/route.ts
medical-ai/app/api/execute-code-stream/route.ts
medical-ai/app/api/execute-code/route.ts
medical-ai/app/api/generate-object/route.ts
medical-ai/app/api/modal-execute/route.ts
medical-ai/app/api/s3-modal/route.ts
medical-ai/app/api/s3-upload/route.ts
medical-ai/app/api/tool-call/route.ts
medical-ai/app/code-stream/chart-components.tsx
medical-ai/app/code-stream/chart-demo.tsx
medical-ai/app/code-stream/demo.tsx
medical-ai/app/code-stream/message-component.tsx
medical-ai/app/code-stream/page.tsx
medical-ai/app/code-stream/reasoning-component.tsx
medical-ai/app/code-stream/report-component.tsx
medical-ai/app/globals.css
medical-ai/app/layout.tsx
medical-ai/app/page.tsx
medical-ai/CODE_EXECUTION_SETUP.md
medical-ai/components.json
medical-ai/components/ai-elements/code-block.tsx
medical-ai/components/ai-elements/reasoning.tsx
medical-ai/components/ai-elements/response.tsx
medical-ai/components/ai-elements/shimmer.tsx
medical-ai/components/file-upload-s3.tsx
medical-ai/components/ui/badge.tsx
medical-ai/components/ui/button.tsx
medical-ai/components/ui/card.tsx
medical-ai/components/ui/collapsible.tsx
medical-ai/components/ui/dropdown-menu.tsx
medical-ai/components/ui/input.tsx
medical-ai/components/ui/scroll-area.tsx
medical-ai/components/ui/separator.tsx
medical-ai/components/ui/table.tsx
medical-ai/components/ui/textarea.tsx
medical-ai/eslint.config.mjs
medical-ai/lib/ai-provider.ts
medical-ai/lib/utils.ts
medical-ai/next.config.ts
medical-ai/package.json
medical-ai/postcss.config.mjs
medical-ai/README.md
medical-ai/sample-data.csv
medical-ai/test-execute-code-api.js
medical-ai/test-vllm-endpoint.js
medical-ai/tsconfig.json
my-app/.gitignore
my-app/app/api/chat/route.ts
my-app/app/api/trpc/[trpc]/route.ts
my-app/app/api/users/route.ts
my-app/app/auth/confirm/route.ts
my-app/app/auth/error/page.tsx
my-app/app/auth/forgot-password/page.tsx
my-app/app/auth/login/page.tsx
my-app/app/auth/sign-up-success/page.tsx
my-app/app/auth/sign-up/page.tsx
my-app/app/auth/update-password/page.tsx
my-app/app/chat/page.tsx
my-app/app/globals.css
my-app/app/layout.tsx
my-app/app/page.tsx
my-app/app/protected/layout.tsx
my-app/app/protected/page.tsx
my-app/app/test/page.tsx
my-app/app/users/page.tsx
my-app/CHAT_README.md
my-app/components.json
my-app/components/ai-elements/reasoning.tsx
my-app/components/ai-elements/response.tsx
my-app/components/ai-elements/shimmer.tsx
my-app/components/auth-button.tsx
my-app/components/deploy-button.tsx
my-app/components/env-var-warning.tsx
my-app/components/forgot-password-form.tsx
my-app/components/hero.tsx
my-app/components/login-form.tsx
my-app/components/logout-button.tsx
my-app/components/next-logo.tsx
my-app/components/sign-up-form.tsx
my-app/components/supabase-logo.tsx
my-app/components/theme-switcher.tsx
my-app/components/tutorial/code-block.tsx
my-app/components/tutorial/connect-supabase-steps.tsx
my-app/components/tutorial/fetch-data-steps.tsx
my-app/components/tutorial/sign-up-user-steps.tsx
[38 more files omitted for size]
```

### Dependencies

- backend-services/modal_server/requirements.txt: aiohappyeyeballs@==2.6.1, aiohttp@==3.13.1, aiosignal@==1.4.0, annotated-doc@==0.0.3, annotated-types@==0.7.0, anyio@==4.11.0, attrs@==25.4.0, cbor2@==5.7.1, certifi@==2025.10.5, click@==8.3.0, colorama@==0.4.6, fastapi@==0.120.0, frozenlist@==1.8.0, grpclib@==0.4.8, h11@==0.16.0, h2@==4.3.0, hpack@==4.1.0, hyperframe@==6.1.0, idna@==3.11, markdown-it-py@==4.0.0, mdurl@==0.1.2, modal@==1.2.1, multidict@==6.7.0, propcache@==0.4.1, protobuf@==6.33.0, pydantic@==2.12.3, pydantic_core@==2.41.4, Pygments@==2.19.2, python-dotenv@==1.1.1, requests@==2.31.0, rich@==14.2.0, shellingham@==1.5.4, sigtools@==4.0.1, sniffio@==1.3.1, starlette@==0.48.0, synchronicity@==0.10.2, toml@==0.10.2, typer@==0.20.0, types-certifi@==2021.10.8.3, types-toml@==0.10.8.20240310, typing_extensions@==4.15.0, typing-inspection@==0.4.2, uvicorn@==0.38.0, watchfiles@==1.1.1, yarl@==1.22.0
- medical-ai/package.json: @ai-sdk/openai-compatible@^1.0.22, @ai-sdk/react@^2.0.78, @aws-sdk/client-s3@^3.917.0, @aws-sdk/s3-request-presigner@^3.917.0, @radix-ui/react-collapsible@^1.1.12, @radix-ui/react-dropdown-menu@^2.1.16, @radix-ui/react-scroll-area@^1.2.10, @radix-ui/react-separator@^1.1.7, @radix-ui/react-slot@^1.2.3, @radix-ui/react-use-controllable-state@^1.2.2, @tailwindcss/postcss@^4, @tanstack/react-query@^5.90.5, @tanstack/react-query-devtools@^5.90.2, @trpc/client@^11.7.0, @trpc/next@^11.7.0, @trpc/react-query@^11.7.0, @trpc/server@^11.7.0, @types/node@^20, @types/react@^19, @types/react-dom@^19, ai@^5.0.78, ai-elements@^1.1.2, chart.js@^4.5.1, class-variance-authority@^0.7.1, clsx@^2.1.1, eslint@^9, eslint-config-next@16.0.0, lucide-react@^0.548.0, motion@^12.23.24, next@16.0.0, react@19.2.0, react-chartjs-2@^5.3.0, react-dom@19.2.0, react-markdown@^10.1.0, remark-gfm@^4.0.1, streamdown@^1.4.0, tailwind-merge@^3.3.1, tailwindcss@^4, tw-animate-css@^1.4.0, tw-animate-css@^1.4.0, typescript@^5, zod@^4.1.12
- my-app/package.json: @ai-sdk/openai-compatible@^1.0.22, @ai-sdk/react@^2.0.79, @eslint/eslintrc@^3, @radix-ui/react-checkbox@^1.3.1, @radix-ui/react-collapsible@^1.1.12, @radix-ui/react-dialog@^1.1.15, @radix-ui/react-dropdown-menu@^2.1.14, @radix-ui/react-label@^2.1.6, @radix-ui/react-progress@^1.1.7, @radix-ui/react-slot@^1.2.2, @radix-ui/react-tabs@^1.1.13, @radix-ui/react-toast@^1.2.15, @radix-ui/react-use-controllable-state@^1.2.2, @supabase/ssr@latest, @supabase/supabase-js@latest, @tanstack/react-query@^5.90.5, @tanstack/react-query-devtools@^5.90.2, @trpc/client@^11.7.0, @trpc/next@^11.7.0, @trpc/react-query@^11.7.0, @trpc/server@^11.7.0, @types/node@^20.19.23, @types/react@^19, @types/react-dom@^19, ai@^5.0.79, autoprefixer@^10.4.20, chart.js@^4.5.1, class-variance-authority@^0.7.1, clsx@^2.1.1, eslint@^9, eslint-config-next@15.3.1, lucide-react@^0.511.0, motion@^12.23.24, next@latest, next-themes@^0.4.6, postcss@^8, prisma@^6.18.0, react@^19.0.0, react-chartjs-2@^5.3.0, react-dom@^19.0.0, react-dropzone@^14.3.8, sonner@^2.0.7, streamdown@^1.4.0, superjson@^2.2.3, tailwind-merge@^3.3.0, tailwindcss@^3.4.1, tailwindcss-animate@^1.0.7, ts-node@^10.9.2, typescript@^5.9.3, zod@^4.1.12
- package.json: @types/react-syntax-highlighter@^15.5.13, react-syntax-highlighter@^16.0.0, refractor@^5.0.0

### Recent commits (newest first)

- Update README.md
- Revise video demo link in README
- Add video link and thumbnail to README
- Update README.md
- Add demo video link
- Update README.md
- logs
- more fixes
- fix pie chart
- Update page.tsx
- Cleanup
- auto scroll
- fix build errors + undo avni changes
- add reports
- Prompt refactor
- Merge branch 'main' of https://github.com/ShauryaJ1/medical
- make pdfs work
- Merge pull request #8 from ShauryaJ1/shaurya-modal
- charts
- Merge pull request #7 from ShauryaJ1/shaurya-modal

## Key source files (fetched from GitHub, selected and truncated for size)

### DEEP_LEARNING_AMI_INFO.md

```markdown
# AWS Deep Learning AMI Configuration

## Overview

This deployment now uses the **AWS Deep Learning Base GPU AMI (Ubuntu 22.04)** instead of the standard Ubuntu AMI. This provides a pre-configured environment optimized for machine learning and deep learning workloads.

## Key Changes

### AMI Details
- **AMI ID (us-east-1)**: `ami-07e05a9b31a088ae5`
- **Base OS**: Ubuntu 22.04 LTS
- **Region**: US-EAST-1 ONLY (configured for this specific region)

### Pre-installed Components

The Deep Learning AMI comes with everything pre-installed and configured:

#### GPU Support
- ✅ NVIDIA drivers (latest stable version)
- ✅ CUDA 12.x toolkit
- ✅ cuDNN 8.x
- ✅ NVIDIA Container Toolkit for Docker
- ✅ GPU monitoring tools (nvidia-smi, nvtop)

#### ML/DL Frameworks
- ✅ PyTorch (latest stable with CUDA support)
- ✅ TensorFlow 2.x (with GPU support)
- ✅ JAX
- ✅ MXNet
- ✅ Hugging Face Transformers

#### Development Environment
- ✅ Conda with pre-configured environments
- ✅ Jupyter Lab/Notebook
- ✅ Docker CE with NVIDIA runtime
- ✅ Python 3.10+
- ✅ Essential Python libraries (NumPy, Pandas, scikit-learn, etc.)

## Benefits Over Standard Ubuntu AMI

1. **Time Savings**: No need to install NVIDIA drivers, CUDA, or frameworks
2. **Compatibility**: All components are tested to work together
3. **Optimized**: AWS-optimized builds for better performance
4. **Ready-to-Use**: Can start training models immediately after launch

## Simplified Setup

Since everything is pre-installed, the UserData script is much simpler:

```bash
#!/bin/bash
# System update
apt-get update && apt-get upgrade -y

# Ensure Docker is enabled (already installed)
systemctl enable docker
systemctl restart docker

# Install monitoring tools
apt-get install -y htop nvtop tmux

# Everything else is already installed!
```

## Quick Test Commands

After deploying, verify your setup:

```bash
# Check GPU
nvidia-smi

# Check CUDA version
nvcc --version

# Test PyTorch
python3 -c "import torch; print(torch.cuda.is_available())"

# Test TensorFlow
python3 -c "import tensorflow as tf; print(len(tf.config.list_physical_devices('GPU')))"

# Run GPU Docker container
docker run --rm --gpus all nvidia/cuda:12.0-base nvidia-smi
```

## Working with Conda Environments

The AMI includes pre-configured Conda environments:

```bash
# List available environments
conda env list

# Activate PyTorch environment
conda activate pytorch

# Activate TensorFlow environment
conda activate tensorflow2

# Create your own environment
conda create -n myenv python=3.10
conda activate myenv
```

## vLLM Deployment Example

Perfect for running vLLM with the pre-installed environment:

```bash
# Using Docker (recommended)
docker run --runtime nvidia --gpus all \
  -v ~/.cache/huggingface:/root/.cache/huggingface \
  -p 8080:8000 \
  vllm/vllm-openai:latest \
  --model meta-llama/Llama-2-7b-chat-hf

# Or install vLLM directly
pip install vllm
python -m vllm.entrypoints.openai.api_server \
  --model meta-llama/Llama-2-7b-chat-hf \
  --po
[truncated — 1541 more characters]
```

### my-app/CHAT_README.md

```markdown
# Medical AI Chat Application

This application provides a comprehensive chat interface for medical document analysis using vLLM backend integration.

## Features

### Document Upload
- **Clinical Trial Protocol**: PDF upload with drag & drop support
- **Raw Clean Data**: CSV/JSON file upload
- **Statistical Analysis Protocol (SAP)**: PDF upload
- Visual indicators for each document type with appropriate icons
- File validation and error handling

### AI Chat Interface
- Real-time chat with vLLM backend
- Document context integration
- Thinking process visualization with collapsible dropdowns
- Secure tRPC integration for all LLM calls

### Security
- All LLM interactions wrapped in tRPC procedures
- Type-safe API calls with Zod validation
- Secure document handling

## Setup

1. Install dependencies:
```bash
npm install
```

2. Configure environment variables:
```bash
# Create .env.local file
VLLM_ENDPOINT=http://localhost:8000/v1
VLLM_MODEL_NAME=your-model-name
```

3. Start the development server:
```bash
npm run dev
```

## Usage

1. Navigate to `/chat` in your browser
2. Upload your medical documents using drag & drop or file browser
3. Ask questions about your uploaded documents
4. View AI thinking process by clicking "Show Thinking" buttons

## Architecture

- **Frontend**: Next.js 15 with TypeScript
- **UI Components**: ShadCN/UI with Tailwind CSS
- **State Management**: React Query via tRPC
- **File Upload**: react-dropzone
- **Backend Integration**: tRPC with vLLM API
- **Type Safety**: Zod validation schemas

## API Endpoints

- `POST /api/trpc/chat` - Chat with AI assistant
- `POST /api/trpc/uploadDocument` - Upload document processing
- `POST /api/trpc/analyzeDocuments` - Document analysis

## Document Types

- **Protocol**: Clinical trial protocol documents (PDF)
- **Raw Data**: Cleaned clinical data (CSV/JSON)
- **SAP**: Statistical analysis protocol (PDF)

```

### package.json

```
{
  "dependencies": {
    "@types/react-syntax-highlighter": "^15.5.13",
    "react-syntax-highlighter": "^16.0.0",
    "refractor": "^5.0.0"
  }
}

```

### medical-ai/package.json

```
{
  "name": "medical-ai",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev --webpack",
    "build": "next build --webpack",
    "start": "next start",
    "lint": "eslint"
  },
  "dependencies": {
    "@ai-sdk/openai-compatible": "^1.0.22",
    "@ai-sdk/react": "^2.0.78",
    "@aws-sdk/client-s3": "^3.917.0",
    "@aws-sdk/s3-request-presigner": "^3.917.0",
    "@radix-ui/react-collapsible": "^1.1.12",
    "@radix-ui/react-dropdown-menu": "^2.1.16",
    "@radix-ui/react-scroll-area": "^1.2.10",
    "@radix-ui/react-separator": "^1.1.7",
    "@radix-ui/react-slot": "^1.2.3",
    "@radix-ui/react-use-controllable-state": "^1.2.2",
    "@tanstack/react-query": "^5.90.5",
    "@tanstack/react-query-devtools": "^5.90.2",
    "@trpc/client": "^11.7.0",
    "@trpc/next": "^11.7.0",
    "@trpc/react-query": "^11.7.0",
    "@trpc/server": "^11.7.0",
    "ai": "^5.0.78",
    "ai-elements": "^1.1.2",
    "chart.js": "^4.5.1",
    "class-variance-authority": "^0.7.1",
    "clsx": "^2.1.1",
    "lucide-react": "^0.548.0",
    "motion": "^12.23.24",
    "next": "16.0.0",
    "react": "19.2.0",
    "react-chartjs-2": "^5.3.0",
    "react-dom": "19.2.0",
    "react-markdown": "^10.1.0",
    "remark-gfm": "^4.0.1",
    "streamdown": "^1.4.0",
    "tailwind-merge": "^3.3.1",
    "tw-animate-css": "^1.4.0",
    "zod": "^4.1.12"
  },
  "devDependencies": {
    "@tailwindcss/postcss": "^4",
    "@types/node": "^20",
    "@types/react": "^19",
    "@types/react-dom": "^19",
    "eslint": "^9",
    "eslint-config-next": "16.0.0",
    "tailwindcss": "^4",
    "tw-animate-css": "^1.4.0",
    "typescript": "^5"
  }
}

```

### my-app/package.json

```
{
  "private": true,
  "scripts": {
    "dev": "next dev --turbopack",
    "build": "next build",
    "start": "next start",
    "lint": "eslint ."
  },
  "dependencies": {
    "@ai-sdk/openai-compatible": "^1.0.22",
    "@ai-sdk/react": "^2.0.79",
    "@radix-ui/react-checkbox": "^1.3.1",
    "@radix-ui/react-collapsible": "^1.1.12",
    "@radix-ui/react-dialog": "^1.1.15",
    "@radix-ui/react-dropdown-menu": "^2.1.14",
    "@radix-ui/react-label": "^2.1.6",
    "@radix-ui/react-progress": "^1.1.7",
    "@radix-ui/react-slot": "^1.2.2",
    "@radix-ui/react-tabs": "^1.1.13",
    "@radix-ui/react-toast": "^1.2.15",
    "@radix-ui/react-use-controllable-state": "^1.2.2",
    "@supabase/ssr": "latest",
    "@supabase/supabase-js": "latest",
    "@tanstack/react-query": "^5.90.5",
    "@tanstack/react-query-devtools": "^5.90.2",
    "@trpc/client": "^11.7.0",
    "@trpc/next": "^11.7.0",
    "@trpc/react-query": "^11.7.0",
    "@trpc/server": "^11.7.0",
    "ai": "^5.0.79",
    "chart.js": "^4.5.1",
    "class-variance-authority": "^0.7.1",
    "clsx": "^2.1.1",
    "lucide-react": "^0.511.0",
    "motion": "^12.23.24",
    "next": "latest",
    "next-themes": "^0.4.6",
    "react": "^19.0.0",
    "react-chartjs-2": "^5.3.0",
    "react-dom": "^19.0.0",
    "react-dropzone": "^14.3.8",
    "sonner": "^2.0.7",
    "streamdown": "^1.4.0",
    "superjson": "^2.2.3",
    "tailwind-merge": "^3.3.0",
    "zod": "^4.1.12"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3",
    "@types/node": "^20.19.23",
    "@types/react": "^19",
    "@types/react-dom": "^19",
    "autoprefixer": "^10.4.20",
    "eslint": "^9",
    "eslint-config-next": "15.3.1",
    "postcss": "^8",
    "prisma": "^6.18.0",
    "tailwindcss": "^3.4.1",
    "tailwindcss-animate": "^1.0.7",
    "ts-node": "^10.9.2",
    "typescript": "^5.9.3"
  },
  "name": "my-app",
  "version": "1.0.0",
  "description": "Next.js and Supabase Starter Kit",
  "directories": {
    "lib": "lib"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

```

### backend-services/modal_server/requirements.txt

```
aiohappyeyeballs==2.6.1
aiohttp==3.13.1
aiosignal==1.4.0
annotated-doc==0.0.3
annotated-types==0.7.0
anyio==4.11.0
attrs==25.4.0
cbor2==5.7.1
certifi==2025.10.5
click==8.3.0
colorama==0.4.6
fastapi==0.120.0
frozenlist==1.8.0
grpclib==0.4.8
h11==0.16.0
h2==4.3.0
hpack==4.1.0
hyperframe==6.1.0
idna==3.11
markdown-it-py==4.0.0
mdurl==0.1.2
modal==1.2.1
multidict==6.7.0
propcache==0.4.1
protobuf==6.33.0
pydantic==2.12.3
pydantic_core==2.41.4
Pygments==2.19.2
python-dotenv==1.1.1
rich==14.2.0
shellingham==1.5.4
sigtools==4.0.1
sniffio==1.3.1
starlette==0.48.0
synchronicity==0.10.2
toml==0.10.2
typer==0.20.0
types-certifi==2021.10.8.3
types-toml==0.10.8.20240310
typing-inspection==0.4.2
typing_extensions==4.15.0
uvicorn==0.38.0
watchfiles==1.1.1
yarl==1.22.0
requests==2.31.0

```

### backend-services/modal_server/Dockerfile

```
# Multi-stage build for Modal FastAPI server
FROM python:3.11-slim as builder

# Set working directory
WORKDIR /app

# Install system dependencies for building Python packages
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements file
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir --user -r requirements.txt

# Production stage
FROM python:3.11-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PATH="/root/.local/bin:${PATH}"

# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy Python packages from builder
COPY --from=builder /root/.local /root/.local

# Copy application code
COPY app.py modal_executor.py ./

# Copy .env file if it exists (for local builds)
# In production, use secrets or environment variables instead
COPY .env* ./

# Copy the flexible entrypoint script
COPY docker-entrypoint.sh /app/docker-entrypoint.sh
RUN chmod +x /app/docker-entrypoint.sh

# Create a non-root user (optional, but good practice)
# RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
# USER appuser

# Expose port
EXPOSE 8000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:8000/health || exit 1

# Run the entrypoint script
ENTRYPOINT ["/app/docker-entrypoint.sh"]

```

### medical-ai/app/page.tsx

```typescript
import { redirect } from 'next/navigation';

export default function HomePage() {
  redirect('/code-stream');
}
```

### medical-ai/app/layout.tsx

```typescript
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";

const geistSans = Geist({
  variable: "--font-geist-sans",
  subsets: ["latin"],
});

const geistMono = Geist_Mono({
  variable: "--font-geist-mono",
  subsets: ["latin"],
});

export const metadata: Metadata = {
  title: "Qwen AI Chat",
  description: "AI Chat powered by VLLM and Qwen3-8B Model using Vercel AI SDK",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body
        className={`${geistSans.variable} ${geistMono.variable} antialiased`}
      >
        {children}
      </body>
    </html>
  );
}

```

### my-app/app/layout.tsx

```typescript
import type { Metadata } from "next";
import { Geist } from "next/font/google";
import { ThemeProvider } from "next-themes";
import { TRPCProvider } from "@/lib/trpc-provider";
import "./globals.css";

const defaultUrl = process.env.VERCEL_URL
  ? `https://${process.env.VERCEL_URL}`
  : "http://localhost:3000";

export const metadata: Metadata = {
  metadataBase: new URL(defaultUrl),
  title: "Next.js and Supabase Starter Kit",
  description: "The fastest way to build apps with Next.js and Supabase",
};

const geistSans = Geist({
  variable: "--font-geist-sans",
  display: "swap",
  subsets: ["latin"],
});

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en" suppressHydrationWarning>
      <body className={`${geistSans.className} antialiased`}>
        <TRPCProvider>
          <ThemeProvider
            attribute="class"
            defaultTheme="system"
            enableSystem
            disableTransitionOnChange
          >
            {children}
          </ThemeProvider>
        </TRPCProvider>
      </body>
    </html>
  );
}

```

[123 more indexed source files omitted to keep this export small. The full file list is in the Codebase structure section above.]