Skip to content

Repository files navigation

Quizzy Backend

A real-time multiplayer quiz game backend built with Go, inspired by Kahoot.

🚀 Features

  • REST API for quiz creation and session management
  • Real-time WebSocket communication
  • PostgreSQL database integration
  • Docker support
  • AI-powered quiz generation (optional)

🛠️ Tech Stack

  • Language: Go 1.22+
  • Web Framework: Gin
  • WebSocket: Gorilla WebSocket
  • Database: PostgreSQL (via pgx)
  • Configuration: Environment variables with .env support
  • Logging: Structured logging with Logrus
  • Deployment: Docker + AWS EC2/RDS

🏃‍♂️ Quick Start

Prerequisites

  • Go 1.22 or higher
  • PostgreSQL database

Setup

  1. Clone and setup the project:

    git clone <your-repo-url>
    cd quizzy-backend
  2. Install dependencies:

    go mod download
  3. Configure environment:

    cp .env.example .env
    # Edit .env with your database credentials
  4. Run the server:

    go run cmd/server/main.go

The server will start on http://localhost:8080

Test the API

  • Health check: GET http://localhost:8080/health
  • API endpoints: http://localhost:8080/api/v1/

📁 Project Structure

quizzy-backend/
├── cmd/server/              # Main entry point
├── internal/
│   ├── config/             # Configuration loading
│   ├── db/
│   │   ├── model/          # Data models
│   │   └── repository/     # Database queries
│   ├── handler/            # HTTP route handlers
│   ├── quiz/               # Quiz business logic
│   ├── session/            # Game session management
│   ├── websocket/          # WebSocket handling
│   └── ai/                 # AI integration
├── pkg/
│   └── logger/             # Logging utilities
├── migrations/             # Database migrations
├── .env.example           # Environment variables template
└── go.mod                 # Go module definition

🔧 Environment Variables

See .env.example for all available configuration options.

🐳 Docker

# Build image
docker build -t quizzy-backend .

# Run container
docker run -p 8080:8080 quizzy-backend

📝 API Endpoints

Quiz Management

  • POST /api/v1/quiz - Create a new quiz
  • GET /api/v1/quiz/:id - Get quiz details

Session Management

  • POST /api/v1/session - Create a game session
  • GET /api/v1/session/:pin - Get session details

Real-time Communication

  • GET /api/v1/ws/:pin - WebSocket connection for game session

🧪 Development

This project is perfect for learning Go! Each component demonstrates different Go concepts:

  • Structs & Interfaces: Data models and repository patterns
  • Goroutines & Channels: WebSocket handling and real-time communication
  • HTTP Servers: REST API with Gin framework
  • Database Integration: PostgreSQL with pgx driver
  • Error Handling: Go's explicit error handling patterns
  • Package Organization: Clean architecture with internal packages

🤝 Contributing

This is a learning project! Feel free to:

  • Add new features
  • Improve error handling
  • Add tests
  • Optimize performance
  • Enhance documentation

📚 Learning Resources

📄 License

This project is for educational purposes.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages