Skip to content

BitBricoleurs/backend-google-hackathon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

254 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SAMU AI Triage System

AI-powered medical triage system for SAMU emergency calls

CI/CD codecov License: MIT

Overview

This system reduces SAMU wait times during peak hours through a conversational AI agent that performs telephone pre-triage, collects critical medical information, and provides structured dashboards to regulatory physicians.

Features

  • Agent-based conversational AI powered by Claude 3.5 Sonnet (Anthropic)
  • ABCD protocol implementation (Airway-Breathing-Circulation-Consciousness)
  • Real-time emergency classification (P0-P5 priority levels)
  • Medical dashboard with structured triage reports
  • GDPR/HDS compliant security
  • Comprehensive observability (logs, metrics, tracing)
  • Production-ready with Docker, CI/CD, and >80% test coverage

Technical Stack

  • Backend: TypeScript + Fastify
  • AI Framework: Mastra AI
  • Database: PostgreSQL 16 + pgvector
  • ORM: Prisma
  • LLM: Claude 3.5 Sonnet (Anthropic)
  • Testing: Vitest
  • CI/CD: GitHub Actions + Google Cloud Build
  • Containerization: Docker + Google Cloud Run

Architecture

src/
├── agents/          # AI agents (triage, classification)
├── workflows/       # Deterministic workflows (ABCD, routing)
├── tools/           # Agent-callable functions
├── rag/             # Medical knowledge base
├── integrations/    # Telephony, Speech-to-Text
├── api/             # Hono routes and middleware
├── services/        # Business logic
├── models/          # Data models
├── utils/           # Logger, Prisma, helpers
├── config/          # Configuration management
└── types/           # TypeScript type definitions

Prerequisites

  • Node.js >= 20.0.0
  • PostgreSQL 16
  • npm >= 10.0.0

Installation

git clone https://github.com/your-org/samu-ai-triage.git
cd samu-ai-triage

npm install

cp .env.example .env

Edit .env with your configuration values.

Database Setup

docker-compose up -d postgres
npm run db:migrate
npm run db:seed

Development

npm run dev

Server runs on http://localhost:3000

Available Scripts

Development

npm run dev          # Start development server with hot reload
npm run build        # Build for production
npm run start        # Start production server

Database

npm run db:generate  # Generate Prisma Client
npm run db:migrate   # Run migrations
npm run db:seed      # Seed database with medical knowledge
npm run db:studio    # Open Prisma Studio
npm run db:reset     # Reset database

Testing

npm run test              # Run tests
npm run test:watch        # Run tests in watch mode
npm run test:coverage     # Run tests with coverage report
npm run test:ui           # Open Vitest UI

Code Quality

npm run lint              # Lint code
npm run lint:fix          # Lint and auto-fix issues
npm run format            # Format code
npm run format:check      # Check code formatting
npm run type-check        # TypeScript type checking
npm run validate          # Run all checks (type + lint + format + test)

Docker

npm run docker:build      # Build Docker image
npm run docker:up         # Start all containers
npm run docker:down       # Stop all containers

Testing

npm run test:coverage

Deployment

Local Development with Docker

docker-compose up

This starts:

  • app: Backend API (port 3000)
  • postgres: Database with pgvector (port 5432)

API available at: http://localhost:3000 Swagger UI: http://localhost:3000/docs

Google Cloud Platform Deployment

Prerequisites

  1. Install Google Cloud SDK:
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
gcloud init
  1. Create a GCP project:
gcloud projects create samu-ai-triage --name="SAMU AI Triage"
gcloud config set project samu-ai-triage
  1. Enable required APIs:
gcloud services enable \
  cloudbuild.googleapis.com \
  run.googleapis.com \
  sqladmin.googleapis.com \
  secretmanager.googleapis.com

Setup Cloud SQL (PostgreSQL)

# Create PostgreSQL instance
gcloud sql instances create samu-db \
  --database-version=POSTGRES_16 \
  --tier=db-f1-micro \
  --region=europe-west1

