Configuration¶
The LMS uses django-environ for configuration via .env files. Django settings are split across environment-specific modules.
Django Settings Structure¶
Settings live in backend/config/settings/:
| File | Purpose |
|---|---|
base.py |
Shared configuration: installed apps, middleware, database, REST framework, Celery, i18n |
development.py |
Debug mode, CORS, console email backend, eager Celery |
production.py |
Security hardening, external services, production caching |
test.py |
Test-specific overrides, in-memory caching, eager Celery |
The active settings module is controlled by DJANGO_SETTINGS_MODULE:
# Development (default)
export DJANGO_SETTINGS_MODULE=config.settings.development
# Production
export DJANGO_SETTINGS_MODULE=config.settings.production
# Testing (set automatically by pytest-django)
export DJANGO_SETTINGS_MODULE=config.settings.test
Environment Variables¶
Required Variables¶
| Variable | Description | Example |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgres://user:pass@localhost:5432/lms |
SECRET_KEY |
Django secret key | Random 50+ character string |
PROVIDER_ENCRYPTION_KEY |
Fernet key for provider credential encryption | Generated via Fernet.generate_key() |
Common Variables¶
| Variable | Description | Default |
|---|---|---|
DEBUG |
Enable debug mode | False |
ALLOWED_HOSTS |
Comma-separated allowed hosts | localhost,127.0.0.1 |
REDIS_URL |
Redis connection string | redis://localhost:6379/0 |
CORS_ALLOWED_ORIGINS |
Comma-separated CORS origins | http://localhost:5173,http://localhost:5174 |
LANGUAGE_CODE |
Default language | en |
TIME_ZONE |
Default timezone | UTC |
External Service Variables¶
These are optional in development but required in production:
| Variable | Service | Purpose |
|---|---|---|
AWS_ACCESS_KEY_ID |
AWS S3 | Document storage |
AWS_SECRET_ACCESS_KEY |
AWS S3 | Document storage |
AWS_STORAGE_BUCKET_NAME |
AWS S3 | Document storage |
SENDGRID_API_KEY |
SendGrid | Email delivery |
TWILIO_ACCOUNT_SID |
Twilio | SMS delivery |
TWILIO_AUTH_TOKEN |
Twilio | SMS delivery |
TWILIO_FROM_NUMBER |
Twilio | SMS sender number |
Note
Payment processor credentials (Authorize.Net, Stripe) are stored per-tenant in the ProviderConfig model, not as environment variables. See Provider Pattern.
Database Configuration¶
PostgreSQL¶
The system requires PostgreSQL 16+ for schema-per-tenant isolation:
Key database settings:
ENGINE:django.db.backends.postgresql(via psycopg 3)DATABASE_ROUTERS:("django_pgschemas.routers.TenantAppsRouter",)--- routes queries to the correct schema
Redis¶
Redis is used as both the Celery broker and result backend:
Multi-Tenancy Configuration¶
The TENANTS setting in base.py defines the three-schema model:
TENANTS = {
"public": {
"APPS": [
"django_pgschemas",
"apps.tenants",
"django.contrib.contenttypes",
],
},
"default": {
"TENANT_MODEL": "tenants.Tenant",
"DOMAIN_MODEL": "tenants.Domain",
"APPS": [
# Django contrib apps
# Third-party apps (allauth, guardian, pghistory, etc.)
# All LMS business apps
],
},
}
Warning
The public and default keys cannot have DOMAINS or FALLBACK_DOMAINS. Domain configuration is done per-tenant in the Domain model.
Celery Configuration¶
Celery is configured in config/celery.py:
# Broker (Redis)
CELERY_BROKER_URL=redis://localhost:6379/0
# Result backend (Redis)
CELERY_RESULT_BACKEND=redis://localhost:6379/0
Development settings use CELERY_TASK_ALWAYS_EAGER=True to execute tasks synchronously.
CORS Configuration¶
For local development with separate frontend dev servers:
Port 5173 is the admin dashboard, port 5174 is the borrower portal.
See Also¶
- Installation --- Initial setup steps
- Project Structure --- Where configuration files live
- Multi-Tenancy --- Schema configuration details
- Provider Pattern --- Per-tenant provider configuration