A confidential patient-to-clinical-trial matching system built on the Terminal 3 Agent Developer Kit (ADK). Uses Trusted Execution Environments (TEEs) to match patients against trial criteria without ever exposing raw patient health data to the matching logic, the platform, or any unauthorized party.
Built for the Terminal 3 Bounty Challenge (June 9–22, 2026).
- ~80% of clinical trials fail to meet enrollment timelines — nearly 30% of sites enroll zero patients
- 85% of cancer patients are unaware trials are an option — 75% would enroll if they knew
- Manual screening bottleneck — doctors review medical records by hand against 50-100+ inclusion/exclusion criteria
- Patient data exposure — PHI flows through sponsors, CROs, recruitment agencies, and sites with no confidential computation layer
- No verifiable audit — regulators cannot independently verify that matching was performed fairly or that patient data was handled appropriately
Full problem statement with sources: Problem-statement.md
TrialMatch uses Terminal 3's TEE contracts to:
| Capability | How It Works |
|---|---|
| Confidential matching | Matching logic runs inside Intel TDX — code + data invisible to all parties |
| PII never enters the contract | http-with-placeholders resolves patient names, DOBs, diagnoses host-side inside the enclave |
| Verifiable identity | Every party (pharma, hospital, CRO, patient, agent) has a cryptographic DID |
| Tamper-resistant audit | Every match decision recorded on T3N's immutable ledger |
| Cross-boundary interoperability | Hospital contract talks to pharma contract via cross-tenant calls — no data siloed in one platform |
| User-granted egress | Patient controls exactly which contracts, functions, and hosts the agent can access |
Full solution architecture: Solution.md
| Deep 6 AI | TriNetX | TrialMatch (TEE Agent) | |
|---|---|---|---|
| Matching logic visibility | Visible to Tempus engineers | Visible to TriNetX platform | Inside TDX — invisible to everyone |
| Patient PII handling | Processed in cloud memory | Shared across federated nodes | Placeholders — never enters contract |
| Audit trail | Internal logs (editable) | Internal logs (editable) | T3N ledger (tamper-resistant) |
| Identity | Platform-managed accounts | Institutional trust | Cryptographic DIDs (verifiable) |
| Cross-boundary | Walled-garden | Walled-garden | Cross-tenant calls (neutral layer) |
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Pharma Tenant │ │ Hospital Tenant │ │ Patient (User) │
│ │ │ │ │ │
│ trial-matching │◄───►│ patient-screening│ │ agent-auth │
│ WASM contract │ ACL │ WASM contract │ │ grant │
│ │ │ │ │ │
│ - KV maps │ │ - KV maps │ └────────┬────────┘
│ - Secrets vault│ │ - http-w-placeholders │
└────────┬────────┘ └────────┬─────────┘ │
│ │ │
└───────────────────────┼────────────────────────┘
│
┌────────────▼────────────┐
│ Matching Agent (DID) │
│ │
│ 1. get-trial-criteria │
│ 2. check-eligibility │
│ 3. submit-match-result │
└─────────────────────────┘
- Pharma publishes trial criteria → stored in KV map (
trial-criteria) - Hospital shares read ACL on
trial-criteriawith pharma contract - Patient grants the matching agent access to specific contracts, functions, and hosts
- Agent fetches trial criteria from pharma contract
- Agent invokes hospital's
check-eligibility— patient data fetched viahttp-with-placeholders(PII never enters WASM) - Hospital contract evaluates criteria inside TEE, returns eligibility result (no raw patient data)
- Agent submits match result to pharma contract — recorded immutably
Backend Infrastructure:
- Fastify REST API with MongoDB integration
- Agent-driven batch matching architecture
- Match result caching system (7-day expiry)
- Access logs tracking for patient data usage
- Pharma organization registration and management
- Patient custodial wallet system with AES-256-GCM encryption
- Seed script for populating test data (5 trials, 10 patients)
Frontend (Patient Portal):
- Patient registration and authentication
- Health data upload interface
- Trial matches dashboard (fetches from backend cache)
- Secure wallet view with real patient DID display
- Access logs display (shows agent authorization events)
- Sign-out functionality for testing multiple accounts
Frontend (Pharma Portal):
- Pharma organization onboarding flow
- Trial creation with LLM-based protocol parsing
- Trial management and listing
- Trial details modal with full criteria display
- Match results aggregation page (eligible patients by trial)
- Reactive organization name in sidebar navigation
TEE Integration:
- Hospital screening contract (eligibility checking)
- Pharma trial contract (criteria management)
- MockTEEClient for local development
- Agent authorization workflow
- Cross-tenant ACL configuration
Data Management:
- 5 seeded trials under RayPharma organization
- 10 comprehensive patient records with realistic medical data
- MongoDB collections: patients, trials, agents, match_results, access_logs, pharma_organizations
- Strategic patient-trial matching for demo purposes
Phase 2:
- Scheduled agent runs (cron-based batch matching every 2 days)
- Email-based patient contact system
- Consent management dashboard
- Real-time agent execution progress tracking
Phase 3:
- In-platform messaging (WebSockets for hospital-patient communication)
- Partial match recommendations (near-eligible patients)
- Advanced analytics (eligibility funnel, criteria impact analysis)
- Multi-hospital support with separate EHR backends
- Node.js >= 18
- pnpm (package manager)
- Rust with
wasm32-wasip2target - Terminal 3 API Key from the claim page
rustup target add wasm32-wasip2pnpm install# Backend
cd server
pnpm install
# Frontend
cd ../Frontend
pnpm installCopy server/.env.example to server/.env and add:
# MongoDB Connection (required)
MONGODB_URI=mongodb+srv://user:pass@cluster.mongodb.net/trialmatch?retryWrites=true&w=majority
# Terminal 3 API Key (optional - uses MockTEEClient if omitted)
T3N_API_KEY=
# LLM Configuration (required for trial parsing)
LLM_PROVIDER=groq
GROQ_API_KEY=your_groq_key_here
# Auto-configured keys (already set in .env)
WALLET_ENCRYPTION_KEY=<generated>
AGENT_KEY=<generated>
EHR_API_KEY=mock-ehr-key
TRIALS_API_KEY=mock-trials-key
EHR_BASE_URL=http://localhost:3008MongoDB Setup:
- Sign up for free MongoDB Atlas account
- Create M0 cluster (512MB free tier)
- Whitelist your IP (or 0.0.0.0/0 for development)
- Get connection string and add to
.env
cd server
pnpm run seedThis populates MongoDB with:
- 5 clinical trials (SGLT2 inhibitor, ARNI therapy, PD-1/CTLA-4 combo)
- 10 patients with comprehensive medical records
- Strategic matching (4 patients for trial 3, 3 each for trials 4-5)
# Terminal 1: Backend
cd server
pnpm dev # http://localhost:3008
# Terminal 2: Frontend
cd Frontend
pnpm dev # http://localhost:5173-
Patient Flow:
- Go to http://localhost:5173
- Click "Enter Patient Portal" → Register with email
- Upload health data (or use seeded patient accounts)
- View trial matches on dashboard
-
Pharma Flow:
- Click "For Institutions" → Register organization
- Create new trial (paste protocol text)
- View match results aggregated by trial
Note: Without
T3N_API_KEY, the system usesMockTEEClientfor local development. All features work normally with mock data.
| Endpoint | Method | Description |
|---|---|---|
/api/trials/create |
POST | Create trial from protocol text (LLM parsing) |
/api/trials/all |
GET | List all trials |
/api/trials/:id |
GET | Get trial details |
/api/trials/:id/check-eligibility |
POST | Check patient eligibility (with caching) |
/api/patients/:patientDid/matches |
GET | Get patient's eligible trials |
/api/pharma/matches |
GET | Get all matches across trials |
/api/access-logs |
GET/POST | Track agent authorization events |
/api/pharma/register |
POST | Register pharma organization |
/api/pharma/login |
POST | Login pharma organization |
/api/patients/register |
POST | Create patient with custodial wallet |
/api/patients/login |
POST | Patient login |
# Database seeding
pnpm run seed # Populate 5 trials + 10 patients
# TEE contract deployment (requires T3N_API_KEY)
pnpm run setup # Register contracts, create KV maps
pnpm run authorize # Grant agent permissions
pnpm run invoke # Test agent execution flow
# Contract building
pnpm run build:pharma # Build pharma-trial contract
pnpm run build:hospital # Build hospital-screening contract
pnpm run build:all # Build both contracts| ADK Feature | Usage in TrialMatch |
|---|---|
| TEE Contracts (WASM) | Eligibility matching inside Intel TDX enclave |
| Agent DIDs | Cryptographic identity for autonomous agents |
| Custodial Wallets | Platform-managed patient wallets (AES-256-GCM encrypted) |
| KV Maps + ACLs | Cross-tenant trial criteria sharing |
| Secrets Vault | EHR URLs and API keys sealed in TEE |
| HTTP with Placeholders | Patient data resolved host-side, never enters WASM |
| Agent Authorization | Patients grant agents access to screening contracts |
| Match Caching | 7-day cache in MongoDB to avoid redundant TEE calls |
- Project Structure — Directory map and file locator
- Server README — Backend architecture, routes, and runbook
- Problem Statement — Research, statistics, competitive landscape
- Solution Architecture — Full technical design and ADK capability mapping
- Terminal 3 ADK Docs
- Agentic AI Security Manifesto
ISC