diff --git a/backend/main.py b/backend/main.py index d292b25..f1657c6 100644 --- a/backend/main.py +++ b/backend/main.py @@ -12,6 +12,7 @@ from backend.config_store import ( set_setting, ) from backend.openai_client import OpenAIConfigurationError, ask_ai +from backend.project_analyzer import analyze_github_project ROOT_DIR = Path(__file__).resolve().parent.parent FRONTEND_DIR = ROOT_DIR / 'frontend' @@ -40,6 +41,10 @@ class PromptTestRequest(BaseModel): task_type: str | None = None +class ProjectAnalyzeRequest(BaseModel): + repo_url: str + + @app.get('/') async def root(): index_file = FRONTEND_DIR / 'index.html' @@ -129,3 +134,21 @@ async def test_openai_connection(): 'model': result['model'], 'answer': result['answer'], } + + +@app.post('/api/projects/analyze') +async def analyze_project(payload: ProjectAnalyzeRequest): + repo_url = payload.repo_url.strip() + + if not repo_url.startswith('http'): + raise HTTPException(status_code=400, detail='Invalid repository URL') + + try: + analysis = analyze_github_project(repo_url) + except Exception as exc: + raise HTTPException(status_code=500, detail=str(exc)) from exc + + return { + 'success': True, + 'analysis': analysis.to_dict(), + }