Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:869413421 Ai moive studio CanvasService

From Leeroopedia
Knowledge Sources
Domains Architecture, UI
Last Updated 2026-10-23 12:00 GMT

Overview

Service that manages canvas document CRUD, item CRUD, connection CRUD, and atomic graph save operations for the infinite-canvas visual workflow editor.

Description

CanvasService provides the data layer for the Canvas Studio. It manages:

  • Document CRUD: create_document, get_document, update_document, delete_document, list_documents
  • Item CRUD: create_item, update_item, delete_item, get_item — each item has type (text/image/video), position, dimensions, content, and generation config
  • Connection CRUD: create_connection, delete_connection — typed edges between items via source/target handles
  • Graph save: save_graph — atomic upsert of the entire graph state; deletes items not in the incoming list, upserts remaining items, and replaces all connections

Media content is sanitized via _sanitize_media_content which normalizes presigned URLs to object keys before storage.

Usage

Import when managing canvas documents and their node/edge graphs. Called by canvas API endpoints and the canvas generation service.

Code Reference

Source Location

Signature

class CanvasService(BaseService):
    async def create_document(self, user_id: str, title: str, description: Optional[str] = None) -> CanvasDocument: ...
    async def create_item(self, document_id: str, user_id: str, payload: Dict[str, Any]) -> CanvasItem: ...
    async def create_connection(self, document_id: str, user_id: str, payload: Dict[str, Any]) -> CanvasConnection: ...
    async def save_graph(self, document_id: str, user_id: str, items: List[Dict[str, Any]], connections: List[Dict[str, Any]]) -> CanvasDocument: ...

Import

from src.services.canvas import CanvasService

I/O Contract

Inputs (create_item)

Name Type Required Description
document_id str Yes Canvas document UUID
user_id str Yes Owner UUID
payload dict Yes item_type, title, position_x/y, width, height, z_index, content, generation_config

Outputs

Name Type Description
create_document CanvasDocument Document with UUID
create_item CanvasItem Item with UUID
create_connection CanvasConnection Connection linking two items
save_graph CanvasDocument Updated document; deletes missing items, replaces connections

Usage Examples

Creating a Canvas Document with Items

from src.services.canvas import CanvasService

service = CanvasService(db_session)

# Create document
doc = await service.create_document(user_id="user-uuid", title="My Workflow")

# Add a text node
item = await service.create_item(
    document_id=str(doc.id),
    user_id="user-uuid",
    payload={
        "item_type": "text",
        "title": "Prompt Node",
        "position_x": 100, "position_y": 100,
        "content": {"text": "A cinematic scene"},
    },
)

# Save the entire graph
await service.save_graph(
    document_id=str(doc.id),
    user_id="user-uuid",
    items=[{"id": str(item.id), "item_type": "text", ...}],
    connections=[],
)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment