Skip to main content
DocuSphere uses Convex as its serverless backend and database. Convex stores all document metadata and exposes a set of typed queries and mutations that the frontend calls directly. This page describes the data model and the API surface you work with when building on top of DocuSphere.
DocuSphere stores document metadata (title, owner, organization) in Convex. The actual rich-text content of each document is stored and synchronized by Liveblocks, not Convex. Convex and Liveblocks work together: Convex manages who can access a document, and Liveblocks handles the real-time editing state.

The documents table

All document metadata lives in a single documents table. Each row represents one document.
FieldTypeRequiredDescription
titlestringYesThe document’s display name. Shown in the dashboard and document header.
initialContentstringNoInitial HTML content to pre-populate the editor. Used when creating a document from a template.
ownerIdstringYesThe Clerk user ID of the person who created the document.
roomIdstringNoThe Liveblocks room ID associated with this document. Used to connect the editor to the correct collaboration room.
organizationIdstringNoThe Clerk organization ID. Set when the document is created while an organization is the active context in the switcher. Documents with an organizationId are visible to all members of that organization.

Indexes

Convex uses indexes to make queries fast. The documents table has three:
  • by_owner_id — indexed on ownerId. Used when listing all documents belonging to a specific user.
  • by_organization_id — indexed on organizationId. Used when listing all documents belonging to a specific organization.
  • search_title — a full-text search index on the title field, filterable by ownerId or organizationId. Powers the title search in the document dashboard.

Available queries and mutations

DocuSphere exposes the following Convex functions via api.documents:
api.documents.create
mutation
required
Creates a new document. Accepts an optional title (defaults to “Untitled Document”) and optional initialContent string. Automatically sets ownerId from the authenticated user and organizationId from their active organization context.
api.documents.get
query
required
Returns a paginated list of documents for the current user or organization. Accepts an optional search string to filter by title using the search_title index.
api.documents.getById
query
required
Fetches a single document by its Convex document ID. Throws a ConvexError with “Document not found” if the document does not exist. Note: this query does not perform an auth check itself — access control is enforced at the Liveblocks auth layer.
api.documents.getByIds
query
required
Fetches multiple documents by an array of Convex document IDs. Useful for bulk lookups, such as loading recently accessed documents.
api.documents.updateById
mutation
required
Renames a document. Accepts the document ID and a new title. Checks that the caller is the document owner or a member of the document’s organization before applying the change.
api.documents.removeById
mutation
required
Permanently deletes a document. Accepts the document ID. Checks that the caller is the document owner or a member of the document’s organization before deleting.

Real-time sync

Convex queries are reactive by default. When you call useQuery(api.documents.get, ...) in the UI, Convex automatically pushes updates to the component whenever the underlying data changes — no polling or manual refetching required. This means your document list updates instantly when a document is created, renamed, or deleted anywhere in the system.

Build docs developers (and LLMs) love