This document consolidates architecture context and instructions from the project guides (CLAUDE.md and AGENTS.md).
Effect Patterns rules (for Claude, Cursor, Gemini, and other AI tools) live in a single canonical file: docs/Effect-Patterns-Rules.md. AGENTS.md, CLAUDE.md, and GEMINI.md point to it; Cursor continues to receive a full copy via ep install add --tool cursor.
Effect Patterns is a community-driven knowledge base of 700+ practical patterns for building robust applications with Effect-TS. The repository contains:
- Pattern Content (
content/published/patterns/) - Markdown-based pattern library with examples and explanations - API Server (
packages/api-server/) - Next.js REST API with Effect services, database access, and Vercel deployment - MCP Transport (
packages/mcp-transport/) - MCP protocol transports (stdio + streamable-http) — HTTP-only transport binaries with internal Effect services for tool execution, caching, logging, and tracing - Admin CLI (
packages/ep-admin/) - Internal tooling for pattern publishing, QA, and migrations - End-user CLI (
packages/ep-cli/) - Public CLI for developers to search and generate code - Toolkit (
packages/toolkit/) - Type-safe Effect library for pattern operations
The repository uses npm workspaces for package management. All cross-package imports use workspace:* dependencies, not TypeScript path aliases.
Effect Patterns Hub
├── packages/
│ ├── api-server/ ← REST API server (Next.js + Effect + PostgreSQL)
│ ├── mcp-transport/ ← MCP protocol transports (stdio + streamable-http)
│ ├── toolkit/ ← Core pattern library & database layer
│ ├── ep-admin/ ← Admin CLI (pattern publishing, migrations)
│ ├── ep-cli/ ← End-user CLI
│ ├── analysis-core/ ← Code analysis rules & detectors
│ ├── ep-shared-services/ ← Shared utilities across packages
│ └── pipeline-state/ ← Publishing pipeline state machine
├── content/published/ ← Pattern markdown files (700+ patterns)
├── scripts/ ← Utility scripts for publishing, testing
└── package.json ← Root workspace definition
The system is split into two packages with clear ownership:
api-serverowns HTTP + database — Next.js routes, Effect services, auth, tracingmcp-transportowns MCP protocol + tool handlers — standalone Node.js binaries that call the API viafetch
The MCP transports have zero database access and zero Next.js imports. They call the API exclusively over HTTP, but they use internal Effect services to structure tool execution, caching, logging, and tracing.
HTTP Endpoints (app/api/)
- 27 REST endpoints for pattern operations
- Authentication: API key validation + tier-based access control (Effect-based)
- Error handling: Centralized via
errorHandler.ts
Services (src/services/)
- Resilience Layer: Cache, circuit-breaker, rate-limiter with KV fallback
- Code Analysis: Review-code, analyze-code, confidence-calculator, snippet-extractor, fix-plan-generator
- Infrastructure: Config, logger, metrics, validation, guidance-loader, pattern-generator
- All services use Effect.Service pattern for dependency injection and composition
Auth (src/auth/)
apiKey.ts— HTTP API key validation (Effect-based)adminAuth.ts— Admin endpoint authenticationsecureCompare.ts— Constant-time string comparison
Dependencies: effect, next, drizzle-orm, postgres, @effect-patterns/toolkit
Entry Points
src/mcp-stdio.ts— stdio transport for IDE integration (Claude Code, Cursor)src/mcp-streamable-http.ts— HTTP transport for remote MCP 2.0 connectionssrc/mcp-production-client.ts— production HTTP client with pooling/dedup
Tool Handlers (src/tools/)
tool-implementations.ts— tool registry with Zod schema validationhandlers/— search-patterns, get-pattern, simple-handlerstool-result-builder.ts— rich MCP response formattingelicitation-helpers.ts— interactive tool clarification
Schemas (src/schemas/)
tool-schemas.ts— Zod schemas for MCP tool inputsoutput-schemas.ts— Zod schemas for structured tool outputsstructured-output.ts— MCP 2.0 content types (text, image, structured)
Auth (src/auth/)
mcpTransportAuth.ts— transport-level API key validationoauth-server.ts,oauth-config.ts,oauth-client.ts— OAuth2 for MCP 2.0pkce.ts— PKCE challenge generation
Dependencies: effect, @effect/opentelemetry, @modelcontextprotocol/sdk, zod (no next, no drizzle-orm, no workspace package deps)
- PostgreSQL with Drizzle ORM
- Tables:
effect_patterns,application_patterns,pattern_relations,skills,skill_patterns - Connection pooling with serverless-aware configuration (Vercel KV fallback)
MCP Clients (Claude Code, Cursor, etc.)
↓
MCP Transport (stdio or streamable-http) ← packages/mcp-transport
↓ fetch()
API Server (Next.js routes) ← packages/api-server
↓
Route Handler Factory (applies auth, errors, logging)
↓
Effect Services (composition via Effect.Service)
├─ Circuit Breaker (protects external calls)
├─ Rate Limiter (per-client quotas)
├─ Cache (in-memory + TTL)
├─ Code Analysis Services (Claude API calls)
└─ Database Layer (Toolkit package)
↓
PostgreSQL (via Drizzle ORM with connection pooling)
Free (MCP protocol):
search_patterns- Search 700+ patterns by query, category, difficultyget_pattern- Get full pattern details and code examples by IDlist_analysis_rules- Browse analysis rule catalog (metadata only)
Paid (HTTP API only):
- Code review (
review_code) - Code analysis (
analyze_code) - Consistency analysis (
analyze_consistency) - Pattern generation (
generate_pattern) - Refactoring (
apply_refactoring) - See MCP_CONFIG.md for HTTP API details
- API Server:
packages/api-server/ - MCP Transport:
packages/mcp-transport/ - Local API:
http://localhost:3000(run:bun run api:dev) - Staging:
https://effect-patterns-mcp-staging.vercel.app - Production:
https://effect-patterns-mcp.vercel.app
effect_patterns - Main pattern records
id,slug(unique),title,skillLevel,category,difficultyexamples,rules(JSONB for flexibility)- Indexed on: slug, skill_level
application_patterns - High-level classifications
id,slug(unique),name,descriptionlearningOrder,effectModule,subPatterns(JSONB)- Indexed on: slug, learning_order
pattern_relations - Related patterns
- Self-referential many-to-many linking related patterns
skills - Agent skills generated from patterns
- One per application pattern category, contains SKILL.md content
skill_patterns - Skill → Pattern join table
- Many-to-many linking skills to their constituent patterns
- Beginner - Fundamentals, first patterns
- Intermediate - Common use cases
- Advanced - Complex compositions
| File | Purpose |
|---|---|
packages/api-server/src/server/init.ts |
Effect layer composition, runtime setup |
packages/api-server/src/server/errorHandler.ts |
Converts Effect errors to HTTP responses |
packages/api-server/src/server/routeHandler.ts |
Factory for authenticated route handlers |
packages/api-server/src/auth/apiKey.ts |
API key authentication (Effect-based) |
packages/api-server/src/tools/schemas.ts |
Effect Schema types shared with API routes |
| File | Purpose |
|---|---|
packages/mcp-transport/src/mcp-stdio.ts |
MCP stdio transport for IDE integration |
packages/mcp-transport/src/mcp-streamable-http.ts |
MCP 2.0 streamable HTTP transport |
packages/mcp-transport/src/tools/tool-implementations.ts |
Tool registry and Zod schema validation |
packages/mcp-transport/src/mcp-content-builders.ts |
Rich MCP response formatting |
packages/mcp-transport/src/config/mcp-environments.ts |
Environment URL selection (local/staging/prod) |
| File | Purpose |
|---|---|
packages/api-server/src/services/config/api.ts |
Centralized config, no async overhead |
packages/api-server/src/services/cache/api.ts |
In-memory cache with TTL and LRU eviction |
packages/api-server/src/services/circuit-breaker/api.ts |
Prevents cascading failures (3-state FSM) |
packages/api-server/src/services/rate-limit/api.ts |
Dual-layer: Vercel KV + in-memory fallback |
packages/api-server/src/services/review-code/api.ts |
Code analysis via Claude API |
packages/api-server/src/services/logger/api.ts |
Structured logging with operation context |
packages/api-server/src/services/metrics/api.ts |
Request/response timing and error tracking |
| File | Purpose |
|---|---|
packages/toolkit/src/db/schema/index.ts |
Drizzle schema: patterns, jobs, relations |
packages/toolkit/src/db/client.ts |
Connection pooling, serverless-aware |
packages/toolkit/src/db/migrations/ |
Incremental schema changes |
| File | Purpose |
|---|---|
packages/api-server/src/services/config/api.ts |
API server environment variables, defaults |
packages/toolkit/src/services/config.ts |
Toolkit-specific config |
packages/mcp-transport/src/config/mcp-environments.ts |
MCP environment URL selection (local/staging/prod) |
| File | Purpose |
|---|---|
packages/api-server/src/errors.ts |
All error types (tagged unions) |
packages/api-server/src/server/errorHandler.ts |
Error to HTTP response mapping |
Use the effect-patterns-services-agents skill (.cursor/skills/effect-patterns-services-agents/SKILL.md) for Effect.Service, error-as-values, and Layer composition. Summary:
- Effect-TS native: Services via Effect.Service / Context.Tag; composition via
Effect.genandLayer. - Errors as values: Tagged errors; recover with
Effect.catchTag. - Workspace: Use
workspace:*deps; no path aliases; run from repo root.
Type-safe SQL queries with Drizzle:
// From packages/toolkit/src/db/schema/index.ts
const patterns = await db
.select()
.from(effectPatterns)
.where(eq(effectPatterns.skillLevel, "intermediate"));Located in packages/api-server/src/services/config/api.ts:
const config = {
// Circuit breaker (prevents cascading failures)
circuitBreaker: {
database: { failureThreshold: 5, timeout: "30s" },
kvCache: { failureThreshold: 3, timeout: "10s" },
},
// Rate limiting (per-client quotas)
rateLimiter: {
requestsPerMinute: 60,
fallbackToMemory: true, // Uses in-memory if KV unavailable
},
// Caching (in-memory, TTL-based, LRU eviction)
cache: {
enabled: true,
maxSize: 1000,
ttl: "1h",
},
};Key variables for development and deployment:
# API Server
PATTERN_API_KEY=your-key # API authentication
DATABASE_URL=postgres://user:pass@host/db # PostgreSQL connection
KV_REST_API_URL=https://your-kv.vercel.sh # Cache (Vercel KV, optional)
KV_REST_API_TOKEN=token
# Observability (API Server)
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
OTEL_EXPORTER_OTLP_HEADERS=authorization=Bearer token
# MCP Transport
EFFECT_PATTERNS_API_URL=http://localhost:3000 # API server URL
MCP_ENV=local|staging|production # Environment selector
MCP_DEBUG=true # Enable verbose logging
# Testing
STAGING_API_KEY=key # For staging deployment tests
PRODUCTION_API_KEY=key # For production deployment tests.ai-cli-config.json- AI CLI settingsconfig/environments.ts- Environment configsvercel.json- Deployment settings
Important: No TypeScript path aliases. Use workspace:* dependencies instead.
{
"dependencies": {
"@effect-patterns/toolkit": "workspace:*"
}
}This ensures:
- Packages resolve via npm workspaces, not tsconfig paths
- Each package has independent
tsconfig.json - Proper module resolution across environments (Node, browser, serverless)
Note: api-server depends on toolkit and analysis-core. mcp-transport has no workspace dependencies — it communicates with the API server purely via HTTP even though its internal execution model uses Effect services.
1. Pattern Analyzer Agent
- Location:
docs/agents/analyzer/(archived) - Purpose: Analyzes Effect-TS patterns for correctness, best practices, and potential improvements.
- Status: Archived - functionality integrated into CLI tools
2. API Server + MCP Transport
- API Server (
packages/api-server/): REST API with database access, Effect services, authentication, and Vercel deployment. - MCP Transport (
packages/mcp-transport/): Standalone MCP protocol transports (stdio + streamable-http) that call the API via HTTP and compose handlers with internal Effect services. - Features: Serves patterns to Claude Code IDE; real-time pattern search and retrieval; context-aware suggestions; pattern generation with AI assistance; API key authentication.
- Deployment: API server deployed to Vercel (staging + production). MCP transports run locally as Node.js binaries.
- API Dependencies:
@effect-patterns/toolkit(workspace:*), Next.js, Effect-TS, Drizzle ORM. - Transport Dependencies:
effect,@effect/opentelemetry,@modelcontextprotocol/sdk,zod(no Next.js, no DB, no workspace package deps).
Use the effect-patterns-services-agents skill (.cursor/skills/effect-patterns-services-agents/SKILL.md) for Effect.Service pattern, agent/service folder layout (api, schema, service, types, tests), and Layer/error-handling conventions.
Agents integrate with the ep-admin CLI through:
- Service composition using Effect layers
- Shared configuration via workspace packages
- Common error handling with Effect error types
- Unified logging through structured logging
- PostgreSQL for pattern storage
- Effect repositories from
@effect-patterns/toolkit - Connection pooling and management via platform services
- RESTful endpoints via
api-serverfor external access - MCP protocol via
mcp-transportfor IDE integration - MCP transports call the API server over HTTP — no shared code or direct imports
- Authentication at the API layer (API keys), transport-level auth for MCP connections
bun install
bun run build
bun run --filter @effect-patterns/toolkit build
bun run typecheck
bun run lint
bun run lint:fix
bun run lint:effect
bun run lint:allbun run api:dev # Start Next.js dev server on :3000
bun run api:build # Build Next.js for production
bun run api:test # Run api-server unit tests
bun run deploy:staging # Preflight + deploy to Vercel staging
bun run deploy:production # Preflight + deploy to Vercel productionbun run mcp:stdio # Build + run stdio transport
bun run mcp:http # Build + run streamable-http transport
bun run mcp:build # Build transport binaries
bun run mcp:test # Run transport unit testsbun run ep:preflight
bun run ep:smoke-test- Scaffold (
bun run scaffold) creates new projects under$HOME/Projects/TestRepos(see scripts/scaffold-test-project.ts and docs/development/SCAFFOLD_USER_GUIDE.md). - Lifecycle harness (
bun run lifecycle-harness --seed <n>) runs seedable E2E over real repos and theepCLI (no mocks; real network/API). It uses the same repo root as the scaffold (defaultScaffoldRootDir()inscripts/lifecycle-harness/src/paths.ts), discovers the monorepo root by walking up from its script dir, and writes JSON reports underscripts/lifecycle-harness/reports/. Templates are assigned in round-robin by scenario index. Full documentation: scripts/lifecycle-harness/README.md.
Unit and integration:
bun run test # All workspace tests
bun run api:test # API server tests
bun run mcp:test # MCP transport testsWithin api-server:
bun run --filter @effect-patterns/api-server test:routes
bun run --filter @effect-patterns/api-server test:integration
bun run --filter @effect-patterns/api-server test:fullWithin mcp-transport:
bun run --filter @effect-patterns/mcp-transport test:mcp:ci # MCP protocol tests
bun run --filter @effect-patterns/mcp-transport test:mcp:local # Against local serverDeployment testing: Set STAGING_API_KEY to the same value as Vercel Preview PATTERN_API_KEY (and PRODUCTION_API_KEY for production).
export STAGING_API_KEY="your-key"
bun run --filter @effect-patterns/api-server test:deployment:staging
export PRODUCTION_API_KEY="your-key"
bun run --filter @effect-patterns/api-server test:deployment:productionStress testing:
bun run test:stress:edge
bun run test:stress:volume
bun run test:stress:load
bun run test:stress:spike
bun run test:stress:endurance
bun run test:stress:allOther:
bun run test:e2e
cd packages/api-server && bun run smoke-testSee packages/api-server/TESTING_GUIDE.md for detailed testing setup.
bun run pipeline
bun run validate
bun run generate
bun run ingest
bun run rules
bun run ep:admin publish pipeline
bun run ep:admin publish lint
bun run ep:admin publish validatebun run db:generate
bun run db:push
bun run db:migrate
bun run db:studio
bun run test:db
bun run test:db:quickbun run qa:process
bun run qa:report
bun run qa:repair
bun run qa:repair:dry
bun run qa:all# API server unit test
bunx vitest run packages/api-server/src/services/cache/__tests__/cache.test.ts
# API server route test (needs DB)
DATABASE_URL=postgres://... bunx vitest run packages/api-server/tests/routes/health.route.test.ts --config vitest.routes.config.ts
# MCP transport tool test
cd packages/mcp-transport && bunx vitest run src/tools/__tests__/tool-handlers.test.ts# In service test or debug script
const service = yield* MyService;
yield* Effect.log(`Debug: ${JSON.stringify(value)}`);# 1. Edit: packages/toolkit/src/db/schema/index.ts
# 2. Generate migration
bun run db:generate
# 3. Review and apply
bun run db:push# Edit: packages/analysis-core/src/rules/
# Then regenerate rule catalog
bun run rules
bun run rules:claudeFollow the effect-patterns-services-agents skill. In this repo: run debug scripts from project root for correct module resolution; add tests and clear API docs.
See effect-patterns-services-agents skill for Effect.Service and folder layout.
Deployed to Vercel with automatic scaling:
- Staging environment for testing
- Production environment for live use
- Health checks at
/api/healthand/api/health?deep=true
Runs locally as Node.js binaries:
- stdio transport for IDE integration (Claude Code, Cursor)
- Streamable HTTP transport for remote MCP 2.0 connections
- Connects to API server via
EFFECT_PATTERNS_API_URLenv var
bun install
bun run --filter @effect-patterns/toolkit build
bun run --filter @effect-patterns/pipeline-state build
bun run --filter @effect-patterns/ep-shared-services build
# Start API server
bun run api:dev
# In another terminal, run MCP transport
bun run mcp:stdio- API key-based authentication
- Environment-specific keys
- Secure key rotation
- 100 requests per 15 minutes
- Per-IP tracking
- Graceful degradation
- No sensitive data logging
- Secure data transmission
- GDPR compliance
- Request counts and response times
- Error rates and types
- Resource utilization
- User interaction patterns
- Structured logs with correlation IDs
- Different log levels for environments
- Centralized log aggregation
/healthendpoint for monitoring- Database connectivity checks
- Service dependency verification
- Always run from project root - Ensures proper
node_modulesresolution - Check env vars first - Use
bun run ep:admin ops health-checkto diagnose issues - Review errors as values - Use
Effect.catchTagto handle specific error types - Profile with time -
time bun run test:mcpto identify bottlenecks - Verify in CI - GitHub Actions config:
.github/workflows/
- Pattern Generator: Automated pattern creation
- Test Generator: Automated test case generation
- Documentation Agent: Auto-generate documentation
- Migration Agent: Assist with code migrations
- Multi-Model Support: Support for multiple AI providers
- Context Awareness: Better understanding of project context
- Collaboration: Multi-agent coordination
- Learning: Agent improvement over time
When contributing to agents:
- Follow Effect-TS patterns and conventions
- Maintain backward compatibility
- Add comprehensive tests
- Update documentation
- Consider security implications
- Effect-TS Documentation
- MCP Protocol Specification
- Claude Code Integration Guide
- Architecture (monorepo structure)
- Split
packages/mcp-server/into two packages with clear ownership packages/api-server/— REST API with Effect services, DB access, Vercel deployment (renamed from mcp-server)packages/mcp-transport/— MCP protocol transports, tool handlers, Zod schemas (new package)- The MCP transports had zero database access and zero Next.js imports — the split codifies this boundary
- Root scripts updated:
api:dev,api:build,api:test,mcp:stdio,mcp:http,mcp:build,mcp:test
- Removed TypeScript path aliases from tsconfig.json
- Packages now resolve via npm workspaces (
workspace:*dependencies) - Each app has independent tsconfig.json configuration
- Improved build reliability and standard monorepo practices
Source: consolidated from CLAUDE.md and AGENTS.md.