Why a Weekly Questions System?
In a community or organization, it’s easy to lose sight of individual experiences, insights, and small wins. The weekly questions system was designed to provide a lightweight, reflective mechanism for members to share their thoughts regularly. The goal is not just data collection, but fostering engagement, insight, and a sense of connection. By aggregating responses and generating AI summaries, the system surfaces trends and insights that might otherwise go unnoticed.
Tools and Technologies
We leveraged a combination of modern web tools and Rust-based backend infrastructure:
- Frontend: Vanilla HTML, Tailwind CSS for styling, and JavaScript for dynamic form handling.
- Backend: Rust with Actix Web for API endpoints and Diesel ORM for SQLite database interaction.
- AI Integration: OpenAI’s GPT models to generate summaries of the collected answers.
- JSON Storage & Utilities: Questions are loaded from a JSON file, and answers are stored with UUID references to each question.
System Architecture
1. Question Selection
- Questions are either loaded from a
questions.jsonfile or fall back to default hard-coded questions. - Five questions are randomly selected each week using a
pickRandomutility function in JavaScript. - Each textarea on the frontend is linked to a
question_uuidso that answers can be tied back to the original question.
2. Answer Submission
- Users enter their responses and submit via a form.
- JavaScript intercepts the submission to prevent page reload and POSTs the data to
/api/weekly-answers. - The payload includes the user’s name, email, and a list of answers with their UUIDs.
3. Backend Storage
- The backend receives the JSON payload and inserts each answer into the
weekly_answerstable. - If needed, question summaries are updated in a separate
question_summarytable. - Diesel ORM manages interactions with SQLite, handling inserts and updates.
4. AI Summaries
- Once answers are stored, the system can query
/api/weekly-answers/allto fetch responses grouped by question UUID. - If a question has fewer than three responses, it is skipped in summary generation.
- A Node.js script submits these grouped responses to OpenAI, generating concise summaries.
- The summaries are then stored via a
/question-summaries/updateendpoint.
5. Frontend Feedback
- Upon successful submission, the form is hidden and a "Thank You" message is displayed.
- AI-generated summaries are dynamically added to the page, showing the summarized text and the number of responses contributing to it.
- Error handling ensures that any issues during submission or summary generation are communicated clearly.
Lessons Learned and Challenges
- Async Form Handling: Avoiding full page reloads required careful management of
event.preventDefault()and asynchronous fetch requests. - JSON Consistency: Frontend expects JSON responses; returning plain text caused parsing errors in
response.json(). - Diesel & SQLite Nuances: Batch inserts and upserts required attention, especially regarding SQLite’s limitations with
DEFAULTkeywords. - Schema Imports and Dsl References: Ensuring Diesel table and column imports were correctly referenced in Rust proved tricky. Mistakes with
question_summaries::dsl::uuidversusquestion_summaries::question_uuidcaused compilation errors and required careful adjustments to imports and field naming. - Error Handling and Response Formatting: Returning proper JSON responses for API endpoints was critical. Initially returning plain text led to parsing failures on the frontend, requiring a structured approach using
HttpResponse::Ok().json(...)andHttpResponse::InternalServerError().json(...). - Modular Design: Separating the question selection, answer collection, and summary generation into discrete components improved maintainability.
Possible Next Steps
- User Authentication: Associate responses with user accounts for longitudinal tracking.
- Analytics Dashboard: Visualize trends in answers and AI-generated summaries over time.
- Advanced AI Summaries: Include sentiment analysis or thematic tagging.
- Multi-format Questions: Allow multiple choice, ratings, or file uploads.
- Notifications: Remind users weekly to submit answers and display new summaries via email or Slack.
The weekly questions system illustrates how small, deliberate data collection and thoughtful AI integration can surface meaningful insights and build a stronger sense of community. By combining Rust, Actix Web, Diesel, and OpenAI, we created a robust yet flexible system that is easy to extend and maintain.