# muthukamalan/voting_app architecture

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

- Interactive diagram: https://gitdiagram.com/muthukamalan/voting_app
- Repository: https://github.com/muthukamalan/voting_app

## Overview

#### Purpose and deployment entry points
This is a distributed voting application demonstrating asynchronous vote processing, persistent aggregation, and production-style observability. Run locally through `compose.yaml` or deploy the complete service set recursively from `k8s/manifests/`. Application containers are built from `vote/Dockerfile`, `worker/Dockerfile`, and `result/Dockerfile`.

#### Vote submission service
The Python/Flask voting UI accepts a browser’s choice between two options and enforces one effective vote per client browser. Its primary application entry point is `vote/app.py`, with the rendered page in `vote/templates/index.html`. The service deployment boundary is defined by `k8s/manifests/vote/vote.deploy.yml` and its service/secret manifests.

#### Asynchronous processing boundary
Votes cross from the synchronous Flask request path into RabbitMQ, decoupling user-facing submission from database persistence. The Celery worker consumes queued messages, uses Redis as its task result/state backend, and writes vote records to PostgreSQL. Core worker implementation and deployment are `worker/worker.py`, `worker/requirements.txt`, and `k8s/manifests/worker/worker.deploy.yml`; broker infrastructure is under `k8s/manifests/amqp/`.

#### Persistent results and read model
PostgreSQL is the durable source of vote data. Initialization is supplied by `postgres/init.sql`; Kubernetes provisions configuration, credentials, a persistent volume claim, and service through `k8s/manifests/postgres/postgres.deploy.yml`, `k8s/manifests/postgres/postgres.pvc.yml`, and `k8s/manifests/postgres/postgres.config.init.yml`. The Node.js results service reads this database and presents live totals, polling every two seconds; its runtime entry points are `result/server.js` and `result/tracing.js`, deployed via `k8s/manifests/result/result.deploy.yml`.

#### Runtime topology
The system spans Python for vote intake and background processing, Node.js for results delivery, RabbitMQ for transport, Redis for Celery state, and PostgreSQL for durable data. Service discovery and exposure are represented by paired deployment/service manifests, especially `k8s/manifests/redis/redis.deploy.yml`, `k8s/manifests/amqp/amqp.deploy.yml`, and `k8s/manifests/result/result.service.yml`. Docker Compose is the local multi-container topology; Kubernetes manifests are the cluster topology.

#### Metrics and operational inspection
Prometheus collects metrics from Redis and PostgreSQL exporters and feeds Grafana dashboards. The architecture-defining manifests are `k8s/manifests/prometheus/prometheus.config.yml`, `prometheus/prometheus.yml`, `k8s/manifests/grafana/grafana.deploy.yml`, `k8s/manifests/redis.exporter/redis.exporter.deploy.yml`, and `k8s/manifests/postgres.exporter/postgres.export.deploy.yml`. Flower provides Celery task/worker monitoring, while RedisInsight exposes Redis inspection: `k8s/manifests/flower/flower.deploy.yml` and `k8s/manifests/redisinsights/redisinsights.deploy.yml`.

#### Distributed tracing
Application traces are collected by OpenTelemetry and visualized in Jaeger. The collector’s concrete configuration is `otel/otel-collector-config.yaml`, while cluster deployment/configuration lives at `k8s/manifests/otel/otel.deploy.yml`, `k8s/manifests/otel/otel.config.yml`, and `k8s/manifests/jager/jager.deploy.yml`. `result/tracing.js` indicates explicit tracing integration in the results service.

