Overview
MedMitra uses environment variables for configuration, keeping sensitive information secure and separate from code. This guide covers all available configuration options for both backend and frontend.Environment Files
MedMitra uses different environment files for different components:Backend
.env in the backend/ directoryFrontend
.env.local in the frontend/ directoryBackend Configuration
The backend requires the following environment variables inbackend/.env:
Supabase Configuration
Supabase provides database, authentication, and file storage services.Your Supabase project URL. Find this in Project Settings → API.Format:
https://your-project-id.supabase.coExample:The service role key with admin privileges. This key bypasses Row Level Security (RLS).Location: Project Settings → API → service_role keyExample:
AI Service Configuration
Groq API
API key for Groq’s LLM inference service. Used for medical text analysis and radiology image interpretation.Models Used:
llama-3.3-70b-versatilefor text analysisllava-v1.5-7b-4096-previewfor vision/image analysis
- Visit console.groq.com
- Sign up or log in
- Navigate to API Keys
- Create a new API key
Groq offers a generous free tier with fast inference speeds. Monitor your usage in the console.
LlamaParse API
API key for LlamaIndex’s LlamaParse document parsing service. Used to extract structured text from PDF lab reports.How to Obtain:
- Visit cloud.llamaindex.ai
- Create an account
- Navigate to API Keys in settings
- Generate a new API key
Vector Database Configuration (Optional)
These settings are for future features involving semantic search and RAG (Retrieval-Augmented Generation).API key for Weaviate vector database (optional, for future features).Example:
Currently not used in production but reserved for future enhancements.
REST endpoint URL for Weaviate instance.Example:
Complete Backend .env Template
Frontend Configuration
The frontend requires the following environment variables infrontend/.env.local:
Supabase Configuration (Client-Side)
Your Supabase project URL. Same as backend but with
NEXT_PUBLIC_ prefix for client-side access.Example:The
NEXT_PUBLIC_ prefix makes this variable accessible in the browser. Only use it for non-sensitive values.The anonymous/public key for client-side Supabase access. This key is safe to expose in the browser.Location: Project Settings → API → anon public keyExample:
This key respects Row Level Security (RLS) policies, making it safe for client-side use.
Backend API Configuration
URL where your FastAPI backend is running.Development:Production:
Speech-to-Text Configuration
API key for Gladia’s speech-to-text service. Used for transcribing doctor’s audio notes.How to Obtain:
- Visit gladia.io
- Sign up and verify your email
- Navigate to the dashboard
- Generate an API key
Gladia provides high-accuracy medical transcription with support for medical terminology.
Complete Frontend .env.local Template
frontend/.env.local
Configuration by Environment
- Development
- Production
- Staging
Development Configuration
Backend (.env):- Backend:
uvicorn app:app --reload - Frontend:
npm run dev
Loading Configuration
Backend (Python)
The backend usespython-dotenv to load environment variables:
config.py
Frontend (Next.js)
Next.js automatically loads.env.local files. Access variables in code:
Only variables prefixed with
NEXT_PUBLIC_ are accessible in client-side code.Security Best Practices
Never Commit Secrets
Never Commit Secrets
- Add
.envand.env.localto.gitignore - Use
.env.examplefiles to document required variables without values - Never hardcode API keys in source code
Rotate Keys Regularly
Rotate Keys Regularly
- Rotate API keys every 3-6 months
- Immediately rotate if a key is accidentally exposed
- Use separate keys for development, staging, and production
Use Environment-Specific Keys
Use Environment-Specific Keys
- Separate Supabase projects for dev/staging/production
- Different API keys for each environment when possible
- Restrict production keys to production servers only
Principle of Least Privilege
Principle of Least Privilege
- Use anon key (not service role) in frontend
- Set up Row Level Security (RLS) policies in Supabase
- Limit API key permissions where possible
Validation and Troubleshooting
Verify Configuration
Create a simple script to verify your configuration:Common Configuration Issues
Variables Not Loading
Variables Not Loading
Backend:
- Ensure
.envfile is in the same directory asapp.py - Verify no typos in variable names
- Check that
load_dotenv()is called before accessing variables - Try
python-dotenvinstead of reading files manually
- Ensure file is named exactly
.env.local(not.envorenv.local) - Restart the dev server after adding/changing variables
- Verify
NEXT_PUBLIC_prefix for client-side variables
CORS Errors
CORS Errors
If you see CORS errors when frontend calls backend:
- Verify
NEXT_PUBLIC_FASTAPI_BACKEND_URLis correct - Check backend CORS configuration in
app.py:
- In production, update
allow_originsto your frontend domain
Supabase Connection Failed
Supabase Connection Failed
- Verify URL format:
https://xyz.supabase.co(no trailing slash) - Check API keys for extra spaces or newlines
- Ensure Supabase project is not paused (free tier)
- Test connection directly in Supabase SQL Editor
API Key Invalid
API Key Invalid
- Verify key is copied completely (no truncation)
- Check if key has expired or been revoked
- Ensure no quotes around the key value in .env
- Try regenerating the key in the provider’s dashboard
Configuration Examples
Template Files
Create example files for your team:Environment Variable Reference
Quick Reference Table
| Variable | Component | Required | Description |
|---|---|---|---|
SUPABASE_URL | Backend | Yes | Supabase project URL |
SUPABASE_SERVICE_ROLE_KEY | Backend | Yes | Admin key for backend operations |
GROQ_API_KEY | Backend | Yes | Groq LLM API key |
LLAMAPARSE_API_KEY | Backend | Yes | LlamaParse document parsing key |
WEAVIATE_API_KEY | Backend | No | Vector database key (future) |
WEAVIATE_REST_URL | Backend | No | Vector database URL (future) |
NEXT_PUBLIC_SUPABASE_URL | Frontend | Yes | Supabase project URL |
NEXT_PUBLIC_SUPABASE_ANON_KEY | Frontend | Yes | Public key for client auth |
NEXT_PUBLIC_FASTAPI_BACKEND_URL | Frontend | Yes | Backend API endpoint |
NEXT_PUBLIC_GLADIA_API_KEY | Frontend | Yes | Speech-to-text API key |
Next Steps
Getting Started
Quick start guide to get MedMitra running
API Reference
Explore all available API endpoints
Authentication
Learn about authentication and user management
AI Agents
Understand the multi-agent AI system
