Skip to content

ajjucoder/ebps

Repository files navigation

EBPS - Electronic Building Permit System

AI-Powered Building Bylaws Verification for Kathmandu Metropolitan City

Python AI License

Automating civil engineering compliance verification for Nepal's capital city


Overview

EBPS is an intelligent document processing system that automates building permit verification for Kathmandu Metropolitan City (KMC), Nepal. It replaces hours of manual calculation with instant, accurate compliance checking against the Kathmandu Building Standards 2080 and historical bylaws (2050, 2060, 2072).

The Problem

Civil engineers at KMC manually verify hundreds of building permit applications against complex zoning regulations. Each verification requires:

  • Reading multiple PDF documents in Nepali and English
  • Cross-referencing 5 different sub-zone categories
  • Calculating Floor Area Ratio (FAR), ground coverage, parking requirements
  • Applying Right of Way (ROW) deductions based on road widening plans
  • Checking setback distances and height restrictions
  • Applying grandfather clauses for pre-existing buildings

This process takes 30-60 minutes per application and is prone to human error.

The Solution

EBPS reduces verification time to under 30 seconds with:

  • Intelligent PDF extraction using PyMuPDF with Google Gemini AI fallback for complex Nepali text
  • Smart file detection that analyzes PDF content to select architectural drawings over structural ones
  • Multi-year bylaws support for historical compliance (grandfather clause implementation)
  • Automated calculations with full formula transparency for auditing
  • Professional reports with floor-by-floor breakdowns

Key Features

Feature Description
One-Command Verification Single command extracts data, verifies compliance, generates report
Bilingual PDF Processing Handles Nepali (देवनागरी) and English documents with AI-powered OCR
Smart File Detection Content-based scoring algorithm selects correct DPC file from multiple candidates
Multi-Year Bylaws Supports 2050, 2060, 2072, and 2080 building standards with automatic year detection
Complete Compliance Suite FAR, Ground Coverage, Parking, Setbacks, Height verification
ROW Calculation Automatic Right of Way deductions based on KMC road widening plans
Data Validation Flags suspicious extraction results (zero values, impossible ratios)
Detailed Reporting Generates audit-ready markdown reports with calculation transparency

Technical Architecture

┌─────────────────────────────────────────────────────────────────────┐
│                        EBPS Architecture                            │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│  ┌──────────────┐    ┌──────────────┐    ┌──────────────────────┐  │
│  │   PDF Input  │───►│  Extractor   │───►│  Structured Data     │  │
│  │  (Nepali/EN) │    │  (PyMuPDF +  │    │  (Pydantic Models)   │  │
│  │              │    │   Gemini AI) │    │                      │  │
│  └──────────────┘    └──────────────┘    └──────────┬───────────┘  │
│                                                      │              │
│  ┌──────────────┐    ┌──────────────┐    ┌──────────▼───────────┐  │
│  │   Report     │◄───│  Verifier    │◄───│  Standards Lookup    │  │
│  │  Generator   │    │   Engine     │    │  (5 Sub-zones ×      │  │
│  │  (Markdown)  │    │              │    │   4 Bylaw Years)     │  │
│  └──────────────┘    └──────────────┘    └──────────────────────┘  │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Core Components

Component Technology Purpose
PDF Extraction PyMuPDF, Google Gemini Pro Text extraction with AI fallback for scanned documents
Data Models Pydantic v2 Type-safe building data validation
Smart Detection Custom scoring algorithm Selects architectural vs structural drawings
Calculations Pure Python FAR, coverage, ROW, parking formulas
Standards Engine JSON configuration 20 zone/year combinations
Report Generation Markdown templating Professional audit-ready output

Quick Start

Installation

# Clone repository
git clone https://github.com/ajjucoder/ebps.git
cd ebps

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure API key (for AI extraction)
echo "GEMINI_API_KEY=your_key_here" > .env

Basic Usage

# Verify a building permit
./venv/bin/python verify_compliance.py "clients/client_name"