Main entry points: [`k8s/manifests/vote/vote.deploy.yml`](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/vote/vote.deploy.yml) (Cluster topology), [`worker/worker.py`](https://github.com/muthukamalan/voting_app/blob/main/worker/worker.py) (Celery worker), [`vote/app.py`](https://github.com/muthukamalan/voting_app/blob/main/vote/app.py) (Vote Flask service), [`k8s/manifests/postgres/postgres.deploy.yml`](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/postgres/postgres.deploy.yml) (PostgreSQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Application services"]
  node_browser(("Voter browser<br/>client"))
  node_vote["Vote Flask service<br/>Python / Flask<br/>[app.py]"]
  node_vote_ui["Voting page<br/>Flask template<br/>[index.html]"]
  node_worker["Celery worker<br/>Python / Celery<br/>[worker.py]"]
  node_result["Results service<br/>Node.js<br/>[server.js]"]
  node_result_tracing["Results tracing<br/>OpenTelemetry integration<br/>[tracing.js]"]
end

subgraph group_data["Messaging and data"]
  node_rabbitmq["RabbitMQ<br/>message broker<br/>[amqp.deploy.yml]"]
  node_redis[("Redis<br/>Celery state backend<br/>[redis.deploy.yml]")]
  node_postgres[("PostgreSQL<br/>durable vote store")]
  node_postgres_init["Database initialization<br/>SQL schema<br/>[init.sql]"]
end

subgraph group_ops["Observability"]
  node_prometheus["Prometheus<br/>metrics collector"]
  node_redis_exporter["Redis exporter<br/>metrics exporter"]
  node_postgres_exporter["PostgreSQL exporter<br/>metrics exporter"]
  node_grafana["Grafana<br/>dashboards<br/>[grafana.deploy.yml]"]
  node_flower["Flower<br/>Celery monitoring<br/>[flower.deploy.yml]"]
  node_redisinsight["RedisInsight<br/>Redis inspection"]
  node_otel["OpenTelemetry Collector<br/>trace collector"]
  node_jaeger["Jaeger<br/>trace visualization<br/>[jager.deploy.yml]"]
end

subgraph group_deploy["Deployment topology"]
  node_result_service{{"Results exposure<br/>Kubernetes Service<br/>[result.service.yml]"}}
  node_compose["Local topology<br/>Docker Compose<br/>[compose.yaml]"]
  node_kubernetes["Cluster topology<br/>Kubernetes manifests<br/>[vote.deploy.yml]"]
end

node_browser -->|"submits vote"| node_vote
node_vote -->|"renders"| node_vote_ui
node_vote -->|"queues vote"| node_rabbitmq
node_rabbitmq -->|"delivers task"| node_worker
node_worker -->|"stores task state"| node_redis
node_worker -->|"writes vote"| node_postgres
node_postgres_init -->|"initializes schema"| node_postgres
node_result -->|"polls totals"| node_postgres
node_browser -->|"views results"| node_result_service
node_result_service -->|"routes traffic"| node_result
node_result_tracing -->|"emits traces"| node_otel
node_otel -->|"exports traces"| node_jaeger
node_redis -.->|"metrics"| node_redis_exporter
node_postgres -.->|"metrics"| node_postgres_exporter
node_redis_exporter -.->|"scraped by"| node_prometheus
node_postgres_exporter -.->|"scraped by"| node_prometheus
node_prometheus -->|"dashboard data"| node_grafana
node_flower -.->|"monitors tasks"| node_worker
node_redisinsight -.->|"inspects"| node_redis
node_compose -.->|"runs locally"| node_vote
node_compose -.->|"runs locally"| node_worker
node_compose -.->|"runs locally"| node_result
node_kubernetes -.->|"deploys"| node_vote
node_kubernetes -.->|"deploys"| node_worker
node_kubernetes -.->|"deploys"| node_result
node_kubernetes -.->|"deploys"| node_rabbitmq
node_kubernetes -.->|"deploys"| node_redis
node_kubernetes -.->|"deploys"| node_postgres

click node_vote "https://github.com/muthukamalan/voting_app/blob/main/vote/app.py"
click node_vote_ui "https://github.com/muthukamalan/voting_app/blob/main/vote/templates/index.html"
click node_rabbitmq "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/amqp/amqp.deploy.yml"
click node_worker "https://github.com/muthukamalan/voting_app/blob/main/worker/worker.py"
click node_redis "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/redis/redis.deploy.yml"
click node_postgres "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/postgres/postgres.deploy.yml"
click node_postgres_init "https://github.com/muthukamalan/voting_app/blob/main/postgres/init.sql"
click node_result "https://github.com/muthukamalan/voting_app/blob/main/result/server.js"
click node_result_tracing "https://github.com/muthukamalan/voting_app/blob/main/result/tracing.js"
click node_result_service "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/result/result.service.yml"
click node_compose "https://github.com/muthukamalan/voting_app/blob/main/compose.yaml"
click node_kubernetes "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/vote/vote.deploy.yml"
click node_prometheus "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/prometheus/prometheus.config.yml"
click node_redis_exporter "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/redis.exporter/redis.exporter.deploy.yml"
click node_postgres_exporter "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/postgres.exporter/postgres.export.deploy.yml"
click node_grafana "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/grafana/grafana.deploy.yml"
click node_flower "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/flower/flower.deploy.yml"
click node_redisinsight "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/redisinsights/redisinsights.deploy.yml"
click node_otel "https://github.com/muthukamalan/voting_app/blob/main/otel/otel-collector-config.yaml"
click node_jaeger "https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/jager/jager.deploy.yml"

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_browser,node_vote,node_vote_ui,node_worker,node_result,node_result_tracing toneBlue
class node_rabbitmq,node_redis,node_postgres,node_postgres_init toneAmber
class node_prometheus,node_redis_exporter,node_postgres_exporter,node_grafana,node_flower,node_redisinsight,node_otel,node_jaeger toneMint
class node_result_service,node_compose,node_kubernetes toneRose
```

## Components

### Application services

- **Voter browser**: client
- [Vote Flask service](https://github.com/muthukamalan/voting_app/blob/main/vote/app.py): Python / Flask · Accepts choices and enforces one effective browser vote. · `vote/app.py`
- [Voting page](https://github.com/muthukamalan/voting_app/blob/main/vote/templates/index.html): Flask template · `vote/templates/index.html`
- [Celery worker](https://github.com/muthukamalan/voting_app/blob/main/worker/worker.py): Python / Celery · Consumes votes and persists vote records. · `worker/worker.py`
- [Results service](https://github.com/muthukamalan/voting_app/blob/main/result/server.js): Node.js · Polls vote totals every two seconds. · `result/server.js`
- [Results tracing](https://github.com/muthukamalan/voting_app/blob/main/result/tracing.js): OpenTelemetry integration · `result/tracing.js`

### Messaging and data

- [RabbitMQ](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/amqp/amqp.deploy.yml): message broker · Decouples vote submission from persistence. · `k8s/manifests/amqp/amqp.deploy.yml`
- [Redis](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/redis/redis.deploy.yml): Celery state backend · `k8s/manifests/redis/redis.deploy.yml`
- [PostgreSQL](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/postgres/postgres.deploy.yml): durable vote store · Durable source of vote data. · `k8s/manifests/postgres/postgres.deploy.yml`
- [Database initialization](https://github.com/muthukamalan/voting_app/blob/main/postgres/init.sql): SQL schema · `postgres/init.sql`

### Observability

- [Prometheus](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/prometheus/prometheus.config.yml): metrics collector · `k8s/manifests/prometheus/prometheus.config.yml`
- [Redis exporter](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/redis.exporter/redis.exporter.deploy.yml): metrics exporter · `k8s/manifests/redis.exporter/redis.exporter.deploy.yml`
- [PostgreSQL exporter](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/postgres.exporter/postgres.export.deploy.yml): metrics exporter · `k8s/manifests/postgres.exporter/postgres.export.deploy.yml`
- [Grafana](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/grafana/grafana.deploy.yml): dashboards · `k8s/manifests/grafana/grafana.deploy.yml`
- [Flower](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/flower/flower.deploy.yml): Celery monitoring · `k8s/manifests/flower/flower.deploy.yml`
- [RedisInsight](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/redisinsights/redisinsights.deploy.yml): Redis inspection · `k8s/manifests/redisinsights/redisinsights.deploy.yml`
- [OpenTelemetry Collector](https://github.com/muthukamalan/voting_app/blob/main/otel/otel-collector-config.yaml): trace collector · `otel/otel-collector-config.yaml`
- [Jaeger](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/jager/jager.deploy.yml): trace visualization · `k8s/manifests/jager/jager.deploy.yml`

### Deployment topology

- [Results exposure](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/result/result.service.yml): Kubernetes Service · `k8s/manifests/result/result.service.yml`
- [Local topology](https://github.com/muthukamalan/voting_app/blob/main/compose.yaml): Docker Compose · Runs the local multi-container stack. · `compose.yaml`
- [Cluster topology](https://github.com/muthukamalan/voting_app/blob/main/k8s/manifests/vote/vote.deploy.yml): Kubernetes manifests · Deployment manifests define the cluster service set. · `k8s/manifests/vote/vote.deploy.yml`

## Connections

- Voter browser → Vote Flask service: submits vote
- Vote Flask service → Voting page: renders
- Vote Flask service → RabbitMQ: queues vote
- RabbitMQ → Celery worker: delivers task
- Celery worker → Redis: stores task state
- Celery worker → PostgreSQL: writes vote
- Database initialization → PostgreSQL: initializes schema
- Results service → PostgreSQL: polls totals
- Voter browser → Results exposure: views results
- Results exposure → Results service: routes traffic
- Results tracing → OpenTelemetry Collector: emits traces
- OpenTelemetry Collector → Jaeger: exports traces
- Redis → Redis exporter: metrics
- PostgreSQL → PostgreSQL exporter: metrics
- Redis exporter → Prometheus: scraped by
- PostgreSQL exporter → Prometheus: scraped by
- Prometheus → Grafana: dashboard data
- Flower → Celery worker: monitors tasks
- RedisInsight → Redis: inspects
- Local topology → Vote Flask service: runs locally
- Local topology → Celery worker: runs locally
- Local topology → Results service: runs locally
- Cluster topology → Vote Flask service: deploys
- Cluster topology → Celery worker: deploys
- Cluster topology → Results service: deploys
- Cluster topology → RabbitMQ: deploys
- Cluster topology → Redis: deploys
- Cluster topology → PostgreSQL: deploys