# Create database
gcloud sql databases create samu_triage --instance=samu-db

# Create user
gcloud sql users create samuai \
  --instance=samu-db \
  --password=YOUR_SECURE_PASSWORD

Setup Secrets

# Store secrets in Google Secret Manager
echo -n "postgresql://samuai:PASSWORD@/cloudsql/PROJECT_ID:europe-west1:samu-db/samu_triage" | \
  gcloud secrets create samu-database-url --data-file=-

echo -n "YOUR_ANTHROPIC_API_KEY" | \
  gcloud secrets create samu-anthropic-key --data-file=-

openssl rand -base64 32 | gcloud secrets create samu-jwt-secret --data-file=-
openssl rand -base64 32 | gcloud secrets create samu-encryption-key --data-file=-

Deploy with Cloud Build

# Submit build (automatically deploys to Cloud Run)
gcloud builds submit --config=cloudbuild.yaml

# Or connect to GitHub repository for automatic deployments
gcloud builds triggers create github \
  --repo-name=Hackaton_google \
  --repo-owner=MirageAiEIP \
  --branch-pattern="^main$" \
  --build-config=cloudbuild.yaml

Manual Deploy to Cloud Run

# Build and push image
docker build -t gcr.io/PROJECT_ID/samu-ai-triage .
docker push gcr.io/PROJECT_ID/samu-ai-triage

# Deploy to Cloud Run
gcloud run deploy samu-ai-triage \
  --image=gcr.io/PROJECT_ID/samu-ai-triage \
  --region=europe-west1 \
  --platform=managed \
  --allow-unauthenticated \
  --set-env-vars=NODE_ENV=production,LOG_LEVEL=info \
  --set-secrets=DATABASE_URL=samu-database-url:latest,ANTHROPIC_API_KEY=samu-anthropic-key:latest \
  --memory=512Mi \
  --cpu=1 \
  --max-instances=10

View Deployment

# Get service URL
gcloud run services describe samu-ai-triage --region=europe-west1 --format='value(status.url)'

# View logs
gcloud run logs read samu-ai-triage --region=europe-west1 --limit=50

Environment Variables

Required environment variables (see .env.example):

NODE_ENV=development
PORT=3000
LOG_LEVEL=info
DATABASE_URL="postgresql://user:password@localhost:5432/samu_triage"
ANTHROPIC_API_KEY=your_anthropic_api_key
JWT_SECRET=your_jwt_secret
ENCRYPTION_KEY=your_encryption_key

API Endpoints

Health Checks

GET /health        # Comprehensive health check
GET /health/live   # Liveness probe (Kubernetes)
GET /health/ready  # Readiness probe (Kubernetes)

Triage API (Coming Soon)

POST /api/v1/calls           # Initiate new triage call
GET  /api/v1/calls/:id       # Retrieve call details
POST /api/v1/calls/:id/msg   # Send message to AI agent
GET  /api/v1/reports/:id     # Get triage report

CI/CD Pipeline

GitHub Actions

Executes on every push and pull request:

  1. Lint (ESLint + Prettier)
  2. Type Check (TypeScript strict mode)
  3. Test (Vitest with PostgreSQL service container)
  4. Build (Production build verification)
  5. Security (npm audit)

Google Cloud Build

Automated deployment pipeline (cloudbuild.yaml):

  1. Install dependencies
  2. Run linter
  3. Run type check
  4. Run tests
  5. Build application
  6. Build Docker image
  7. Push to Google Container Registry
  8. Deploy to Cloud Run

Triggered automatically on push to main branch when connected to GitHub.

Documentation

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m 'Add feature')
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License.

Acknowledgments

  • Mastra AI - TypeScript AI framework
  • Anthropic - Claude LLM
  • Fastify - Web framework
  • Prisma - Database ORM
  • Google Cloud - Cloud infrastructure

Contact

SAMU AI Team - Google Hackathon 2025

Project Repository: https://github.com/MirageAiEIP/Hackaton_google

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors