# zacharydhamilton/jackpot architecture

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

- Interactive diagram: https://gitdiagram.com/zacharydhamilton/jackpot
- Repository: https://github.com/zacharydhamilton/jackpot

## Overview

##### Project type and purpose
- This is a full-stack, event-driven slot-machine application that uses:
- A React SPA (frontend)
- A Spring Boot API server (backend)
- PostgreSQL as the master-data store
- Confluent Cloud (Kafka, Schema Registry, ksqlDB, Connect) for real-time streaming
- Terraform for provisioning (AWS Postgres, Confluent resources)
- Docker Compose for local container orchestration

##### File-structure overview
- Top-level directories:
- apiserver/ – Java Spring Boot service
- react/ – React UI + Nginx Docker setup
- terraform/ – IaC for AWS and Confluent Cloud
- postgres/ – Local Dockerfile and CSV data for Postgres
- Key files:
- docker-compose.yaml – orchestrates api server, react, postgres locally
- ksql.sql – example stream/table statements
- Patterns:
- Layered backend (controllers → services → repository)
- Event-streaming pipeline via Kafka topics and ksqlDB
- Infrastructure as code (Terraform + Docker)

1. Infrastructure layer
– Terraform-provisioned AWS Postgres (EC2 or RDS)
– Terraform-provisioned Confluent Cloud cluster:
- Kafka Brokers
- Schema Registry
- ksqlDB App
- Kafka Connect
2. Data pipeline
– Postgres CDC Source Connector → Kafka topic “jackpot.games.pools”
– KsqlDB:
- STREAM wagers (topic “wagers”)
- STREAM pool_changes (topic “jackpot.games.pools”)
- TABLE jackpotPools (materialized state)
- TABLE jackpots (joined/enriched aggregates, topic “jackpots”)
3. Backend layer
– Spring Boot API server container
- HTTPController → exposes REST endpoints for placing wagers
- WsController → WebSocket endpoint
- ProducerService → writes to “wagers” topic
- KsqlService / PushQuerySubscriber → subscribes to “jackpots” for push queries
4. Frontend layer
– React + Nginx container
- HTTP calls to API for new wagers
- WebSocket client for live jackpot updates
– Browser (user interface)

C. Highlight architectural patterns & principles
– Event-driven / streaming architecture
– CQRS-style separation: write stream (“wagers”) vs read stream (“jackpots”)
– Layered design in backend service (controllers → services → repositories)
– Infrastructure as code (Terraform + Docker Compose) for reproducibility

