Skip to content
Pravaah

Pravaah

Transparent Workflows, Accountable Systems

Created on 22nd March 2026

•

Pravaah

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):

  1. Templates: We define a Process (e.g., "Aadhar Correction").
  2. Blueprints: We define Process Steps that belong to that process. Each step defines an order (1, 2, 3) and a strictly required role_id (e.g., "Only a Verifier can do Step 1, Only an Approver can do Step 2").
  3. Execution: When a citizen submits a ticket, an Application is created. The engine maps the blueprint steps into live Application Steps assigned to that ticket.
  4. 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 as in_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):

  1. Behind every state transition endpoint (Create, Receive, Complete, Forward), there operates an asynchronous Fire-and-Forget Hook.
  2. Once the workflow transitions successfully, it triggers create_event_log().
  3. Immutability (Append-only): The event_logs table strictly rejects UPDATE and DELETE commands.
  4. Hash Chaining (Blockchain-inspired): Every event calculates a SHA-256 hash mathematically incorporating the current_hash from 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):

  1. Critical actions (like pushing an application to the next phase / STEP_FORWARDED) require documentation.
  2. The /event/with-proof endpoint intercepts the file upload stream in raw bytes.
  3. The server computes a SHA-256 hash of the exact file bytes themselves.
  4. The file is saved locally to avoid complex cloud dependencies, and the proof_url alongside the file_hash is 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_hash stored 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):

  1. Every process_step carries an sla_hours field set at template creation time (e.g. "Verification must finish within 48 hours").
  2. When a step is completed, a fire-and-forget hook inside complete_step automatically triggers calculate_delay_for_step().
  3. The engine fetches started_at and completed_at from the application step, computes the actual delta, and compares it to the SLA.
  4. It then upserts a structured row into the delays tab

Tracks Applied (1)

CivicTech

We are digitizing and structuring complex government workflows like Aadhaar, passport, and license processes into a tran...Read More

Discussion

Builders also viewed

See more projects on Devfolio