# jamestrichmond/posthog architecture

> Architecture diagram of the GitHub repository jamestrichmond/posthog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jamestrichmond/posthog
- Repository: https://github.com/jamestrichmond/posthog

## Overview

PostHog is a product-data platform: teams and their agents send product context, then query it to understand behavior and take action. The repository includes event and replay ingestion, query and warehouse capabilities, and product areas for analytics, observability, experimentation, user communication, and AI. The README supports this high-level flow and capability map; sampled code additionally shows selected query, storage, and ingestion relationships. Many product modules are represented by their existing directories because their implementation was not sampled, so unverified internal connections are omitted.

Main entry points: [`products/logs/backend/services_query_runner.py`](https://github.com/jamestrichmond/posthog/blob/master/products/logs/backend/services_query_runner.py) (Logs query), [`frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx`](https://github.com/jamestrichmond/posthog/blob/master/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx) (Warehouse editor), [`nodejs/src/ingestion/pipelines/sessionreplay/session-replay-pipeline.ts`](https://github.com/jamestrichmond/posthog/blob/master/nodejs/src/ingestion/pipelines/sessionreplay/session-replay-pipeline.ts) (Replay ingestion), [`products/data_warehouse/backend/direct_query_engines.py`](https://github.com/jamestrichmond/posthog/blob/master/products/data_warehouse/backend/direct_query_engines.py) (SQL engine adapters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Ingestion"]
  node_eventpipe["Event ingestion"]
  node_replaypipe["Replay ingestion"]
  node_logpipe["Log ingestion"]
  node_logconsumer["Log consumer"]
end

subgraph group_query["Query and data"]
  node_warehouse[("Warehouse sources")]
  node_engineadapters["SQL engine adapters"]
  node_warehouseui["Warehouse editor"]
  node_hogql["HogQL parser<br/>[parser.py]"]
  node_queryrunner["Query runner<br/>[query_runner.py]"]
  node_cache[("Query cache<br/>[storage.py]")]
  node_objectstore[("Object storage<br/>[object_storage.py]")]
  node_pipelines["Data pipelines"]
end

subgraph group_analytics["Product analytics"]
  node_eventanalytics["Product and web analytics"]
  node_replay["Session replay and heatmaps"]
end

subgraph group_observe["Observability"]
  node_logsrunner["Logs query"]
  node_logmodels[("Log models<br/>[models.py]")]
  node_aiobs["AI observability"]
end

subgraph group_action["Ship and engage"]
  node_flags["Flags and experiments"]
  node_surveys["Surveys and support"]
end

subgraph group_ai["AI and agents"]
  node_posthogai["PostHog AI"]
  node_mcp["MCP analytics<br/>[mcp_tool.py]"]
  node_selfdriving["Self-driving"]
end

node_teams(("Teams and agents"))

node_teams -->|"send events"| node_eventpipe
node_teams -->|"send recordings"| node_replaypipe
node_teams -->|"send logs"| node_logpipe
node_replaypipe -->|"processes recordings"| node_replay
node_logconsumer -->|"uses context"| node_logpipe
node_teams -->|"query data"| node_warehouseui
node_warehouseui -->|"selects sources"| node_engineadapters
node_engineadapters -->|"builds table rows"| node_warehouse
node_warehouseui -.->|"runs SQL"| node_queryrunner
node_logsrunner -->|"uses parser"| node_hogql
node_logsrunner -->|"uses query runner"| node_queryrunner
node_logsrunner -->|"queries models"| node_logmodels
node_cache -->|"stores large results"| node_objectstore
node_teams -->|"analyze behavior"| node_eventanalytics
node_teams -->|"watch sessions"| node_replay
node_teams -->|"roll out and test"| node_flags
node_teams -->|"engage users"| node_surveys
node_teams -->|"transform and export"| node_pipelines
node_teams -->|"inspect AI traces"| node_aiobs
node_teams -->|"ask product data"| node_posthogai
node_teams -->|"inspect agent usage"| node_mcp
node_teams -->|"review reports"| node_selfdriving

click node_eventpipe "https://github.com/jamestrichmond/posthog/blob/master/nodejs/src/ingestion/common/common-ingestion-pipeline.ts"
click node_replaypipe "https://github.com/jamestrichmond/posthog/blob/master/nodejs/src/ingestion/pipelines/sessionreplay/session-replay-pipeline.ts"
click node_logpipe "https://github.com/jamestrichmond/posthog/blob/master/nodejs/src/logs/framework/logs-pipeline-context.ts"
click node_logconsumer "https://github.com/jamestrichmond/posthog/blob/master/nodejs/src/logs/logs-ingestion-consumer.ts"
click node_warehouse "https://github.com/jamestrichmond/posthog/tree/master/products/data_warehouse/backend"
click node_engineadapters "https://github.com/jamestrichmond/posthog/blob/master/products/data_warehouse/backend/direct_query_engines.py"
click node_warehouseui "https://github.com/jamestrichmond/posthog/blob/master/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx"
click node_hogql "https://github.com/jamestrichmond/posthog/blob/master/posthog/hogql/parser.py"
click node_queryrunner "https://github.com/jamestrichmond/posthog/blob/master/posthog/hogql_queries/query_runner.py"
click node_logsrunner "https://github.com/jamestrichmond/posthog/blob/master/products/logs/backend/services_query_runner.py"
click node_logmodels "https://github.com/jamestrichmond/posthog/blob/master/products/logs/backend/models.py"
click node_cache "https://github.com/jamestrichmond/posthog/blob/master/posthog/query_cache/storage.py"
click node_objectstore "https://github.com/jamestrichmond/posthog/blob/master/posthog/storage/object_storage.py"
click node_eventanalytics "https://github.com/jamestrichmond/posthog/tree/master/products"
click node_replay "https://github.com/jamestrichmond/posthog/tree/master/common/replay-headless/src"
click node_flags "https://github.com/jamestrichmond/posthog/tree/master/products"
click node_surveys "https://github.com/jamestrichmond/posthog/tree/master/products"
click node_pipelines "https://github.com/jamestrichmond/posthog/tree/master/products"
click node_aiobs "https://github.com/jamestrichmond/posthog/tree/master/products/ai_observability"
click node_posthogai "https://github.com/jamestrichmond/posthog/tree/master/ee/hogai"
click node_mcp "https://github.com/jamestrichmond/posthog/blob/master/ee/hogai/mcp_tool.py"
click node_selfdriving "https://github.com/jamestrichmond/posthog/tree/master/products"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_eventpipe,node_replaypipe,node_logpipe,node_logconsumer toneBlue
class node_warehouse,node_engineadapters,node_warehouseui,node_hogql,node_queryrunner,node_cache,node_objectstore,node_pipelines toneAmber
class node_eventanalytics,node_replay toneMint
class node_logsrunner,node_logmodels,node_aiobs toneRose
class node_flags,node_surveys,node_teams toneIndigo
class node_posthogai,node_mcp,node_selfdriving toneTeal
```

## Components

### Ingestion

- [Event ingestion](https://github.com/jamestrichmond/posthog/blob/master/nodejs/src/ingestion/common/common-ingestion-pipeline.ts): `nodejs/src/ingestion/common/common-ingestion-pipeline.ts`
- [Replay ingestion](https://github.com/jamestrichmond/posthog/blob/master/nodejs/src/ingestion/pipelines/sessionreplay/session-replay-pipeline.ts): `nodejs/src/ingestion/pipelines/sessionreplay/session-replay-pipeline.ts`
- [Log ingestion](https://github.com/jamestrichmond/posthog/blob/master/nodejs/src/logs/framework/logs-pipeline-context.ts): `nodejs/src/logs/framework/logs-pipeline-context.ts`
- [Log consumer](https://github.com/jamestrichmond/posthog/blob/master/nodejs/src/logs/logs-ingestion-consumer.ts): `nodejs/src/logs/logs-ingestion-consumer.ts`

### Query and data

- [Warehouse sources](https://github.com/jamestrichmond/posthog/tree/master/products/data_warehouse/backend): `products/data_warehouse/backend`
- [SQL engine adapters](https://github.com/jamestrichmond/posthog/blob/master/products/data_warehouse/backend/direct_query_engines.py): `products/data_warehouse/backend/direct_query_engines.py`
- [Warehouse editor](https://github.com/jamestrichmond/posthog/blob/master/frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx): `frontend/src/scenes/data-warehouse/editor/sidebar/queryDatabaseLogic.tsx`
- [HogQL parser](https://github.com/jamestrichmond/posthog/blob/master/posthog/hogql/parser.py): `posthog/hogql/parser.py`
- [Query runner](https://github.com/jamestrichmond/posthog/blob/master/posthog/hogql_queries/query_runner.py): `posthog/hogql_queries/query_runner.py`
- [Query cache](https://github.com/jamestrichmond/posthog/blob/master/posthog/query_cache/storage.py): `posthog/query_cache/storage.py`
- [Object storage](https://github.com/jamestrichmond/posthog/blob/master/posthog/storage/object_storage.py): `posthog/storage/object_storage.py`
- [Data pipelines](https://github.com/jamestrichmond/posthog/tree/master/products): `products`

### Product analytics

- [Product and web analytics](https://github.com/jamestrichmond/posthog/tree/master/products): `products`
- [Session replay and heatmaps](https://github.com/jamestrichmond/posthog/tree/master/common/replay-headless/src): `common/replay-headless/src`

### Observability

- [Logs query](https://github.com/jamestrichmond/posthog/blob/master/products/logs/backend/services_query_runner.py): `products/logs/backend/services_query_runner.py`
- [Log models](https://github.com/jamestrichmond/posthog/blob/master/products/logs/backend/models.py): `products/logs/backend/models.py`
- [AI observability](https://github.com/jamestrichmond/posthog/tree/master/products/ai_observability): `products/ai_observability`

### Ship and engage

- [Flags and experiments](https://github.com/jamestrichmond/posthog/tree/master/products): `products`
- [Surveys and support](https://github.com/jamestrichmond/posthog/tree/master/products): `products`

### AI and agents

- [PostHog AI](https://github.com/jamestrichmond/posthog/tree/master/ee/hogai): `ee/hogai`
- [MCP analytics](https://github.com/jamestrichmond/posthog/blob/master/ee/hogai/mcp_tool.py): `ee/hogai/mcp_tool.py`
- [Self-driving](https://github.com/jamestrichmond/posthog/tree/master/products): `products`

### Other components

- **Teams and agents**

## Connections

- Teams and agents → Event ingestion: send events
- Teams and agents → Replay ingestion: send recordings
- Teams and agents → Log ingestion: send logs
- Replay ingestion → Session replay and heatmaps: processes recordings (evidence: `nodejs/src/ingestion/pipelines/sessionreplay/session-replay-pipeline.ts`)
- Log consumer → Log ingestion: uses context (evidence: `nodejs/src/logs/framework/logs-pipeline-context.ts`)
- Teams and agents → Warehouse editor: query data
- Warehouse editor → SQL engine adapters: selects sources (evidence: `products/data_warehouse/backend/direct_query_engines.py`)
- SQL engine adapters → Warehouse sources: builds table rows (evidence: `products/data_warehouse/backend/direct_query_engines.py`)
- Warehouse editor → Query runner: runs SQL
- Logs query → HogQL parser: uses parser (evidence: `products/logs/backend/services_query_runner.py`)
- Logs query → Query runner: uses query runner (evidence: `products/logs/backend/services_query_runner.py`)
- Logs query → Log models: queries models (evidence: `products/logs/backend/services_query_runner.py`)
- Query cache → Object storage: stores large results (evidence: `posthog/query_cache/storage.py`)
- Teams and agents → Product and web analytics: analyze behavior
- Teams and agents → Session replay and heatmaps: watch sessions
- Teams and agents → Flags and experiments: roll out and test
- Teams and agents → Surveys and support: engage users
- Teams and agents → Data pipelines: transform and export
- Teams and agents → AI observability: inspect AI traces
- Teams and agents → PostHog AI: ask product data
- Teams and agents → MCP analytics: inspect agent usage
- Teams and agents → Self-driving: review reports
