xiaohongshu
xiaohongshu
clay-reference-architecture
Implement Clay reference architecture with best-practice project layout. Use when designing new Clay integrations, reviewing project structure, or establishing architecture standards for Clay applications. Trigger with phrases like "clay architecture", "clay best practices", "clay project structu...
Full skill instructions
Production-ready architecture patterns for Clay integrations.
my-clay-project/
├── src/
│ ├── clay/
│ │ ├── client.ts # Singleton client wrapper
│ │ ├── config.ts # Environment configuration
│ │ ├── types.ts # TypeScript types
│ │ ├── errors.ts # Custom error classes
│ │ └── handlers/
│ │ ├── webhooks.ts # Webhook handlers
│ │ └── events.ts # Event processing
│ ├── services/
│ │ └── clay/
│ │ ├── index.ts # Service facade
│ │ ├── sync.ts # Data synchronization
│ │ └── cache.ts # Caching layer
│ ├── api/
│ │ └── clay/
│ │ └── webhook.ts # Webhook endpoint
│ └── jobs/
│ └── clay/
│ └── sync.ts # Background sync job
├── tests/
│ ├── unit/
│ │ └── clay/
│ └── integration/
│ └── clay/
├── config/
│ ├── clay.development.json
│ ├── clay.staging.json
│ └── clay.production.json
└── docs/
└── clay/
├── SETUP.md
└── RUNBOOK.md
┌─────────────────────────────────────────┐
│ API Layer │
│ (Controllers, Routes, Webhooks) │
├─────────────────────────────────────────┤
│ Service Layer │
│ (Business Logic, Orchestration) │
├─────────────────────────────────────────┤
│ Clay Layer │
│ (Client, Types, Error Handling) │
├─────────────────────────────────────────┤
│ Infrastructure Layer │
│ (Cache, Queue, Monitoring) │
└─────────────────────────────────────────┘
// src/clay/client.ts
export class ClayService {
private client: ClayClient;
private cache: Cache;
private monitor: Monitor;
constructor(config: ClayConfig) {
this.client = new ClayClient(config);
this.cache = new Cache(config.cacheOptions);
this.monitor = new Monitor('clay');
}
async get(id: string): Promise<Resource> {
return this.cache.getOrFetch(id, () =>
this.monitor.track('get', () => this.client.get(id))
);
}
}
// src/clay/errors.ts
export class ClayServiceError extends Error {
constructor(
message: string,
public readonly code: string,
public readonly retryable: boolean,
public readonly originalError?: Error
) {
super(message);
this.name = 'ClayServiceError';
}
}
export function wrapClayError(error: unknown): ClayServiceError {
// Transform SDK errors to application errors
}
// src/clay/health.ts
export async function checkClayHealth(): Promise<HealthStatus> {
try {
const start = Date.now();
await clayClient.ping();
return {
status: 'healthy',
latencyMs: Date.now() - start,
};
} catch (error) {
return { status: 'unhealthy', error: error.message };
}
}
User Request
│
▼
┌─────────────┐
│ API │
│ Gateway │
└──────┬──────┘
│
▼
┌─────────────┐ ┌─────────────┐
│ Service │───▶│ Cache │
│ Layer │ │ (Redis) │
└──────┬──────┘ └─────────────┘
│
▼
┌─────────────┐
│ Clay │
│ Client │
└──────┬──────┘
│
▼
┌─────────────┐
│ Clay │
│ API │
└─────────────┘
// config/clay.ts
export interface ClayConfig {
apiKey: string;
environment: 'development' | 'staging' | 'production';
timeout: number;
retries: number;
cache: {
enabled: boolean;
ttlSeconds: number;
};
}
export function loadClayConfig(): ClayConfig {
const env = process.env.NODE_ENV || 'development';
return require(`./clay.${env}.json`);
}
Set up the project layout following the reference structure above.
Create the singleton client with caching and monitoring.
Implement custom error classes for Clay operations.
Add health check endpoint for Clay connectivity.
| Issue | Cause | Solution |
|---|---|---|
| Circular dependencies | Wrong layering | Separate concerns by layer |
| Config not loading | Wrong paths | Verify config file locations |
| Type errors | Missing types | Add Clay types |
| Test isolation | Shared state | Use dependency injection |
# Create reference structure
mkdir -p src/clay/{handlers} src/services/clay src/api/clay
touch src/clay/{client,config,types,errors}.ts
touch src/services/clay/{index,sync,cache}.ts
For multi-environment setup, see clay-multi-env-setup.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience