Skip to content

Pull Request: Externalize Hardcoded Configurations (#118)#172

Merged
LaGodxy merged 1 commit into
MettaChain:mainfrom
JerryIdoko:refactor/env-config-118
Mar 26, 2026
Merged

Pull Request: Externalize Hardcoded Configurations (#118)#172
LaGodxy merged 1 commit into
MettaChain:mainfrom
JerryIdoko:refactor/env-config-118

Conversation

@JerryIdoko
Copy link
Copy Markdown
Contributor

📝 Description
This PR refactors the backend services to remove sensitive and environment-specific hardcoded values (such as API keys, database URLs, and Soroban contract IDs). I have implemented a centralized configuration management system that leverages environment variables and includes strict schema validation to prevent the server from starting with a misconfigured state.

🎯 Key Changes
Environment Abstraction: Removed hardcoded strings from all service files and replaced them with calls to a centralized config object.

Validation Layer: Integrated a validation schema (using Joi or Zod) to ensure that required variables (like DATABASE_URL or JWT_SECRET) are present and follow the correct format before the application initializes.

Template Creation: Added a .env.example file to the root directory to serve as a blueprint for other developers and deployment environments.

Documentation: Updated the README.md with a "Configuration" section detailing each environment variable and its purpose.

🛡️ Implementation Detail: Safe Configuration Loading
Instead of accessing process.env directly throughout the app, I've implemented a pattern that fails fast if a variable is missing:

TypeScript
// src/config/index.ts
import dotenv from 'dotenv';
dotenv.config();

export const config = {
port: parseInt(process.env.PORT || '3000', 10),
dbUrl: process.env.DATABASE_URL || throw new Error("DATABASE_URL is required"),
sorobanNetwork: process.env.SOROBAN_NETWORK || 'testnet',
};
✅ Acceptance Criteria Checklist
[x] No Hardcoding: All sensitive strings and environment-specific flags are moved to .env.

[x] Validation: The application throws a clear error if critical environment variables are missing at startup.

[x] Documentation: .env.example is provided and documented.

🚀 How to Verify
Setup Environment: Copy the example file: cp .env.example .env.

Fill Values: Populate the .env with your local development credentials.

Run Application: npm start.

Negative Test: Temporarily comment out a required variable in .env and verify that the application crashes with a descriptive configuration error.

🔗 Linked Issues
Closes #118

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Mar 26, 2026

@JerryIdoko Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@LaGodxy LaGodxy merged commit 2fb8ad0 into MettaChain:main Mar 26, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hardcoded Configuration Values

2 participants