backend-dev-guidelines

Automate backend development guidelines for Langfuse's Next.js 14 monorepo.

32.8k|3.5k|Updated May 18, 2023
One-click install
npx skills add https://github.com/langfuse/langfuse --skill backend-dev-guidelines-langfuse
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: backend-dev-guidelines
Source: https://github.com/langfuse/langfuse/tree/main/.claude/skills/backend-dev-guidelines
Command: npx skills add https://github.com/langfuse/langfuse --skill backend-dev-guidelines-langfuse

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a centralized, comprehensive guide to Langfuse's backend architecture and development patterns, reducing onboarding time and ensuring consistent, high-quality code across the monorepo. It helps developers quickly understand and apply best practices for tRPC, public APIs, services, databases, and testing, minimizing errors and rework.

Core Features & Use Cases

  • Architectural Guidance: Explains the layered architecture, request flows, and separation of concerns for tRPC and public REST APIs, simplifying complex system understanding.
  • Database Access Patterns: Details how to interact with PostgreSQL (Prisma) for transactional data and ClickHouse for analytics, emphasizing critical projectId filtering for tenant isolation.
  • Testing Strategies: Outlines various testing approaches (integration, tRPC, service, worker) to ensure robust and reliable backend components, saving time on manual QA.
  • Use Case: When building a new tRPC endpoint for a UI feature, this skill guides you through defining the procedure, implementing business logic in a service, accessing the database while ensuring tenant isolation, and writing comprehensive tests to validate functionality.

Quick Start

When starting a new backend feature, begin by reviewing the "Architecture Overview" and "Routing Patterns" sections to understand the system's structure and how to define new endpoints or procedures.

Frequently Asked Questions about backend-dev-guidelines

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a new tRPC endpoint in a Next.js monorepo?

Define tRPC procedures following Langfuse's layered architecture: create the procedure in a router, implement business logic in a service layer, access data through Prisma for PostgreSQL or ClickHouse for analytics, and ensure projectId filtering for tenant isolation. This separation maintains consistent code quality across the monorepo.

What's the best way to ensure tenant isolation when querying PostgreSQL and ClickHouse?

Apply projectId filtering at the database access layer for both Prisma queries and ClickHouse analytics queries. This pattern prevents cross-tenant data leakage and is enforced through the traceException error handling and Zod v4 validation framework across all backend components.

How do I test tRPC endpoints and worker processors in a TypeScript monorepo?

Use Jest for web package tests and vitest for worker package tests. Test tRPC routers with integration tests, service layer with unit tests, and BullMQ queue processors with worker tests. This multi-layer strategy validates functionality across web, worker, and shared packages consistently.

Can I use tRPC with Express and public REST APIs in the same backend?

Yes. Langfuse's architecture supports both tRPC routers for type-safe internal procedures and Express-based public API endpoints. Both follow the same layered pattern: routing layer, service layer, and database access with Prisma and ClickHouse, enabling flexible API design.

What observability and error handling practices should I follow?

Instrument code with OpenTelemetry for observability and use traceException for structured error handling across tRPC, public APIs, services, and BullMQ processors. Configure environment variables through env.mjs to ensure consistent setup across the monorepo's dual database system.

Does this cover validation patterns for API requests?

Yes. Use Zod v4 for schema validation across tRPC procedures, public API endpoints, and service inputs. Validation ensures type safety and tenant isolation enforcement, reducing errors and runtime issues in production deployments.