Documentation Index
Fetch the complete documentation index at: https://mintlify.com/marchena96/Paradigma-lab1/llms.txt
Use this file to discover all available pages before exploring further.
LibraryService API reads configuration from two sources that are merged at startup by the .NET configuration system. appsettings.json is committed to source control and holds safe-to-share defaults (including a placeholder for the database password). .NET User Secrets overlay those defaults in the Development environment and are the correct place to store real credentials on a local machine — they are never written to disk inside the repository.
Connection String
Placeholder in appsettings.json
The file committed to the repository uses a placeholder value so no real credentials are ever exposed:
{
"ConnectionStrings": {
"DefaultConnection": "Host=aws-1-us-west-2.pooler.supabase.com;Port=5432;Database=postgres;Username=postgres.gyktxhzyeyisdbafvvpm;Password=[SUPABASE-PASSWORD];SSL Mode=Require;Trust Server Certificate=true; Pooling=false"
}
}
Supplying the real password via User Secrets
Run the following command from inside the HackerRank1/ directory. User Secrets are keyed to the project’s UserSecretsId and are loaded automatically when ASPNETCORE_ENVIRONMENT is Development:
cd HackerRank1
dotnet user-secrets set "ConnectionStrings:DefaultConnection" \
"Host=<host>;Port=5432;Database=postgres;Username=<user>;Password=<password>;SSL Mode=Require;Trust Server Certificate=true;Pooling=false"
The secrets file is stored locally at:
- Windows:
%APPDATA%\Microsoft\UserSecrets\9cbbfeab-44b3-447c-8aa1-4d5adea68ef6\secrets.json
- macOS / Linux:
~/.microsoft/usersecrets/9cbbfeab-44b3-447c-8aa1-4d5adea68ef6/secrets.json
UserSecretsId: 9cbbfeab-44b3-447c-8aa1-4d5adea68ef6
The password must be set via User Secrets for the Development environment. Without a valid connection string, the application compiles cleanly but crashes at startup when db.Database.Migrate() attempts to connect to the database.
JWT Settings
JWT configuration lives under the JwtSettings key in appsettings.json:
{
"JwtSettings": {
"Issuer": "MyApp",
"Audience": "localhost:80",
"SecretKey": "a_very_long_super_secret_key_here"
}
}
| Field | Default value | Description |
|---|
Issuer | MyApp | Validated on every incoming token (ValidateIssuer = true) |
Audience | localhost:80 | Validated on every incoming token (ValidateAudience = true) |
SecretKey | a_very_long_super_secret_key_here | Used to sign and verify HS256 tokens via SymmetricSecurityKey |
These values are bound to the JwtSettings entity class in Startup.cs and injected as a singleton:
var jwtSettings = Configuration
.GetSection("JwtSettings")
.Get<JwtSettings>()
?? throw new InvalidOperationException("Invalid JWT Settings");
services.AddSingleton(jwtSettings);
The default SecretKey is a well-known placeholder. Change it before any production deployment. Anyone who knows the key can forge valid tokens for your API.
Launch Profiles
Launch profiles are defined in HackerRank1/Properties/launchSettings.json. The primary profile used with dotnet run is HackerRank1:
{
"profiles": {
"HackerRank1": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7098;http://localhost:5219",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
| Setting | Value | Notes |
|---|
| HTTPS port | 7098 | Primary URL: https://localhost:7098 |
| HTTP port | 5219 | Fallback URL: http://localhost:5219 |
ASPNETCORE_ENVIRONMENT | Development | Enables User Secrets, Developer Exception Page, and Swagger UI |
launchUrl | swagger | Browser opens directly to the Swagger UI on launch |
CORS
The API defines a single named CORS policy called Frontend, which permits requests from the Vite development server:
// Startup.cs — ConfigureServices
services.AddCors(o => o.AddPolicy("Frontend", p => p
.WithOrigins("http://localhost:5173")
.AllowAnyHeader()
.AllowAnyMethod()));
The policy is applied in the middleware pipeline after routing and before authentication:
// Startup.cs — Configure
app.UseRouting();
app.UseCors("Frontend");
app.UseAuthentication();
app.UseAuthorization();
| Policy name | Allowed origin | Headers | Methods |
|---|
Frontend | http://localhost:5173 | Any | Any |
To allow additional origins (e.g. a deployed front-end), add further .WithOrigins(...) calls or replace the hardcoded value with a configuration key.
Database Connection Pool
The LibraryContext is registered using AddDbContextPool with Npgsql and retry-on-failure enabled:
// Startup.cs — ConfigureServices
services.AddDbContextPool<LibraryContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"), npgsqlOptions =>
{
npgsqlOptions.EnableRetryOnFailure(
maxRetryCount: 1,
maxRetryDelay: TimeSpan.FromSeconds(5),
errorCodesToAdd: null);
}),
poolSize: 20);
| Parameter | Value | Description |
|---|
poolSize | 20 | Maximum number of LibraryContext instances held in the pool |
maxRetryCount | 1 | Number of automatic retries on transient database failures |
maxRetryDelay | 5 seconds | Maximum delay between retry attempts |
errorCodesToAdd | null | No additional PostgreSQL error codes beyond the default retry list |