D. Note key technologies / frameworks
– Java + Spring Boot (apiserver)
– React + Nginx (frontend)
– Kafka / ksqlDB / Connect / Schema Registry (Confluent Cloud)
– PostgreSQL (master data)
– Terraform (AWS + Confluent)
– Docker Compose (local orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        direction TB
        InfraAWSPostgres["AWS Postgres (RDS)"]:::cloud
        InfraWebInstances["AWS Web Instances"]:::cloud
        subgraph "Confluent Cloud"
            direction TB
            KafkaBrokers["Kafka Brokers"]:::cloud
            SchemaRegistry["Schema Registry"]:::cloud
            ksqlDBApp["ksqlDB App"]:::cloud
            KafkaConnect["Kafka Connect"]:::cloud
        end
    end

    %% Data Pipeline
    subgraph "Data Pipeline"
        direction TB
        CDCConnector["Postgres CDC Connector"]:::pipeline
        KafkaTopicPools["Topic: jackpot.games.pools"]:::cylinder
        KafkaTopicWagers["Topic: wagers"]:::cylinder
        StreamWagers["STREAM wagers"]:::pipeline
        StreamPoolChanges["STREAM pool_changes"]:::pipeline
        TableJackpotPools["TABLE jackpotPools"]:::pipeline
        TableJackpots["TABLE jackpots"]:::pipeline
        TopicJackpots["Topic: jackpots"]:::cylinder
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        ApiserverContainer["Spring Boot API Server"]:::backend
        HTTPController["HTTPController"]:::backend
        WsController["WsController"]:::backend
        ProducerService["ProducerService"]:::backend
        KsqlService["KsqlService"]:::backend
        PushQuerySubscriber["PushQuerySubscriber"]:::backend
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        ReactNginx["React + Nginx Container"]:::frontend
        Browser["Browser (User)"]:::frontend
    end

    %% Relationships / Data Flows
    Browser -->|"HTTP Request"| ReactNginx
    ReactNginx -->|"HTTP POST /wager"| HTTPController
    HTTPController -->|"calls ProducerService"| ProducerService
    ProducerService -->|"writes to topic"| KafkaTopicWagers

    InfraAWSPostgres -->|"Change Events"| CDCConnector
    CDCConnector -->|"CDC →"| KafkaTopicPools

    KafkaTopicWagers -->|"wagers →"| StreamWagers
    KafkaTopicPools -->|"pool_changes →"| StreamPoolChanges
    StreamPoolChanges --> TableJackpotPools
    StreamWagers --> TableJackpots
    TableJackpots -->|"publish"| TopicJackpots

    TopicJackpots -->|"push queries"| PushQuerySubscriber
    PushQuerySubscriber -->|"onMessage"| WsController
    WsController -->|"WebSocket"| Browser

    %% Click Events
    click InfraAWSPostgres "https://github.com/zacharydhamilton/jackpot/tree/main/terraform/aws/postgres"
    click InfraWebInstances "https://github.com/zacharydhamilton/jackpot/tree/main/terraform/aws/web"
    click kafkaBrokers "https://github.com/zacharydhamilton/jackpot/blob/main/terraform/confluent.tf"
    click SchemaRegistry "https://github.com/zacharydhamilton/jackpot/blob/main/terraform/confluent.tf"
    click ksqlDBApp "https://github.com/zacharydhamilton/jackpot/blob/main/terraform/confluent.tf"
    click KafkaConnect "https://github.com/zacharydhamilton/jackpot/blob/main/terraform/confluent.tf"
    click CDCConnector "https://github.com/zacharydhamilton/jackpot/blob/main/docker-compose.yaml"
    click KafkaTopicPools "https://github.com/zacharydhamilton/jackpot/blob/main/docker-compose.yaml"
    click KafkaTopicWagers "https://github.com/zacharydhamilton/jackpot/blob/main/docker-compose.yaml"
    click ksqlDBApp "https://github.com/zacharydhamilton/jackpot/blob/main/ksql.sql"
    click StreamWagers "https://github.com/zacharydhamilton/jackpot/blob/main/ksql.sql"
    click StreamPoolChanges "https://github.com/zacharydhamilton/jackpot/blob/main/ksql.sql"
    click TableJackpotPools "https://github.com/zacharydhamilton/jackpot/blob/main/ksql.sql"
    click TableJackpots "https://github.com/zacharydhamilton/jackpot/blob/main/ksql.sql"
    click TopicJackpots "https://github.com/zacharydhamilton/jackpot/blob/main/ksql.sql"
    click LocalPostgres "https://github.com/zacharydhamilton/jackpot/tree/main/postgres"
    click ApiserverContainer "https://github.com/zacharydhamilton/jackpot/tree/main/apiserver"
    click HTTPController "https://github.com/zacharydhamilton/jackpot/blob/main/apiserver/src/main/java/com/example/apiserver/api/HttpController.java"
    click WsController "https://github.com/zacharydhamilton/jackpot/blob/main/apiserver/src/main/java/com/example/apiserver/api/WsController.java"
    click ProducerService "https://github.com/zacharydhamilton/jackpot/blob/main/apiserver/src/main/java/com/example/apiserver/services/producer/ProducerService.java"
    click KsqlService "https://github.com/zacharydhamilton/jackpot/blob/main/apiserver/src/main/java/com/example/apiserver/services/ksql/KsqlService.java"
    click PushQuerySubscriber "https://github.com/zacharydhamilton/jackpot/blob/main/apiserver/src/main/java/com/example/apiserver/services/ksql/PushQuerySubscriber.java"
    click ReactNginx "https://github.com/zacharydhamilton/jackpot/tree/main/react"
    click Browser "https://github.com/zacharydhamilton/jackpot/blob/main/react/src/index.js"

    %% Styles
    classDef cloud fill:#bbdefb,stroke:#1976d2,color:#0d47a1
    classDef cylinder fill:#c8e6c9,stroke:#388e3c,color:#1b5e20
    classDef pipeline fill:#dcedc8,stroke:#689f38,color:#33691e
    classDef backend fill:#ffe0b2,stroke:#fb8c00,color:#e65100
    classDef frontend fill:#fff9c4,stroke:#fbc02d,color:#f57f17
```
