iToverDose/Software· 29 JUNE 2026 · 12:02

Discover PostgreSQL schemas instantly with AI-powered SchemaLens

Meet SchemaLens, a new AI-driven tool that automatically maps PostgreSQL databases into interactive diagrams and answers queries in plain English. No manual setup, no documentation gaps.

DEV Community4 min read0 Comments

The first day on a new project should spark curiosity, not dread. Yet too many developers face the nightmare of inheriting a sprawling PostgreSQL database with 30 tables, no documentation, and cryptic column names like status_v2_legacy. Existing tools either lock you into rigid interfaces or demand tedious manual input that breaks after every migration.

That’s why I built SchemaLens for the H0 Hackathon — a web-based assistant that automatically discovers, visualizes, documents, and queries PostgreSQL schemas using natural language. In just minutes, it transforms raw database metadata into an interactive entity-relationship diagram, assigns health scores, and lets you chat with your schema via AI.

Instant Schema Discovery Without Manual Work

SchemaLens eliminates the tedious setup that plagues traditional database tools. Instead of drawing schemas by hand in dbdiagram.io or wrestling with CLI tools like SchemaSpy, users simply paste a PostgreSQL connection string. The platform then queries information_schema to extract every table, column, data type, constraint, foreign key, and row estimate — no manual input, no domain-specific language, and no installation required.

Once connected, an interactive ERD renders automatically. Tables appear as nodes with clear relationships shown as edges. Click any table to see its columns with types, nullability, defaults, and constraints. The diagram stays in sync with live schema changes, eliminating stale documentation.

AI-Powered Schema Health Scoring

Not all schemas are built equal. SchemaLens evaluates your database using 10 automated checks that produce a weighted health score and letter grade (A–F). These checks include:

  • Presence of primary keys
  • Foreign key validity and referential integrity
  • Naming conventions and consistency
  • Appropriate column types and sizes
  • Enforced NOT NULL constraints
  • Standard timestamp patterns
  • Detection of oversized or redundant columns
  • Unique constraint coverage
  • Boolean field naming clarity
  • Table size awareness

Each finding comes with a severity level and actionable recommendations, turning vague concerns into clear next steps.

Natural Language Queries with Real-Time Safety

The highlight of SchemaLens is its AI agent, which lets you ask questions about your database in plain English. Want to see all users who registered last month? Ask: "Show me all users who signed up last month." The agent interprets your request, generates valid SQL, validates it for safety, executes it against your live PostgreSQL database, and displays results in a formatted table.

Behind the scenes, the tool-calling pipeline follows a strict workflow:

generate_sql → check_sql → execute_sql → retry_loop

If the initial query fails, the agent reads the error, corrects the SQL, and retries automatically. The entire reasoning process streams in real time, so you see exactly how the AI arrived at each answer — and why.

Zero-Trust Security Model for AI Access

Giving an AI direct access to a production database demands robust safeguards. SchemaLens implements a two-layer defense system:

  • Application layer: Blocks destructive keywords (INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE) and sanitizes input using regex patterns to prevent SQL injection
  • Database layer: PostgreSQL runs in READ ONLY mode, rejecting any write operation regardless of application intent

Even if an AI error produces an INSERT query, PostgreSQL rejects it. The agent can read data but cannot modify it — defense in depth that goes beyond polite prompts.

Built for Production, Not Just Hackathons

SchemaLens runs on a modern stack designed for scalability and reliability:

  • Frontend: Next.js 16, React, TypeScript with Tailwind v4 and shadcn/ui components
  • Auth: better-auth for secure email/password login
  • ORM: Drizzle ORM for type-safe database interactions
  • Backend DB: Amazon Aurora PostgreSQL 16, handling schema snapshots, user data, and conversation history
  • LLM: DeepSeek V4 Flash via a compatible API
  • AI SDK: Vercel AI SDK with streamText and tool calling
  • Deployment: Vercel for serverless scaling and fast CI/CD

Aurora PostgreSQL serves as the backbone, auto-discovering schemas from system catalogs and storing snapshots as JSONB. The serverless setup scales automatically without always-on infrastructure, making it suitable for real-world use beyond hackathons.

Overcoming Real-World Challenges

Building SchemaLens wasn’t just about connecting a database. Several technical hurdles required creative solutions:

  • SSL Certificate Validation: Aurora enforces SSL, but default drivers rejected self-signed certs. Silent connection failures were resolved by properly configuring certificate chain acceptance.
  • Auth Integration Bugs: A table key mismatch in the better-auth Drizzle adapter caused silent authentication failures. Debugging required inspecting handler output to trace empty responses back to schema mismatches.
  • AI Self-Correction Loop: Making the retry mechanism reliable with real-time streaming took extensive testing. Invalid SQL generation, database error parsing, and query correction had to work seamlessly across diverse schemas.
  • Health Check Tuning: Initial rules flagged too many false positives. Balancing sensitivity and specificity required iterative refinement to avoid overwhelming users with noise.

Each challenge reinforced a key lesson: PostgreSQL’s system catalog contains everything you need to know about a schema — you just have to query it correctly.

What’s Next for SchemaLens

The project is just getting started. Upcoming features include:

  • Schema diffing to highlight changes between introspections
  • Export options for SQL migrations, dbdiagram.io DSL, and markdown documentation
  • Team collaboration tools with role-based access control and Slack integration
  • Support for additional databases like MySQL, SQLite, and MongoDB
  • Continuous monitoring with drift alerts and scheduled re-introspection

SchemaLens isn’t just a hackathon experiment — it’s a glimpse at the future of database interaction, where AI handles the heavy lifting and humans focus on solving real problems.

Try it today by signing up at the platform and pasting your PostgreSQL connection string. Whether it’s an Aurora instance, Railway deployment, or Supabase project, SchemaLens adapts instantly. Start chatting with your schema, generate shareable links for your team, and reclaim time lost to undocumented databases.

The tool is open source. Contributions, feedback, and feature ideas are welcome on the GitHub repository.

AI summary

Discover how SchemaLens uses AI to automatically map PostgreSQL databases into interactive ERDs, score schema health, and answer queries in plain English — all without manual setup.

Comments

00
LEAVE A COMMENT
ID #8FLJ33

0 / 1200 CHARACTERS

Human check

5 + 8 = ?

Will appear after editor review

Moderation · Spam protection active

No approved comments yet. Be first.