From 39b226ff00056f8b9063493865199cd6302375ae Mon Sep 17 00:00:00 2001 From: Devananda Jyothi Date: Fri, 19 Sep 2025 22:36:57 +0530 Subject: [PATCH 1/3] added env configs --- .env.development | 35 + .env.example | 61 + .gitignore | 8 +- ENVIRONMENT.md | 248 ++ ENVIRONMENT_IMPLEMENTATION.md | 259 ++ src/app/compare/page.tsx | 1410 +++++------ src/app/layout.tsx | 30 +- src/app/predictor/[counselling]/page.tsx | 2094 +++++++++-------- src/app/robot.ts | 25 +- src/app/sitemap.ts | 23 +- .../[counselling]/[uni]/cutoff/page.tsx | 599 ++--- .../universities/[counselling]/[uni]/page.tsx | 194 +- .../[counselling]/[uni]/placement/page.tsx | 192 +- .../[counselling]/[uni]/seatmatrix/page.tsx | 440 ++-- src/app/universities/[counselling]/page.tsx | 759 +++--- src/components/app/nav-bar/nav-bar.tsx | 273 ++- src/components/footer/footer.tsx | 217 +- src/components/upper-nav/upper-nav.tsx | 212 +- src/config.ts | 77 +- 19 files changed, 4130 insertions(+), 3026 deletions(-) create mode 100644 .env.development create mode 100644 .env.example create mode 100644 ENVIRONMENT.md create mode 100644 ENVIRONMENT_IMPLEMENTATION.md diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..7087371 --- /dev/null +++ b/.env.development @@ -0,0 +1,35 @@ +# Development Environment Variables +# This file contains configuration for local development + +# Deployment +NODE_ENV=development +NEXT_PUBLIC_APP_ENV=development + +# API Configuration +NEXT_PUBLIC_API_URL=https://api.jeepedia.in/api +NEXT_PUBLIC_CDN_URL=https://res.cloudinary.com +NEXT_PUBLIC_ASSETS_URL=https://assets.jeepedia.in + +# Website Configuration +NEXT_PUBLIC_SITE_URL=http://localhost:3000 +NEXT_PUBLIC_DEV_TUNNEL_URL=https://7rfkcr7r-3000.inc1.devtunnels.ms +NEXT_PUBLIC_CONTACT_EMAIL=jeepedia.in@gmail.com + +# Social Media +NEXT_PUBLIC_DISCORD_URL=https://discord.gg/Z8s9JECw4C +NEXT_PUBLIC_INSTAGRAM_URL=https://www.instagram.com/jeepedia.in +NEXT_PUBLIC_GITHUB_URL=https://github.com/J2J-App + +# Analytics (disabled in development) +NEXT_PUBLIC_UMAMI_WEBSITE_ID=dev-test-id +NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://cloud.umami.is/script.js +NEXT_PUBLIC_GOOGLE_ADSENSE_ID=ca-pub-6258466000437582 + +# Feature Flags +NEXT_PUBLIC_ENABLE_ANALYTICS=false +NEXT_PUBLIC_ENABLE_CONSOLE_LOGS=true +NEXT_PUBLIC_MAINTENANCE_MODE=false + +# Performance +NEXT_PUBLIC_API_TIMEOUT=15000 +NEXT_PUBLIC_MAX_RETRIES=3 diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..08952b9 --- /dev/null +++ b/.env.example @@ -0,0 +1,61 @@ +# Environment Variables Template +# Copy this file to .env.local and fill in your actual values +# See README.md for detailed instructions + +# =================== +# DEPLOYMENT CONFIGURATION +# =================== +NODE_ENV=development +NEXT_PUBLIC_APP_ENV=development + +# =================== +# API CONFIGURATION +# =================== +# Main API endpoint +NEXT_PUBLIC_API_URL=https://api.jeepedia.in/api + +# CDN and Asset URLs +NEXT_PUBLIC_CDN_URL=https://res.cloudinary.com +NEXT_PUBLIC_ASSETS_URL=https://assets.jeepedia.in + +# =================== +# WEBSITE CONFIGURATION +# =================== +# Main website URL (used for sitemap, metadata, etc.) +NEXT_PUBLIC_SITE_URL=https://www.jeepedia.in + +# Development tunnel URL (for local development with external access) +NEXT_PUBLIC_DEV_TUNNEL_URL=https://7rfkcr7r-3000.inc1.devtunnels.ms + +# Contact email +NEXT_PUBLIC_CONTACT_EMAIL=jeepedia.in@gmail.com + +# =================== +# SOCIAL MEDIA LINKS +# =================== +NEXT_PUBLIC_DISCORD_URL=https://discord.gg/Z8s9JECw4C +NEXT_PUBLIC_INSTAGRAM_URL=https://www.instagram.com/jeepedia.in +NEXT_PUBLIC_GITHUB_URL=https://github.com/J2J-App + +# =================== +# ANALYTICS & TRACKING +# =================== +# Umami Analytics +NEXT_PUBLIC_UMAMI_WEBSITE_ID=your-umami-website-id +NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://cloud.umami.is/script.js + +# Google Analytics / AdSense +NEXT_PUBLIC_GOOGLE_ADSENSE_ID=ca-pub-6258466000437582 + +# =================== +# FEATURE FLAGS +# =================== +NEXT_PUBLIC_ENABLE_ANALYTICS=true +NEXT_PUBLIC_ENABLE_CONSOLE_LOGS=false +NEXT_PUBLIC_MAINTENANCE_MODE=false + +# =================== +# RATE LIMITING & PERFORMANCE +# =================== +NEXT_PUBLIC_API_TIMEOUT=10000 +NEXT_PUBLIC_MAX_RETRIES=3 diff --git a/.gitignore b/.gitignore index 5ef6a52..fc7dba6 100644 --- a/.gitignore +++ b/.gitignore @@ -30,8 +30,12 @@ yarn-debug.log* yarn-error.log* .pnpm-debug.log* -# env files (can opt-in for committing if needed) -.env* +# env files - allow template and development files, ignore sensitive local files +.env*.local +.env.staging +.env.production +!.env.example +!.env.development # vercel .vercel diff --git a/ENVIRONMENT.md b/ENVIRONMENT.md new file mode 100644 index 0000000..7ec90e4 --- /dev/null +++ b/ENVIRONMENT.md @@ -0,0 +1,248 @@ +# Environment Configuration Guide + +## Overview + +This application uses environment variables for configuration management to support different deployment environments (development, staging, production) and to keep sensitive information secure. + +## Environment Files Structure + +### Available Environment Files + +- `.env.example` - Template with all available environment variables and documentation +- `.env.development` - Development-specific configuration +- `.env.production` - Production-specific configuration +- `.env.local` - Local overrides (ignored by git, create manually) + +### Git Handling + +- `.env.example` and `.env.development` are tracked in git for team consistency +- `.env.production`, `.env.staging`, and `.env*.local` files are ignored by git for security + +## Quick Setup + +### 1. For Development + +```bash +# Copy the development environment file to .env.local +cp .env.development .env.local + +# Or start with the example template +cp .env.example .env.local +``` + +### 2. Configure Your Values + +Edit `.env.local` with your specific configuration: + +```env +# Required Variables +NEXT_PUBLIC_API_URL=https://api.jeepedia.in/api +NEXT_PUBLIC_SITE_URL=http://localhost:3000 + +# Optional: Add your analytics IDs +NEXT_PUBLIC_UMAMI_WEBSITE_ID=your-website-id-here +``` + +### 3. Start Development + +```bash +npm run dev +``` + +## Environment Variables Reference + +### ๐Ÿš€ Deployment Configuration + +| Variable | Description | Default | Required | +| --------------------- | -------------------------- | ------------- | -------- | +| `NODE_ENV` | Node environment | `development` | No | +| `NEXT_PUBLIC_APP_ENV` | App environment identifier | `development` | No | + +### ๐ŸŒ API Configuration + +| Variable | Description | Default | Required | +| ------------------------ | ----------------- | ---------------------------- | -------- | +| `NEXT_PUBLIC_API_URL` | Main API endpoint | - | **Yes** | +| `NEXT_PUBLIC_CDN_URL` | CDN base URL | `https://res.cloudinary.com` | No | +| `NEXT_PUBLIC_ASSETS_URL` | Assets base URL | `https://assets.jeepedia.in` | No | + +### ๐Ÿ  Website Configuration + +| Variable | Description | Default | Required | +| ---------------------------- | ---------------------- | ----------------------- | -------- | +| `NEXT_PUBLIC_SITE_URL` | Main website URL | - | **Yes** | +| `NEXT_PUBLIC_DEV_TUNNEL_URL` | Development tunnel URL | - | No | +| `NEXT_PUBLIC_CONTACT_EMAIL` | Contact email | `jeepedia.in@gmail.com` | No | + +### ๐Ÿ“ฑ Social Media + +| Variable | Description | Default | Required | +| --------------------------- | ------------------- | --------------------------------------- | -------- | +| `NEXT_PUBLIC_DISCORD_URL` | Discord server link | `https://discord.gg/Z8s9JECw4C` | No | +| `NEXT_PUBLIC_INSTAGRAM_URL` | Instagram profile | `https://www.instagram.com/jeepedia.in` | No | +| `NEXT_PUBLIC_GITHUB_URL` | GitHub organization | `https://github.com/J2J-App` | No | + +### ๐Ÿ“Š Analytics & Tracking + +| Variable | Description | Default | Required | +| ------------------------------- | --------------------------- | ---------------------------------- | -------- | +| `NEXT_PUBLIC_UMAMI_WEBSITE_ID` | Umami analytics website ID | - | No | +| `NEXT_PUBLIC_UMAMI_SCRIPT_URL` | Umami script URL | `https://cloud.umami.is/script.js` | No | +| `NEXT_PUBLIC_GOOGLE_ADSENSE_ID` | Google AdSense publisher ID | - | No | + +### ๐ŸŽ›๏ธ Feature Flags + +| Variable | Description | Default | Required | +| --------------------------------- | ------------------------ | ------- | -------- | +| `NEXT_PUBLIC_ENABLE_ANALYTICS` | Enable/disable analytics | `true` | No | +| `NEXT_PUBLIC_ENABLE_CONSOLE_LOGS` | Enable debug logging | `false` | No | +| `NEXT_PUBLIC_MAINTENANCE_MODE` | Enable maintenance mode | `false` | No | + +### โšก Performance + +| Variable | Description | Default | Required | +| ------------------------- | ------------------------ | ------- | -------- | +| `NEXT_PUBLIC_API_TIMEOUT` | API request timeout (ms) | `10000` | No | +| `NEXT_PUBLIC_MAX_RETRIES` | Max API retry attempts | `3` | No | + +## Environment-Specific Configuration + +### Development Environment + +- Analytics disabled by default +- Console logging enabled +- Localhost site URL +- Extended API timeout for debugging + +### Production Environment + +- Analytics enabled +- Console logging disabled +- Production site URL +- Optimized performance settings + +## Configuration Usage in Code + +### Importing Configuration + +```typescript +import { API_URL, SOCIAL_LINKS, FEATURES } from "@/config"; +``` + +### Using Configuration + +```typescript +// API calls +const response = await fetch(`${API_URL}/v2/users`); + +// Social media links +Join Discord; + +// Feature flags +{ + FEATURES.enableAnalytics && ; +} +``` + +### Environment Information + +```typescript +import { ENV } from "@/config"; + +if (ENV.isDevelopment) { + console.log("Development mode"); +} +``` + +## Troubleshooting + +### Common Issues + +#### โŒ "Missing required environment variables" error + +``` +Missing required environment variables: API_URL, SITE_URL +``` + +**Solution:** Ensure `.env.local` contains the required variables: + +```env +NEXT_PUBLIC_API_URL=https://api.jeepedia.in/api +NEXT_PUBLIC_SITE_URL=http://localhost:3000 +``` + +#### โŒ Environment variables not loading + +1. Check file naming (must start with `.env`) +2. Ensure variables start with `NEXT_PUBLIC_` for client-side access +3. Restart development server after changes +4. Verify file is in project root directory + +#### โŒ Analytics not working + +1. Check `NEXT_PUBLIC_ENABLE_ANALYTICS=true` +2. Verify analytics IDs are set correctly +3. Check browser console for script loading errors + +### Debugging Environment Configuration + +```typescript +import { ENV, devLog } from "@/config"; + +// Check current environment +devLog("Current environment:", ENV.appEnv); +devLog("Is development:", ENV.isDevelopment); + +// Log all config values (development only) +if (ENV.isDevelopment) { + console.log("Configuration loaded:", { + API_URL, + SITE_URL, + FEATURES, + // ... other config values + }); +} +``` + +## Security Best Practices + +### โœ… Do: + +- Use `NEXT_PUBLIC_` prefix only for client-side variables +- Keep sensitive keys in server-side environment variables +- Use different values for different environments +- Document all environment variables in `.env.example` + +### โŒ Don't: + +- Commit `.env.local` or `.env.production` files +- Put sensitive API keys in `NEXT_PUBLIC_` variables +- Use production values in development environment +- Hardcode URLs or configuration in components + +## Deployment + +### Vercel + +Environment variables are automatically loaded from `.env.production` in production builds. + +### Custom Deployment + +1. Set environment variables in your hosting platform +2. Ensure all required variables are present +3. Use production-optimized values +4. Test configuration before going live + +## Migration from Hardcoded Values + +If migrating from hardcoded configuration: + +1. **Identify hardcoded values** in your codebase +2. **Add to environment files** with appropriate defaults +3. **Update imports** to use new config structure +4. **Test thoroughly** in development environment +5. **Deploy incrementally** to avoid breaking changes + +--- + +For additional help or questions about environment configuration, refer to the [Next.js Environment Variables documentation](https://nextjs.org/docs/basic-features/environment-variables). diff --git a/ENVIRONMENT_IMPLEMENTATION.md b/ENVIRONMENT_IMPLEMENTATION.md new file mode 100644 index 0000000..f1edcf1 --- /dev/null +++ b/ENVIRONMENT_IMPLEMENTATION.md @@ -0,0 +1,259 @@ +# Environment Configuration Implementation Summary + +## ๐ŸŽฏ Overview + +Successfully implemented a comprehensive environment configuration system to replace all hardcoded URLs and configuration values throughout the JEEPedia application. + +## โœ… Completed Tasks + +### 1. Environment Files Created + +- **`.env.example`** - Template with all available environment variables and documentation +- **`.env.development`** - Development-specific configuration (analytics disabled, debug enabled) +- **`.env.production`** - Production-optimized configuration (analytics enabled, debug disabled) +- **`.env.local`** - Local development file for immediate use + +### 2. Configuration System (`src/config.ts`) + +- **Complete rewrite** from single hardcoded `API_URL` to comprehensive configuration system +- **Environment validation** - Throws descriptive errors for missing required variables +- **Organized into categories**: + - API Configuration (`API_URL`, `CDN_URL`, `ASSETS_URL`) + - Website Configuration (`SITE_URL`, `CONTACT_EMAIL`, `DEV_TUNNEL_URL`) + - Social Media Links (`discord`, `instagram`, `github`) + - Analytics Configuration (`umami`, `google adsense`) + - Feature Flags (`enableAnalytics`, `enableConsoleLogs`, `maintenanceMode`) + - Performance Settings (`apiTimeout`, `maxRetries`) + - Environment Information (`isDevelopment`, `isProduction`) + +### 3. Updated Components & Files + +#### Core Application Files + +- **`src/app/layout.tsx`** - Analytics scripts now conditional based on feature flags +- **`src/app/sitemap.ts`** - Dynamic sitemap generation using `SITE_URL` +- **`src/app/robot.ts`** - Dynamic robots.txt using `SITE_URL` + +#### Navigation & Footer Components + +- **`src/components/app/nav-bar/nav-bar.tsx`** - Social media links from config +- **`src/components/footer/footer.tsx`** - Contact email and social links from config + +#### API Integration Files + +- **`src/components/upper-nav/upper-nav.tsx`** - Uses `API_URL` from config +- **`src/app/predictor/[counselling]/page.tsx`** - Uses `API_URL` from config +- **`src/app/compare/page.tsx`** - Uses `API_URL` from config +- **`src/app/universities/[counselling]/page.tsx`** - Uses `API_URL` from config +- **`src/app/universities/[counselling]/[uni]/page.tsx`** - Uses `API_URL` from config +- **`src/app/universities/[counselling]/[uni]/cutoff/page.tsx`** - Uses `API_URL` from config +- **`src/app/universities/[counselling]/[uni]/placement/page.tsx`** - Uses `API_URL` from config +- **`src/app/universities/[counselling]/[uni]/seatmatrix/page.tsx`** - Uses `API_URL` from config + +### 4. Git Configuration + +- **`.gitignore`** - Updated to allow `.env.example` and `.env.development` while ignoring sensitive production files + +### 5. Documentation + +- **`ENVIRONMENT.md`** - Comprehensive guide covering: + - Quick setup instructions + - Complete environment variables reference + - Environment-specific configurations + - Code usage examples + - Troubleshooting guide + - Security best practices + - Migration guide + +## ๐Ÿ”ง Technical Implementation Details + +### Environment Variables Structure + +```env +# Deployment Configuration +NODE_ENV, NEXT_PUBLIC_APP_ENV + +# API Configuration +NEXT_PUBLIC_API_URL (required) +NEXT_PUBLIC_CDN_URL, NEXT_PUBLIC_ASSETS_URL + +# Website Configuration +NEXT_PUBLIC_SITE_URL (required) +NEXT_PUBLIC_CONTACT_EMAIL, NEXT_PUBLIC_DEV_TUNNEL_URL + +# Social Media +NEXT_PUBLIC_DISCORD_URL, NEXT_PUBLIC_INSTAGRAM_URL, NEXT_PUBLIC_GITHUB_URL + +# Analytics +NEXT_PUBLIC_UMAMI_WEBSITE_ID, NEXT_PUBLIC_UMAMI_SCRIPT_URL +NEXT_PUBLIC_GOOGLE_ADSENSE_ID + +# Feature Flags +NEXT_PUBLIC_ENABLE_ANALYTICS, NEXT_PUBLIC_ENABLE_CONSOLE_LOGS +NEXT_PUBLIC_MAINTENANCE_MODE + +# Performance +NEXT_PUBLIC_API_TIMEOUT, NEXT_PUBLIC_MAX_RETRIES +``` + +### Import Pattern Migration + +**Before:** + +```typescript +import API_URL from "@/config"; +``` + +**After:** + +```typescript +import { API_URL, SOCIAL_LINKS, FEATURES } from "@/config"; +``` + +### Feature Flag Implementation + +```typescript +// Analytics conditionally loaded +{ + FEATURES.enableAnalytics && ANALYTICS.umamiWebsiteId && ( + - + {FEATURES.enableAnalytics && ANALYTICS.umamiWebsiteId && ( +