fractafrag/scripts/seed.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

115 lines
3 KiB
Python

"""Fractafrag — Development seed data."""
# TODO: Implement seed script (Track A completion)
# This script will:
# 1. Create test users (admin, moderator, regular, pro, studio)
# 2. Insert sample shaders with known-good GLSL code
# 3. Create sample desires/bounties
# 4. Set up initial engagement data for recommendation testing
SAMPLE_SHADERS = [
{
"title": "Plasma Wave",
"glsl_code": """
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
float t = iTime;
float c = sin(uv.x * 10.0 + t) + sin(uv.y * 10.0 + t * 0.7);
c += sin((uv.x + uv.y) * 5.0 + t * 1.3);
c = c / 3.0 * 0.5 + 0.5;
fragColor = vec4(c, c * 0.5, 1.0 - c, 1.0);
}
""",
"tags": ["plasma", "colorful", "animated"],
"shader_type": "2d",
},
{
"title": "Fractal Noise",
"glsl_code": """
float hash(vec2 p) {
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
}
float noise(vec2 p) {
vec2 i = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(
mix(hash(i), hash(i + vec2(1.0, 0.0)), f.x),
mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), f.x),
f.y
);
}
float fbm(vec2 p) {
float v = 0.0, a = 0.5;
for (int i = 0; i < 6; i++) {
v += a * noise(p);
p *= 2.0;
a *= 0.5;
}
return v;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
float n = fbm(uv * 5.0 + iTime * 0.3);
fragColor = vec4(n * 0.3, n * 0.6, n, 1.0);
}
""",
"tags": ["noise", "fractal", "generative"],
"shader_type": "2d",
},
{
"title": "Ray March Sphere",
"glsl_code": """
float sdSphere(vec3 p, float r) { return length(p) - r; }
float map(vec3 p) {
return sdSphere(p - vec3(0.0, 0.0, 0.0), 1.0);
}
vec3 getNormal(vec3 p) {
vec2 e = vec2(0.001, 0.0);
return normalize(vec3(
map(p + e.xyy) - map(p - e.xyy),
map(p + e.yxy) - map(p - e.yxy),
map(p + e.yyx) - map(p - e.yyx)
));
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
vec3 ro = vec3(0.0, 0.0, -3.0);
vec3 rd = normalize(vec3(uv, 1.0));
float t = 0.0;
for (int i = 0; i < 64; i++) {
vec3 p = ro + rd * t;
float d = map(p);
if (d < 0.001) break;
t += d;
if (t > 20.0) break;
}
vec3 col = vec3(0.05);
if (t < 20.0) {
vec3 p = ro + rd * t;
vec3 n = getNormal(p);
vec3 light = normalize(vec3(sin(iTime), 1.0, cos(iTime)));
float diff = max(dot(n, light), 0.0);
col = vec3(0.2, 0.5, 0.9) * diff + vec3(0.05);
}
fragColor = vec4(col, 1.0);
}
""",
"tags": ["raymarching", "3d", "sphere", "lighting"],
"shader_type": "3d",
},
]
if __name__ == "__main__":
print("Seed script — run with: python scripts/seed.py")
print(f"Sample shaders available: {len(SAMPLE_SHADERS)}")
# TODO: Connect to DB and insert seed data