← Back to Portfolio

pypgsvg

Automated PostgreSQL Entity Relationship Diagram Generator

View on GitHub →
PortfolioSite →

Project Overview

Interactive SVG diagram showing hover effects and relationship highlighting

pypgsvg is a powerful Python tool that automatically generates interactive SVG Entity Relationship Diagrams from PostgreSQL database schemas. Processes PostgreSQL dump files, to create real-time visual documentation that keeps pace with rapid development cycles.

Technologies Used

Python 3.8+ PostgreSQL Graphviz SVG JavaScript CSS3 pytest Playwright Command Line Interface Interactive UI Open Source

Installation

Available on PyPI for simple installation with pip:

Terminal demonstration of pypgsvg installation process

Interactive SVG Generation & Visualization

Creates stanalone dynamic, explorable diagrams that can be embedded in documentation and presentations.

  • Dynamic layout algorithms for optimal table positioning
  • Interactive hover states showing detailed column information
  • Clickable relationships for relationship exploration
  • Responsive design that scales for different screen sizes
  • Export capabilities for documentation and presentations

SVG rendering engine with post-processing coordinate calculation, CSS styling integration, and JavaScript event handling for interactivity.

Interactive hover effects and relationship highlighting

Interactive SVG diagram showing hover effects and relationship highlighting

This is the pypgsvg output of a more interesting database schema of a recent project with the informational popups hidden. Grab the image to move and mousewheel to zoom, for the full experience see the full screen version.

Technical Implementation

pypgsvg demonstrates advanced database introspection and dynamic SVG generation capabilities, solving real-world documentation challenges for database-driven applications.

Usage & Automation

Designed as a command-line tool, pypgsvg is also callable from applications real-time ERD generation. This portfolio site demonstrates live PostgreSQL schema visualization using the tool.

The application supports key Graphviz layout options including rankdir, nodesep, and packmode for customizable diagram layouts. Being fully scriptable, it integrates seamlessly into CI/CD pipelines to keep documentation synchronized with database changes.

Command-line interface with some of the configuration options.

pypgsvg command line help and configuration options

Automated Schema Discovery & Analysis

Database schemas evolve rapidly during development, and not everyone speaks SQL fluently. Manual ERD maintenance becomes an error-prone bottleneck, especially in containerized environments. pypgsvg automates this process by providing real-time visual representations of PostgreSQL databases.

The tool connects directly to PostgreSQL databases and performs comprehensive schema introspection with:

  • Automated table discovery with column metadata extraction
  • Foreign key relationship mapping and constraint analysis
  • Data type recognition and nullable field identification
  • Index detection and primary key identification
  • Multi-schema support for complex database architectures

Implementation Details: Uses PostgreSQL's information_schema and pg_catalog system tables for comprehensive metadata extraction. Handles various PostgreSQL versions.

Testing and Code Coverage

The unit test suite has over 94% coverage.

pypgsvg successful completion with generated output

Browser tests are needed to validate the JS.

pypgsvg successful completion with generated output

Technical Highlights

Core Technologies

Python 3.8+, PostgreSQL, Graphviz, SVG, JavaScript, CSS3

Testing & Quality

pytest with 90+ % coverage, Playwright browser testing, CI/CD integration

Database Features

Real-time schema introspection, foreign key analysis, multi-schema support

Visualization

Interactive SVG output, responsive design, export capabilities

Complete Technology Stack

Comprehensive list of all technologies and libraries used

Backend Technologies
  • Python 3.8+ - Primary programming language with modern feature support
  • Graphviz (>=0.20.1) - Graph visualization library for automatic layout generation
  • argparse - Command-line interface parsing and validation
  • xml.etree.ElementTree - XML parsing and SVG manipulation
  • re (Regular Expressions) - SQL pattern matching and data extraction
  • tempfile - Secure temporary file handling for processing
  • base64 - Binary data encoding for embedded resources
  • datetime - Timestamp generation and metadata tracking
  • os/sys - System integration and file path management
  • logging - Comprehensive error reporting and debugging
  • webbrowser - Cross-platform browser integration
Frontend Technologies
  • SVG (Scalable Vector Graphics) - Vector-based diagram rendering
  • JavaScript ES6+ - Interactive behavior and DOM manipulation
  • CSS3 - Advanced styling with gradients, shadows, and animations
  • HTML5 - Semantic markup and modern web standards
  • Event Listeners - Mouse, keyboard, and touch interaction handling
  • Canvas API - High-performance graphics rendering
  • Drag & Drop API - Interactive element manipulation
  • Viewport Management - Responsive design and zoom controls
  • Local Storage - Client-side state persistence
Testing & Quality Assurance
  • pytest (>=7.0.0) - Python unit testing framework
  • pytest-cov (>=4.0.0) - Code coverage analysis and reporting
  • pytest-mock - Advanced mocking and test fixtures
  • Playwright (>=1.37.0) - Cross-browser automation testing
  • Chrome/Firefox/Safari - Multi-browser compatibility testing
  • Headless Testing - CI/CD pipeline integration
  • Visual Regression Testing - UI consistency validation
  • Coverage Reports - HTML/XML test coverage reporting
Development & Deployment
  • setuptools - Python package creation and distribution
  • pip - Python package installation and dependency management
  • PyPI - Public package repository and distribution
  • Virtual Environments - Isolated development environments
  • Git - Version control and collaborative development
  • GitHub - Code hosting and issue tracking
  • Bash Scripting - Automated testing and deployment scripts
  • Entry Points - Command-line executable generation
  • Cross-Platform Support - Windows, macOS, and Linux compatibility
Database & Data Processing
  • PostgreSQL - Primary database system support
  • SQL Parsing - Complex schema introspection and analysis
  • information_schema - Metadata extraction from system catalogs
  • pg_catalog - PostgreSQL system table analysis
  • Foreign Key Analysis - Relationship mapping and constraint detection
  • Data Type Recognition - PostgreSQL type system integration
  • Trigger Detection - Database automation discovery
  • Index Analysis - Performance optimization identification
Algorithms & Computer Science
  • Graph Theory - Entity relationship modeling and visualization
  • Layout Algorithms - Automatic node positioning and edge routing
  • Color Theory - Accessible color palette generation
  • Hash Functions - Consistent color assignment algorithms
  • String Algorithms - Text processing and sanitization
  • Tree Traversal - Hierarchical data structure navigation
  • Pattern Matching - Regular expression optimization
  • Memory Optimization - Efficient data structure design

Core Architecture

  • Database Introspection: PostgreSQL metadata extraction
  • Schema Analysis: Relationship mapping and constraint detection
  • Layout Engine: Automated positioning algorithms
  • SVG Generation: Interactive diagram creation
  • Export System: Multiple format support

Key Features

  • Real-time Generation: Live database schema reading
  • Interactive Elements: Hover states and click events
  • Responsive Design: Scalable for all screen sizes
  • CI/CD Ready: Command-line automation support
  • Multi-Schema: Complex database support