Skip to content

feat: add environment variable validation and update documentation#23

Merged
ayushHardeniya merged 2 commits into
ZenYukti:mainfrom
Shreenath-14:main
Feb 17, 2026
Merged

feat: add environment variable validation and update documentation#23
ayushHardeniya merged 2 commits into
ZenYukti:mainfrom
Shreenath-14:main

Conversation

@Shreenath-14

Copy link
Copy Markdown
Contributor

Description

Implemented a "fail-fast" environment variable validation system for the backend. Previously, the server would start with missing or malformed .env variables, leading to silent failures and a confusing developer experience. Now, the server validates all required keys (Supabase, Port, Frontend URL) upon startup and provides clear error messages if any are invalid. Closes #5.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🧹 Code refactoring (no functional changes)
  • ⚡ Performance improvement
  • ✅ Test improvement
  • 🔧 Build or CI/CD configuration changes

How Has This Been Tested?

  • Startup Validation: Verified that the server crashes with a specific error message if PORT is not a number or if SUPABASE_URL is an invalid URL.

  • CORS Verification: Confirmed that updating the FRONTEND_URL in the .env correctly resolves browser console errors and allows the frontend to fetch room data.

  • Database Connectivity: Verified that valid anonymous sign-ins and message persistence work after correctly configuring Supabase keys and RLS policies.

Screenshots

image image

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Additional Information

Updated the CORS middleware to dynamically use the FRONTEND_URL from the environment configuration to prevent port mismatch errors between development environments (e.g., port 3000 vs 5173).

Learning Outcomes

I learned how to implement centralized configuration validation in Node.js/TypeScript and how to manage Row-Level Security (RLS) policies in Supabase for anonymous user sessions.

@github-actions

github-actions Bot commented Feb 6, 2026

Copy link
Copy Markdown

ZenYukti Banner

Yay! You're officially a Contributor! 🎉

Huge thanks for opening this Pull Request. Being a contributor to ZenYukti is a big deal, and we’re excited to have you on board.

Next Steps:

  1. A maintainer will review your code soon.
  2. Please ensure you've linked an assigned issue in the description.
  3. Stay tuned for feedback!

@Shreenath-14

Copy link
Copy Markdown
Contributor Author

Hi Team ! I've implemented the environment variable validation as requested in Issue #5. I've also updated the README with a configuration table. All local tests and CI checks passed. Looking forward to your feedback!

Comment thread backend/database/schema.sql Outdated
ALTER TABLE volunteers ENABLE ROW LEVEL SECURITY;

-- Profiles policies
-- Profiles policies

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert these changes from this file.

because, it looks like some comments were accidentally duplicated (e.g., -- Profiles policies) nd some whitespace was changed...

we should keep this PR focused strictly on the environment variable validation to keep the git history clean

Comment thread frontend/.env.example Outdated
Comment thread backend/src/config/index.ts
Comment thread README.md Outdated
@ayushHardeniya

Copy link
Copy Markdown
Member

also why this "feat: typing indicater for better UI experience" commit is here, in thsi PR?

this is completely irrelevant as per the target of this PR!

I'd suggest you - probably rebase it, avoid "revert" or "do not merge" to keep the commit history clean for future visitors.

@Shreenath-14 Shreenath-14 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done the changes you told me just review it and let me know

@Shreenath-14 Shreenath-14 marked this pull request as draft February 8, 2026 07:03
@Shreenath-14 Shreenath-14 marked this pull request as ready for review February 8, 2026 07:10
@Shreenath-14 Shreenath-14 reopened this Feb 8, 2026
@Shreenath-14 Shreenath-14 marked this pull request as draft February 8, 2026 08:11
@Shreenath-14 Shreenath-14 marked this pull request as ready for review February 8, 2026 08:28
@Shreenath-14

Copy link
Copy Markdown
Contributor Author

Hi @ayushHardeniya ,
I’ve fixed the YAML syntax issues in the welcome workflow and verified that the GitHub Actions workflow is now valid.
All requested changes have been addressed.
Requesting re-review.

@ayushHardeniya

Copy link
Copy Markdown
Member

Hi @Shreenath-14, can you tell me what this PR is actually about!
You have mixed up multiple different scopes/directories into same branch?

I'd suggest to filter it out, and stick with key purpose!
You can create further PRs with respective chnages if needed.

@Shreenath-14

Copy link
Copy Markdown
Contributor Author

Sir actully this PR was my first PR thats why its been mess please ignore I'll explain.
Firstly this PR solves 2 issues :

  1. server doesn't validate environment variables server doesn't validate environment variables #5
    In this issue I have fixed the env variable verification and validation with the specific error message display on screen and if all present then check is it valid keys or not

  2. No way to tell if someone's typing No way to tell if someone's typing #8
    This is another issue assigned to me where I have implemented a typing indicator which shows is someone typing or not you can review it

also for previous you said to make some style changes which has been done and also added detailed readme changes

@Shreenath-14

Copy link
Copy Markdown
Contributor Author

Hi @ayushHardeniya, I've completely reset this PR to focus strictly on Issue #5. I removed the emojis, numbered comments, and accidental schema changes as requested. I've also moved the typing indicator to a separate PR to keep the history clean. Could you please re-review when you have a moment?

@ayushHardeniya ayushHardeniya added developer-experience Enhances experience of a developer in IDE or while working on project apertre3.0 Apertre 3.0 open source program medium features involving multiple files or logic. backend Server-side logic and APIs labels Feb 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements environment variable validation for the backend using Zod to provide a "fail-fast" startup experience. Previously, the server could start with missing or malformed environment variables, leading to runtime errors. Now, all required configuration is validated at startup with clear error messages, addressing issue #5.

Changes:

  • Added Zod-based environment variable validation with type coercion and URL validation
  • Refactored configuration management to use centralized validation module
  • Simplified .env.example documentation (removed some helpful comments)

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
backend/src/config/env.ts New file implementing Zod schema for environment validation with fail-fast error handling
backend/src/config/index.ts Refactored to import validated env variables instead of direct process.env access
backend/package.json Added Zod dependency (invalid version 4.3.6)
backend/package-lock.json Lock file update for Zod dependency (invalid version)
backend/.env.example Simplified environment variable documentation
Files not reviewed (1)
  • backend/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/src/config/env.ts Outdated
Comment thread backend/.env.example
Comment on lines +1 to 7
# Supabase Configuration
SUPABASE_URL=https://your-project-id.supabase.co
SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key

# HuggingFace API Token (optional - get from https://huggingface.co/settings/tokens)
# If not provided, crisis detection will use keyword-based fallback
# HuggingFace API Token (Optional)
HUGGINGFACE_API_TOKEN=hf_YourTokenHere

Copilot AI Feb 14, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated .env.example file removes helpful documentation that was present in the original version, such as URLs where developers can obtain the required keys (e.g., "get from https://app.supabase.com → Project Settings → API" for Supabase configuration, "get from https://huggingface.co/settings/tokens" for HuggingFace). Consider restoring these comments to improve the developer experience, especially for new contributors who may not know where to find these credentials.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@ayushHardeniya ayushHardeniya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ayushHardeniya ayushHardeniya removed the request for review from Blazzzeee February 17, 2026 15:56
@ayushHardeniya ayushHardeniya merged commit 8cec413 into ZenYukti:main Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

apertre3.0 Apertre 3.0 open source program backend Server-side logic and APIs developer-experience Enhances experience of a developer in IDE or while working on project medium features involving multiple files or logic.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server doesn't validate environment variables

3 participants