betting-brain-v3 / rules
Cursor rule8 starsChanged 14 months agoMITView on GitHub
Cloudflare Workers specific patterns and requirements
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,531 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository27 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/99-floor.mdcCursor rule
- .cursor/rules/ai-friendly-testing.mdcCursor rule
- .cursor/rules/analytics-stub-api.mdcCursor rule
- .cursor/rules/analytics-testing.mdcCursor rule
- .cursor/rules/api-patterns.mdcCursor rule
- .cursor/rules/browser-extension.mdcCursor rule
- .cursor/rules/bun-runtime.mdcCursor rule
- .cursor/rules/cache-optimization.mdcCursor rule
- .cursor/rules/ci-integration.mdcCursor rule
- .cursor/rules/ci-patterns.mdcCursor rule
- .cursor/rules/cloudflare-infrastructure.mdcCursor rule
- .cursor/rules/code-searchability.mdcCursor rule
- .cursor/rules/coverage-thresholds.mdcCursor rule
- .cursor/rules/database-patterns.mdcCursor rule
- .cursor/rules/documentation.mdcCursor rule
- .cursor/rules/endpoint-routing.mdcCursor rule
- .cursor/rules/file-naming.mdcCursor rule
- .cursor/rules/mcp-integration.mdcCursor rule
- .cursor/rules/process-management.mdcCursor rule
- .cursor/rules/production-security.mdcCursor rule
- .cursor/rules/quality-standards.mdcCursor rule
- .cursor/rules/root-organization.mdcCursor rule
- .cursor/rules/security-patterns.mdcCursor rule
- .cursor/rules/testing.mdcCursor rule
- .cursor/rules/testing-patterns.mdcCursor rule
- .cursor/rules/test-setup-patterns.mdcCursor rule
The file
We split this cloudflare-workers.mdc into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 108
Always include CORS headers for dashboard access:
- Very specific: line 137
Use ctx.waitUntil() for non-blocking operations:
- Distinctive: line 194
Consider Durable Objects for distributed rate limiting
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
version: "2.0.0"
globs: "src/**/*.ts,wrangler*.toml"
alwaysApply: true
description: "Cloudflare Workers specific patterns and requirements"
lastUpdated: "2025-10-08"
dependencies: ["quality-standards", "api-patterns", "endpoint-routing", "bun-runtime"]
---
# Cloudflare Workers Rules
## 🔍 Code Searchability Patterns
### Find cloudflare-workers Issues with ast-grep
```bash
# Find export default { fetch($$$) }
# Find env.$BINDING
# Find ctx.waitUntil($$$)
# Find new Response($$$)
ast-grep --pattern 'export default { fetch($$$) }' src/
ast-grep --pattern 'env.$BINDING' src/
ast-grep --pattern 'ctx.waitUntil($$$)' src/
ast-grep --pattern 'new Response($$$)' src/
sg -p 'export' src/
sg -p 'env.$BINDING' src/
sg -p 'ctx.waitUntil($$$)' src/
sg -p 'new' src/
```
### cloudflare-workers Discovery Commands
```bash
sg search "export default" src/
sg search "env." src/
sg search "ctx.waitUntil" src/
sg search "new Response" src/
```
### Search Examples
```bash
# Find worker entry points
sg search 'export' src/
# Find environment bindings
sg search 'env.$BINDING' src/
# Find background tasks
sg search 'ctx.waitUntil($$$)' src/
# Find response creation
sg search 'new' src/
```
## Entry Point
Main worker handler: [src/index.ts](mdc:src/index.ts)
```typescript
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
// Handle requests
}
}
```
## Environment Bindings
Configuration: [wrangler.toml](mdc:wrangler.toml)
### D1 Databases
- `ANALYTICS` - Main betting analytics database
- `RAW_FEED_DB` - Raw feed database
### KV Namespaces
- `BET_TICKER_RAW` - API response storage (7-day retention)
- `TOKEN_STORE` - Authentication tokens
- `USER_STORE` - User data
- `SESSION_STORE` - Active sessions
- `REFRESH_STORE` - Refresh tokens
- `LIVEBETS_STORE` - Live betting data
### Queues
- `LINE_INGRESS` - Line movement ingestion
- `STEAM_WEBHOOK` - Steam move notifications
- `STEAM_QUEUE` - Steam processing
- `EXPOSURE_QUEUE` - Exposure calculation
### Analytics Engine
- `ANALYTICS_ENGINE` - Metrics collection
## Routing Pattern
```typescript
const url = new URL(request.url);
// Route by pathname
switch (url.pathname) {
case '/health':
return handleHealth();
case '/mcp':
return handleMCPRequest(request, env);
case '/tools/getBettingExposure':
return handleTool(request, env);
// ...
}
```
## CORS Headers
Always include CORS headers for dashboard access:
```typescript
import { CORS_HEADERS, createOPTIONSResponse, createJSONResponse } from '../utils/request';
// Use CORS_HEADERS constant
// No need to define inline
// Handle OPTIONS preflight
if (request.method === 'OPTIONS') {
return createOPTIONSResponse();
}
// Use in responses (automatic with createJSONResponse)
return createJSONResponse({ data });
```
## Request ID Tracking
```typescript
import { generateRequestId } from '../utils/request';
import { createLogger } from '../utils/logger';
const requestId = generateRequestId();
const logger = createLogger(request);
logger.info('request_received', { requestId });
```
## Async Storage
Use `ctx.waitUntil()` for non-blocking operations:
```typescript
ctx.waitUntil(
env.KV.put(key, value, { expirationTtl: 86400 })
);
```
## Queue Consumers
```typescript
export default {
async queue(batch: MessageBatch, env: Env): Promise<void> {
for (const message of batch.messages) {
// Process message
message.ack();
}
}
}
```
## Scheduled Tasks
```typescript
export default {
async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
// Run on cron schedule
}
}
```
## Type Definitions
See [src/types/api.ts](mdc:src/types/api.ts) for:
- `Env` interface - All bindings
- `BetTickerSnifferEnv` - BetTicker specific
- `MCPEnv` - MCP specific
## Limits
From [wrangler.toml](mdc:wrangler.toml):
```toml
[limits]
cpu_ms = 50 # 50ms CPU time limit per request
```
## Cost Guards
See [src/guards/costCap.ts](mdc:src/guards/costCap.ts) for:
- Hard cost limits
- Graceful degradation
- Request quotas
## Rate Limiting
See [src/guards/rateLimit.ts](mdc:src/guards/rateLimit.ts):
- 10 req/s per IP (in-memory, per-instance)
- ⚠️ Not shared across instances
- Consider Durable Objects for distributed rate limiting
## Deployment
```bash
# Deploy to default
wrangler deploy
# Deploy to production
wrangler deploy --env production
# Apply migrations first
wrangler d1 migrations apply betting-analytics --remote
```
## Environments
- Base: [wrangler.toml](mdc:wrangler.toml)
- Staging: [wrangler.staging.toml](mdc:wrangler.staging.toml)
- Production: [wrangler.production.toml](mdc:wrangler.production.toml)
---
## Related Rules
- [Quality Standards](mdc:.cursor/rules/quality-standards.mdc) - Code quality standards ⭐ **NEW**
- [API Patterns](mdc:.cursor/rules/api-patterns.mdc) - API design patterns
- [Endpoint Routing](mdc:.cursor/rules/endpoint-routing.mdc) - Endpoint routing patterns
- [Database Patterns](mdc:.cursor/rules/database-patterns.mdc) - Database best practices
- [MCP Integration](mdc:.cursor/rules/mcp-integration.mdc) - MCP server patterns
## Related Documentation
- [docs/QUALITY_STANDARDS.md](mdc:docs/QUALITY_STANDARDS.md) - Complete quality guide ⭐ **NEW**
- [src/utils/request.ts](mdc:src/utils/request.ts) - Request utilities ⭐ **NEW**
- [src/utils/logger.ts](mdc:src/utils/logger.ts) - Logging utilities ⭐ **NEW**
- [src/shared/constants.ts](mdc:src/shared/constants.ts) - All constants ⭐ **NEW**
- [docs/DEPLOYMENT.md](mdc:docs/DEPLOYMENT.md) - Deployment guide
- [wrangler.toml](mdc:wrangler.toml) - Configuration reference
---
**Status:** Production patterns established
**Last Updated:** 2025-10-08
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

