How jharnasaxena/ai-bill-analytics works
This repository contains a local AI-usage analytics pipeline. Synthetic usage events are generated and written to both Kafka and raw files; Spark processes the two feeds as streaming and batch paths, applying shared validation and pricing logic before publishing serving data for dashboards. The streaming job also maintains cumulative usage and budget-alert state. The tree includes an earlier rough implementation, but this map focuses on the more developed local_project version. Evidence is limited to the supplied excerpts and source index; dashboard-to-database wiring is inferred from configuration and shown as unverified.
Main entry points: producer.py Usage producer · stream_job.py Streaming aggregation · batch_job.py Batch aggregation · init Serving database
Components 11
Event ingestion
- Event generator
local_project/producers/event_generator.py - Usage producer
local_project/producers/producer.py - Kafka topic
- Raw event files
local_project
Spark processing
- Batch aggregation
local_project/jobs/batch_job.py - Streaming aggregation
local_project/jobs/stream_job.py - Validation and pricing
local_project/jobs/transformations.py
Serving and state
- Serving database
local_project/db/init - Windowed and cumulative state
local_project/jobs/stream_job.py
Analytics UI
- Usage dashboards
local_project/grafana/provisioning/dashboards/ai-bill.json
Other components
- Pipeline operator
Connections 12
- Pipeline operator → Usage producer: starts
- Usage producer → Event generator: creates events
local_project/producers/producer.py - Usage producer → Kafka topic: publishes events
local_project/producers/producer.py - Usage producer → Raw event files: writes events
local_project/producers/producer.py - Kafka topic → Streaming aggregation: streams events
local_project/jobs/stream_job.py - Raw event files → Batch aggregation: reads events
local_project/jobs/batch_job.py - Batch aggregation → Validation and pricing: uses
local_project/jobs/batch_job.py - Streaming aggregation → Validation and pricing: uses
local_project/jobs/stream_job.py - Batch aggregation → Serving database: writes aggregates
local_project/jobs/batch_job.py - Streaming aggregation → Serving database: reads and writes
local_project/jobs/stream_job.py - Streaming aggregation → Windowed and cumulative state: maintains state
local_project/jobs/stream_job.py - Usage dashboards → Serving database: queries data