$npx -y skills add PolarCoding85/convex-agent-skillz --skill convex-components-skillUniversal patterns for Convex components including installation, configuration, and usage. Use when working with Rate Limiter, Aggregate, Workpool, Workflow, or any Convex component from the ecosystem.
| 1 | # Convex Components |
| 2 | |
| 3 | Components are sandboxed packages with their own database tables, functions, and isolated execution. |
| 4 | |
| 5 | ## Universal Installation Pattern |
| 6 | |
| 7 | All components follow the same installation pattern: |
| 8 | |
| 9 | ```bash |
| 10 | npm install @convex-dev/<component-name> |
| 11 | ``` |
| 12 | |
| 13 | ```typescript |
| 14 | // convex/convex.config.ts |
| 15 | import { defineApp } from 'convex/server'; |
| 16 | import componentName from '@convex-dev/<component-name>/convex.config'; |
| 17 | |
| 18 | const app = defineApp(); |
| 19 | app.use(componentName); |
| 20 | |
| 21 | // Multiple instances with different names |
| 22 | app.use(componentName, { name: 'instance2' }); |
| 23 | |
| 24 | export default app; |
| 25 | ``` |
| 26 | |
| 27 | Run `npx convex dev` to generate code. |
| 28 | |
| 29 | ## Accessing Components |
| 30 | |
| 31 | ```typescript |
| 32 | import { components } from './_generated/api'; |
| 33 | |
| 34 | // Default instance |
| 35 | const instance = new ComponentClass(components.componentName, { |
| 36 | /* config */ |
| 37 | }); |
| 38 | |
| 39 | // Named instance |
| 40 | const instance2 = new ComponentClass(components.instance2, { |
| 41 | /* config */ |
| 42 | }); |
| 43 | ``` |
| 44 | |
| 45 | ## Transaction Semantics |
| 46 | |
| 47 | Component mutations participate in the parent transaction: |
| 48 | |
| 49 | ```typescript |
| 50 | export const doWork = mutation({ |
| 51 | handler: async (ctx) => { |
| 52 | await ctx.db.insert('myTable', { data: 'value' }); |
| 53 | await component.doSomething(ctx); // Same transaction |
| 54 | |
| 55 | // If mutation throws, BOTH writes roll back |
| 56 | } |
| 57 | }); |
| 58 | ``` |
| 59 | |
| 60 | Component exceptions can be caught: |
| 61 | |
| 62 | ```typescript |
| 63 | try { |
| 64 | await rateLimiter.limit(ctx, 'myLimit', { throws: true }); |
| 65 | } catch (e) { |
| 66 | // Only component's writes roll back |
| 67 | // Parent mutation can continue |
| 68 | } |
| 69 | ``` |
| 70 | |
| 71 | ## Available Components |
| 72 | |
| 73 | ### Durable Functions |
| 74 | |
| 75 | - **[Workflow](references/WORKFLOW.md)** - Long-running, durable code flows with retries |
| 76 | - **[Workpool](references/WORKPOOL.md)** - Queue actions with parallelism limits |
| 77 | - **[Action Retrier](references/ACTION-RETRIER.md)** - Retry failed actions with backoff |
| 78 | |
| 79 | ### Backend Utilities |
| 80 | |
| 81 | - **[Rate Limiter](references/RATE-LIMITER.md)** - Application-layer rate limiting |
| 82 | - **[Aggregate](references/AGGREGATE.md)** - Efficient COUNT, SUM, MAX operations |
| 83 | - **[Sharded Counter](references/SHARDED-COUNTER.md)** - High-throughput counting |
| 84 | - **[Presence](references/PRESENCE.md)** - Real-time user presence tracking |
| 85 | - **[Action Cache](references/ACTION-CACHE.md)** - Cache expensive action results |
| 86 | - **[Migrations](references/MIGRATIONS.md)** - Stateful online data migrations |
| 87 | |
| 88 | ### Payments |
| 89 | |
| 90 | - **[Stripe](references/STRIPE.md)** - Payments, subscriptions, and billing |
| 91 | |
| 92 | ### Integrations |
| 93 | |
| 94 | - **[ProseMirror Sync](references/PROSEMIRROR-SYNC.md)** - Collaborative text editing (Tiptap/BlockNote) |
| 95 | - **[Resend](references/RESEND.md)** - Transactional email with queuing and webhooks |
| 96 | |
| 97 | ### AI Components |
| 98 | |
| 99 | - **[Agent](../convex-agent-skill/SKILL.md)** - AI agents with persistent threads (separate skill) |
| 100 | |
| 101 | ## Quick Reference |
| 102 | |
| 103 | | Component | Package | Primary Use | |
| 104 | | ---------------- | ------------------------------ | -------------------------- | |
| 105 | | Rate Limiter | `@convex-dev/rate-limiter` | Control action frequency | |
| 106 | | Aggregate | `@convex-dev/aggregate` | Fast count/sum queries | |
| 107 | | Sharded Counter | `@convex-dev/sharded-counter` | High-throughput counting | |
| 108 | | Presence | `@convex-dev/presence` | Real-time user tracking | |
| 109 | | Action Cache | `@convex-dev/action-cache` | Cache expensive results | |
| 110 | | Migrations | `@convex-dev/migrations` | Online data migrations | |
| 111 | | Workpool | `@convex-dev/workpool` | Queue work with limits | |
| 112 | | Workflow | `@convex-dev/workflow` | Durable multi-step flows | |
| 113 | | Action Retrier | `@convex-dev/action-retrier` | Retry failed actions | |
| 114 | | ProseMirror Sync | `@convex-dev/prosemirror-sync` | Collaborative text editing | |
| 115 | | Resend | `@convex-dev/resend` | Transactional email | |
| 116 | | Stripe | `@convex-dev/stripe` | Payments & subscriptions | |
| 117 | | Agent | `@convex-dev/agent` | AI chat with history | |
| 118 | |
| 119 | ## Common Patterns |
| 120 | |
| 121 | ### Component + Triggers |
| 122 | |
| 123 | Auto-sync components with table changes using `convex-helpers` triggers: |
| 124 | |
| 125 | ```typescript |
| 126 | import { Triggers } from 'convex-helpers/server/triggers'; |
| 127 | import { |
| 128 | customCtx, |
| 129 | customMutation |
| 130 | } from 'convex-helpers/server/customFunctions'; |
| 131 | |
| 132 | const triggers = new Triggers<DataModel>(); |
| 133 | |
| 134 | // Register component trigger |
| 135 | triggers.register('myTable', aggregate.trigger()); |
| 136 | |
| 137 | // Wrap mutation to use triggers |
| 138 | const mutation = customMutation(mutationRaw, customCtx(triggers.wrapDB)); |
| 139 | ``` |
| 140 | |
| 141 | ### Testing Components |
| 142 | |
| 143 | ```typescript |
| 144 | import componentTest from '@convex-dev/<component>/test'; |
| 145 | import { convexTest } from 'convex-test'; |
| 146 | |
| 147 | function initTest() { |
| 148 | const t = convexTest(); |
| 149 | componentTest.register(t); |
| 150 | return t; |
| 151 | } |
| 152 | |
| 153 | test('component test', asy |