Add initial project configuration and setup for Reference Board Viewer application. Include EditorConfig for consistent coding styles, pre-commit hooks for linting and formatting, Docker Compose for local development with PostgreSQL and MinIO, and a Nix flake for development environment management. Establish CI/CD pipeline for automated testing and deployment.

This commit is contained in:
Danilo Reyes
2025-11-01 22:28:46 -06:00
parent 58f463867e
commit 1bc657e0fd
33 changed files with 1756 additions and 38 deletions

102
backend/app/main.py Normal file
View File

@@ -0,0 +1,102 @@
"""FastAPI application entry point."""
import logging
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from app.core.config import settings
from app.core.errors import WebRefException
from app.core.logging import setup_logging
from app.core.middleware import setup_middleware
# Setup logging
setup_logging()
logger = logging.getLogger(__name__)
# Create FastAPI application
app = FastAPI(
title=settings.APP_NAME,
version=settings.APP_VERSION,
description="Reference Board Viewer - Web-based visual reference management",
docs_url="/docs",
redoc_url="/redoc",
openapi_url=f"{settings.API_V1_PREFIX}/openapi.json",
)
# Setup middleware
setup_middleware(app)
# Exception handlers
@app.exception_handler(WebRefException)
async def webref_exception_handler(request: Request, exc: WebRefException):
"""Handle custom WebRef exceptions."""
logger.error(f"WebRef exception: {exc.message}", extra={"details": exc.details})
return JSONResponse(
status_code=exc.status_code,
content={
"error": exc.message,
"details": exc.details,
"status_code": exc.status_code,
},
)
@app.exception_handler(Exception)
async def general_exception_handler(request: Request, exc: Exception):
"""Handle unexpected exceptions."""
logger.exception("Unexpected error occurred")
return JSONResponse(
status_code=500,
content={
"error": "Internal server error",
"details": str(exc) if settings.DEBUG else {},
"status_code": 500,
},
)
# Health check endpoint
@app.get("/health", tags=["System"])
async def health_check():
"""Health check endpoint."""
return {
"status": "healthy",
"version": settings.APP_VERSION,
"app": settings.APP_NAME,
}
# Root endpoint
@app.get("/", tags=["System"])
async def root():
"""Root endpoint with API information."""
return {
"message": f"Welcome to {settings.APP_NAME} API",
"version": settings.APP_VERSION,
"docs": "/docs",
"health": "/health",
}
# API routers will be added here in subsequent phases
# Example:
# from app.api import auth, boards, images
# app.include_router(auth.router, prefix=f"{settings.API_V1_PREFIX}/auth", tags=["Auth"])
# app.include_router(boards.router, prefix=f"{settings.API_V1_PREFIX}/boards", tags=["Boards"])
@app.on_event("startup")
async def startup_event():
"""Application startup tasks."""
logger.info(f"Starting {settings.APP_NAME} v{settings.APP_VERSION}")
logger.info(f"Debug mode: {settings.DEBUG}")
logger.info(f"API prefix: {settings.API_V1_PREFIX}")
@app.on_event("shutdown")
async def shutdown_event():
"""Application shutdown tasks."""
logger.info(f"Shutting down {settings.APP_NAME}")