From majestic-engineer
Builds TypeScript apps on Cloudflare Workers using Hono, Workers API, KV/D1/R2 storage, Durable Objects, Queues, and testing patterns. For serverless edge functions and services.
npx claudepluginhub majesticlabs-dev/majestic-marketplace --plugin majestic-engineerThis skill is limited to using the following tools:
**Development patterns for TypeScript Workers.**
Builds and deploys serverless APIs, full-stack web apps, edge functions, background jobs, and real-time applications using Cloudflare Workers. Supports JavaScript, TypeScript, Python, Rust with Wrangler CLI.
Provides expertise in Cloudflare Workers for edge computing, covering Wrangler, KV, D1, Durable Objects, R2 for serverless deployment, storage, and latency optimization.
Scaffolds and deploys Cloudflare Workers with Hono routing, Vite dev server, static assets, and D1/R2/KV bindings. Troubleshoots export errors, API conflicts, HMR, and deployments.
Share bugs, ideas, or general feedback.
Development patterns for TypeScript Workers.
Related skills (majestic-devops):
wrangler-coder: CLI deployment, secrets, testing, multi-environmentcloudflare-coder: Infrastructure provisioning with Terraform/OpenTofu| Storage | Use Case | Consistency | Latency |
|---|---|---|---|
| KV | Config, flags, cached data | Eventually consistent | ~10ms |
| D1 | Relational data, transactions | Strong (single region) | ~30-50ms |
| R2 | Files, images, large objects | Strong | ~50-100ms |
| Durable Objects | Real-time state, WebSockets | Strong (per-object) | ~50ms |
| Queues | Async processing, batching | At-least-once | Async |
my-worker/
├── src/
│ ├── index.ts # Entry point
│ ├── routes/ # Route handlers
│ ├── services/ # Business logic
│ └── types.ts # Type definitions
├── test/
├── wrangler.toml # Cloudflare config
├── package.json
└── tsconfig.json
name = "my-worker"
main = "src/index.ts"
compatibility_date = "2024-12-01"
compatibility_flags = ["nodejs_compat"]
See references/setup.md for full configuration with all bindings.
import { Hono } from 'hono';
import { Env } from './types';
const app = new Hono<{ Bindings: Env }>();
app.get('/', (c) => c.json({ status: 'ok' }));
app.onError((err, c) => c.json({ error: 'Internal Error' }, 500));
app.notFound((c) => c.json({ error: 'Not Found' }, 404));
export default app;
See references/hono.md for route organization and middleware patterns.
await env.CACHE.get('key', 'json');
await env.CACHE.put('key', value, { expirationTtl: 3600 });
await env.CACHE.delete('key');
const user = await env.DB.prepare('SELECT * FROM users WHERE id = ?')
.bind(id).first();
await env.STORAGE.put('path/file.json', JSON.stringify(data));
const object = await env.STORAGE.get('path/file.json');
See references/storage.md for caching patterns, migrations, and queries.
Use for: real-time coordination, WebSockets, rate limiting, distributed locks.
// Get DO stub
const id = c.env.COUNTER.idFromName('my-counter');
const stub = c.env.COUNTER.get(id);
const response = await stub.fetch(new Request('http://do/increment'));
See references/durable-objects.md for full patterns including WebSocket Hibernation.
// Producer
await env.QUEUE.send({ type: 'email', payload: { to: 'user@example.com' } });
// Consumer (add to default export)
async queue(batch: MessageBatch, env: Env) {
for (const msg of batch.messages) {
try { await process(msg.body); msg.ack(); }
catch { msg.retry(); }
}
}
See references/queues-testing.md for consumer patterns and testing setup.
# Development
wrangler dev # Start local server
wrangler dev --remote # Dev with remote bindings
# Deploy
wrangler deploy
# D1
wrangler d1 migrations apply my-database
# Secrets
wrangler secret put API_KEY
# Logs
wrangler tail
| Don't | Do Instead |
|---|---|
| Service Worker format | ES modules |
await cache writes | waitUntil for non-blocking |
| Large KV values (>25MB) | R2 for files |
server.accept() for WebSockets | ctx.acceptWebSocket() (Hibernation API) |
| Block on analytics/logging | waitUntil for background tasks |
| Assume KV immediate consistency | D1 or DOs for consistency-critical |