TIF_E41253310/Backend/app/main.py

47 lines
1.6 KiB
Python

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config.config import settings
from app.config.database import engine
from app.models.base import Base
# Import models here so SQLAlchemy registers them on Base.metadata before creation
from app.models.user import User
from app.models.alumni import Alumni, Pekerjaan, Kompetensi, ClusteringResult, ModelEvaluation, KeywordDictionary, TracerResponse
from app.models.models import Question, AnswerOption
from app.routers.api import api_router
from app.routers.questions import router as questions_router
# Auto-create database tables (highly convenient helper for junior developers)
Base.metadata.create_all(bind=engine)
app = FastAPI(
title=settings.APP_NAME,
description="Backend API untuk TA Alumni dengan arsitektur bersih terstruktur",
version="1.0.0",
debug=settings.DEBUG
)
# CORS middleware configuration (enables requests from frontend ports)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Replace with specific origins in production
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Register central router with prefixed versioning (default: /api/v1)
app.include_router(api_router, prefix=settings.API_PREFIX)
# Register questions router
app.include_router(questions_router, prefix=settings.API_PREFIX)
@app.get("/", tags=["Root"])
def root():
"""
Root status check endpoint.
"""
return {
"status": "online",
"message": f"Welcome to {settings.APP_NAME} API. Silakan kunjungi /docs untuk dokumentasi API lengkap."
}