Introduction
Lawn uses Convex as its backend platform, providing real-time queries, mutations, and actions. All backend functions are located inconvex/ and are accessible through the auto-generated api object.
Architecture
The Convex backend is organized into functional modules:- Authentication - Clerk integration for user identity and team-based access control
- Videos - Core video management (upload, metadata, workflow status)
- Comments - Time-based commenting system with threading support
- Teams - Team and member management with role-based permissions
- Projects - Project organization within teams
- Share Links - Secure video sharing with optional passwords and expiration
Function Types
Queries
Queries read data from the database and run reactively. They automatically re-run when underlying data changes.Mutations
Mutations modify data in the database. They’re transactional and atomic.Actions
Actions can call external APIs and perform long-running operations. They’re used for integrations with services like Mux and S3.Data Model
The Convex schema defines the following core tables:teams- Team organizationsteamMembers- User memberships in teamsprojects- Projects within teamsvideos- Video files and metadatacomments- Video comments with timestampsshareLinks- Shareable video linksshareAccessGrants- Temporary access tokens
Authentication
All API functions require authentication through Clerk. The backend validates user identity and checks permissions based on:- Team membership
- Project access
- Video access
- Role hierarchy:
owner>admin>member>viewer
Error Handling
Convex functions throw errors that are automatically propagated to the client:Type Safety
Convex automatically generates TypeScript types for all functions:Real-time Updates
Queries are reactive and update automatically when data changes:Best Practices
- Use queries for reads - They’re reactive and optimized
- Batch mutations - Combine related updates in a single mutation
- Validate inputs - Use Convex validators (
v.string(),v.id(), etc.) - Handle loading states - Queries return
undefinedwhile loading - Optimize queries - Use indexes defined in the schema
Next Steps
- Authentication - Learn about Clerk integration
- Videos API - Manage video uploads and metadata
- Comments API - Add time-based comments
- Teams API - Organize users into teams
- Projects API - Create project structures
- Share Links API - Generate shareable links
