Prompt Manager

Core Concepts

Understanding the architecture of Prompt Manager

Core Concepts

Prompt Manager is built around several key concepts that work together to provide a flexible prompt management system.

Prompt Manager

The PromptManager is the main entry point for interacting with the system. It coordinates between storage, templates, and caching.

import { PromptManager } from '@prompt-manager/core';

const manager = new PromptManager({
  storage: storageAdapter,
  template: templateEngine,
  cache: cacheAdapter, // optional
});

Storage Adapters

Storage adapters handle persisting and retrieving prompts. All storage adapters implement the same interface:

interface StorageAdapter {
  get(key: string): Promise<string | null>;
  set(key: string, value: string): Promise<void>;
  delete(key: string): Promise<void>;
  list(): Promise<string[]>;
}

Available Storage Adapters

  • MemoryStorage: In-memory storage (lost on restart)
  • SQLiteStorage: File-based SQLite database using Bun's native driver with Drizzle ORM
  • PostgresStorage: PostgreSQL database using Bun.sql with Drizzle ORM

Template Engines

Template engines handle rendering prompts with dynamic data:

interface TemplateEngine {
  render(template: string, data: Record<string, unknown>): Promise<string>;
}

Available Template Engines

  • SimpleTemplate: Basic {{variable}} interpolation
  • HandlebarsTemplate: Full Handlebars support with helpers, partials, etc.

Cache Adapters

Cache adapters improve performance by caching rendered prompts:

interface CacheAdapter {
  get(key: string): Promise<string | null>;
  set(key: string, value: string, ttl?: number): Promise<void>;
  delete(key: string): Promise<void>;
  clear(): Promise<void>;
}

Available Cache Adapters

  • MemoryCache: In-memory cache with TTL support
  • RedisCache: Distributed caching using Bun's native Redis client
  • CloudflareKVCache: Edge caching for Cloudflare Workers using Cloudflare KV

Workflow

Here's how the components work together:

  1. Store a Prompt: Save a template string to storage
  2. Retrieve a Prompt: Fetch the template from storage (or cache)
  3. Render a Prompt: Apply data to the template using the template engine
  4. Cache the Result: Optionally cache the rendered output
// 1. Store
await manager.set('welcome', 'Welcome {{name}} to {{app}}!');

// 2. & 3. Retrieve and Render
const result = await manager.render('welcome', {
  name: 'Alice',
  app: 'Prompt Manager'
});

// Result: "Welcome Alice to Prompt Manager!"

Best Practices

  • Use MemoryStorage for development and testing
  • Use SQLiteStorage for single-server deployments or PostgresStorage for distributed systems
  • Enable caching for frequently-used prompts
  • Choose the template engine that matches your complexity needs