fractafrag/services/api/app/routers/generate.py
John Lightner 05d39fdda8 M0: Foundation scaffold — Docker Compose, DB schema, FastAPI app, all service stubs
Track A (Infrastructure & Data Layer):
- docker-compose.yml with all 7 services (nginx, frontend, api, mcp, renderer, worker, postgres, redis)
- docker-compose.override.yml for local dev (hot reload, port exposure)
- PostgreSQL init.sql with full schema (15 tables, pgvector indexes, creator economy stubs)
- .env.example with all required environment variables

Track A+B (API Layer):
- FastAPI app with 10 routers (auth, shaders, feed, votes, generate, desires, users, payments, mcp_keys, health)
- SQLAlchemy ORM models for all 15 tables
- Pydantic schemas for all request/response types
- JWT auth middleware (access + refresh tokens, Redis blocklist)
- Redis rate limiting middleware
- Celery worker config with job stubs (render, embed, generate, feed cache, expire bounties)
- Alembic migration framework

Service stubs:
- MCP server (health endpoint, 501 for all tools)
- Renderer service (Express + Puppeteer scaffold, 501 for /render)
- Frontend (package.json with React/Vite/Three.js/TanStack/Tailwind deps)
- Nginx reverse proxy config (/, /api, /mcp, /renders)

Project:
- DECISIONS.md with 11 recorded architectural decisions
- README.md with architecture overview
- Sample shader seed data (plasma, fractal noise, raymarched sphere)
2026-03-24 20:45:08 -05:00

49 lines
1.5 KiB
Python

"""AI Generation router — start generation, poll status, check credits."""
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from app.database import get_db
from app.models import User
from app.schemas import GenerateRequest, GenerateStatusResponse
from app.middleware.auth import get_current_user
router = APIRouter()
@router.post("", response_model=GenerateStatusResponse)
async def start_generation(
body: GenerateRequest,
db: AsyncSession = Depends(get_db),
user: User = Depends(get_current_user),
):
"""Start an AI shader generation job. (Track I — stub)"""
# TODO: Implement in Track I
# - Credits check / BYOK validation
# - Enqueue ai_generate job
# - Return job_id for polling
raise HTTPException(
status_code=status.HTTP_501_NOT_IMPLEMENTED,
detail="AI generation coming in M5"
)
@router.get("/status/{job_id}", response_model=GenerateStatusResponse)
async def get_generation_status(
job_id: str,
user: User = Depends(get_current_user),
):
"""Poll AI generation job status. (Track I — stub)"""
raise HTTPException(
status_code=status.HTTP_501_NOT_IMPLEMENTED,
detail="AI generation coming in M5"
)
@router.get("/credits")
async def get_credits(user: User = Depends(get_current_user)):
"""Check remaining AI generation credits."""
return {
"credits_remaining": user.ai_credits_remaining,
"subscription_tier": user.subscription_tier,
}