# hah23255/drawings-ai architecture

> Architecture diagram of the GitHub repository hah23255/drawings-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hah23255/drawings-ai
- Repository: https://github.com/hah23255/drawings-ai

## Overview

#### 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: [`src/drawings_ai/pipeline.py`](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/pipeline.py) (DrawingsAIPipeline), [`src/drawings_ai/parser.py`](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/parser.py) (Drawing parser), [`src/drawings_ai/llm_tool.py`](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/llm_tool.py) (LLM tool layer), [`src/drawings_ai/database.py`](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/database.py) (SQLite index layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core indexing pipeline"]
  node_package["Package exports<br/>Python package<br/>[__init__.py]"]
  node_pipeline["DrawingsAIPipeline<br/>orchestrator<br/>[pipeline.py]"]
  node_parser["Drawing parser<br/>ingestion boundary<br/>[parser.py]"]
  node_ocr{{"Tesseract OCR<br/>optional external runtime"}}
  node_schemas["Domain schemas<br/>normalized contract<br/>[schemas.py]"]
end

subgraph group_outputs["Workspace outputs"]
  node_database["SQLite index layer<br/>persistence<br/>[database.py]"]
  node_sqlite[("drawings.db<br/>SQLite database")]
  node_wiki["Markdown wiki generator<br/>documentation output<br/>[wiki.py]"]
  node_markdown["drawings.md<br/>Markdown wiki"]
end

subgraph group_agent["LLM access"]
  node_llm_tool["LLM tool layer<br/>validated tool interface<br/>[llm_tool.py]"]
  node_llm_agent(("LLM agent<br/>tool caller"))
end

node_prompts["Prompt templates<br/>support materials"]
node_samples["Construction samples<br/>support materials"]
node_pyproject["Project runtime config<br/>Python project config<br/>[pyproject.toml]"]

node_package -->|"exports"| node_pipeline
node_pipeline -->|"indexes drawing"| node_parser
node_pipeline -->|"returns results"| node_schemas
node_parser -->|"normalizes extraction"| node_schemas
node_parser -.->|"scanned pages"| node_ocr
node_pipeline -->|"persists append-mode index"| node_database
node_pipeline -->|"generates documentation"| node_wiki
node_database -->|"writes"| node_sqlite
node_wiki -->|"updates"| node_markdown
node_llm_agent -->|"tool calls"| node_llm_tool
node_llm_tool -->|"guarded queries"| node_database
node_llm_tool -->|"tool contracts"| node_schemas
node_pyproject -.->|"configures"| node_package
node_prompts -.->|"supports workflows"| node_llm_agent
node_samples -.->|"example inputs"| node_pipeline

click node_package "https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/__init__.py"
click node_pipeline "https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/pipeline.py"
click node_parser "https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/parser.py"
click node_schemas "https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/schemas.py"
click node_database "https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/database.py"
click node_wiki "https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/wiki.py"
click node_llm_tool "https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/llm_tool.py"
click node_prompts "https://github.com/hah23255/drawings-ai/blob/main/support_materials/prompts/draft_of_thought_template.md"
click node_samples "https://github.com/hah23255/drawings-ai/blob/main/support_materials/samples/architectural_schedules_sample.json"
click node_pyproject "https://github.com/hah23255/drawings-ai/blob/main/pyproject.toml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_package,node_pipeline,node_parser,node_ocr,node_schemas toneBlue
class node_database,node_sqlite,node_wiki,node_markdown toneAmber
class node_llm_tool,node_llm_agent toneMint
class node_prompts,node_samples,node_pyproject toneNeutral
```

## Components

### Core indexing pipeline

- [Package exports](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/__init__.py): Python package · Public API begins here. · `src/drawings_ai/__init__.py`
- [DrawingsAIPipeline](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/pipeline.py): orchestrator · Coordinates append-mode indexing for each drawing file. · `src/drawings_ai/pipeline.py`
- [Drawing parser](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/parser.py): ingestion boundary · Extracts CAD/PDF text and tags; detects scanned pages. · `src/drawings_ai/parser.py`
- **Tesseract OCR**: optional external runtime · Transcribes raster or scanned PDF pages when enabled.
- [Domain schemas](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/schemas.py): normalized contract · Sheets, entities, tags, confidence, and indexing results. · `src/drawings_ai/schemas.py`

### Workspace outputs

- [SQLite index layer](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/database.py): persistence · Materializes structured drawing data and preserves prior sheets on append. · `src/drawings_ai/database.py`
- **drawings.db**: SQLite database · Authoritative store for takeoffs, aggregation, and deterministic queries.
- [Markdown wiki generator](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/wiki.py): documentation output · Updates trade-readable specifications, notes, and drawing context. · `src/drawings_ai/wiki.py`
- **drawings.md**: Markdown wiki

### LLM access

- [LLM tool layer](https://github.com/hah23255/drawings-ai/blob/main/src/drawings_ai/llm_tool.py): validated tool interface · Exposes OpenAI/Anthropic-style tools and guards database access. · `src/drawings_ai/llm_tool.py`
- **LLM agent**: tool caller · Submits natural-language requests through validated tools.

### Other components

- [Prompt templates](https://github.com/hah23255/drawings-ai/blob/main/support_materials/prompts/draft_of_thought_template.md): support materials · Supports downstream tender and specification workflows. · `support_materials/prompts/draft_of_thought_template.md`
- [Construction samples](https://github.com/hah23255/drawings-ai/blob/main/support_materials/samples/architectural_schedules_sample.json): support materials · Sample artifacts for downstream workflows. · `support_materials/samples/architectural_schedules_sample.json`
- [Project runtime config](https://github.com/hah23255/drawings-ai/blob/main/pyproject.toml): Python project config · Defines library packaging and dependencies. · `pyproject.toml`

## Connections

- 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
