Implement PostHog reference architecture with best-practice project layout. Use when designing new PostHog integrations, reviewing project structure, or establishing architecture standards for PostHog applications. Trigger with phrases like "posthog architecture", "posthog best practices", "posthog project structure", "how to organize posthog", "posthog layout".
View on GitHubjeremylongshore/claude-code-plugins-plus-skills
posthog-pack
plugins/saas-packs/posthog-pack/skills/posthog-reference-architecture/SKILL.md
February 1, 2026
Select agents to install to:
npx add-skill https://github.com/jeremylongshore/claude-code-plugins-plus-skills/blob/main/plugins/saas-packs/posthog-pack/skills/posthog-reference-architecture/SKILL.md -a claude-code --skill posthog-reference-architectureInstallation paths:
.claude/skills/posthog-reference-architecture/# PostHog Reference Architecture
## Overview
Production-ready architecture patterns for PostHog integrations.
## Prerequisites
- Understanding of layered architecture
- PostHog SDK knowledge
- TypeScript project setup
- Testing framework configured
## Project Structure
```
my-posthog-project/
├── src/
│ ├── posthog/
│ │ ├── 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/
│ │ └── posthog/
│ │ ├── index.ts # Service facade
│ │ ├── sync.ts # Data synchronization
│ │ └── cache.ts # Caching layer
│ ├── api/
│ │ └── posthog/
│ │ └── webhook.ts # Webhook endpoint
│ └── jobs/
│ └── posthog/
│ └── sync.ts # Background sync job
├── tests/
│ ├── unit/
│ │ └── posthog/
│ └── integration/
│ └── posthog/
├── config/
│ ├── posthog.development.json
│ ├── posthog.staging.json
│ └── posthog.production.json
└── docs/
└── posthog/
├── SETUP.md
└── RUNBOOK.md
```
## Layer Architecture
```
┌─────────────────────────────────────────┐
│ API Layer │
│ (Controllers, Routes, Webhooks) │
├─────────────────────────────────────────┤
│ Service Layer │
│ (Business Logic, Orchestration) │
├─────────────────────────────────────────┤
│ PostHog Layer │
│ (Client, Types, Error Handling) │
├─────────────────────────────────────────┤
│ Infrastructure Layer │
│ (Cache, Queue, Monitoring) │
└─────────────────────────────────────────┘
```
## Key Components
### Step 1: Client Wrapper
```typescript
// src/posthog/client.ts
export