Skip to main content

Configuration Documentation

Environment Variables

Setup

Copy the example file and fill in your values:

cp .env.example .env.local

Complete Environment Variables Reference

Below is a comprehensive list of all environment variables used in the application:


ML API Configuration

VariableTypeRequiredDefaultDescription
NEXT_PUBLIC_ML_API_URLstringYeshttp://localhost:8000Base URL for the ML API backend. Used for predictions and WebSocket connections.
# ML API Backend URL
NEXT_PUBLIC_ML_API_URL=http://localhost:8000

Usage:

  • Local development: http://localhost:8000
  • Production: Your deployed FastAPI URL (e.g., https://api.yourapp.com)
  • WebSocket URLs are derived by replacing http with ws

App URL Configuration

VariableTypeRequiredDefaultDescription
NEXT_PUBLIC_APP_URLstringNohttp://localhost:3000Public URL of the Next.js app. Used for email links and redirects.
# App URL (for email links and redirects)
NEXT_PUBLIC_APP_URL=http://localhost:3000

Email Service (Resend)

VariableTypeRequiredDefaultDescription
RESEND_API_KEYstringNo-API key from Resend for sending emails.
RESEND_FROM_EMAILstringNo-Verified sender email address in format Name <email>.
# Resend Email Service
# Get your API key from https://resend.com/api-keys
RESEND_API_KEY=re_your_api_key_here

# Configure your verified domain in Resend dashboard
RESEND_FROM_EMAIL=EduBotX <noreply@yourdomain.com>

How to get:

  1. Sign up at Resend
  2. Navigate to API Keys → Create API Key
  3. Verify your domain in Resend dashboard
  4. Use the verified domain in RESEND_FROM_EMAIL

Firebase Configuration

VariableTypeRequiredDefaultDescription
NEXT_PUBLIC_FIREBASE_API_KEYstringYes-Firebase Web API key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAINstringYes-Firebase Auth domain
NEXT_PUBLIC_FIREBASE_PROJECT_IDstringYes-Firebase project ID
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_IDstringYes-Firebase Cloud Messaging sender ID
NEXT_PUBLIC_FIREBASE_APP_IDstringYes-Firebase app ID
# Firebase Web App Configuration
NEXT_PUBLIC_FIREBASE_API_KEY=AIza...your-api-key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789012
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789012:web:abc123def456

How to get:

  1. Go to Firebase Console
  2. Create a new project or select existing
  3. Navigate to Project Settings → General
  4. Scroll to "Your apps" → Add web app (if not exists)
  5. Copy the config values

Firebase Services Used:

  • Authentication: Email/password, Google OAuth
  • Firestore: Report storage, user data

Blockchain Configuration (Polygon)

VariableTypeRequiredDefaultDescription
BLOCKCHAIN_PRIVATE_KEYstringNo*-Server wallet private key (⚠️ SERVER-SIDE ONLY)
BLOCKCHAIN_RPC_URLstringNohttps://rpc-amoy.polygon.technologyPolygon network RPC endpoint
BLOCKCHAIN_CHAIN_IDnumberNo80002Chain ID (80002 for Amoy testnet, 137 for mainnet)
BLOCKCHAIN_CONTRACT_ADDRESSstringNo*-Deployed ReportRegistry contract address
# Blockchain Configuration
# Generate wallet: node -e "console.log(require('ethers').Wallet.createRandom().privateKey)"
# Get testnet MATIC: https://faucet.polygon.technology/
BLOCKCHAIN_PRIVATE_KEY=0x_your_server_wallet_private_key

# Testnet (FREE - for development)
BLOCKCHAIN_RPC_URL=https://rpc-amoy.polygon.technology
BLOCKCHAIN_CHAIN_ID=80002

# Mainnet (uncomment for production)
# BLOCKCHAIN_RPC_URL=https://polygon-rpc.com
# BLOCKCHAIN_CHAIN_ID=137

# Contract address (after deployment)
BLOCKCHAIN_CONTRACT_ADDRESS=0x_your_deployed_contract_address

⚠️ Security Warning:

  • BLOCKCHAIN_PRIVATE_KEY must NEVER be exposed to the client
  • It is used server-side only in API routes
  • Use a dedicated wallet specifically for this application
  • Fund with MATIC for gas fees (testnet MATIC is free from faucets)

How to set up:

  1. Generate a new wallet: node -e "console.log(require('ethers').Wallet.createRandom().privateKey)"
  2. Get testnet MATIC from Polygon Faucet
  3. Deploy the ReportRegistry contract (see /blockchain folder)
  4. Copy the deployed contract address

Environment File Structure

# ============================================
# REQUIRED VARIABLES
# ============================================

# ML API
NEXT_PUBLIC_ML_API_URL=http://localhost:8000

# Firebase (required for auth & database)
NEXT_PUBLIC_FIREBASE_API_KEY=your-api-key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abc123

# ============================================
# OPTIONAL VARIABLES
# ============================================

# App URL
NEXT_PUBLIC_APP_URL=http://localhost:3000

# Email Service (Resend)
RESEND_API_KEY=re_your_api_key_here
RESEND_FROM_EMAIL=EduBotX <noreply@yourdomain.com>

# Blockchain (Polygon) - Server-side only
BLOCKCHAIN_PRIVATE_KEY=0x_your_private_key
BLOCKCHAIN_RPC_URL=https://rpc-amoy.polygon.technology
BLOCKCHAIN_CHAIN_ID=80002
BLOCKCHAIN_CONTRACT_ADDRESS=0x_your_contract_address

Application Constants

Location: src/config/constants.ts

API Configuration

export const ML_API_BASE_URL = process.env.NEXT_PUBLIC_ML_API_URL || "http://localhost:8000";

UI Constants

export const TOAST_DURATION_MS = 4000;

export const ANIMATION_DURATION = {
fast: 150,
normal: 300,
slow: 500,
} as const;

Report Type Labels & Colors

export const REPORT_TYPE_LABELS = {
prediction: "Reusability Prediction",
treatment: "Treatment Recommendation",
"twin-engine": "Twin Engine Analysis",
"adaptive-optimizer": "Adaptive Optimizer",
} as const;

export const REPORT_TYPE_COLORS = {
prediction: {
bg: "bg-blue-100",
text: "text-blue-700",
border: "border-blue-200",
},
treatment: {
bg: "bg-green-100",
text: "text-green-700",
border: "border-green-200",
},
"twin-engine": {
bg: "bg-purple-100",
text: "text-purple-700",
border: "border-purple-200",
},
"adaptive-optimizer": {
bg: "bg-orange-100",
text: "text-orange-700",
border: "border-orange-200",
},
} as const;

Severity & Status Colors

export const SEVERITY_COLORS = {
low: "bg-green-50 text-green-700 border-green-100",
moderate: "bg-yellow-50 text-yellow-700 border-yellow-100",
high: "bg-red-50 text-red-700 border-red-100",
critical: "bg-red-100 text-red-800 border-red-200",
} as const;

export const STATUS_COLORS = {
good: "text-green-600",
moderate: "text-yellow-600",
poor: "text-red-600",
pass: "bg-green-100 text-green-700",
fail: "bg-red-100 text-red-700",
unknown: "bg-yellow-100 text-yellow-700",
} as const;

export const COMPLIANCE_STATUS = {
PASS: { bg: "bg-green-100", text: "text-green-700" },
FAIL: { bg: "bg-red-100", text: "text-red-700" },
UNKNOWN: { bg: "bg-yellow-100", text: "text-yellow-700" },
} as const;

Water Quality Parameters

Location: src/config/parameters.ts

Parameter Interface

interface ParameterConfig {
key: string; // Form field key
label: string; // Display label
unit?: string; // Unit of measurement
min?: number; // Minimum value
max?: number; // Maximum value
step?: number; // Input step
defaultValue?: number; // Default form value
description?: string; // Help text
}

Influent Parameters (Prediction Model)

export const INFLUENT_PARAMETERS: ParameterConfig[] = [
{ key: "influent_BOD", label: "Influent BOD", unit: "mg/L", min: 0, max: 1000, defaultValue: 18 },
{ key: "influent_COD", label: "Influent COD", unit: "mg/L", min: 0, max: 2000, defaultValue: 36 },
{ key: "influent_TSS", label: "Influent TSS", unit: "mg/L", min: 0, max: 1000, defaultValue: 22 },
{ key: "influent_pH", label: "Influent pH", unit: "", min: 0, max: 14, step: 0.1, defaultValue: 6 },
{ key: "influent_TDS", label: "Influent TDS", unit: "mg/L", min: 0, max: 5000, defaultValue: 65 },
];

Effluent Parameters (Optional)

export const EFFLUENT_PARAMETERS: ParameterConfig[] = [
{ key: "effluent_BOD", label: "Effluent BOD", unit: "mg/L", min: 0, max: 500 },
{ key: "effluent_COD", label: "Effluent COD", unit: "mg/L", min: 0, max: 1000 },
{ key: "effluent_TSS", label: "Effluent TSS", unit: "mg/L", min: 0, max: 500 },
{ key: "effluent_TDS", label: "Effluent TDS", unit: "mg/L", min: 0, max: 5000 },
{ key: "effluent_pH", label: "Effluent pH", unit: "", min: 0, max: 14, step: 0.1, defaultValue: 7.5 },
{ key: "effluent_BOD_lag1", label: "Effluent BOD (Previous)", unit: "mg/L", min: 0, max: 500, defaultValue: 22 },
];

Operational Parameters

export const OPERATIONAL_PARAMETERS: ParameterConfig[] = [
{ key: "flow_rate", label: "Flow Rate", unit: "m³/hr", min: 0, max: 10000, defaultValue: 150 },
{ key: "aeration_rate", label: "Aeration Rate", unit: "m³/hr", min: 0, max: 500, defaultValue: 35 },
{ key: "chemical_dose", label: "Chemical Dose", unit: "mg/L", min: 0, max: 100, defaultValue: 12 },
{ key: "sludge_recycle_rate", label: "Sludge Recycle Rate", unit: "%", min: 0, max: 100, defaultValue: 25 },
{ key: "retention_time", label: "Retention Time", unit: "hours", min: 0, max: 48, defaultValue: 6 },
{ key: "temperature", label: "Temperature", unit: "°C", min: 0, max: 50, defaultValue: 25 },
];

Treatment Parameters

export const TREATMENT_PARAMETERS: ParameterConfig[] = [
{ key: "pH", label: "pH", unit: "", min: 0, max: 14, step: 0.1, defaultValue: 7.5 },
{ key: "TSS", label: "TSS", unit: "mg/L", min: 0, max: 1000, defaultValue: 120 },
{ key: "Turbidity", label: "Turbidity", unit: "NTU", min: 0, max: 500, defaultValue: 45 },
{ key: "BOD", label: "BOD", unit: "mg/L", min: 0, max: 1000, defaultValue: 180 },
{ key: "COD", label: "COD", unit: "mg/L", min: 0, max: 2000, defaultValue: 350 },
{ key: "NH4_N", label: "Ammoniacal Nitrogen", unit: "mg/L", min: 0, max: 100, defaultValue: 25 },
{ key: "Total_Nitrogen", label: "Total Nitrogen", unit: "mg/L", min: 0, max: 200, defaultValue: 40 },
{ key: "Phosphate", label: "Phosphate", unit: "mg/L", min: 0, max: 50, defaultValue: 8 },
{ key: "Fecal_Coliform", label: "Fecal Coliform", unit: "MPN/100mL", min: 0, max: 100000, defaultValue: 5000 },
{ key: "Oil_Grease", label: "Oil & Grease", unit: "mg/L", min: 0, max: 100, defaultValue: 15 },
{ key: "TDS", label: "TDS", unit: "mg/L", min: 0, max: 5000, defaultValue: 600 },
{ key: "Heavy_Metals", label: "Heavy Metals", unit: "mg/L", min: 0, max: 10, step: 0.1, defaultValue: 0.5 },
];

Default Form Values

export const PREDICTION_DEFAULT_VALUES = {
flow_rate: 150,
influent_BOD: 18,
influent_COD: 36,
influent_TSS: 22,
influent_pH: 6,
influent_TDS: 65,
aeration_rate: 35,
chemical_dose: 12,
sludge_recycle_rate: 25,
retention_time: 6,
temperature: 25,
effluent_BOD_lag1: 22,
effluent_BOD: "",
effluent_COD: "",
effluent_TSS: "",
effluent_TDS: "",
effluent_pH: 7.5,
};

export const TREATMENT_DEFAULT_VALUES = {
pH: 7.5,
TSS: 120,
Turbidity: 45,
BOD: 180,
COD: 350,
NH4_N: 25,
Total_Nitrogen: 40,
Phosphate: 8,
Fecal_Coliform: 5000,
Oil_Grease: 15,
TDS: 600,
Heavy_Metals: 0.5,
target_use_case: "Auto (based on parameters)",
};

Treatment Use Cases

export const TREATMENT_USE_CASES = [
"Auto (based on parameters)",
"Irrigation",
"Domestic Use",
"Industrial Use",
"Drinking Water",
"Aquaculture",
] as const;

export type TreatmentUseCaseOption = (typeof TREATMENT_USE_CASES)[number];

Blockchain Configuration

Location: src/lib/blockchain/config.ts

export const BLOCKCHAIN_CONFIG = {
rpcUrl: process.env.NEXT_PUBLIC_POLYGON_RPC_URL || "https://rpc-amoy.polygon.technology",
chainId: 80002,
chainName: "Polygon Amoy Testnet",
contractAddress: process.env.NEXT_PUBLIC_CONTRACT_ADDRESS || "",
explorerUrl: "https://amoy.polygonscan.com",
};

export const CONTRACT_ABI = [
// Store single report
"function storeReport(string reportId, bytes32 reportHash, string reportType, bytes32 userIdHash)",
// Store batch
"function storeReportsBatch(string[] reportIds, bytes32[] reportHashes, string[] reportTypes, bytes32[] userIdHashes)",
// Verify hash (free, view function)
"function verifyHash(bytes32 reportHash) view returns (bool)",
// Get total count
"function totalReports() view returns (uint256)",
];

Next.js Configuration

Location: next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
// Configuration options
};

export default nextConfig;

TypeScript Configuration

Location: tsconfig.json

{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [{ "name": "next" }],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}

shadcn/ui Configuration

Location: components.json

{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "",
"css": "src/app/globals.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}

Adding New Configuration

Adding Environment Variables

  1. Add to .env.example:

    NEW_VARIABLE=example-value
  2. Add to .env.local:

    NEW_VARIABLE=actual-value
  3. If client-side, prefix with NEXT_PUBLIC_:

    NEXT_PUBLIC_CLIENT_VARIABLE=value

Adding Constants

  1. Add to src/config/constants.ts:

    export const NEW_CONSTANT = "value";
  2. Export from src/config/index.ts:

    export { NEW_CONSTANT } from "./constants";

Adding Parameters

  1. Add to src/config/parameters.ts:
    export const NEW_PARAMETERS: ParameterConfig[] = [...];

Last Updated: December 2024