Feature: AI Image Generation
Relevant source files
The following files were used as context for generating this wiki page:The AI Image Generation feature is a backend service designed to create or edit images based on text prompts. It interfaces with an internal ImageService API, processes the request, and stores the resulting image in a cloud storage bucket, returning a public URL to the generated asset.
Currently, this feature is implemented exclusively on the backend. Analysis of the frontend source code, design documents, and project plans indicates that there is no user interface integrated with this service yet. The existing "Generate" screen in the mobile app is for creating legal documents, not images.
Sources: server/_core/imageGeneration.ts, app/(tabs)/generate.tsx, design.md, todo.md
Backend Service Architecture
The core logic resides in the server/_core/imageGeneration.ts file, which exposes a single function, generateImage, to handle the entire process.
Sources: server/_core/imageGeneration.ts
Core Function: generateImage
This asynchronous function orchestrates the image generation process. It takes a prompt and optional original images, sends them to the ImageService, receives the generated image data, uploads it to storage, and returns the public URL.
Parameters (GenerateImageOptions)
| Parameter | Type | Description |
|---|---|---|
prompt | string | The text prompt describing the desired image. |
originalImages | Array<{ url?: string; b64Json?: string; mimeType?: string; }> | (Optional) An array of original images to be used as a basis for editing. |
Return Value (GenerateImageResponse)
| Field | Type | Description |
|---|---|---|
url | string | The public URL of the final image stored in the cloud. |
Sources: server/_core/imageGeneration.ts:19-27
API Interaction
The service communicates with an internal ImageService via a POST request.
- Endpoint: The URL is constructed by combining the base URL from the
BUILT_IN_FORGE_API_URLenvironment variable with the pathimages.v1.ImageService/GenerateImage. - Authentication: The request is authenticated using a Bearer token from the
BUILT_IN_FORGE_API_KEYenvironment variable. - Payload: The body of the request is a JSON object containing the
promptandoriginal_images.
Environment Variables
The feature's configuration relies on two critical environment variables.
| Variable | Purpose |
|---|---|
BUILT_IN_FORGE_API_URL | The base URL for the internal Forge API, which hosts the Image Service. |
BUILT_IN_FORGE_API_KEY | The API key for authenticating requests to the Forge API. |
If these variables are not configured, the generateImage function will throw an error.
Sources: server/_core/imageGeneration.ts:29-35
Data Flow
The following sequence diagram illustrates the end-to-end process when generateImage is called.
This diagram shows the sequence of operations from the initial function call to the final URL being returned.
Sources: server/_core/imageGeneration.ts:28-66
Storage Integration
Generated images are not returned directly to the caller. Instead, they are uploaded to a cloud storage service using the storagePut helper function from server/storage.ts.
The generated image is saved with a unique key based on the current timestamp.
- Storage Path:
generated/${Date.now()}.png
The storagePut function handles the multi-step process of authenticating with the storage proxy, constructing an upload URL, and POSTing the image data as FormData.
The overall storage upload flow is as follows:
This diagram depicts the steps within the storagePut function to upload a file.
Sources: server/_core/imageGeneration.ts:64, server/storage.ts:68-87
Frontend Integration Status
As of the current version, the AI Image Generation feature is not integrated into the mobile application's user interface.
- The
app/(tabs)/generate.tsxscreen is dedicated to legal document generation. It contains form fields for "Party A," "Party B," and "Key Terms," which are unrelated to image generation. - The
design.mddocument, which outlines the app's screen list and user flows, makes no mention of an image generation feature. The defined flows are "Analyze a Document," "Generate a Legal Document," and "Chat with AI." - The
todo.mdproject plan lists tasks related to document analysis, document generation, and AI chat, but does not include any items for implementing an image generation UI.
This indicates that server/_core/imageGeneration.ts is a backend component that is either planned for future integration or used for other internal purposes.
Sources: app/(tabs)/generate.tsx:10-21, design.md:36-47, todo.md:28-34