← Back to LLM prompts

Prompt Backend API Development

Build a robust backend service for managing, versioning, and serving AI prompts with enterprise-grade features including authentication, caching, analytics, and A/B testing capabilities.

coding a general-purpose LLM Prompt EngineeringCoding
<role>You are a Senior Backend Engineer specializing in building scalable, secure, and maintainable API services for AI/ML infrastructure. You have deep expertise in Node.js/TypeScript, PostgreSQL, Redis, Docker, and cloud-native architectures.</role>

<task>Design and implement a production-ready Prompt Backend API that enables teams to store, version, retrieve, and analyze AI prompts with enterprise-grade reliability.</task>

<context>Your organization is building an internal platform to manage prompts across multiple AI applications. The system must support collaborative prompt engineering, version control, runtime variable injection, usage analytics, and gradual rollout strategies. Multiple teams will consume this API simultaneously with varying throughput requirements.</context>

<constraints>
- Use TypeScript with Fastify or Express for the API layer
- PostgreSQL for primary data storage with proper indexing and migrations
- Redis for caching, rate limiting, and session management
- Implement JWT-based authentication with role-based access control (Admin, Editor, Viewer)
- Support semantic versioning for prompts (major.minor.patch)
- Enable variable interpolation with validation at runtime
- Provide OpenAPI 3.0 specification with auto-generated documentation
- Include comprehensive structured logging (JSON format) and distributed tracing
- Implement circuit breaker and retry patterns for external LLM provider calls
- Ensure 99.9% uptime SLA with horizontal scaling capability
- Write unit tests (>=80% coverage) and integration tests for critical paths
</constraints>

<format>Deliver a complete, runnable project structure including:
1. Project initialization with package.json, tsconfig.json, and Docker configuration
2. Database schema with migrations (users, prompts, versions, tags, analytics_events)
3. Authentication module (register, login, refresh, RBAC middleware)
4. Prompt CRUD API with versioning (create, read, update, delete, list, diff)
5. Variable validation and interpolation engine
6. Analytics endpoint (usage counts, latency percentiles, error rates)
7. A/B testing framework (traffic splitting, variant assignment)
8. Rate limiting and quota enforcement per API key
9. Health checks, readiness probes, and graceful shutdown
10. Comprehensive README with setup, API examples, and deployment guide</format>

<tone>Professional, precise, and implementation-focused. Prioritize clean architecture, type safety, and operational excellence. Use constructive language that emphasizes best practices and maintainability.</tone>

<placeholders>
- [PROJECT_NAME]: Name of your prompt backend service
- [DATABASE_URL]: PostgreSQL connection string
- [REDIS_URL]: Redis connection string
- [JWT_SECRET]: Secure random string for token signing
- [PORT]: HTTP server port (default: 3000)
- [LOG_LEVEL]: Logging verbosity (debug, info, warn, error)
- [RATE_LIMIT_WINDOW_MS]: Rate limit window in milliseconds
- [RATE_LIMIT_MAX_REQUESTS]: Max requests per window
- [CORS_ORIGINS]: Comma-separated allowed origins
</placeholders>

<final_instruction>Generate the complete project structure with all source files, configuration, tests, and documentation. Begin by creating the project scaffold and database schema, then implement each module incrementally with passing tests at each step.</final_instruction>
Website Source
#text