Skip to content

๐ŸŒ Find Capital API โ€” backend for a geography guessing game where players try to find a randomly chosen capital city by guessing other capitals and getting hints based on distance and color gradients.

License

Notifications You must be signed in to change notification settings

m1n64/find-capital-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงญ Find Capital API

A backend API for a game where you need to find a randomly chosen capital city. You input guesses of capital cities and the system tells you how far you are from the correct one โ€” using distances and beautiful gradient lines.


๐ŸŽฎ Gameplay Flow

  1. Start a game โ€” a random capital city is secretly chosen.
  2. Guess a capital โ€” type any capital city name.
  3. System responds with:
    • Distance in kilometers between your guess and the target.
    • A colorful CSS gradient line representing closeness.
  4. Try again โ€” you keep guessing until you find the correct capital.
  5. Game ends once the correct city is guessed.

Each attempt is visualized with coordinates and gradients. The closer your guess, the more intense the red in the gradient.


โœจ Inspiration & Attribution

This project was inspired by the amazing game Globle Capitals.

All code, logic, and architecture presented here are entirely self-written. The game mechanics were built from scratch, inspired only by the core idea. No code or assets were reused or copied from the original website.

All rights to the original Globle Capitals game belong to Trainwreck Labs. This is a developer-made homage, not a commercial clone.


๐Ÿš€ Features

  • Autocomplete for cities via Elasticsearch
  • Real-time distance calculations (Haversine formula)
  • Stylish visual feedback via CSS gradients
  • Persistent game sessions stored in PostgreSQL
  • Redis caching for fast lookup and TTL-based game expiration
  • Clean Architecture with DDD principles
  • Fully documented OpenAPI spec via ReDoc

๐Ÿ›  Tech Stack

  • Go (Golang) โ€” backend API
  • Gin โ€” HTTP web framework
  • GORM โ€” ORM for PostgreSQL
  • Redis โ€” for fast cache and session TTL
  • PostgreSQL โ€” for persistent game sessions
  • Elasticsearch โ€” full-text search for cities
  • Docker & Docker Compose โ€” containerized development
  • Makefile โ€” for devtools and automation
  • OpenAPI + ReDoc โ€” API documentation

๐Ÿ”— API Endpoints Overview

Method Endpoint Description
GET /v1/autocomplete?q= Autocomplete capital city names
POST /v1/game/start Start a new game session
POST /v1/game/guess Make a guess for a capital city
GET /v1/game/list List all games played by user (by IP)
GET /v1/game/info/{uuid} Get info about a specific game

Postman collection: Find Capitals API.postman_collection.json


โšก๏ธ Getting Started

# Clone the repo
git clone https://github.com/m1n64/find-capital-api
cd find-capital-api
# Copy environment variables
cp .env.example .env
# Start environment
make up
# Seed database
make seed

View API Docs

Go to http://localhost:8000/docs


๐Ÿ“‹ Makefile Commands

Command Description
make up Start the DEV environment
make prod Start the PROD environment
make stop Stop all containers
make down Remove all containers and volumes
make restart Restart all containers
make restart-container CONTAINER=name Restart a specific container
make stop-container CONTAINER=name Stop a specific container
make bash Open a bash shell inside the app container
make logs name View logs of a specific container
make app-logs View last logs from the app container
make psql Open psql shell with credentials from .env
make redis Open redis-cli inside the Redis container
make seed Run seeders to populate countries & cities

๐Ÿ“˜ API Documentation

ReDoc is available at: ๐Ÿ‘‰ http://localhost:8000/docs

Raw OpenAPI JSON: ๐Ÿ‘‰ http://localhost:8000/docs/openapi.json

API host: ๐Ÿ‘‰ http://localhost:8000/v1


๐Ÿง™โ€โ™‚๏ธ Author

Made with โค๏ธ by the Kirill Sakharov (LinkedIn)

About

๐ŸŒ Find Capital API โ€” backend for a geography guessing game where players try to find a randomly chosen capital city by guessing other capitals and getting hints based on distance and color gradients.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published