FastAPI backend + Vite frontend for voice-based patient check-ins using Vapi.
This project currently includes:
- MongoDB-backed APIs for storing question sets and submitted answers.
- PostgreSQL-backed APIs for survey templates and Vapi call answer ingestion.
- A frontend client using
@vapi-ai/web.
vapi_dev/
├── backend/
│ ├── main.py
│ ├── requirements.txt
│ └── app/
│ ├── core/
│ │ ├── config.py
│ │ ├── database.py
│ │ ├── pg_database.py
│ │ └── security.py
│ ├── models/
│ │ ├── mongoDB_schemas.py
│ │ └── sql_models.py
│ └── routes/
│ ├── health.py
│ ├── data.py
│ └── vapi.py
├── frontend/
│ ├── index.html
│ ├── main.js
│ ├── style.css
│ ├── package.json
│ └── vite.config.js
├── Terraform/
└── README.md
- Python 3.10+
- Node.js 18+
- PostgreSQL 14+
- MongoDB 6+ (required for
/api/questionsand/api/answersroutes)
- Create and activate a virtual environment:
cd vapi_dev
python3 -m venv .venv
source .venv/bin/activate- Install backend dependencies:
pip install -r backend/requirements.txt- Create a
.envfile in the project root (vapi_dev/.env) and configure values:
# MongoDB
MONGODB_URL=mongodb://localhost:27017
DATABASE_NAME=vapi_db
# PostgreSQL
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/vapi_db
# API security
API_KEY=change-this-in-production
# Vapi
VAPI_API_KEY=
VAPI_ASSISTANT_ID=
VAPI_PHONE_NUMBER_ID=
VAPI_SERVER_URL=- Run the backend:
python -m backend.mainBackend runs on http://localhost:8000 by default.
- Install frontend dependencies:
cd frontend
npm install- Run frontend dev server:
npm run devVite runs on http://localhost:3000 by default.
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
GET /- basic service metadataGET /health- health check
All routes below require X-API-Key header.
POST /api/questions- store parsed question listGET /api/questions?limit=10&skip=0- list question documentsGET /api/questions/{question_id}- get one question documentDELETE /api/questions/{question_id}- delete question documentPOST /api/answers- store a session's answersGET /api/answers?limit=10&skip=0- list answersGET /api/answers/{answer_id}- get one answer documentDELETE /api/answers/{answer_id}- delete answer document
GET /start-session/{patient_id}- returns Vapi launch config (
vapiApiKey,assistantId,assistantOverrides) generated from latestsurvey_templatesrecord.
- returns Vapi launch config (
POST /vapi-webhook- receives Vapi tool-call payloads and records
record_answeroutputs intopatient_responses.
- receives Vapi tool-call payloads and records
curl http://localhost:8000/healthcurl -X POST "http://localhost:8000/api/questions" \
-H "Content-Type: application/json" \
-H "X-API-Key: change-this-in-production" \
-d '{
"questions": [
{"type": "mcq", "Q": "How are you today?", "A": ["Good", "Okay", "Not great"]},
{"type": "open", "Q": "Anything else to share?", "A": []}
],
"metadata": {"source": "intake-form"}
}'curl "http://localhost:8000/start-session/patient-123"- In
backend/main.py, MongoDB connect/disconnect calls are currently commented out. If you use/api/questionsor/api/answers, ensure MongoDB is initialized in startup (or re-enable those calls). - Frontend currently proxies
/get-vapi-config, while backend exposes/start-session/{patient_id}. Align either the frontend fetch path or backend route naming before full end-to-end use. - CORS currently allows
*; lock this down for production.
- Use strong secrets for
API_KEYand Vapi credentials. - Restrict CORS origins and methods.
- Put backend behind HTTPS.
- Add request validation/rate-limiting for public-facing endpoints.
- Add logging/monitoring around webhook handling.
Add your license information here.