2025-08-11 02:59:21 -06:00
|
|
|
"""
|
|
|
|
|
Claude Code Project Tracker - FastAPI Application
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
|
from fastapi import FastAPI
|
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
from fastapi.staticfiles import StaticFiles
|
|
|
|
|
from fastapi.responses import RedirectResponse
|
|
|
|
|
|
|
|
|
|
from app.database.connection import init_database, close_database
|
2025-08-11 05:58:27 -06:00
|
|
|
from app.api import sessions, conversations, activities, waiting, git, projects, analytics, importer, tool_calls
|
2025-08-11 02:59:21 -06:00
|
|
|
from app.dashboard.routes import dashboard_router
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager
|
|
|
|
|
async def lifespan(app: FastAPI):
|
|
|
|
|
"""Application lifespan management."""
|
|
|
|
|
# Startup
|
|
|
|
|
print("Starting Claude Code Project Tracker...")
|
|
|
|
|
await init_database()
|
|
|
|
|
yield
|
|
|
|
|
# Shutdown
|
|
|
|
|
print("Shutting down...")
|
|
|
|
|
await close_database()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create FastAPI app
|
|
|
|
|
app = FastAPI(
|
|
|
|
|
title="Claude Code Project Tracker",
|
|
|
|
|
description="API for tracking Claude Code development sessions and productivity",
|
|
|
|
|
version="1.0.0",
|
|
|
|
|
lifespan=lifespan
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Add CORS middleware
|
|
|
|
|
app.add_middleware(
|
|
|
|
|
CORSMiddleware,
|
|
|
|
|
allow_origins=["*"], # In production, replace with specific origins
|
|
|
|
|
allow_credentials=True,
|
|
|
|
|
allow_methods=["*"],
|
|
|
|
|
allow_headers=["*"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Include API routers
|
|
|
|
|
app.include_router(sessions.router, prefix="/api", tags=["Sessions"])
|
|
|
|
|
app.include_router(conversations.router, prefix="/api", tags=["Conversations"])
|
|
|
|
|
app.include_router(activities.router, prefix="/api", tags=["Activities"])
|
|
|
|
|
app.include_router(waiting.router, prefix="/api", tags=["Waiting Periods"])
|
|
|
|
|
app.include_router(git.router, prefix="/api", tags=["Git Operations"])
|
|
|
|
|
app.include_router(projects.router, prefix="/api", tags=["Projects"])
|
|
|
|
|
app.include_router(analytics.router, prefix="/api", tags=["Analytics"])
|
2025-08-11 05:58:27 -06:00
|
|
|
app.include_router(importer.router, prefix="/api", tags=["Data Import"])
|
|
|
|
|
app.include_router(tool_calls.router, prefix="/api", tags=["Tool Calls"])
|
2025-08-11 02:59:21 -06:00
|
|
|
|
|
|
|
|
# Include dashboard routes
|
|
|
|
|
app.include_router(dashboard_router, tags=["Dashboard"])
|
|
|
|
|
|
|
|
|
|
# Mount static files
|
|
|
|
|
app.mount("/static", StaticFiles(directory="app/dashboard/static"), name="static")
|
|
|
|
|
|
|
|
|
|
# Root redirect to dashboard
|
|
|
|
|
@app.get("/")
|
|
|
|
|
async def root():
|
|
|
|
|
"""Redirect root to dashboard."""
|
|
|
|
|
return RedirectResponse(url="/dashboard")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/health")
|
|
|
|
|
async def health_check():
|
|
|
|
|
"""Health check endpoint."""
|
|
|
|
|
return {"status": "healthy", "service": "claude-code-tracker"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
import uvicorn
|
|
|
|
|
uvicorn.run(
|
|
|
|
|
"main:app",
|
|
|
|
|
host="0.0.0.0",
|
|
|
|
|
port=8000,
|
|
|
|
|
reload=True,
|
|
|
|
|
log_level="info"
|
|
|
|
|
)
|