← Resources/GuideLegal & Compliance

Legal & Compliance Platform Architecture: Contract Lifecycle, Obligation Tracking, and Audit Design

6 April 2026·14 min read

Overview

A legal compliance platform must solve a problem that is simultaneously document-heavy and deadline-critical: contracts and regulatory obligations must be ingested, parsed for key dates and obligations, monitored continuously, and escalated before deadlines - with a tamper-proof audit trail that satisfies legal discovery requirements. This guide covers the architectural decisions behind IdeaSprout's Legal & Compliance module.


1. Contract Ingestion and Storage

Document Storage Architecture

Contracts are binary documents (PDF, DOCX) that must be stored with:

  • •Version control: Every amendment creates a new version, not an overwrite
  • •Immutability: Executed contracts cannot be modified
  • •Access control: Contracts are sensitive - role-based access at the document level
  • •Full-text search: Legal teams need to search across all contracts

Storage Design

Contract Document → S3 (object storage) → SHA-256 hash stored in DB
                 → Text extraction (Apache Tika) → PostgreSQL full-text index
                 → Metadata extraction → contracts table

Each contract version is stored as an immutable S3 object with a content-addressed key (sha256_hash.pdf). The database stores the hash, not the file - ensuring the stored document matches what was originally uploaded.

sql
CREATE TABLE contract_versions (
  id              UUID PRIMARY KEY,
  contract_id     UUID NOT NULL,
  version_number  INTEGER NOT NULL,
  s3_key          TEXT NOT NULL,
  sha256_hash     TEXT NOT NULL,
  file_size_bytes BIGINT,
  uploaded_by     UUID,
  uploaded_at     TIMESTAMPTZ DEFAULT NOW(),
  is_executed     BOOLEAN DEFAULT FALSE,
  UNIQUE (contract_id, version_number)
);

2. Obligation Extraction Engine

The Core Challenge

A 50-page contract may contain dozens of obligations scattered throughout the document: payment terms, renewal clauses, notice periods, reporting requirements, insurance obligations, and regulatory compliance requirements. Manually extracting these is error-prone and time-consuming.

Extraction Approaches

Rule-based extraction (implemented in IdeaSprout):

  • •Regex patterns for dates: (d{1,2}[/-]d{1,2}[/-]d{2,4}), (January|February|...) d{1,2}, d{4}
  • •Keyword proximity matching: "renew", "terminate", "notice", "payment due" within 50 words of a date
  • •Section header detection: "Term and Termination", "Payment Terms", "Renewal"

NLP-based extraction (for higher accuracy):

  • •Named Entity Recognition (NER) for dates, parties, and monetary amounts
  • •Relation extraction to link obligations to their deadlines
  • •Clause classification to categorise obligation types

Obligation Schema

json
{
  "obligationId": "uuid",
  "contractId": "uuid",
  "type": "renewal_notice | payment | reporting | insurance | regulatory",
  "description": "Provide 90 days written notice before contract end date to renew",
  "dueDate": "2026-09-01",
  "recurrence": "annual | one-time | monthly",
  "responsibleParty": "us | counterparty",
  "extractedFrom": { "page": 12, "paragraph": 3 },
  "status": "pending | completed | overdue | waived"
}

3. Deadline Engine

The Problem with Calendar Reminders

Most companies manage contract deadlines with calendar reminders or spreadsheets. These fail because:

  • •Reminders are tied to individuals - when someone leaves, reminders disappear
  • •No escalation if the reminder is ignored
  • •No audit trail of who was notified and when
  • •Cannot handle complex recurrence rules (e.g., "30 days before each annual renewal")

Deadline Engine Architecture

The deadline engine is a scheduled job that runs every hour and evaluates all active obligations:

python
def evaluate_deadlines():
    obligations = db.query("""
        SELECT * FROM obligations
        WHERE status = 'pending'
        AND due_date > NOW()
        AND due_date <= NOW() + INTERVAL '90 days'
    """)
    
    for obligation in obligations:
        days_until_due = (obligation.due_date - today).days
        
        # Check if notification should be sent
        for threshold in obligation.notification_thresholds:  # e.g., [90, 60, 30, 14, 7, 1]
            if days_until_due == threshold:
                if not already_notified(obligation.id, threshold):
                    send_notification(obligation, days_until_due)
                    record_notification(obligation.id, threshold)