# With vision OCR for scanned documents
./venv/bin/python verify_compliance.py "clients/client_name" --vision

# For older buildings (apply historical bylaws)
./venv/bin/python verify_compliance.py "clients/client_name" --construction-year 2065

Example Output

============================================================
COMPLIANCE VERIFICATION REPORT
============================================================
Client: Niroj Dangol
Ward: 15, Kitta: 164
Sub-Zone: Other Residential Sub-Zone
Land Area: 200.81 sqm (6.31 Aana)

APPLICABLE STANDARDS (Kathmandu Building Standards 2080):
  Maximum FAR: 3.5
  Maximum Coverage: 70% (plot < 8 Aana)
  Maximum Height: 5 stories / 17m
  Required Setback: 1.524m

VERIFICATION RESULTS:
  ✅ FAR: 0.62 / 3.5 max (PASS)
  ✅ Ground Coverage: 59.87% / 70.0% max (PASS)
  ✅ Parking: 588 sft / 432 sft required (PASS)
  ✅ Height: 4.5 / 5 stories max (PASS)
  ✅ Setback (West): 10.414m / 1.524m min (PASS)

OVERALL: ✅ COMPLIANT
============================================================

Compliance Checks Explained

Floor Area Ratio (FAR)

FAR = Total FAR Countable Area / Land Area

Example:
  Total FAR Countable: 1,338.52 sft
  Land Area: 2,161.70 sft
  FAR = 1,338.52 / 2,161.70 = 0.62

  Allowed FAR: 3.5 (Other Residential)
  Result: 0.62 ≤ 3.5 → PASS

Ground Coverage

Coverage % = (Ground Floor Area / Land Area) × 100

Example:
  Ground Floor: 1,294.46 sft
  Land Area: 2,161.70 sft
  Coverage = (1,294.46 / 2,161.70) × 100 = 59.87%

  Allowed: 70% (plot < 8 Aana)
  Result: 59.87% ≤ 70% → PASS

Right of Way (ROW) Deduction

Government road widening affects parking calculations:

Current Road Width Future Road Width Deduction per Side
< 8 ft 13 ft 6.5 ft
8-12 ft 20 ft 10 ft
12-20 ft 26 ft 13 ft
≥ 20 ft No change 0 ft
Net Parking = Gross Parking Area - (ROW Deduction × Frontage)
Required Parking = Land Area × 20% (for plots ≥ 4 Aana)

Sub-Zone Standards (2080)

Sub-Zone FAR Limit Coverage (< 8 Aana) Coverage (≥ 8 Aana) Max Height Setback
Other Residential 3.5 70% 60% 5 stories / 17m 1.524m
Planned Residential 3.5 70% 60% 7 stories / 22.86m 2.0m
Dense Mixed 4.0 70% 60% 6 stories / 20m 1.524m
Main Residential 3.0 60% 50% 4 stories / 14m 1.524m
Commercial 4.5 70% 50% 7 stories / 22.86m 2.0m

Smart File Detection Algorithm

When a client folder contains multiple DPC files, EBPS uses content analysis to select the correct architectural drawing:

Positive Indicators (Architectural):

  • Floor plan keywords (+15 points)
  • Area tables with sq.ft/sqm (+15 points)
  • "FAR countable" mentions (+20 points)
  • Ground floor, first floor labels (+12 points)

Negative Indicators (Structural):

  • Trench plan (-25 points)
  • Tie beam details (-20 points)
  • Foundation drawings (-15 points)
  • Structural detail (-30 points)

This solves the critical bug where structural drawings (with zero floor areas) were incorrectly selected over architectural drawings.


Historical Bylaws Support

EBPS implements the grandfather clause for buildings constructed under previous regulations:

Construction Year (BS) Applicable Bylaws Folder
2080 onwards Standards 2080 BYLAWS_2080/
2072-2079 Bylaws 2072 BYLAWS_2072/
2060-2071 Bylaws 2060 BYLAWS_2060/
Before 2060 Bylaws 2050 BYLAWS_2050/
# Apply 2065 construction year (uses 2060 bylaws)
./venv/bin/python verify_compliance.py "clients/old_building" --construction-year 2065

