Skip to content
← All work

05 · AI survey platform

Quicksurvey.store

Describe what you want to learn; the survey writes itself.

Writing a good survey is harder than answering one. Quicksurvey takes a plain-language brief — who you are asking, what you need to decide — and produces a complete questionnaire with sensible question types, then hosts it and collects responses.

Two services: a PHP and MySQL web application that owns accounts, surveys and results, and a separate Flask service that asks Gemini for the questionnaire as strict JSON. Keeping them apart meant the AI side could change models without touching the product.

Year
2024
Role
Web app & AI service
Stack
PHP 8, MySQL, Python, Flask, Gemini API
Languages
  • PHP97.9%
  • CSS1.7%
  • Python0.3%
  • Other0.1%

From the repository

Independent services
2
JSON API endpoints
15
Question types
9
Database tables
6

Technical architecture

Two deployables. A PHP 8 and MySQL application owns users, surveys and answers through a small JSON API; a Flask service on Render owns the one thing that talks to Gemini.

  1. L1

    Interfaces

    • Admin panel
    • Respondent pages
    • QR codes
    • Embeddable frame

    Owners build and report in /admin; respondents answer one question per page from a link, a QR code or an iframe.

  2. L2

    PHP API

    • create / update / delete_survey
    • survey_fields
    • publish
    • getNumericalResponses
    • sendRequestToAi

    Pages call endpoints instead of mixing SQL into templates; the classes underneath are static, one per table.

  3. L3

    AI service

    • Flask
    • Gunicorn
    • Gemini 1.5 Flash-8B
    • flask-cors

    POST /generate-survey takes a brief and returns JSON with a title, description, expiry date and nine typed fields.

  4. L4

    Data & delivery

    • MySQL / MariaDB
    • PHPMailer
    • phpqrcode

    Surveys, fields, responses and profiles in MySQL; PHPMailer for account mail; phpqrcode for shareable codes.

From a brief to a live survey

Generation is one request; everything after it is ordinary CRUD.

  1. 01

    Brief

    The owner writes who they are asking and why. PHP forwards it to the Flask service.

  2. 02

    Generate

    A system instruction pins Gemini to JSON-only output, exactly nine questions and the platform's type ids 3–11.

  3. 03

    Persist

    sendRequestToAi strips the Markdown fence, decodes the JSON, creates the survey with a random hash_id and one survey_fields row per question — all still editable.

  4. 04

    Answer

    Respondents start from the survey's hash_id and walk field to field; numeric and text answers are reported separately.

Data model

A survey is a header row plus an ordered set of fields; each field's type id decides which respondent page renders it.

  • survey

    • created_by → users
    • title, description
    • exp_date
    • hash_id
    • isPrivacyMode
    • colours
  • survey_fields

    • survey_id → survey
    • type_id → form_types
    • title, description
    • min, max
    • isOptional
  • responses

    • survey_fields_id
    • value
    • profile_id → profiles
  • form_types

    • id 3–11
    • emoji, choice, range, yes/no, text, number, rate
  • profiles

    • name, surname
    • email
  • users

    • account
    • credentials

Relationships · 5

  • users 1 ─< N survey (created_by)
  • survey 1 ─< N survey_fields
  • form_types 1 ─< N survey_fields
  • survey_fields 1 ─< N responses
  • profiles 1 ─< N responses

API examples

Request and response shapes are taken from the code; values are examples.

POST/generate-survey

Flask AI service — the only code that talks to Gemini.

Request

{ "prompt": "Customer satisfaction survey for a coffee shop" }

Response

// "survey" is the model's raw text: JSON, often inside a Markdown fence
{ "survey": "```json\n{ \"title\": \"Coffee Shop Satisfaction\", … }\n```" }

// after the PHP side strips the fence and decodes it
{
  "title": "Coffee Shop Satisfaction",
  "description": "How was your visit?",
  "exp_date": "2025-04-01",
  "fields": [
    { "type": "10", "label": "Rate the coffee from 1 to 5", "required": true },
    { "type": "6",  "label": "Would you come back?",         "required": true },
    { "type": "8",  "label": "Anything we could improve?",   "required": false }
  ]
}

GET/api/sendRequestToAi.php?request=…

PHP side: calls the service, cleans the JSON, writes the survey and its fields.

Response

{ "success": true, "message": "Survey successfully created.", "hash_id": "9f2c41d07ab3e815" }

Engineering decisions

  • A survey is a linked list

    The respondent flow finds the first field from the hash_id, then asks for the next one until there is none — previous and next are queries, not page numbers.

  • The model only speaks JSON

    Mapping question types to the platform's own ids inside the prompt means the output can be inserted without a translation layer.

  • Keep the model at arm's length

    Because generation lives in a separate Flask service, the model can change — or the provider — without redeploying the PHP product.

Engineering checklist

The questions a reviewer asks, answered from the code — including the ones where the honest answer is no.

Database designIn place
Six tables and five foreign keys. Question types live in their own form_types table so adding a type is a row, not a migration; surveys are soft-deleted with isDeleted so responses are never lost.
Authentication & authorizationIn place
bcrypt via password_hash and password_verify, PHP sessions, and a random verification hash e-mailed with PHPMailer before an account is active.
API & data securityPartly
Over a hundred prepared statements and no string-built SQL; but some endpoints, such as delete_survey, check neither the session nor the survey's owner.
PerformancePartly
Generation is the only slow call and runs on its own service, so the PHP site never waits on a model except at the moment a survey is created.
Errors & loggingPartly
Endpoints answer with JSON success and message fields and catch exceptions; cURL failures from the AI service are reported back instead of hanging.
TestsNot yet
No automated tests.
Deployment & CI/CDPartly
PHP on Apache with mod_rewrite clean URLs; the Flask service on Render under Gunicorn. Deployed by hand.

What I would change now

  • Validate the model's JSON against a schema before inserting it; malformed output should fail loudly, not half-save.
  • Composer instead of vendored PHPMailer and phpqrcode folders would keep the repository about the product.

Next project

AutoER

Business rules in, database schema out.