# dan-sones/prism architecture

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

- Interactive diagram: https://gitdiagram.com/dan-sones/prism
- Repository: https://github.com/dan-sones/prism

## Overview

1. This repository is a monorepo for an experimentation platform, not a single app. The core domain is feature/experiment management, event ingestion, assignment/bucketing, statistics, and analytics storage. The main runtime boundaries are Go microservices, one Java ingestion service, one Python stats service, React-based admin UIs, and shared protocol/model libraries.

2. The primary backend control plane is `services/experimentation-service`. It exposes HTTP APIs and gRPC servers for experiments, events catalog, metrics catalog, assignment-related operations, and experiment results. It is the central orchestrator that persists domain state in Postgres, queries analytics data from ClickHouse, and calls the stats engine for sample-size and test-result calculations.

3. `services/assignment-service` is the assignment/bucketing service. It owns the logic for selecting variants, caching experiment state in Redis, and reacting to cache invalidation. It also listens to Kafka and serves gRPC/HTTP endpoints so other services and SDK-facing clients can resolve assignments quickly without hitting the main experimentation database on every request.

4. `services/events-service` is the ingestion entry point for downstream business events. It is a Java Spring Boot service that validates event requests against the events catalog, publishes normalized events to Kafka, and uses cached catalog data plus gRPC lookups where needed. This service is the front door for event collection from applications.

5. `services/clickhouse-writer` is the streaming sink for analytics. It consumes Kafka events in microbatches and writes them into ClickHouse. This is the main path from raw event traffic into the analytical store used for reporting and experiment analysis.

6. `services/data-cooking-service` sits between raw assignment/event data and analysis-ready data. It consumes Kafka and reads from assignment/external services and ClickHouse to “cook” experiment data into a richer shape for downstream use. Its role is to enrich and reconcile data rather than to be the system of record.

7. `services/stats-engine` is a separate Python gRPC service for statistics. It implements sample-size calculations, z-tests, and decision logic. `experimentation-service` invokes it through generated gRPC clients, so statistical computation is isolated from business CRUD and API concerns.

8. The frontend/admin boundary is `services/experimentation-portal`. It is a Vite/React application that drives experiment, metrics, and events catalog workflows. Its API layer mirrors the backend service capabilities, and the UI is organized around routes for home, experiments, metrics catalog, and events catalog.

9. `openfeature-provider-react` and `examples/powell-motors` form the client-side runtime integration story. The provider package exposes a Prism web provider for OpenFeature-style flag/experiment resolution, and the example site demonstrates how a product frontend consumes it.

10. Shared contracts are a major architectural boundary. Protobuf definitions live in `services/protos`, and generated gRPC code is checked into each service. Shared Go libraries in `libs/` cover DB/domain models, logging, and microbatching so that services can share consistent schemas and ingestion patterns without coupling their business logic.

11. Infrastructure is first-class in `infrastructure/`. Docker Compose defines local dev/test topology, Postgres migrations define the experiment catalog and assignment schemas, ClickHouse migrations define analytics storage, Kafka bootstrap scripts wire the event bus, and Terraform provisions the VM-based deployment environment. This repo is therefore built around a distributed data pipeline with transactional state in Postgres and analytical state in ClickHouse.

12. The docs site under `docs/` is part of the product architecture, not just documentation. It contains OpenAPI and service reference material for the assignment and experimentation services, which reflects the public API boundaries and helps keep the service contracts explicit.

13. The main end-to-end data flow is: client/UI or SDK calls assignment/experimentation APIs → assignment is resolved and/or experiment state is updated → events are ingested through events-service → Kafka fans out to ClickHouse writer and cooking/analysis services → experimentation-service reads results and asks stats-engine for calculations → portal renders experiment health and outcomes from those APIs.

14. The repository also includes simulation and load-testing tooling. `tools/experiment-simulator` generates synthetic experiments/events and can push cache invalidations, while `tools/gatling-load-testing` and `tools/bucket-finder` support stress testing and assignment verification. These tools are important because they exercise the same service boundaries as production traffic.

