1c96ae17fc
Co-authored-by: Copilot <copilot@github.com>
4.0 KiB
4.0 KiB
6. Runtime View
Describes concrete behavior and interactions of the system's building blocks in form of scenarios from the following areas:
- Important use cases or features: how do building blocks execute them?
- Interactions at critical external interfaces: how do building blocks cooperate with users and neighboring systems?
- Operation and administration: launch, start-up, stop
- Error and exception scenarios
Scenario 1: User Authentication
- User submits login form in Flask frontend
- Flask POSTs credentials to
POST /auth/login - Auth Service validates credentials against DuckDB
- Auth Service returns JWT token
- Flask stores token in session cookie
- User is redirected to dashboard
Scenario 2: AI Text Generation
- User fills in text generation form in Flask frontend
- Flask POSTs prompt + model to
POST /generate/textwith JWT header - Auth Service validates JWT
- AI Service sends prompt to openrouter.ai
- openrouter.ai returns generated text
- FastAPI returns result to Flask
- Flask renders result page for user
Scenario 3: Image Generation
- User submits image generation form with prompt, model, size, aspect ratio, and resolution
- Flask POSTs to
POST /generate/imagewith JWT header - Router auto-detects model type:
- FLUX / GPT-5 Image Mini: calls
/chat/completionswithmodalities: ["image"]andimage_config - DALL-E 3: calls
/images/generationswithsizeandn
- FLUX / GPT-5 Image Mini: calls
- Image URL (base64 data URL or hosted URL) returned to Flask
- Flask renders page with generated image(s)
Scenario 3a: Image Generation with Aspect Ratio & Resolution
- User selects aspect ratio (e.g.
16:9) and resolution (2K) on the image generation form - Flask POSTs
aspect_ratioandimage_sizetoPOST /generate/image - Backend passes these as
image_configto the chat completions endpoint (for FLUX/GPT-5 Image Mini) - Generated image respects the requested aspect ratio and resolution
Scenario 4: Video Generation (Text-to-Video)
- User submits video generation form with prompt, model, aspect ratio, resolution, and duration
- Flask POSTs to
POST /generate/videowith JWT header - Auth Service validates JWT
- Backend calls OpenRouter
POST /api/v1/videoswith model, prompt, aspect_ratio, resolution, duration_seconds - OpenRouter returns
{"id": "...", "polling_url": "..."}withstatus: "queued" - FastAPI returns
VideoResponsewithpolling_urlto Flask - Flask renders result page with polling UI
- Frontend JavaScript polls
GET /generate/video/status?polling_url=...every 5 seconds - When
statusbecomes"completed", the response includesunsigned_urls— the video is displayed in a<video>element - If
statusbecomes"failed", an error message is shown
Scenario 4a: Video Generation (Image-to-Video)
- User provides an image URL, motion prompt, model, aspect ratio, resolution, and duration
- Flask POSTs to
POST /generate/video/from-imagewith JWT header - Backend calls OpenRouter
POST /api/v1/videoswithimage_url, prompt, and parameters - Same polling flow as Scenario 4
Scenario 5: Token Refresh
- Access token expires (TTL 15 min)
- Client POSTs current refresh token to
POST /auth/refresh - Auth Service validates JTI against
refresh_tokenstable (not revoked, not expired) - Old JTI is revoked; new JTI inserted into
refresh_tokens - New access token + new refresh token returned to client
Scenario 6: Admin User Management
- Admin logs in and receives access token with
role: admin - Admin GETs
/admin/statsto view user and token counts - Admin DELETEs
/users/{id}to remove a user — refresh tokens for that user are cascade-deleted - Admin PUTs
/users/{id}/roleto promote a user to admin or demote to user
Scenario 7: User Profile Update
- Authenticated user navigates to
/users/profile - User submits updated email and/or new password
- Flask POSTs to
PUT /users/mewith JWT header - Auth Service validates credentials and updates user record in DuckDB
- Session
user_emailis updated; user sees success message