Overview
VIGIA uses environment variables for configuration, managed through Pydantic Settings. All configuration is centralized inbackend/app/core/config.py and loaded from .env files.
Configuration Architecture
Settings Class
TheSettings class (backend/app/core/config.py:45-295) uses Pydantic for validation and type safety:
Settings Instance
A singleton settings instance is cached using@lru_cache (backend/app/core/config.py:297-313):
Configuration Categories
Database Configuration
Single-Tenant (Legacy)
Multi-Tenant (SaaS)
{db_name} placeholder (backend/app/core/config.py:278-294).
Authentication & Security
backend/app/core/config.py:70-77:
CORS Configuration
backend/app/core/config.py:198-201:
Mail Configuration
Provider Selection
IMAP Settings
backend/app/core/config.py:98-117.
POP Settings
SMTP Settings
backend/app/core/config.py:124-133.
Mail Poller
LLM Configuration
Provider Selection
backend/app/core/config.py:238-260:
OpenAI Configuration
backend/app/core/config.py:153-157.
Azure OpenAI Configuration
backend/app/core/config.py:159-163.
Gemini Configuration
backend/app/core/config.py:166-170.
External APIs
VigiAccess (WHO Database)
Bioportal (Terminology)
ICD-11 (WHO Classification)
backend/app/core/config.py:185-190.
Translation Services
Media & Documents
backend/app/core/config.py:53-56 and 135-141.
OCR Configuration
backend/app/core/config.py:79-82.
Timezone & Scheduling
backend/app/core/config.py:143-147.
Internal Services
backend/app/core/config.py:172-177.
Configuration Validation
List Parsing Helper
Many settings accept both comma-separated strings and JSON arrays (backend/app/core/config.py:15-31):
Field Validators
IMAP Sent Folders
Mail Provider
IMAP Password Fallback
Master Database Default
Environment Files
File Locations
Configuration is loaded from.env files in the following order:
backend/.env(primary)backend/.env.local(local overrides, gitignored)- Environment variables (highest priority)
Example .env File
Frombackend/.env.example:
Multi-Tenant .env
Derived Configuration
Computed Paths
Digest Recipients Helper
Configuration at Runtime
Accessing Settings
Environment-Specific Config
Admin Configuration Endpoints
VIGIA provides admin endpoints for managing background jobs (backend/app/routers/admin.py).
Mail Poller Status
Start Poller
MAIL_POLL_ENABLED=false.
Stop Poller
Run Poller Immediately
Best Practices
Security
- Never commit
.envfiles to version control - Use strong
SECRET_KEY(256-bit random string) - Rotate secrets periodically
- Use environment-specific keys (dev, staging, prod)
- Restrict
CORS_ORIGINSto known domains
Performance
- Cache settings using
@lru_cache - Use connection pooling (
pool_pre_ping=True) - Set appropriate timeouts for external APIs
- Configure worker counts based on load
Maintenance
- Document custom settings in
.env.example - Use validation to catch config errors early
- Log configuration (without secrets) at startup
- Version control
.env.exampleonly
Multi-Tenant
- Validate
TENANT_DB_TEMPLATEincludes{db_name} - Use separate databases for master and tenants
- Configure
SAAS_BASE_DOMAINfor production - Test tenant isolation thoroughly
Troubleshooting
Configuration Not Loading
Problem: Changes to.env not reflected
Solution:
- Restart application (settings cached via
@lru_cache) - Check
.envfile location (must be in backend directory) - Verify no typos in variable names (case-insensitive)
Database Connection Errors
Problem:DATABASE_URL connection fails
Solution:
- Test connection string manually:
psql $DATABASE_URL - Check PostgreSQL is running
- Verify credentials and database exists
- Use
pool_pre_ping=Truefor connection health checks
CORS Errors
Problem: Frontend blocked by CORS policy Solution:- Add frontend URL to
CORS_ORIGINS - Include protocol (http/https) and port
- Use comma-separated or JSON array format
- Restart backend after changes
LLM Provider Errors
Problem: LLM API calls failing Solution:- Verify API key is correct
- Check provider is in
ALLOWED_PROVIDERS - Test API key with curl
- Review
LLM_ORDERfallback configuration