Skip to content

kbruck97/ai-construction-suite

Repository files navigation

AI Construction Bid Assistant Suite

AI-powered platform that ingests construction bid documents (PDFs, DXF/DWG, DOCX, images) and produces quantity takeoffs, cost estimates, and construction schedules — all driven by Anthropic claude-sonnet-4-6.


Architecture

┌──────────────────────────────────────────────────────────────────┐
│                        FastAPI  (port 8000)                      │
│                                                                  │
│  /api/v1/auth   /api/v1/documents   /api/v1/takeoffs            │
│  /api/v1/estimates   /api/v1/schedules                          │
│  /api/v1/process-bid   /api/v1/analyze-documents   /health      │
└─────────────────────────────┬────────────────────────────────────┘
                              │
                   ┌──────────▼──────────┐
                   │     AICoordinator    │
                   │  (orchestrates all   │
                   │   agents in order)   │
                   └──┬──┬──┬──┬──┬──────┘
                      │  │  │  │  │
          ┌───────────┘  │  │  │  └──────────────┐
          │        ┌─────┘  └─────┐               │
          ▼        ▼              ▼               ▼
  ┌────────────┐ ┌───────────┐ ┌───────────┐ ┌──────────────┐
  │  Document  │ │ Utilities │ │ Earthwork │ │  Estimating  │
  │   Parser   │ │   Agent   │ │   Agent   │ │    Agent     │
  │(classify + │ │(pipe len, │ │(cut/fill, │ │(RSMeans line │
  │ OCR/DXF)   │ │ structures│ │  volumes) │ │   items)     │
  └────────────┘ └───────────┘ └───────────┘ └──────────────┘
                                                      │
                                             ┌────────▼────────┐
                                             │    Scheduling    │
                                             │      Agent       │
                                             │(phases, critical │
                                             │    path, CPM)    │
                                             └─────────────────┘
                                 │
          ┌──────────────────────┼───────────────────────┐
          ▼                      ▼                       ▼
  ┌──────────────┐       ┌──────────────┐       ┌──────────────┐
  │  PostgreSQL  │       │    Redis 7   │       │  Anthropic   │
  │  16 + async  │       │   (cache /   │       │  claude-     │
  │  SQLAlchemy  │       │   sessions)  │       │  sonnet-4-6  │
  │  + Alembic   │       └──────────────┘       └──────────────┘
  └──────────────┘

Prerequisites

  • Docker >= 24 and Docker Compose v2
  • An Anthropic API key (ANTHROPIC_API_KEY)
  • (Optional) A Sentry DSN for error tracking

Quick Start

# 1. Clone and enter the repo
git clone <repo-url>
cd ai-construction-suite

# 2. Configure environment
cp .env.example .env
# Edit .env — at minimum set ANTHROPIC_API_KEY and JWT_SECRET

# 3. Generate a secure JWT secret
openssl rand -hex 32

# 4. Start all services (API + DB + Redis + frontend)
docker compose up --build

# API:      http://localhost:8000
# API docs: http://localhost:8000/docs
# Frontend: http://localhost:5173

Run database migrations manually

docker compose exec app alembic upgrade head

Run tests

docker compose exec app pytest --cov=. tests/

API Endpoints

All endpoints under /api/v1/ require Authorization: Bearer <token> except the auth routes.

Auth — /api/v1/auth

Method Path Auth Description
POST /register No Register a new user, returns JWT
POST /login No Authenticate, returns JWT

Request body (both):

{ "email": "[email protected]", "password": "secret" }

Documents — /api/v1/documents

Method Path Description
POST /upload Upload one or more files to a project
GET /{document_id} Retrieve document metadata by ID
GET / List documents (optional ?project_id=<uuid>)

Upload query params: ?project_id=<uuid>
Accepted types: .pdf, .dxf, .dwg, .xlsx, .docx, .png, .jpg, .jpeg
Max file size: configured via MAX_FILE_SIZE_MB (default 50 MB)


Takeoffs — /api/v1/takeoffs

Method Path Description
POST / Run a quantity takeoff on documents
GET /{takeoff_id} Retrieve takeoff results

POST body:

{
  "project_id": "<uuid>",
  "document_ids": ["<uuid>", "..."],
  "discipline": "utilities"
}

discipline must be "utilities" or "earthwork".


Estimates — /api/v1/estimates

Method Path Description
POST / Generate cost estimate from takeoffs
GET /{estimate_id} Retrieve estimate details

POST body:

{
  "project_id": "<uuid>",
  "takeoff_ids": ["<uuid>", "..."],
  "project_details": {}
}

Schedules — /api/v1/schedules

Method Path Description
POST / Generate project schedule from an estimate

POST body:

{
  "project_id": "<uuid>",
  "estimate_id": "<uuid>",
  "constraints": {}
}

Orchestration (top-level)

Method Path Auth Description
POST /api/v1/process-bid Yes Full pipeline: parse → takeoff → estimate → schedule
POST /api/v1/analyze-documents Yes Classify and extract text from uploaded documents
GET /health No PostgreSQL + Redis health check
GET / No Version info

Agents

Coordinator (services/coordinator/coordinator.py)

Orchestrates the full bid pipeline. Accepts uploaded files, fans out to the document parser and takeoff agents concurrently, then sequences the estimating and scheduling agents. Enforces MAX_CONCURRENT_REQUESTS via an in-process counter. Entry points: process_bid() and analyze_documents().

Document Parser (services/document_parser/parser.py)

Extracts text from PDFs (PyMuPDF with pytesseract OCR fallback), images (pytesseract), DXF files (ezdxf), and DOCX files. Calls claude-sonnet-4-6 to classify each document into one of: utility_plans, grading_plans, specifications, bid_forms, general.

Utilities Agent (services/utilities_agent/agent.py)

Extracts underground utility quantities from classified plan text: pipe lengths by material and diameter, structure counts (manholes, catch basins, cleanouts, fire hydrants). Returns structured JSON with total_pipe_length_ft, total_structures, per-type breakdowns, and a confidence score.

Earthwork Agent (services/earthwork_agent/agent.py)

Calculates earthwork volumes from grading plan text: cut CY, fill CY, topsoil CY, import/export volumes, stripping acreage. Returns structured JSON with per-item line entries and a confidence score.

Estimating Agent (services/estimating_agent/agent.py)

Produces detailed cost estimates from takeoff quantities using RSMeans national average pricing. Returns CSI-coded line items (description, quantity, unit, unit cost, total), a 10% contingency, total project cost (USD), assumptions, and a confidence score.

Scheduling Agent (services/scheduling_agent/agent.py)

Generates a construction schedule from an estimate. Outputs phases with durations and resource assignments, predecessor relationships, project milestones, critical path identification, cost allocation percentages, total project duration in calendar days, and a confidence score.


Environment Variables

Copy .env.example to .env and fill in required values.

Variable Required Default Description
DATABASE_URL yes postgresql+asyncpg://... Async PostgreSQL connection string
REDIS_URL yes redis://localhost:6379/0 Redis connection string
ANTHROPIC_API_KEY yes Anthropic API key for all AI agents
JWT_SECRET yes (insecure placeholder) Min 32-char random secret — openssl rand -hex 32
JWT_ALGORITHM no HS256 JWT signing algorithm
JWT_EXPIRE_MINUTES no 60 Token lifetime in minutes
UPLOAD_DIR no /tmp/uploads Directory for uploaded files
MAX_FILE_SIZE_MB no 50 Maximum upload file size per file
CORS_ORIGINS no ["http://localhost:3000", ...] JSON list of allowed CORS origins
ENVIRONMENT no development development or production
MAX_CONCURRENT_REQUESTS no 10 Coordinator concurrency cap
SENTRY_DSN no (empty) Sentry DSN for error tracking
DB_PASSWORD no postgres PostgreSQL password (docker-compose only)

Tech Stack

Layer Technology
API framework FastAPI + Uvicorn
ORM / DB SQLAlchemy 2 (async) + asyncpg
Migrations Alembic
Database PostgreSQL 16
Cache Redis 7
AI model Anthropic claude-sonnet-4-6
Document parsing PyMuPDF, pytesseract, ezdxf, python-docx
Auth JWT (python-jose) + bcrypt (passlib)
Monitoring Prometheus metrics + optional Sentry
Logging structlog (JSON in production)
Containers Docker Compose
Frontend React 18 + TypeScript + Vite (port 5173)

Project Structure

ai-construction-suite/
├── api/routes/          # FastAPI route handlers
│   ├── auth.py
│   ├── documents.py
│   ├── estimates.py
│   ├── schedules.py
│   └── takeoffs.py
├── services/            # AI agent implementations
│   ├── coordinator/
│   ├── document_parser/
│   ├── earthwork_agent/
│   ├── estimating_agent/
│   ├── scheduling_agent/
│   └── utilities_agent/
├── shared/
│   ├── models/          # SQLAlchemy ORM models + engine
│   └── utils/           # Auth, config, logging, monitoring, OCR, CAD parsing
├── alembic/             # Database migrations
├── tests/               # pytest test suite
├── frontend/            # React + Vite UI (scaffolded)
├── main.py              # Application entry point
├── docker-compose.yml
├── .env.example
└── AUDIT.md             # Security and quality audit findings

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors