| name | replit-sdk-patterns |
| description | Apply production-ready patterns for Replit Database, Object Storage, and Auth APIs.
Use when implementing Replit integrations, structuring data access layers,
or establishing team coding standards for Replit services.
Trigger with phrases like "replit patterns", "replit best practices",
"replit code patterns", "idiomatic replit", "replit SDK".
|
| allowed-tools | Read, Write, Edit |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","replit","python","typescript","patterns"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Replit SDK Patterns
Overview
Production-ready patterns for Replit's built-in services: Key-Value Database (@replit/database / replit.db), Object Storage (@replit/object-storage), PostgreSQL (DATABASE_URL), and Auth headers. Covers singleton clients, error handling, and type-safe wrappers.
Prerequisites
.replit and replit.nix configured (see replit-install-auth)
- Familiarity with async/await patterns
- Understanding of Replit's service model
Instructions
Step 1: Database Client Singleton (Node.js)
import Database from '@replit/database';
let instance: Database | null = null;
export function getKV(): Database {
if (!instance) {
instance = new Database();
}
return instance;
}
export async function kvGet<T>(key: string): Promise<T | null> {
const value = await getKV().get(key);
return value as T | null;
}
export async function kvSet<T>(: , : T): <> {
().(key, value);
}
(): <[]> {
().(prefix);
}
(): <> {
().(key);
}