# Event Registration System

> Event registration system for a cultural event organizer. Handles registration, LINE & email payment confirmation, Google Sheets storage, and retry queue.

- Result: Full registration flow: form → payment → email notification
- Stack: Python, Flask, JavaScript, Google Sheets API, LINE Pay, Gunicorn

An online registration and ticketing system built for a cultural event organiser, with a separated front end and back end: a Flask API handles registration, payment and notification logic, the front end is plain HTML/CSS/JS, and it was deployed on Render (started by gunicorn).

## Problem

Online registration and ticketing for a railway-themed cultural event. Requirements: a limited number of seats per train car, registering 1–10 people at once, several ticket types and add-ons, participants must read the event rules before they can tick "I agree", payment by bank transfer within three days, and the organiser notifies participants after reconciling payments.

## Key decisions

1. **Store data in Google Sheets instead of running a database**: The organiser reads the list and reconciles payments right in the spreadsheet, so no admin panel was needed — and on Render's free tier there was no database to maintain.
2. **Registration ID = date + running number; ID generation and writes are locked, and writes are de-duplicated by ID**: If a user double-clicks submit or the network retries, the list never ends up with two copies of the same registration.
3. **Every row records the version of the sheet's schema**: After the columns change, the system detects the version mismatch at start-up and tries to fix it automatically, so old rows don't shift out of place.
4. **Layered error codes, and a retry queue for failed emails**: E_VALIDATION, E_SHEET_UNAVAILABLE, E_SHEET_WRITE and E_SMTP_SEND show at a glance which layer failed; payment emails that fail can be resent through an API instead of disappearing silently.
5. **Fall back to a temporary mode when Google Sheets is unreachable**: The registration page doesn't go down entirely, and participants can still fill in their details.

## Trade-offs

- Seat checks and writes are protected by a lock inside a single process; that holds because Render runs one gunicorn worker — scaling to several workers would need a database with transactions
- Each write first reads the whole sheet to de-duplicate, so the longer the list, the more each write costs

## Results

- While it was live it handled about 20–30 real registrations; it also met bots submitting fake registrations in bulk, which were blocked afterwards with validation and limits
- The full flow went live: fill in the form → the system calculates the total and emails payment details → participants report the last five digits of their account via LINE or email → the organiser reconciles
- On phones, multi-person registration switches participants with a drop-down — one person at a time, three steps each
- Deployed on Render's free tier (gunicorn), with the front end and back end separated

## Architecture

```mermaid
flowchart TD
  U["Visitor"] -->|"fills in the form"| F["Front end<br/>frontend/ static pages"]
  F -->|"POST /api/register"| B["Flask API<br/>backend/app.py"]
  B --> R["registration_service"]
  R --> S["sheet_service"]
  S --> G[("Google Sheets")]
  R --> E["email_service"]
  E -->|"payment email"| U
  E -.retry on failure.-> Q["/api/retry-email-queue"]
```

## Architecture

- Back end (backend/): Flask API entry point app.py, split into config / registration_service / sheet_service / email_service / models / errors / logging_utils / startup_guard modules
- Front end (frontend/): templates + static assets, fully separated from the back end
- Storage: written to Google Sheets in real time through the Google Sheets API, not a traditional database
- Deployment: Render free tier, WSGI entry backend.app:app, with an app.py shim in the root kept for older gunicorn start commands

## Highlights

- Two ways to confirm payment: a LINE message or an email reply, each with the last five digits of the account to speed up reconciliation
- Failed emails go to their own retry queue (/api/retry-email-queue) instead of being dropped silently
- Explicit error codes — E_VALIDATION, E_SHEET_UNAVAILABLE, E_SHEET_WRITE, E_SMTP_SEND and more — to trace which layer a problem came from
- Responsive front end; on mobile the participant picker becomes a drop-down

## API

- GET /api/bootstrap — load the event settings and remaining seats
- POST /api/register — submit a registration
- POST /api/retry-email-queue — resend failed payment emails

---

Author: PINGWEI LI (李秉威, Li Ping-Wei)
Original page: https://kbs0830.com/en/projects/ticketing-system
