Initial commit: SQL audit platform v0.1.0

FastAPI backend with auth, user, instance, ticket, query, dashboard APIs.
React + TypeScript frontend with mock data UI (10 pages).
SQLite + async SQLAlchemy, JWT auth, role-based access control.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
loganandClaude Opus 4.7 committed 2026-05-22 11:11:57 +08:00
commit 439155c92e
290 files changed
+61950

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
import asyncio
from contextlib import asynccontextmanager
from datetime import datetime, timezone
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from sqlalchemy import select
from app.core.config import get_settings
from app.core.database import init_db, async_session
from app.core.security import hash_password
from app.models.user import User
from app.models.instance import Instance
from app.models.ticket import Ticket
from app.models.audit_log import AuditLog
from app.api.v1.router import api_router
settings = get_settings()
async def seed_data():
"""Create default admin user and seed data."""
async with async_session() as db:
result = await db.execute(select(User).where(User.username == settings.ADMIN_USERNAME))
if not result.scalar_one_or_none():
users = [
User(username="admin", display_name="管理员", role="admin",
hashed_password=hash_password("123456")),
User(username="dba", display_name="DBA 张三", role="dba",
hashed_password=hash_password("123456")),
User(username="dev1", display_name="开发者 李四", role="developer",
hashed_password=hash_password("123456")),
User(username="dev2", display_name="开发者 王五", role="developer",
hashed_password=hash_password("123456")),
User(username="auditor", display_name="审计员 赵六", role="developer",
email="auditor@example.com", hashed_password=hash_password("123456")),
]
db.add_all(users)
await db.commit()
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup
from app.core.database import Base
# Import all models so create_all picks them up
import app.models.user # noqa
import app.models.instance # noqa
import app.models.ticket # noqa
import app.models.audit_log # noqa
await init_db()
await seed_data()
yield
app = FastAPI(
title="Web-Lite API",
version="1.0.0",
description="数据审核平台 API",
lifespan=lifespan,
docs_url="/docs" if settings.DEBUG else None,
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"] if settings.DEBUG else [],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(api_router)
@app.get("/health")
async def health_check():
return {"status": "ok", "version": "1.0.0", "time": datetime.now(timezone.utc).isoformat()}
if __name__ == "__main__":
import uvicorn
uvicorn.run("app.main:app", host="0.0.0.0", port=9000, reload=True)