feat: add FastAPI app factory and health check endpoint

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-24 09:12:31 -06:00
parent fb4b948681
commit b3b34222c8
6 changed files with 156 additions and 2 deletions

57
app/main.py Normal file
View File

@@ -0,0 +1,57 @@
"""FastAPI application factory for SneakySwole.
Creates and configures the FastAPI app with routes, templates,
static files, and structured logging.
"""
from pathlib import Path
import structlog
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from app.config import get_settings
from app.logging_config import setup_logging
from app.routes.health import router as health_router
logger = structlog.get_logger(__name__)
# Template and static file directories
_BASE_DIR = Path(__file__).resolve().parent
TEMPLATES_DIR = _BASE_DIR / "templates"
STATIC_DIR = _BASE_DIR / "static"
def create_app() -> FastAPI:
"""Create and configure the FastAPI application.
Returns:
A fully configured FastAPI application instance.
"""
settings = get_settings()
setup_logging(log_level=settings.app_log_level)
app = FastAPI(
title="SneakySwole",
description="Open-source workout tracking and programming",
version="0.1.0",
)
# Mount static files
app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
# Jinja2 templates (available to routes via request.state or dependency)
templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
app.state.templates = templates
# Register route modules
app.include_router(health_router)
logger.info("app_started", environment=settings.app_env)
return app
# Uvicorn entry point
app = create_app()

23
app/routes/health.py Normal file
View File

@@ -0,0 +1,23 @@
"""Health check route for monitoring and readiness probes.
Provides a simple GET /health endpoint that returns application
status, name, and version.
"""
from fastapi import APIRouter
router = APIRouter(tags=["health"])
@router.get("/health")
async def health_check() -> dict:
"""Return application health status.
Returns:
JSON with app name, version, and status.
"""
return {
"app": "sneakyswole",
"version": "0.1.0",
"status": "ok",
}