Overview
Happy Habitat uses a hierarchical configuration system that supports multiple sources:appsettings.json, environment-specific files, and environment variables. This guide documents all available configuration options.
Configuration Hierarchy
Configuration sources are loaded in this order (later sources override earlier ones):appsettings.json(base configuration)appsettings.{Environment}.json(e.g.,appsettings.Production.json)- Environment variables
- Command-line arguments
Environment Variable Format
.NET configuration uses double underscores (__) to represent nested configuration:
Backend Configuration
Required Settings
ConnectionStrings:DefaultConnection
Database connection string for SQL Server.- Type: String
- Required: Yes
- Default: None
- Environment Variable:
ConnectionStrings__DefaultConnection
Jwt:Key
Secret key for signing JWT authentication tokens. Must be at least 32 characters.- Type: String
- Required: Yes (production)
- Default:
YourSuperSecretKeyThatShouldBeAtLeast32CharactersLong!(development only) - Environment Variable:
Jwt__Key - Validation:
- Cannot be empty in production (Program.cs:79-84)
- Cannot use default value in production (Program.cs:85-88)
- Minimum 32 characters recommended
Cors:Origins
Semicolon-separated list of allowed frontend origins for CORS.- Type: String (semicolon-separated)
- Required: Yes (production)
- Default:
http://localhost:4200;https://localhost:4200;http://localhost:5080;https://localhost:7177(development only) - Environment Variable:
Cors__Origins - Validation: Application fails to start if not configured in production (Program.cs:54-56)
- Do not include trailing slashes
- Use exact protocol (http vs https)
- Include port if non-standard
Database:RecreateOnStartup
Whether to drop and recreate the database on application startup.- Type: Boolean
- Required: No
- Default:
false - Environment Variable:
Database__RecreateOnStartup - Validation:
- Must be
falsein production (Program.cs:251-252) - Application fails to start if
truein production
- Must be
Optional Settings
Jwt:Issuer
JWT token issuer identifier.- Type: String
- Required: No
- Default:
HappyHabitat - Environment Variable:
Jwt__Issuer
Jwt:Audience
JWT token audience identifier.- Type: String
- Required: No
- Default:
HappyHabitatUsers - Environment Variable:
Jwt__Audience
Logging:LogLevel:Default
Default minimum log level for application logging.- Type: String
- Required: No
- Default:
Information - Allowed Values:
Trace,Debug,Information,Warning,Error,Critical,None - Environment Variable:
Logging__LogLevel__Default
Logging:LogLevel:Microsoft.AspNetCore
Log level for ASP.NET Core framework logs.- Type: String
- Required: No
- Default:
Warning - Environment Variable:
Logging__LogLevel__Microsoft.AspNetCore
Logging:LogLevel:Microsoft.EntityFrameworkCore
Log level for Entity Framework Core database logs.- Type: String
- Required: No
- Default: Not set (inherits from Default)
- Environment Variable:
Logging__LogLevel__Microsoft.EntityFrameworkCore
AllowedHosts
Semicolon-separated list of allowed host headers for host filtering middleware.- Type: String
- Required: No
- Default:
*(all hosts allowed) - Environment Variable:
AllowedHosts
ASPNETCORE_ENVIRONMENT
Specifies the hosting environment.- Type: String
- Required: No
- Default:
Production - Allowed Values:
Development,Staging,Production - Environment Variable:
ASPNETCORE_ENVIRONMENT
- Development:
- Swagger UI enabled (Program.cs:203-211)
- Dummy data seeding (Program.cs:270-275)
- Allows default JWT key
- Allows default CORS origins
- Production:
- Swagger UI disabled
- HTTPS redirection enabled (Program.cs:220-223)
- Requires explicit JWT key and CORS origins
- Strict validation on startup
ASPNETCORE_URLS
URLs the application listens on.- Type: String (semicolon-separated)
- Required: No
- Default:
http://localhost:5000 - Environment Variable:
ASPNETCORE_URLS
Frontend Configuration
Frontend configuration is managed through environment files, not environment variables. Configuration is baked into the build at compile time.Development (environment.ts)
Production (environment.prod.ts)
Frontend Configuration Options
production
Whether the application is running in production mode.- Type: Boolean
- Default:
false(development),true(production) - Impact: Enables production optimizations, disables debug features
apiUrl
Base URL for backend API requests.- Type: String
- Required: Yes
- Format:
https://domain.com/api(no trailing slash)
This value is compiled into the JavaScript bundle. To change it, you must rebuild the application.
apiVersion
API version identifier.- Type: String
- Default:
v1
appName
Application display name.- Type: String
- Default:
Happy Habitat
appVersion
Application version number.- Type: String
- Default:
0.0.0 - Recommendation: Update with each release
logging.level
Minimum log level for client-side logging.- Type: LogLevel enum
- Values:
DEBUG,INFO,WARN,ERROR - Default:
DEBUG(development),WARN(production)
logging.enableConsole
Whether to output logs to browser console.- Type: Boolean
- Default:
true(development),false(production)
logging.enableRemote
Whether to send logs to remote logging service.- Type: Boolean
- Default:
false(development),true(production)
logging.enableStackTraces
Whether to include stack traces in error logs.- Type: Boolean
- Default:
true
auth.useMockAuth
Whether to use mock authentication (for testing without backend).- Type: Boolean
- Default:
false - Recommendation: Always
falsein production
Configuration Templates
Development Environment
Backend (appsettings.Development.json):
environment.ts (see above)
Production Environment
Backend (appsettings.Production.json or environment variables):
environment.prod.ts with production settings.
Docker Environment
docker-compose.yml:Azure App Service
Configure application settings via Azure Portal or CLI:Security Best Practices
Sensitive Data
Secrets Management
Options:- Environment Variables - Simple, works everywhere
- Azure Key Vault - Centralized secret management
- AWS Secrets Manager - For AWS deployments
- Docker Secrets - For Docker Swarm
- Kubernetes Secrets - For Kubernetes deployments
Azure Key Vault Integration
Validation Checklist
Before deploying to production, verify:-
Jwt:Keyis set to a secure, unique value (minimum 32 characters) -
Cors:Originsincludes all frontend URLs -
Database:RecreateOnStartupisfalse - Connection string uses secure credentials
- Connection string enables encryption (
Encrypt=True) -
ASPNETCORE_ENVIRONMENTis set toProduction - Logging level is set to
Warningor higher - Secrets are not in source control
- Frontend
environment.prod.tshas correct API URL
Troubleshooting
Application Fails to Start
Check logs for validation errors:- Missing or invalid
Jwt:Key - Missing
Cors:Originsin production Database:RecreateOnStartup=truein production- Invalid connection string
CORS Errors
Verify:Cors:Originsincludes frontend URL exactly (no trailing slash)- Protocol matches (http vs https)
- Port is included if non-standard
Database Connection Fails
Verify:- Connection string format is correct
- Database server is accessible
- Credentials are correct
- Firewall allows connection
- SQL Server is running
Next Steps
- Backend Deployment - Deploy the API
- Frontend Deployment - Deploy the client
- Database Setup - Configure SQL Server