Escalation Logic

If a notification is sent but the obligation is not marked complete within 3 days, the system escalates to the next level:

Day -90: Notify assigned owner
Day -60: Notify assigned owner (reminder)
Day -30: Notify assigned owner + manager
Day -14: Notify assigned owner + manager + legal head
Day -7:  Notify all above + CEO (for high-value contracts)
Day 0:   Mark as OVERDUE, create urgent task
Day +1:  Daily escalation until resolved

4. Regulatory Compliance Calendar

Indian Regulatory Landscape

Indian businesses must track compliance across multiple regulators:

RegulatorKey FilingsFrequency
MCA (Companies Act)Annual Return, Financial StatementsAnnual
Income TaxITR, TDS Returns, Advance TaxQuarterly/Annual
GSTGSTR-1, GSTR-3B, Annual ReturnMonthly/Annual
EPFOECR, Annual ReturnMonthly/Annual
ESICMonthly ReturnMonthly
SEBI (if listed)Quarterly Results, DisclosuresQuarterly
State Labour DeptVarious state-specific filingsVaries

Calendar Architecture

The regulatory calendar is a master table of all compliance obligations with their recurrence rules, maintained by IdeaSprout and updated when regulations change:

sql
CREATE TABLE regulatory_obligations (
  id              UUID PRIMARY KEY,
  regulator       TEXT,
  obligation_name TEXT,
  description     TEXT,
  recurrence_rule TEXT,  -- iCal RRULE format
  lead_time_days  INTEGER,  -- how many days before due to start reminder
  applicable_to   TEXT[],  -- ['private_limited', 'llp', 'proprietorship']
  penalty_desc    TEXT
);

Each company's compliance calendar is generated by filtering the master table by their entity type and state, then instantiating the recurrence rules for the current year.


Requirements

Legal contracts and compliance records may be subject to:

  • •Legal discovery: Courts can order production of all communications and records related to a dispute
  • •Regulatory audit: Regulators can inspect compliance records going back 7–10 years
  • •Internal audit: Board and audit committee reviews

Implementation

Every action on a contract or compliance record is logged to an immutable audit log:

sql
CREATE TABLE legal_audit_log (
  id           UUID PRIMARY KEY,
  entity_type  TEXT,  -- 'contract', 'obligation', 'compliance_filing'
  entity_id    UUID,
  action       TEXT,  -- 'viewed', 'downloaded', 'status_changed', 'notified'
  actor_id     UUID,
  actor_name   TEXT,  -- snapshot in case user is deleted
  actor_ip     INET,
  occurred_at  TIMESTAMPTZ DEFAULT NOW(),
  details      JSONB
);

The audit log is append-only - no UPDATE or DELETE is permitted. Retention: 10 years minimum.

Document Integrity Verification

At any time, the system can verify that a stored contract document has not been tampered with:

python
def verify_document_integrity(contract_version_id):
    version = db.get(contract_version_id)
    s3_content = s3.get_object(version.s3_key)
    computed_hash = sha256(s3_content)
    return computed_hash == version.sha256_hash

6. Common Architectural Pitfalls

PitfallConsequenceFix
Mutable contract storageCannot prove document hasn't been alteredContent-addressed immutable storage with hash
Calendar reminders tied to individualsReminders lost when employee leavesSystem-owned deadline engine with escalation
Manual obligation extractionMissed deadlines, human errorAutomated extraction with human review
No regulatory calendarCompliance filings missedMaster regulatory calendar with entity-type filtering
Audit log with UPDATE/DELETECannot satisfy legal discoveryAppend-only audit log with 10-year retention

Summary

A production legal compliance platform requires content-addressed immutable document storage, automated obligation extraction with human review, a system-owned deadline engine with multi-level escalation, a master regulatory calendar, and an append-only audit log that satisfies legal discovery and regulatory audit requirements.

legal architectureCLMcontract lifecycleobligation trackingcompliance audit