Quiz Game

A serverless quiz POC application built with a Go backend and a Svelte frontend, deployed on AWS using Terraform.

Architecture

The application follows a modern serverless architecture designed for maximum cost-efficiency:

  • Frontend: A Svelte Single Page Application (SPA) hosted on S3 and delivered via CloudFront.
  • API: An AWS Lambda function (Go) exposed through Amazon API Gateway (HTTP API).
  • Data Storage: For this Proof of Concept (PoC), quiz questions are stored as a JSON file in a private S3 bucket. This approach was chosen to achieve the cheapest possible solution by avoiding the overhead and cost of a managed database like DynamoDB.
  • Infrastructure: Semi automated deployment using Terraform with a remote S3 backend.

Project Structure

  • backend/: Go source code for the Lambda API.
  • frontend/: Svelte application code.
  • terraform/: Infrastructure as Code definitions.

Prerequisites

  • Go 1.24.x
  • Node.js and npm
  • Terraform 1.12.x or later
  • AWS CLI configured with appropriate credentials

Deployment

1. Build the Backend

The Lambda function uses the provided.al2023 runtime, requiring the binary to be named bootstrap and arm64 architecture.

cd backend/questions
GOOS=linux GOARCH=arm64 go build -o build/bootstrap main.go models.go

2. Configure Infrastructure

Navigate to the terraform directory and initialize with your backend configuration:

cd terraform
terraform init -backend-config=backend.hcl

Review and apply the changes:

terraform plan
terraform apply

3. Build and Deploy Frontend

Once the infrastructure is deployed, note the api_endpoint output. Configure your frontend environment:

  1. Create frontend/.env:

    VITE_GET_URL=your_api_gateway_endpoint
    
  2. Build the application:

    cd frontend
    npm install
    npm run build
    
  3. Upload the contents of frontend/build/ to the frontend S3 bucket created by Terraform.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Top categories

Loading Svelte Themes