feat: create backend project structure

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-03-24 14:49:13 +08:00
parent eb47af57c4
commit f7a61bc7c6
22 changed files with 105 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
# TODO: Dockerfile will be implemented in a later task
+1
View File
@@ -0,0 +1 @@
"""ImageCreator backend application."""
+1
View File
@@ -0,0 +1 @@
"""API module."""
+1
View File
@@ -0,0 +1 @@
"""API dependencies placeholder."""
+31
View File
@@ -0,0 +1,31 @@
from pydantic_settings import BaseSettings
from functools import lru_cache
class Settings(BaseSettings):
# Database
DATABASE_URL: str = "postgresql://user:pass@localhost:5432/imagecreator"
# JWT
SECRET_KEY: str = "your-secret-key-change-in-production"
ALGORITHM: str = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
REFRESH_TOKEN_EXPIRE_DAYS: int = 7
# CORS
CORS_ORIGINS: list[str] = ["http://localhost:3000"]
# LLM API Keys
GEMINI_API_KEY: str = ""
OPENAI_API_KEY: str = ""
# Image storage
IMAGE_STORAGE_PATH: str = "/app/uploads"
class Config:
env_file = ".env"
@lru_cache()
def get_settings():
return Settings()
settings = get_settings()
@@ -0,0 +1 @@
"""Core module."""
@@ -0,0 +1 @@
"""Security utilities placeholder."""
+15
View File
@@ -0,0 +1,15 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base
from app.config import settings
engine = create_engine(settings.DATABASE_URL, pool_pre_ping=True)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
+26
View File
@@ -0,0 +1,26 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api import auth, users, images, history
from app.config import settings
from app.database import engine
from app.models import user, history as history_model
app = FastAPI(title="ImageCreator API", version="1.0.0")
app.add_middleware(
CORSMiddleware,
allow_origins=settings.CORS_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
app.include_router(users.router, prefix="/api/users", tags=["users"])
app.include_router(images.router, prefix="/api/images", tags=["images"])
app.include_router(history.router, prefix="/api/history", tags=["history"])
@app.get("/health")
def health_check():
return {"status": "ok"}
@@ -0,0 +1 @@
"""Models module."""
@@ -0,0 +1 @@
"""History model placeholder."""
+1
View File
@@ -0,0 +1 @@
"""User model placeholder."""
@@ -0,0 +1 @@
"""Schemas module."""
+1
View File
@@ -0,0 +1 @@
"""Auth schemas placeholder."""
@@ -0,0 +1 @@
"""History schemas placeholder."""
@@ -0,0 +1 @@
"""Image schemas placeholder."""
+1
View File
@@ -0,0 +1 @@
"""User schemas placeholder."""
@@ -0,0 +1 @@
"""Services module."""
@@ -0,0 +1 @@
"""Auth service placeholder."""
@@ -0,0 +1 @@
"""Image service placeholder."""
+1
View File
@@ -0,0 +1 @@
"""LLM service placeholder."""
+15
View File
@@ -0,0 +1,15 @@
fastapi==0.109.0
uvicorn[standard]==0.27.0
sqlalchemy==2.0.25
psycopg2-binary==2.9.9
python-jose[cryptography]==3.3.0
passlib[bcrypt]==1.7.4
python-multipart==0.0.6
pydantic==2.5.3
pydantic-settings==2.1.0
google-genai==0.8.0
openai==1.12.0
aiofiles==23.2.1
httpx==0.26.0
pytest==8.0.0
pytest-asyncio==0.23.4