This repository has been archived on 2026-02-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BreakPilot Dev 19855efacc
Some checks failed
Tests / Go Tests (push) Has been cancelled
Tests / Python Tests (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / Go Lint (push) Has been cancelled
Tests / Python Lint (push) Has been cancelled
Tests / Security Scan (push) Has been cancelled
Tests / All Checks Passed (push) Has been cancelled
Security Scanning / Secret Scanning (push) Has been cancelled
Security Scanning / Dependency Vulnerability Scan (push) Has been cancelled
Security Scanning / Go Security Scan (push) Has been cancelled
Security Scanning / Python Security Scan (push) Has been cancelled
Security Scanning / Node.js Security Scan (push) Has been cancelled
Security Scanning / Docker Image Security (push) Has been cancelled
Security Scanning / Security Summary (push) Has been cancelled
CI/CD Pipeline / Go Tests (push) Has been cancelled
CI/CD Pipeline / Python Tests (push) Has been cancelled
CI/CD Pipeline / Website Tests (push) Has been cancelled
CI/CD Pipeline / Linting (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Docker Build & Push (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / CI Summary (push) Has been cancelled
ci/woodpecker/manual/build-ci-image Pipeline was successful
ci/woodpecker/manual/main Pipeline failed
feat: BreakPilot PWA - Full codebase (clean push without large binaries)
All services: admin-v2, studio-v2, website, ai-compliance-sdk,
consent-service, klausur-service, voice-service, and infrastructure.
Large PDFs and compiled binaries excluded via .gitignore.
2026-02-11 13:25:58 +01:00

193 lines
5.7 KiB
Python

"""
GeoEdu Service - Self-Hosted OSM + Terrain Learning Platform
DSGVO-konforme Erdkunde-Lernplattform mit selbst gehostetem OpenStreetMap
Main FastAPI Application
"""
import structlog
from contextlib import asynccontextmanager
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import time
from config import settings
# Configure structured logging
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.stdlib.add_logger_name,
structlog.stdlib.add_log_level,
structlog.stdlib.PositionalArgumentsFormatter(),
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.UnicodeDecoder(),
structlog.processors.JSONRenderer() if not settings.is_development else structlog.dev.ConsoleRenderer(),
],
wrapper_class=structlog.stdlib.BoundLogger,
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
cache_logger_on_first_use=True,
)
logger = structlog.get_logger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Application lifespan manager."""
# Startup
logger.info(
"Starting GeoEdu Service",
environment=settings.environment,
port=settings.port,
)
# Check data directories
import os
for dir_name, dir_path in [
("OSM Data", settings.osm_data_dir),
("DEM Data", settings.dem_data_dir),
("Tile Cache", settings.tile_cache_dir),
("Bundles", settings.bundle_dir),
]:
if os.path.exists(dir_path):
logger.info(f"{dir_name} directory exists", path=dir_path)
else:
logger.warning(f"{dir_name} directory missing", path=dir_path)
os.makedirs(dir_path, exist_ok=True)
yield
# Shutdown
logger.info("Shutting down GeoEdu Service")
# Create FastAPI app
app = FastAPI(
title="GeoEdu Service",
description="DSGVO-konforme Erdkunde-Lernplattform mit selbst gehostetem OpenStreetMap",
version="1.0.0",
docs_url="/docs" if settings.is_development else None,
redoc_url="/redoc" if settings.is_development else None,
lifespan=lifespan,
)
# CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=settings.cors_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Request timing middleware
@app.middleware("http")
async def add_timing_header(request: Request, call_next):
"""Add X-Process-Time header to all responses."""
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
response.headers["X-Process-Time"] = str(process_time)
return response
# Import and register routers
from api.tiles import router as tiles_router
from api.terrain import router as terrain_router
from api.aoi import router as aoi_router
from api.learning import router as learning_router
app.include_router(tiles_router, prefix="/api/v1/tiles", tags=["Tiles"])
app.include_router(terrain_router, prefix="/api/v1/terrain", tags=["Terrain"])
app.include_router(aoi_router, prefix="/api/v1/aoi", tags=["AOI"])
app.include_router(learning_router, prefix="/api/v1/learning", tags=["Learning"])
# Health check endpoint
@app.get("/health", tags=["System"])
async def health_check():
"""
Health check endpoint for Docker/Kubernetes probes.
Returns service status and basic metrics.
"""
import os
# Check data availability
pmtiles_exists = os.path.exists(settings.pmtiles_path)
dem_exists = os.path.exists(settings.dem_data_dir) and len(os.listdir(settings.dem_data_dir)) > 0
return {
"status": "healthy",
"service": "geo-service",
"version": "1.0.0",
"environment": settings.environment,
"data_status": {
"pmtiles_available": pmtiles_exists,
"dem_available": dem_exists,
"tile_cache_dir": os.path.exists(settings.tile_cache_dir),
"bundle_dir": os.path.exists(settings.bundle_dir),
},
"config": {
"max_aoi_size_km2": settings.max_aoi_size_km2,
"supported_themes": settings.supported_themes,
},
}
# Root endpoint
@app.get("/", tags=["System"])
async def root():
"""Root endpoint with service information."""
return {
"service": "GeoEdu Service",
"description": "DSGVO-konforme Erdkunde-Lernplattform",
"version": "1.0.0",
"docs": "/docs" if settings.is_development else "disabled",
"endpoints": {
"tiles": "/api/v1/tiles",
"terrain": "/api/v1/terrain",
"aoi": "/api/v1/aoi",
"learning": "/api/v1/learning",
},
"attribution": {
"osm": "© OpenStreetMap contributors (ODbL)",
"dem": "© Copernicus Service (free, attribution required)",
},
}
# Error handlers
@app.exception_handler(404)
async def not_found_handler(request: Request, exc):
"""Handle 404 errors."""
return JSONResponse(
status_code=404,
content={"error": "Not found", "path": str(request.url.path)},
)
@app.exception_handler(500)
async def internal_error_handler(request: Request, exc):
"""Handle 500 errors."""
logger.error("Internal server error", path=str(request.url.path), error=str(exc))
return JSONResponse(
status_code=500,
content={"error": "Internal server error"},
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"main:app",
host="0.0.0.0",
port=settings.port,
reload=settings.is_development,
)