Skip to content

Commit abf0925

Browse files
authored
Merge pull request #247 from DevanshuNEU/fix/p0-and-p1-sprint
fix: error boundary, NavLink remount, env var standardization, useQuery refactor
2 parents 56694d1 + 3010c16 commit abf0925

17 files changed

Lines changed: 635 additions & 97 deletions

.env.example

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ PINECONE_INDEX_NAME=codeintel
1919
# Get from: https://app.supabase.com/project/_/settings/api
2020
SUPABASE_URL=https://your-project.supabase.co
2121
SUPABASE_ANON_KEY=eyJ...
22-
SUPABASE_JWT_SECRET=your-jwt-secret # From Project Settings → API → JWT Secret
22+
# From Project Settings -> API -> JWT Secret
23+
SUPABASE_JWT_SECRET=your-jwt-secret
24+
# From Project Settings -> API -> service_role key
25+
SUPABASE_SERVICE_ROLE_KEY=eyJ...
2326

2427
# Backend API
2528
API_KEY=change-this-secret-key-for-production
@@ -46,3 +49,7 @@ ENVIRONMENT=development # development, staging, production
4649
# Free tier: 10K requests/month
4750
COHERE_API_KEY=
4851
SEARCH_V2_ENABLED=true
52+
53+
# Voyage AI - code-specific embeddings (Optional - improves code search quality)
54+
# Get from: https://dash.voyageai.com/
55+
VOYAGE_API_KEY=

backend/config/startup_checks.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Startup environment validation.
3+
Fails fast with clear error messages if required config is missing.
4+
"""
5+
import os
6+
import sys
7+
from typing import List, Tuple
8+
9+
from services.observability import logger
10+
11+
12+
# (env_var_name, description)
13+
REQUIRED_VARS: List[Tuple[str, str]] = [
14+
("SUPABASE_URL", "Supabase project URL"),
15+
("SUPABASE_ANON_KEY", "Supabase anon/public key"),
16+
("SUPABASE_JWT_SECRET", "Supabase JWT secret for token verification"),
17+
("OPENAI_API_KEY", "OpenAI API key for embeddings"),
18+
("PINECONE_API_KEY", "Pinecone API key for vector storage"),
19+
]
20+
21+
OPTIONAL_VARS: List[Tuple[str, str, str]] = [
22+
("SUPABASE_SERVICE_ROLE_KEY", "Supabase service role key", "Using anon key as fallback"),
23+
("COHERE_API_KEY", "Cohere API key for reranking", "Search reranking disabled"),
24+
("VOYAGE_API_KEY", "Voyage AI key for code embeddings", "Using OpenAI embeddings"),
25+
("SENTRY_DSN", "Sentry DSN for error tracking", "Error tracking disabled"),
26+
("REDIS_HOST", "Redis host for caching", "Using default localhost"),
27+
]
28+
29+
30+
def validate_environment() -> None:
31+
"""Check required env vars exist. Log warnings for optional ones."""
32+
missing: List[str] = []
33+
34+
for var_name, description in REQUIRED_VARS:
35+
value = os.getenv(var_name)
36+
if not value:
37+
missing.append(f" {var_name} -- {description}")
38+
39+
if missing:
40+
msg = "Missing required environment variables:\n" + "\n".join(missing)
41+
msg += "\n\nSee .env.example for configuration reference."
42+
logger.error(msg)
43+
print(f"\n[FATAL] {msg}\n", file=sys.stderr)
44+
sys.exit(1)
45+
46+
# warn about optional vars
47+
for var_name, description, fallback_msg in OPTIONAL_VARS:
48+
if not os.getenv(var_name):
49+
logger.warning(f"{var_name} not set ({description}). {fallback_msg}")
50+
51+
logger.info("Environment validation passed")

backend/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
# Import API config (single source of truth for versioning)
1818
from config.api import API_PREFIX, API_VERSION
19+
from config.startup_checks import validate_environment
1920

2021
# Import routers
2122
from routes.auth import router as auth_router
@@ -36,7 +37,7 @@
3637
# Lifespan context manager for startup/shutdown
3738
@asynccontextmanager
3839
async def lifespan(app: FastAPI):
39-
# Startup
40+
validate_environment()
4041
await load_demo_repos()
4142
yield
4243
# Shutdown (cleanup if needed)

backend/services/supabase_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class SupabaseService:
1919

2020
def __init__(self):
2121
supabase_url = os.getenv("SUPABASE_URL")
22-
# Use service role key to bypass RLS for backend operations
23-
supabase_key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") or os.getenv("SUPABASE_KEY")
22+
# prefer service role key for backend (bypasses RLS), fall back to anon key
23+
supabase_key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") or os.getenv("SUPABASE_ANON_KEY")
2424

2525
if not supabase_url or not supabase_key:
26-
raise ValueError("SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY (or SUPABASE_KEY) must be set")
26+
raise ValueError("SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY (or SUPABASE_ANON_KEY) must be set")
2727

2828
# Create client with options to avoid auth cleanup issues
2929
options = ClientOptions(

docker-compose.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ services:
3232
- PINECONE_API_KEY=${PINECONE_API_KEY}
3333
- PINECONE_INDEX_NAME=${PINECONE_INDEX_NAME}
3434
- SUPABASE_URL=${SUPABASE_URL}
35-
- SUPABASE_KEY=${SUPABASE_KEY}
35+
- SUPABASE_ANON_KEY=${SUPABASE_ANON_KEY}
36+
- SUPABASE_JWT_SECRET=${SUPABASE_JWT_SECRET}
3637
- SUPABASE_SERVICE_ROLE_KEY=${SUPABASE_SERVICE_ROLE_KEY}
3738
- API_KEY=${API_KEY}
3839
- BACKEND_API_URL=http://backend:8000
3940
- DISCORD_FEEDBACK_WEBHOOK=${DISCORD_FEEDBACK_WEBHOOK}
41+
- COHERE_API_KEY=${COHERE_API_KEY}
42+
- VOYAGE_API_KEY=${VOYAGE_API_KEY}
43+
- SENTRY_DSN=${SENTRY_DSN}
4044
- FORWARDED_ALLOW_IPS=*
4145
volumes:
4246
- ./backend/repos:/app/repos
@@ -62,14 +66,14 @@ services:
6266
args:
6367
- VITE_API_URL=http://localhost:8000
6468
- VITE_SUPABASE_URL=${SUPABASE_URL}
65-
- VITE_SUPABASE_ANON_KEY=${SUPABASE_KEY}
69+
- VITE_SUPABASE_ANON_KEY=${SUPABASE_ANON_KEY}
6670
container_name: codeintel-frontend
6771
ports:
6872
- "3000:80"
6973
environment:
7074
- VITE_API_URL=http://localhost:8000
7175
- VITE_SUPABASE_URL=${SUPABASE_URL}
72-
- VITE_SUPABASE_ANON_KEY=${SUPABASE_KEY}
76+
- VITE_SUPABASE_ANON_KEY=${SUPABASE_ANON_KEY}
7377
depends_on:
7478
- backend
7579
healthcheck:

0 commit comments

Comments
 (0)