Decisions and Architecture: FormForge AI
This document details the core engineering assumptions, Part D choices, trade-offs accepted, and future roadmap for FormForge AI. It aligns directly with the "Engineering Differentiators" outlined in the README.md.
1. Assumptions Made
During the design and implementation of FormForge AI, we operated under the following engineering and product assumptions:
- Single-Tenant / Admin-First Focus: We assumed that the creator of the forms is an administrative user who has complete control over the layout, sections, and schemas. Comprehensive multi-tenant workspace isolation and complex role-based access control (RBAC) were scoped out for this initial proof-of-concept.
- LLM Key Availability & Robust Mocking: We assumed that some environments or testing runners might not have a valid
GEMINI_API_KEYconfigured. To keep the app 100% functional and testable out-of-the-box, we built a local fallback mockup service that auto-generates representative form schemas. - Stateless Public Submissions: We assumed that public users filling out forms are external, unauthenticated users. Thus, public form filling does not require a login, but requires strict, automated server-side verification to prevent malicious payload injections.
- Standard Document Layouts: For Word (
.docx) and Excel (.xlsx) imports, we assumed standard layouts (e.g., column headers in the first row of spreadsheets, list paragraphs/headings in Word documents) to extract headers and values deterministically before handing them off to the AI.
2. Part D Choices & Why (Engineering Differentiators)
To elevate FormForge AI into a robust, enterprise-ready product, we selected and implemented the following three key differentiators under Part D:
1. Queue-Based Asynchronous AI Engine & Live Progress Polling
- The User Problem: Running long LLM requests or heavy document parsing synchronously blocks the PHP thread, leading to gateway timeouts, frozen pages, and a poor user experience.
- Our Choice & Why: We decoupled the generation process using a database queue system. Dispatched jobs run asynchronously in the background. The Livewire creation page uses Alpine.js and
wire:pollto check the database status (ai_generation_jobstable) and display real-time progress to the user (e.g., "Waiting in queue...", "Generating fields...", or "Completed!"). - Trade-offs Accepted: Requires the runner to start a background queue worker (
php artisan queue:listen). - With More Time: We would transition from database queues to Redis or SQS for sub-millisecond dispatching, and replace Livewire polling with real-time WebSockets (via Laravel Echo) to stream progress events directly.
2. Portable Containerization via Laravel Sail (Docker)
- The User Problem: Setting up local databases and matching PHP versions/extensions (like
ziporxmlrequired for document import libraries) can cause environment drift and "works on my machine" issues. - Our Choice & Why: We containerized the entire stack using Laravel Sail. The included
compose.yamlfile orchestrates isolated containers for PHP 8.3, MySQL 8, Redis, and Mailpit (local email testing). - Trade-offs Accepted: Docker requires initial image downloads and WSL2 configuration on Windows, slightly increasing initial setup time for developers without Docker pre-installed.
- With More Time: We would configure multi-stage production Dockerfiles and integrate a CI/CD pipeline (e.g., GitHub Actions) to run the test suite and verify the build on every push.
3. Strict Server-Side Validation & Self-Healing Schemas
- The User Problem: Dynamic forms are vulnerable to client-side validation bypass, and LLMs frequently hallucinate invalid input types or validation parameters.
- Our Choice & Why: We built a dedicated
FormSchemaServicethat parses the active JSON schema from the database, builds Laravel validation rules on the fly, and validates all public submissions against them. It also auto-heals hallucinated field configurations (e.g., converting unsupported types to a stabletextfallback). - Trade-offs Accepted: Strict validation schemas restrict dynamic values, requiring all custom fields to conform exactly to our predefined types.
- With More Time: We would add schema version hashing so that changing a form structure midway doesn't invalidate old, historical submission entries.
3. What We'd Build Next (2-Week Roadmap)
Given two additional weeks, we would focus on these three high-impact roadmap items:
Week 1: Advanced Form Features
- Conditional Branching & Field Visibility (Product): Build a visual rule builder in the editor (e.g., "Show field B if option A is checked") and evaluate it client-side with Alpine.js, while mirroring the logic in the PHP validation layer.
- Schema Versioning & Historic Data Integrity (Engineering): Introduce a
form_versionstable and link submissions to a specific version hash. This ensures historic submissions remain intact even if a builder edits the active form schema later.
Week 2: Real-time Infrastructure & Distribution
- WebSockets Integration (Engineering): Swap polling out for Pusher/Laravel Echo to enable instant, real-time feedback during AI form generation without polling the database.
- Embeddable Widgets & Distribution (Product): Create copy-pasteable JS iframe widgets and generate QR codes automatically for every form to make public sharing seamless.