Main entry points: [`services/assignment-service`](https://github.com/dan-sones/prism/tree/main/services/assignment-service) (Assignment service), [`services/experimentation-service`](https://github.com/dan-sones/prism/tree/main/services/experimentation-service) (Experimentation service), [`infrastructure`](https://github.com/dan-sones/prism/tree/main/infrastructure) (Infrastructure), [`services/clickhouse-writer`](https://github.com/dan-sones/prism/tree/main/services/clickhouse-writer) (ClickHouse writer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core_services["Core services"]
  node_experimentation_service["Experimentation service<br/>Go control plane"]
  node_assignment_service["Assignment service<br/>Go bucketer"]
  node_events_service["Events service<br/>Java ingestion"]
  node_clickhouse_writer[("ClickHouse writer<br/>Go sink")]
  node_data_cooking_service["Data cooking<br/>Go enrichment"]
  node_stats_engine["Stats engine<br/>Python gRPC"]
end

subgraph group_client_apps["Client apps"]
  node_experimentation_portal["Experimentation portal<br/>React admin UI"]
  node_openfeature_provider["OpenFeature provider<br/>React provider"]
  node_powell_motors_example["Example site<br/>React demo"]
end

subgraph group_shared_platform["Shared platform"]
  node_protos["Protos<br/>gRPC contracts"]
  node_prismdbmodels["DB models<br/>Go shared models"]
  node_prismlogger["Logger<br/>Go logging lib"]
  node_prismmicrobatcher["Microbatcher<br/>Go batch lib"]
  node_docs_site["Docs site<br/>Docusaurus"]
  node_infrastructure[("Infrastructure<br/>DevOps")]
  node_kafka_bus["Kafka bus<br/>stream bus"]
end

subgraph group_dev_tools["Tools"]
  node_experiment_simulator["Simulator<br/>Go simulation tool"]
  node_gatling_testing["Gatling tests<br/>Java load test"]
  node_bucket_finder["Bucket finder<br/>Go verifier"]
end

node_experimentation_portal -->|"CRUD + results"| node_experimentation_service
node_experimentation_portal -->|"resolve assignment"| node_assignment_service
node_openfeature_provider -->|"flag resolution"| node_assignment_service
node_powell_motors_example -->|"uses provider"| node_openfeature_provider
node_experimentation_service -->|"grpc stats"| node_stats_engine
node_experimentation_service -->|"analytics queries"| node_clickhouse_writer
node_events_service -->|"catalog contract"| node_protos
node_events_service -->|"grpc lookups"| node_experimentation_service
node_events_service -->|"publish events"| node_kafka_bus
node_assignment_service -->|"assignment contract"| node_protos
node_assignment_service -->|"invalidate cache"| node_kafka_bus
node_clickhouse_writer -->|"consume stream"| node_kafka_bus
node_clickhouse_writer -.->|"clickhouse schema"| node_infrastructure
node_data_cooking_service -->|"assignment lookup"| node_assignment_service
node_data_cooking_service -->|"experiment lookup"| node_experimentation_service
node_data_cooking_service -->|"analysis input"| node_clickhouse_writer
node_data_cooking_service -->|"consume stream"| node_kafka_bus
node_experimentation_service -->|"domain models"| node_prismdbmodels
node_assignment_service -->|"domain models"| node_prismdbmodels
node_clickhouse_writer -->|"batching"| node_prismmicrobatcher
node_experiment_simulator -->|"simulate assignment"| node_assignment_service
node_experiment_simulator -->|"simulate events"| node_events_service
node_gatling_testing -->|"load test"| node_events_service
node_bucket_finder -->|"verify buckets"| node_assignment_service
node_docs_site -->|"api docs"| node_experimentation_service
node_docs_site -->|"api docs"| node_assignment_service
node_infrastructure -.->|"deploy/runtime"| node_experimentation_service
node_infrastructure -.->|"deploy/runtime"| node_assignment_service
node_infrastructure -.->|"deploy/runtime"| node_events_service
node_infrastructure -.->|"deploy/runtime"| node_clickhouse_writer
node_infrastructure -.->|"bootstrap"| node_kafka_bus

click node_experimentation_service "https://github.com/dan-sones/prism/tree/main/services/experimentation-service"
click node_assignment_service "https://github.com/dan-sones/prism/tree/main/services/assignment-service"
click node_events_service "https://github.com/dan-sones/prism/tree/main/services/events-service"
click node_clickhouse_writer "https://github.com/dan-sones/prism/tree/main/services/clickhouse-writer"
click node_data_cooking_service "https://github.com/dan-sones/prism/tree/main/services/data-cooking-service"
click node_stats_engine "https://github.com/dan-sones/prism/tree/main/services/stats-engine"
click node_experimentation_portal "https://github.com/dan-sones/prism/tree/main/services/experimentation-portal"
click node_openfeature_provider "https://github.com/dan-sones/prism/tree/main/openfeature-provider-react"
click node_powell_motors_example "https://github.com/dan-sones/prism/tree/main/examples/powell-motors/powell-motors-website"
click node_protos "https://github.com/dan-sones/prism/tree/main/services/protos"
click node_prismdbmodels "https://github.com/dan-sones/prism/tree/main/libs/prismdbmodels"
click node_prismlogger "https://github.com/dan-sones/prism/tree/main/libs/prismlogger"
click node_prismmicrobatcher "https://github.com/dan-sones/prism/tree/main/libs/prismmicrobatcher"
click node_docs_site "https://github.com/dan-sones/prism/tree/main/docs"
click node_infrastructure "https://github.com/dan-sones/prism/tree/main/infrastructure"
click node_kafka_bus "https://github.com/dan-sones/prism/tree/main/infrastructure/kafka"
click node_experiment_simulator "https://github.com/dan-sones/prism/tree/main/tools/experiment-simulator"
click node_gatling_testing "https://github.com/dan-sones/prism/tree/main/tools/gatling-load-testing"
click node_bucket_finder "https://github.com/dan-sones/prism/tree/main/tools/bucket-finder"

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_experimentation_service,node_assignment_service,node_events_service,node_clickhouse_writer,node_data_cooking_service,node_stats_engine toneBlue
class node_experimentation_portal,node_openfeature_provider,node_powell_motors_example toneAmber
class node_protos,node_prismdbmodels,node_prismlogger,node_prismmicrobatcher,node_docs_site,node_infrastructure,node_kafka_bus toneMint
class node_experiment_simulator,node_gatling_testing,node_bucket_finder toneRose
```

## Components

### Core services

Primary backend runtime boundaries for experimentation, assignment, ingestion, and analytics.

- [Experimentation service](https://github.com/dan-sones/prism/tree/main/services/experimentation-service): Go control plane · Central API and orchestration service for experiments, events catalog, metrics catalog, results, and assignment-related operations. · `services/experimentation-service`
- [Assignment service](https://github.com/dan-sones/prism/tree/main/services/assignment-service): Go bucketer · Low-latency assignment resolution service with Redis-backed experiment cache and Kafka-driven invalidation. · `services/assignment-service`
- [Events service](https://github.com/dan-sones/prism/tree/main/services/events-service): Java ingestion · Spring Boot entry point for validating, normalizing, and publishing business events to Kafka. · `services/events-service`
- [ClickHouse writer](https://github.com/dan-sones/prism/tree/main/services/clickhouse-writer): Go sink · Consumes Kafka microbatches and persists analytics events into ClickHouse. · `services/clickhouse-writer`
- [Data cooking](https://github.com/dan-sones/prism/tree/main/services/data-cooking-service): Go enrichment · Reconciles assignment and event data into analysis-ready cooked records for downstream use. · `services/data-cooking-service`
- [Stats engine](https://github.com/dan-sones/prism/tree/main/services/stats-engine): Python gRPC · Isolated statistics service for sample-size, z-test, and decision calculations. · `services/stats-engine`

### Client apps

Admin UI and frontend integration packages.

- [Experimentation portal](https://github.com/dan-sones/prism/tree/main/services/experimentation-portal): React admin UI · Vite/React application for managing experiments, metrics, and events catalog workflows. · `services/experimentation-portal`
- [OpenFeature provider](https://github.com/dan-sones/prism/tree/main/openfeature-provider-react): React provider · Prism web provider package for client-side feature and experiment resolution. · `openfeature-provider-react`
- [Example site](https://github.com/dan-sones/prism/tree/main/examples/powell-motors/powell-motors-website): React demo · Sample product frontend demonstrating provider integration and experiment-driven UI behavior. · `examples/powell-motors/powell-motors-website`

### Shared platform

Protocol definitions, reusable libraries, docs, and infrastructure.

- [Protos](https://github.com/dan-sones/prism/tree/main/services/protos): gRPC contracts · Shared protobuf definitions for assignment, events catalog, experimentation, and stats engine APIs. · `services/protos`
- [DB models](https://github.com/dan-sones/prism/tree/main/libs/prismdbmodels): Go shared models · Shared domain and persistence models reused across services for experiments, events, and metrics. · `libs/prismdbmodels`
- [Logger](https://github.com/dan-sones/prism/tree/main/libs/prismlogger): Go logging lib · Shared logging helper used by Go services and tools. · `libs/prismlogger`
- [Microbatcher](https://github.com/dan-sones/prism/tree/main/libs/prismmicrobatcher): Go batch lib · Reusable microbatch processing primitives for Kafka-to-storage pipelines. · `libs/prismmicrobatcher`
- [Docs site](https://github.com/dan-sones/prism/tree/main/docs): Docusaurus · Documentation and OpenAPI reference for the public service boundaries. · `docs`
- [Infrastructure](https://github.com/dan-sones/prism/tree/main/infrastructure): DevOps · Local and deployment infrastructure: Docker Compose, migrations, Kafka bootstrap, and Terraform. · `infrastructure`
- [Kafka bus](https://github.com/dan-sones/prism/tree/main/infrastructure/kafka): stream bus · Event backbone used for ingestion, assignment invalidation, and analytics fan-out. · `infrastructure/kafka`

### Tools

Simulation and load-testing utilities.

- [Simulator](https://github.com/dan-sones/prism/tree/main/tools/experiment-simulator): Go simulation tool · Generates synthetic experiments, events, and cache invalidations against service boundaries. · `tools/experiment-simulator`
- [Gatling tests](https://github.com/dan-sones/prism/tree/main/tools/gatling-load-testing): Java load test · Load-testing harness for assignment and ingestion paths. · `tools/gatling-load-testing`
- [Bucket finder](https://github.com/dan-sones/prism/tree/main/tools/bucket-finder): Go verifier · Assignment verification utility that exercises the assignment service. · `tools/bucket-finder`

## Connections

- Experimentation portal → Experimentation service: CRUD + results · Admin UI drives experiment, metrics, and events workflows through the control plane.
- Experimentation portal → Assignment service: resolve assignment · Portal-related flows depend on assignment resolution and bucket state.
- OpenFeature provider → Assignment service: flag resolution · Client-side provider resolves experiments and variants through assignment APIs.
- Example site → OpenFeature provider: uses provider · Example app demonstrates integration with the OpenFeature provider package.
- Experimentation service → Stats engine: grpc stats · Control plane delegates sample-size and decision calculations to the stats service.
- Experimentation service → ClickHouse writer: analytics queries · Reads analytical data from ClickHouse-backed storage for reporting and results.
- Events service → Protos: catalog contract · Uses shared events catalog gRPC definitions and generated code.
- Events service → Experimentation service: grpc lookups · Queries catalog and related domain data when validating inbound events.
- Events service → Kafka bus: publish events · Normalizes requests and pushes downstream events onto Kafka.
- Assignment service → Protos: assignment contract · Implements shared assignment gRPC/HTTP contract.
- Assignment service → Kafka bus: invalidate cache · Consumes invalidation and coordination messages from the event bus.
- ClickHouse writer → Kafka bus: consume stream · Consumes event traffic from Kafka microbatches.
- ClickHouse writer → Infrastructure: clickhouse schema · Writes into ClickHouse storage defined by repo migrations and config.
- Data cooking → Assignment service: assignment lookup · Reconciles and enriches event data with assignment state.
- Data cooking → Experimentation service: experiment lookup · Pulls experiment metadata and related domain state.
- Data cooking → ClickHouse writer: analysis input · Reads analytical event data as part of cooking and enrichment flows.
- Data cooking → Kafka bus: consume stream · Processes stream inputs from Kafka.
- Experimentation service → DB models: domain models · Shares experiment, metric, and event domain structures.
- Assignment service → DB models: domain models · Reuses assignment and experiment cache models.
- ClickHouse writer → Microbatcher: batching · Uses shared microbatching primitives for Kafka ingestion.
- Simulator → Assignment service: simulate assignment · Exercises assignment resolution and invalidation flows.
- Simulator → Events service: simulate events · Generates synthetic event traffic for ingestion paths.
- Gatling tests → Events service: load test · Stress tests the event ingestion boundary.
- Bucket finder → Assignment service: verify buckets · Checks assignment distribution and bucketing behavior.
- Docs site → Experimentation service: api docs · Documents the experimentation service HTTP/OpenAPI boundary.
- Docs site → Assignment service: api docs · Documents the assignment service contract.
- Infrastructure → Experimentation service: deploy/runtime · Defines service deployment, databases, and local topology.
- Infrastructure → Assignment service: deploy/runtime · Defines service deployment, cache, and message-bus topology.
- Infrastructure → Events service: deploy/runtime · Defines service deployment and supporting infrastructure.
- Infrastructure → ClickHouse writer: deploy/runtime · Defines analytics storage and stream-processing infrastructure.
- Infrastructure → Kafka bus: bootstrap · Creates and configures the shared stream backbone.