Project Structure

ebps/
├── verify_compliance.py          # Main CLI entry point
├── smart_extract.py              # PDF extraction utility
├── src/
│   ├── verifier.py               # Compliance verification engine
│   ├── calculations.py           # FAR, coverage, parking formulas
│   ├── standards.py              # Sub-zone standards (20 combinations)
│   ├── report_generator.py       # Markdown report generation
│   ├── models.py                 # Pydantic data models
│   ├── extractor.py              # Smart PDF extraction + file detection
│   ├── pdf_reader.py             # PyMuPDF text extraction
│   └── gemini_parser.py          # Gemini AI parsing fallback
├── Building Bylaws/              # Regulatory documents (4 versions)
│   ├── BYLAWS_2080/              # Current standards
│   ├── BYLAWS_2072/              # 2072-2079 buildings
│   ├── BYLAWS_2060/              # 2060-2071 buildings
│   └── BYLAWS_2050/              # Pre-2060 buildings
├── clients/                      # Client data (gitignored)
├── docs/                         # Technical documentation
├── CLAUDE.md                     # AI assistant instructions
└── CHANGELOG.md                  # Version history

CLI Reference

# Basic verification
./venv/bin/python verify_compliance.py "clients/CLIENT" [OPTIONS]

Options:
  --bylaws-year YEAR      Specify bylaws version (2050, 2060, 2072, 2080)
  --construction-year YEAR Auto-select bylaws from construction year (BS)
  --force-extract         Re-extract PDFs even if cached data exists
  --vision                Use vision OCR for scanned/blurry documents
  --json                  Output results as JSON
  --dpc-file PATH         Override DPC file auto-detection
  --compliance-file PATH  Override compliance file auto-detection
  --verbose               Show detailed extraction logs

Real-World Impact

This system was developed for practical use at Kathmandu Metropolitan City, Nepal's largest municipality:

  • Time Savings: Reduces verification from 30-60 minutes to under 30 seconds
  • Accuracy: Eliminates calculation errors in FAR and coverage percentages
  • Consistency: Applies regulations uniformly across all applications
  • Transparency: Full calculation breakdown for audit trails
  • Historical Compliance: Properly handles grandfather clause for older buildings

Technologies Used

Category Technologies
Language Python 3.11+
AI/ML Google Gemini Pro (multimodal LLM)
PDF Processing PyMuPDF (fitz), pdf2image
Data Validation Pydantic v2
Configuration python-dotenv
Testing Manual verification with real KMC documents

Skills Demonstrated

  • Software Engineering: Clean architecture, modular design, CLI development
  • AI Integration: LLM-powered document extraction with fallback strategies
  • Domain Expertise: Civil engineering regulations, urban planning concepts
  • Data Processing: PDF parsing, bilingual text extraction (Nepali/English)
  • Algorithm Design: Content-based file scoring, multi-criteria validation
  • Government Tech: Real-world municipal compliance automation

Privacy & Security

  • Client documents remain local in clients/ (gitignored)
  • API keys stored in .env (gitignored)
  • No client data is transmitted except for AI extraction via Gemini API
  • All processing can be done offline with --vision flag (local OCR)

Future Roadmap

  • Web interface for non-technical users
  • Batch processing for multiple clients
  • Integration with KMC document management system
  • Mobile app for field verification
  • Support for additional municipalities

Contributing

Contributions are welcome. Please read the contribution guidelines before submitting pull requests.


License

MIT License - See LICENSE for details.


Acknowledgments

  • Kathmandu Metropolitan City for the building bylaws documentation
  • Google AI for the Gemini Pro API

EBPS v5.1.0 | Built for real-world government use in Nepal

Transforming how Kathmandu Metropolitan City verifies building permits

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages