How hah23255/drawings-ai works
Purpose and Entry Point
Drawings AI is a Python data-engineering pipeline that converts 2D CAD/PDF construction drawing sets into a queryable SQLite index and trade-oriented Markdown wiki. The primary public API is DrawingsAIPipeline, initialized with a workspace and optional OCR, then invoked through index_drawings(..., append=True). Package exports begin at src/drawings_ai/__init__.py; orchestration is in src/drawings_ai/pipeline.py.
Pipeline Orchestration
DrawingsAIPipeline coordinates parsing, persistence, and wiki generation for each drawing file. It supports append-mode aggregation so many sheets contribute to one workspace-level index rather than replacing prior results. The pipeline returns structured indexing results, including registered drawing sheets. Core paths: src/drawings_ai/pipeline.py, src/drawings_ai/schemas.py.
Drawing Extraction and OCR Boundary
The parser is the document-ingestion boundary for CAD/PDF content. It extracts drawing text/tags and detects raster/scanned PDF pages; OCR transcription is delegated to Tesseract when enabled. Parsing rules are extensible at runtime through registered regex patterns and defaults such as material and confidence. Core paths: src/drawings_ai/parser.py, src/drawings_ai/schemas.py.
Structured Domain Model
Schemas define the normalized objects exchanged between parser, database, wiki, and LLM-facing layers: drawing sheets, extracted entities/tags, confidence/reliability, and indexing results. This model is the contract that prevents document-format-specific extraction concerns from leaking into persistence or querying. Core path: src/drawings_ai/schemas.py.
SQLite Index Layer
The database component materializes extracted drawing data into the workspace SQLite database (drawings.db). It is the authoritative structured store for quantity takeoffs, cross-sheet aggregation, and deterministic metric/spec queries. Append behavior is implemented at this persistence boundary to preserve prior indexed sheets. Core path: src/drawings_ai/database.py.
Markdown Wiki Layer
The wiki component produces and updates localized technical Markdown documentation (drawings.md) for specifications, general notes, and trade-readable drawing context. It complements SQLite: narrative/specification information is retained in Markdown while quantitative and relational data stays in the database. Core path: src/drawings_ai/wiki.py.
LLM Tool Integration and Safety
The LLM integration layer exposes validated tool schemas suitable for OpenAI and Anthropic-style tool calling. It mediates LLM access to the SQLite index and applies SQL-injection guardrails, separating natural-language agent requests from direct database execution. Core paths: src/drawings_ai/llm_tool.py, src/drawings_ai/database.py.
Runtime and External Dependencies
The system runs as a Python library, configured through pyproject.toml, with SQLite as embedded persistence and Tesseract as the optional external OCR runtime. Prompt templates and sample construction artifacts support downstream tender/specification workflows but are separate from the core indexing pipeline: support_materials/prompts/, support_materials/samples/.
Main entry points: pipeline.py DrawingsAIPipeline · parser.py Drawing parser · llm_tool.py LLM tool layer · database.py SQLite index layer
Components 14
Core indexing pipeline
- Package exports · Public API begins here.
src/drawings_ai/__init__.py - DrawingsAIPipeline · Coordinates append-mode indexing for each drawing file.
src/drawings_ai/pipeline.py - Drawing parser · Extracts CAD/PDF text and tags; detects scanned pages.
src/drawings_ai/parser.py - Tesseract OCR · Transcribes raster or scanned PDF pages when enabled.
- Domain schemas · Sheets, entities, tags, confidence, and indexing results.
src/drawings_ai/schemas.py
Workspace outputs
- SQLite index layer · Materializes structured drawing data and preserves prior sheets on append.
src/drawings_ai/database.py - drawings.db · Authoritative store for takeoffs, aggregation, and deterministic queries.
- Markdown wiki generator · Updates trade-readable specifications, notes, and drawing context.
src/drawings_ai/wiki.py - drawings.md
LLM access
- LLM tool layer · Exposes OpenAI/Anthropic-style tools and guards database access.
src/drawings_ai/llm_tool.py - LLM agent · Submits natural-language requests through validated tools.
Other components
- Prompt templates · Supports downstream tender and specification workflows.
support_materials/prompts/draft_of_thought_template.md - Construction samples · Sample artifacts for downstream workflows.
support_materials/samples/architectural_schedules_sample.json - Project runtime config · Defines library packaging and dependencies.
pyproject.toml
Connections 15
- Package exports → DrawingsAIPipeline: exports
- DrawingsAIPipeline → Drawing parser: indexes drawing
- DrawingsAIPipeline → Domain schemas: returns results
- Drawing parser → Domain schemas: normalizes extraction
- Drawing parser → Tesseract OCR: scanned pages
- DrawingsAIPipeline → SQLite index layer: persists append-mode index
- DrawingsAIPipeline → Markdown wiki generator: generates documentation
- SQLite index layer → drawings.db: writes
- Markdown wiki generator → drawings.md: updates
- LLM agent → LLM tool layer: tool calls
- LLM tool layer → SQLite index layer: guarded queries · Validates requests and blocks SQL injection.
- LLM tool layer → Domain schemas: tool contracts
- Project runtime config → Package exports: configures
- Prompt templates → LLM agent: supports workflows
- Construction samples → DrawingsAIPipeline: example inputs