AI-Driven Document Template Builder (Integrate in exsisting program)

Job ID: 39341937

Budget: $750 – $1,500 USD

Objective

You will build a “Create Template” screen that lets construction and civil-works staff design Excel, Word and PDF templates. Should integrate in exsisting program.
Users must be able to:

lock headings (columns, rows or section titles) so the AI can’t alter them

attach an instruction to each heading that tells the AI what to write beneath it from system data.

preview and export the final document with live data injected under the locked headings



Recommended tooling

Front end: React 18 + TypeScript, Zustand for state, shadcn/ui for components, dnd-kit for drag-and-drop

Back end: NestJS + PostgreSQL + TypeORM

AI: OpenAI GPT-03

Office exports:

Excel → xlsx-populate (allows locking and named ranges)

Word → docxtemplater (supports content-controls)

PDF → pdfmake (HTML → PDF)



Step-by-step tasks

Project set-up

Initialise a monorepo or two TS projects (api / web).

Enable strict TS, ESLint, Prettier and Husky pre-commit checks.

Database and entities

Create three tables: template, block, generated_doc.

A template holds meta-data; a block holds one locked heading plus its AI instruction; a generated_doc archives finished files.

REST API

Add endpoints for template CRUD, block updates, and “generate”.

Expose Swagger docs so QA can test calls quickly.

Create-Template UI

Build a top header with template name, file-type selector and save button.

Implement a canvas where BlockCards can be dragged to reorder.

Each BlockCard shows the heading text, a lock/unlock icon and a mini tooltip with its datasource name.

Show a right-side properties panel when a card is selected; include fields for heading text (disabled if locked), a toggle to lock/unlock, a textarea for the AI instruction and a dropdown to pick datasource.

Auto-save changes every few seconds or on blur.

Add a Run Test button that calls the generate endpoint with dryRun=true and streams the AI response into a side drawer—no file written yet.

Excel export logic

Start from a blank workbook.

Loop through blocks in order:

Write the heading to row 1 of the next column.

Lock that cell with sheet.protect.

Store a named range _meta_{blockId} that points to the heading cell (carries hidden metadata).

Call the AI, split its answer by \n, and fill downward in the same column.

Word export logic

Keep a barebones DOCX with only the headings styled as Heading 2.

Under every heading place a rich-text content-control whose tag equals the block ID.

When exporting, iterate over blocks, call the AI and drop the returned text inside the matching content-control.

Leave headings untouched so users see them as locked.

PDF export logic

Store each PDF template as an HTML fragment saved in the database.

Mark headings with <h2 data-block-id="…"> and placeholders as {{blockId}}.

Replace placeholders with AI output, then pipe the HTML through pdfmake to get the final PDF.

AI pipeline per block

Fetch data for the selected datasource.

Build a prompt containing: system message, heading text, user-written instruction, and the raw data.

Call the OpenAI chat completion endpoint.

Strip any unwanted markup or profanity, then forward the text to the export logic.

Abort the block if the answer exceeds 8 000 tokens.

Testing

Unit-test services and utilities with Jest (target ≥80 % coverage).

Use Playwright or Cypress for an end-to-end flow: create template → add two blocks → dry-run AI → export Excel → assert locked headings.

Delivery cadence

Week 1: DB migrations and NestJS scaffolding.

Week 2: Template and Block CRUD APIs finished.

Week 3: Front-end skeleton and draggable BlockCards.

Week 4: Excel export works with locked headings.

Week 5: Word export works with content-controls.

Week 6: PDF export works via HTML.

Week 7: AI integration and dry-run test panel.

Week 8: End-to-end tests, code freeze, doc hand-off.

Handover

Push code to the company GitLab with a detailed README, an ER-diagram and a high-level architecture graphic.

Record a 30-minute walkthrough call.

Provide five-day bug-fix support after acceptance.



Coding standards to obey:

Use Conventional Commits (feat:, fix:, chore: …).

Keep secrets and API keys in .env, never in the repo.

Comment business logic; skip trivial getters/setters.

Write TypeScript everywhere—no any, no implicit any.