Skip to content

Improvement: Make .env loading path relative to project in ai-service #18

@pragnyanramtha

Description

@pragnyanramtha

Description

The ai-service loads .env from a hardcoded relative path which will break depending on where the service is started from.

Location

File: backend/ai-service/app/main.py
Line: 17

Current Code

load_dotenv("../../.env")  # Hardcoded relative path

Problem

  • Only works if cwd is backend/ai-service/app/
  • Fails when running with uvicorn from project root
  • Fails in Docker containers
  • Fragile and error-prone

Suggested Fix

import os
from pathlib import Path

# Get the project root (3 levels up from this file)
env_path = Path(__file__).parent.parent.parent.parent / ".env"
load_dotenv(env_path)

Or use environment variable directly without dotenv in production.

Labels

enhancement, ai-service, config

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions