- Backend: FastAPI with email filtering and invoice processing - Database: PostgreSQL models (Invoice, EmailLog, InvoiceDetail, User) - PDF Processing: PyMuPDF for text extraction and tax detection - Excel Export: openpyxl for invoice documentation - Frontend: React/Vite with TypeScript - Docker: Backend container configuration - Documentation: Schema and API docs
75 lines
1.8 KiB
Python
75 lines
1.8 KiB
Python
"""
|
|
C-Stone Invoice Check — Hauptanwendung
|
|
FastAPI Backend für Email-Filterung und Rechnungsverarbeitung
|
|
"""
|
|
|
|
from fastapi import FastAPI, Depends, HTTPException
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.responses import JSONResponse
|
|
from sqlalchemy.orm import Session
|
|
|
|
from backend.database import get_db, engine, Base
|
|
|
|
# Models importieren für Alembic
|
|
from backend.models import Invoice, InvoiceDetail
|
|
|
|
# Routers
|
|
from backend.routers import emails, invoices, auth
|
|
|
|
# App erstellen
|
|
app = FastAPI(
|
|
title="C-Stone Invoice Check API",
|
|
description="Email-Filterung und Rechnungsverarbeitung",
|
|
version="1.0.0",
|
|
docs_url="/docs",
|
|
redoc_url="/redoc"
|
|
)
|
|
|
|
# CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Health Check
|
|
@app.get("/health")
|
|
async def health_check(db: Session = Depends(get_db)):
|
|
"""Health Check Endpoint"""
|
|
try:
|
|
db.execute("SELECT 1")
|
|
return {"status": "healthy", "database": "connected"}
|
|
except Exception as e:
|
|
return {"status": "unhealthy", "database": "disconnected", "error": str(e)}
|
|
|
|
|
|
# Root Endpoint
|
|
@app.get("/")
|
|
async def root():
|
|
"""Root Endpoint"""
|
|
return {
|
|
"name": "C-Stone Invoice Check API",
|
|
"version": "1.0.0",
|
|
"status": "running",
|
|
"docs": "/docs"
|
|
}
|
|
|
|
|
|
# Initialisierung
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
"""Datenbank erstellen bei Start"""
|
|
Base.metadata.create_all(bind=engine)
|
|
|
|
|
|
# Router einbinden
|
|
app.include_router(auth.router, prefix="/auth", tags=["authentication"])
|
|
app.include_router(emails.router, prefix="/emails", tags=["emails"])
|
|
app.include_router(invoices.router, prefix="/invoices", tags=["invoices"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8001)
|