How dinmukhamad/puls works
Purpose and Entry Points
Puls is an internal call-center operator motivation/gamification platform: roles, KPI ratings, coin economy, rewards, learning missions, and operational reporting. FastAPI serves both the JSON API and the vanilla-JS SPA.
• app/main.py
• app/api/router.py
• index.html
Application Composition
app/main.py assembles the application: configuration, middleware, lifespan startup/shutdown work, API router, health/readiness endpoints, and static SPA delivery. Domain routers are centrally mounted once rather than independently exposed.
• app/core/config.py
• app/core/lifespan.py
• app/core/static.py
Security and Request Boundary
Authentication is JWT-backed HttpOnly cookie auth. Middleware enforces CORS, compression, and CSRF/origin protections; authorization is implemented at domain API boundaries for operator, supervisor, manager, and admin scopes. Production startup rejects unsafe configuration.
• app/modules/auth/router.py
• app/core/security.py
• app/core/middleware.py
Persistence, Schema, and Startup
PostgreSQL is the production system of record, accessed through the database layer and shared ORM entities. Alembic owns schema evolution; startup can verify schema/readiness and seed initial/admin/economy data. Local tests use temporary SQLite, but production requires PostgreSQL/psycopg.
• app/database/db.py
• app/models/entities.py
• migrations/env.py
• app/services/database_readiness.py
Reporting-to-Analytics Pipeline
Period-report uploads are parsed, validated, persisted, and used as the durable basis for ratings and analytics rather than transient JSON data. Analytics repositories/calculators produce KPI summaries, operator tables, group comparisons, and cached results; ratings add nomination and ranking logic.
• app/modules/reports/service.py
• app/modules/reports/excel_parser.py
• app/modules/analytics/service.py
• app/modules/rating/service.py
Engagement and Economy Domains
The core gamification flow connects operators and groups to levels/achievements, coin balances and transactions, seasonal shop purchases, raffles, Wheel of WOW eligibility/spins, notifications, and weekly accruals. These modules expose APIs while service layers contain transaction and rule orchestration.
• app/modules/wallet/service.py
• app/modules/economy/service.py
• app/modules/wheel/service.py
• app/modules/weekly_results/accrual_service.py
• app/modules/missions/service.py
Frontend and Delivery
The client is an HTML/CSS/vanilla-JS SPA served by FastAPI. Editable source fragments are concatenated in numeric filename order into committed browser bundles; API domain wrappers call the backend and view modules render major workflows.
• js/src/app/00-core-shell.js
• js/src/api/client/00-client-auth.js
• js/app.js
• css/styles.css
• scripts/build-frontend.mjs
Runtime and Deployment
Python 3.13/FastAPI runs under Uvicorn. Deployment targets Railway and can use Docker/Compose plus Nginx; start.sh applies Alembic migrations before serving. Required external infrastructure is PostgreSQL; no Node backend is used.
• start.sh
• Dockerfile
• deploy/docker-compose.yml
• railway.toml
Main entry points: router.py Central API router · db.py Database layer · main.py Application composition · service.py Wallet and economy
Components 23
FastAPI backend
Single process serves API, health checks, and SPA assets.
- Application composition · Assembles middleware, lifespan, routers, health endpoints, and static delivery.
app/main.py - Central API router · Mounts domain routers under one API boundary.
app/api/router.py - Cookie JWT auth · Authenticates users and enforces role-scoped access.
app/modules/auth/router.py - Security middleware · Provides JWT, CSRF/origin, CORS, and compression protections.
app/core/middleware.py - Startup lifecycle · Runs startup and shutdown work including readiness and seeding.
app/core/lifespan.py - SPA static delivery · Serves the HTML client and browser assets.
app/core/static.py
Data and analytics
PostgreSQL-backed reporting and KPI processing.
- Database layer · Shared PostgreSQL sessions and ORM entities.
app/database/db.py - Domain entities
app/models/entities.py - Alembic schema evolution · Owns production schema migrations.
migrations/env.py - Database readiness · Verifies schema and database availability.
app/services/database_readiness.py - Report ingestion · Validates and persists uploaded period reports.
app/modules/reports/service.py - Excel parser
app/modules/reports/excel_parser.py - KPI analytics · Builds summaries, operator tables, comparisons, and cached results.
app/modules/analytics/service.py - Ratings and rankings · Adds nomination and ranking logic over durable reports.
app/modules/rating/service.py
Engagement domains
Gamification rules and economy transactions.
- Wallet and economy · Orchestrates balances, transactions, shop purchases, and rewards.
app/modules/economy/service.py - Wheel of WOW · Determines eligibility and records spins.
app/modules/wheel/service.py - Weekly accruals · Awards recurring engagement results.
app/modules/weekly_results/accrual_service.py - Learning missions
app/modules/missions/service.py
Browser client
Vanilla-JS SPA source is built into committed assets.
- SPA source modules · Core shell and API wrappers define browser workflows.
js/src/app/00-core-shell.js - Frontend bundler · Concatenates ordered source fragments into browser bundles.
scripts/build-frontend.mjs - Committed SPA bundle · The built client calls API domains and renders workflows.
js/app.js
Runtime and deployment
Production startup migrates PostgreSQL before serving.
- Production startup · Applies migrations before starting Uvicorn.
start.sh - Container deployment · Supports Docker, Compose, Nginx, and Railway deployment.
Dockerfile
Connections 28
- Application composition → Central API router: mounts
- Application composition → Security middleware: installs
- Application composition → Startup lifecycle: runs
- Application composition → SPA static delivery: serves through
- Central API router → Cookie JWT auth: includes
- Central API router → Report ingestion: exposes
- Central API router → KPI analytics: exposes
- Central API router → Wallet and economy: exposes
- Security middleware → Cookie JWT auth: protects
- Startup lifecycle → Database readiness: checks
- Database readiness → Database layer: verifies
- Database layer → Domain entities: persists
- Alembic schema evolution → Database layer: evolves schema for
- Report ingestion → Excel parser: parses uploads with
- Report ingestion → Database layer: persists reports
- KPI analytics → Database layer: queries durable reports
- Ratings and rankings → KPI analytics: uses KPI results
- Wallet and economy → Database layer: records transactions
- Wheel of WOW → Wallet and economy: uses reward economy
- Weekly accruals → Wallet and economy: awards coins
- Learning missions → Wallet and economy: rewards completion
- Frontend bundler → SPA source modules: concatenates ordered modules
- Frontend bundler → Committed SPA bundle: produces
- SPA static delivery → Committed SPA bundle: delivers
- Committed SPA bundle → Central API router: calls JSON API
- Production startup → Alembic schema evolution: applies
- Production startup → Application composition: starts Uvicorn app
- Container deployment → Production startup: runs