Team Ai
Apppublic

mikemichez/codebase-genius-agentic-code-documentation-system

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
server.py74 linesDownload Raw Back to root
1python2from fastapi import FastAPI, HTTPException3from fastapi.middleware.cors import CORSMiddleware4from fastapi.staticfiles import StaticFiles5from pydantic import BaseModel6import os7import subprocess8import uvicorn9 10app = FastAPI()11 12# CORS setup13app.add_middleware(14    CORSMiddleware,15    allow_origins=["*"],16    allow_methods=["*"],17    allow_headers=["*"],18)19 20class RepoRequest(BaseModel):21    repo_url: str22 23@app.post("/analyze")24async def analyze_repo(request: RepoRequest):25    """Trigger code analysis for a GitHub repo"""26    try:27        # Start Jac worker process28        proc = subprocess.Popen([29            "jac", "run", "main.jac", 30            "--walk", "code_genius",31            "--ctx", f'{{"repo_url": "{request.repo_url}"}}'32        ])33        34        return {35            "status": "started",36            "repo_url": request.repo_url,37            "pid": proc.pid38        }39    except Exception as e:40        raise HTTPException(status_code=500, detail=str(e))41 42@app.get("/health")43async def health_check():44    return {"status": "ok"}45 46@app.get("/history")47async def get_history():48    """List previously analyzed repos"""49    if not os.path.exists("./outputs"):50        return {"repos": []}51    52    repos = []53    for repo_dir in os.listdir("./outputs"):54        if os.path.exists(f"./outputs/{repo_dir}/docs.md"):55            repos.append({56                "name": repo_dir,57                "docs_path": f"./outputs/{repo_dir}/docs.md"58            })59    60    return {"repos": repos}61 62@app.get("/download/{repo_name}")63async def download_docs(repo_name: str):64    """Download generated documentation"""65    docs_path = f"./outputs/{repo_name}/docs.md"66    if not os.path.exists(docs_path):67        raise HTTPException(status_code=404, detail="Documentation not found")68    69    return {"docs_path": docs_path}70 71if __name__ == "__main__":72    uvicorn.run(app, host="0.0.0.0", port=8000)73 74</html>