Pravaah
Transparent Workflows, Accountable Systems
The problem Pravaah solves
QuadHacks Workflow Engine — System Architecture & Concepts
This document explains how the system works under the hood, the engineering concepts implemented, and the phase-by-phase evolution of the application.
The Big Picture
At its core, this backend is a Secure Event-Driven State Machine. It is designed to model multi-stage real-world bureaucratic processes (like name corrections, license approvals, etc.) while leaving behind a mathematically provable, tamper-resistant trail of exactly who did what and when, backed by uploaded evidence.
We actively eschewed heavy abstractions like ORMs (Object-Relational Mappers), opting directly for raw asynchronous SQL via asyncpg. This ensures maximum database performance and granular control over how transactions are constructed.
Phase-by-Phase Breakdown
Phase 1: Core Workflow Engine (The Foundation)
Goal: Build a dynamic pipeline that routes applications through different stages.
How it works (The Flow):
- Templates: We define a
Process(e.g., "Aadhar Correction"). - Blueprints: We define
Process Stepsthat belong to that process. Each step defines an order (1, 2, 3) and a strictly requiredrole_id(e.g., "Only a Verifier can do Step 1, Only an Approver can do Step 2"). - Execution: When a citizen submits a ticket, an
Applicationis created. The engine maps the blueprint steps into liveApplication Stepsassigned to that ticket. - State Transitions: Officers interact safely via a strict transition lifecycle:
ASSIGN: A task is pushed to a specific officer.RECEIVE: The officer actively acknowledges they are starting work, locking the step asin_progress.COMPLETE: The officer submits their approval/completion.NEXT: The engine evaluates the pipeline. If Step 1 is done, it wakes up Step 2. If no steps remain, the overall application is finalized.
Key Concept: Strict Boundary Enforcements. The engine natively queries the database to ensure the interacting officer actually possesses the correct role_id mandated by the step blueprint before permitting a transition.
Phase 2: Tamper-Resistant Ledger (The Truth Layer)
Goal: Guarantee non-repudiation natively. If an officer approves a step, they cannot delete the record later to avoid accountability.
How it works (The Flow):
- Behind every state transition endpoint (Create, Receive, Complete, Forward), there operates an asynchronous Fire-and-Forget Hook.
- Once the workflow transitions successfully, it triggers
create_event_log(). - Immutability (Append-only): The
event_logstable strictly rejectsUPDATEandDELETEcommands. - Hash Chaining (Blockchain-inspired): Every event calculates a SHA-256 hash mathematically incorporating the
current_hashfrom the immediately preceding event.Event #1 Hash = SHA256( "GENESIS" + Data )Event #2 Hash = SHA256( Event_1_Hash + Data )
Key Concept: If someone with malicious admin DB access alters Event #1 retroactively, the hash they recalculate will wildly mismatch the previous_hash frozen into Event #2, breaking the chain and mathematically proving tampering occurred.
Phase 3: Evidence Layer (The Proof System)
Goal: A cryptographic hash in a database is great, but it requires physical evidence to bind to reality.
How it works (The Flow):
- Critical actions (like pushing an application to the next phase /
STEP_FORWARDED) require documentation. - The
/event/with-proofendpoint intercepts the file upload stream in raw bytes. - The server computes a SHA-256 hash of the exact file bytes themselves.
- The file is saved locally to avoid complex cloud dependencies, and the
proof_urlalongside thefile_hashis written to the DB as evidence, linked by a Foreign Key directly to the Phase 2 Event Log.
Key Concepts:
- Strict Validation: The system maps event types to mandatory arrays. It will throw an HTTP 422 Unprocessable Entity if you attempt to forward a step without uploading the legally required documents.
- Traceability: If the file server is compromised and a document is swapped, re-hashing the document will not match the immutable
file_hashstored in the database link.
Phase 4: Delay Detection Engine (The Time Analysis Layer)
Goal: Mathematically detect where a workflow is running behind schedule by comparing actual processing time against predefined SLA targets.
How it works (The Flow):
- Every
process_stepcarries ansla_hoursfield set at template creation time (e.g. "Verification must finish within 48 hours"). - When a step is completed, a fire-and-forget hook inside
complete_stepautomatically triggerscalculate_delay_for_step(). - The engine fetches
started_atandcompleted_atfrom the application step, computes the actual delta, and compares it to the SLA. - It then upserts a structured row into the
delaystab
Tracks Applied (1)
