299ad7d943
Co-authored-by: Copilot <copilot@github.com>
4.7 KiB
4.7 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 inserts a row into
generated_videoswithstatus: "queued"and returns the DB job ID - Flask renders result page with polling UI
- Background worker (
video_worker.py) picks up queued jobs every 15 seconds:- Calls OpenRouter
POST /api/v1/videoswith model, prompt, and parameters - Receives
{"id": "...", "polling_url": "..."}and updates the DB row tostatus: "processing" - Polls the
polling_urlevery 15 seconds untilstatusis"completed"or"failed" - Updates the DB row with the final status and video URL
- Calls OpenRouter
- Frontend JavaScript polls
GET /generate/video/{db_id}/statusevery 5 seconds - When
statusbecomes"completed", the response includesvideo_url— the video is displayed in a<video>element - If
statusbecomes"failed", an error message is shown - User can click "Cancel Job" to mark the job as
"cancelled"(stops local polling, does not stop the provider job)
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 - Same background worker flow as Scenario 4, with
generation_type: "image_to_video"
Scenario 4b: Video Job Cancellation
- User clicks "Cancel Job" on the video detail page or gallery pending card
- Frontend POSTs to
/generate/video/{id}/cancel - Backend verifies the job belongs to the user and is not in a terminal state
- Backend updates the DB row
statusto"cancelled" - Frontend stops polling and updates the UI to show "Job cancelled"
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