AI-assisted tender intelligence, BOQ management, and contractor bid comparison.
Every Tender. Every Item. Every Detail. Under Control.
- Next.js 16 (App Router, TypeScript), Tailwind CSS v4
- Supabase (Postgres, Auth, Storage) with Row Level Security
- Claude (via
@anthropic-ai/sdk) for bounded, schema-validated workbook interpretation - ExcelJS for deterministic workbook parsing
- Zod for strict validation of AI output
See .env.example. NEXT_PUBLIC_SUPABASE_URL / NEXT_PUBLIC_SUPABASE_ANON_KEY / ANTHROPIC_API_KEY
are already set in .env.local for this project (that file is gitignored — never commit it).
ANTHROPIC_MODEL defaults to claude-sonnet-5-5; check the Anthropic docs if that model is later
renamed/retired.
npm install
npm run devnpm test # unit tests for the deterministic parser + formula engine (no network/DB required)
npm run build # also runs the full TypeScript checknpm test covers the highest-risk, hand-written logic: formula evaluation (precedence, SUM ranges,
division-by-zero, unsupported functions), worksheet manifesting (hidden/empty sheets never silently
dropped), merged-cell handling, and the "never fabricate a missing value" guarantee. It intentionally
does not hit Claude or Supabase — that was instead verified with a live end-to-end run (sign-in →
create tender → upload a BOQ with merged headers, a hidden notes sheet, an empty sheet, and formulas
with and without cached results → AI interpretation → review → contractor quote upload with a
quantity deviation and an unmatched item → comparison totals), which produced correct
amounts, correctly flagged the deviation, and correctly left two formula-dependent cells "unavailable"
rather than inventing a result for an upstream formula with no cached value.
For a complete, code-level walkthrough of exactly how values are extracted, verified, and never
silently altered — what's sent to the LLM, how its output is reconciled against the source file, and
how formula amounts are independently recalculated — see docs/DATA_ACCURACY.md.
- Extraction pipeline (
src/lib/excel,src/lib/claude,src/lib/validation): deterministic ExcelJS parsing → per-sheet chunked Claude interpretation (schema-validated, never trusted blindly) → structural/semantic/financial validation → draft persistence. Every worksheet gets a manifest row even if empty, hidden, or failed; nothing is marked "complete" while blocking issues are open. - Draft/commit staging: extraction never writes directly into the "real" BOQ or comparison. Both
tender_requirementsandcontractor_bid_itemscarry acommittedflag (defaultfalse) plus theupload_idthat produced them. A dedicated review screen —/tenders/[id]/reviewfor the tender's own requirement sheet,/tenders/[id]/contractors/[submissionId]/reviewfor a contractor's quoted sheet — shows only that upload's draft rows next to any flagged issues, lets the user correct fields inline, and only an explicit Save to DB action flipscommitted = true. The BOQ page, the comparison dashboard, and reports all filter oncommitted = true, so nothing counts until a human has reviewed and saved it. - Contractor sheets go through the same AI pipeline as the tender sheet (
runContractorExtractionPipelineinsrc/lib/validation/pipeline.ts): deterministic parse → Claude interpretation → row mapping, then matched against the tender's own committed requirements by item number first, description second (src/lib/validation/bid-matching.ts). Unmatched rows and quantity deviations are raised asextraction_issuesexactly like the tender side, not silently dropped. - Source fidelity:
source_cellsis an append-only archive of every populated cell (value, type, formula, cached result, independently recalculated result via a constrained formula engine that only evaluates arithmetic/SUM over known cells — never arbitrary code). Corrections made in a review screen update the draft row but are audit-logged and never touchsource_cells. - RLS: every table is organization-scoped via
is_org_member()/org_role_of(); storage objects are scoped by the organization ID encoded in the object path.
- Anthropic enforces per-account rate limits; a sheet (tender or contractor) that fails interpretation
because of one is correctly flagged as an
extraction_issue/partially_processedupload rather than silently producing nothing. Reprocessing (/api/tenders/[id]/uploads/[uploadId]/reprocess) picks it back up once the limit clears, reusing the stored file. - PDF export is not implemented — only Excel (BOQ export, contractor comparison). Excel covers the spec's reporting requirement; PDF would be an additive follow-up.
- The automated adversarial-workbook test suite in the spec (16 named cases) is covered in spirit by
the unit tests plus the live smoke run above, not as 16 discrete fixture files. Hidden sheets, empty
sheets, merged headers, missing values, and formula/cached-result mismatches are explicitly tested;
malicious-instruction-in-cell-text and LLM-timeout/invalid-JSON paths are handled in code (Rule 9 of
the system prompt;
interpretChunk's retry/validation loop) but not yet exercised by a dedicated fixture. - No background job queue — large workbook processing runs synchronously inside the upload request
(bounded by
maxDurationon the route handler). Fine for the workbook sizes tested; a genuinely huge BOQ would want a queue.