game tracker api
A RESTful API built with Node.js, Express, and TypeScript to track your video game collection and backlog. Features clean layered architecture, Swagger documentation, and Joi validation.
Languages
Technologies
# README.md
๐ฎ Game Tracker API
A RESTful API for tracking your video game collection and backlog, built with Node.js, Express, and TypeScript.
Based on this awesome repository by Marcio Zabeu. Created with love (and knowledge).
๐ Table of Contents
- Features
- Tech Stack
- Project Structure
- Prerequisites
- Getting Started
- API Endpoints
- Environment Variables
- API Documentation
- Architecture Overview
- TODO / Roadmap
- License
โจ Features
- Game Collection Management: Add, view, search, and delete games from your collection
- Status Tracking: Track your gaming progress with states:
backlog,playing,completed - Multi-Platform Support: Track games across classic platforms (NES, SNES, Mega Drive, GameBoy, PS1, N64)
- Input Validation: Comprehensive request validation using Joi schemas
- Swagger Documentation: Interactive API documentation with Swagger UI
- Clean Architecture: Layered architecture with Controllers, Services, and Repositories
- TypeScript Support: Full type safety with TypeScript
- Graceful Shutdown: Proper server shutdown handling
๐ Tech Stack
| Technology | Purpose |
|---|---|
| Node.js | Runtime environment |
| Express 5 | Web framework |
| TypeScript | Type-safe JavaScript |
| Sequelize | ORM for database operations |
| PostgreSQL | Relational database |
| Joi | Request validation |
| Swagger | API documentation |
| Docker | Database containerization |
๐ Project Structure
game-tracker-api/
โโโ postgresql/
โ โโโ compose.yaml # Docker Compose for PostgreSQL
โโโ src/
โ โโโ app.ts # Express application setup
โ โโโ server.ts # Server entry point
โ โโโ config/
โ โ โโโ database.ts # Sequelize database configuration
โ โ โโโ env.ts # Environment variables
โ โ โโโ swagger.ts # Swagger documentation setup
โ โโโ controllers/
โ โ โโโ game/ # Game controller (request handling)
โ โโโ docs/
โ โ โโโ game.docs.yaml # OpenAPI/Swagger documentation
โ โโโ helpers/
โ โ โโโ apiError.ts # Custom API error handler
โ โโโ middlewares/
โ โ โโโ error.ts # Global error middleware
โ โ โโโ logger.ts # Request logger middleware
โ โ โโโ validation/ # Validation middlewares (body, param, query)
โ โโโ repositories/
โ โ โโโ game/ # Game data access layer
โ โโโ routes/
โ โ โโโ game/ # Game routes definition
โ โโโ schemas/
โ โ โโโ game/ # Joi validation schemas
โ โโโ services/
โ โ โโโ game/ # Business logic layer
โ โโโ types/
โ โโโ game/ # TypeScript type definitions
โโโ package.json
โโโ tsconfig.json
โโโ README.md๐ฆ Prerequisites
- Node.js v18 or higher
- npm or yarn
- Docker (for PostgreSQL database)
๐ Getting Started
1. Clone the Repository
git clone https://github.com/your-username/game-tracker-api.git
cd game-tracker-api2. Install Dependencies
npm install3. Start PostgreSQL with Docker
cd postgresql
docker compose up -dThis will start a PostgreSQL container with:
- Database:
game_tracker_db - User:
admin - Password:
admin123 - Port:
5432
4. Configure Environment Variables
Create a .env file in the root directory:
PORT=3000
NODE_ENV=development
# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=game_tracker_db
DB_USERNAME=admin
DB_PASSWORD=admin1235. Start the Development Server
npm run devThe server will start on http://localhost:3000 with hot-reload enabled.
6. Access API Documentation
Open your browser and navigate to: http://localhost:3000/api-docs
๐ API Endpoints
Games
| Method | Endpoint | Description |
|---|---|---|
GET | /games | Get all games |
POST | /games | Add a new game |
DELETE | /games/:id | Delete a game by ID |
GET | /games/search | Search games with filters |
PATCH | /games/:id/status | Update game status |
Request/Response Examples
Add a New Game
POST /games
Content-Type: application/json
{
"title": "Super Mario World",
"year": 1990,
"platform": "SNES",
"genre": ["Platformer", "Adventure"],
"status": "backlog"
}Search Games
GET /games/search?platform=SNES&status=playingUpdate Game Status
PATCH /games/:id/status
Content-Type: application/json
{
"status": "completed"
}Game Statuses
| Status | Description |
|---|---|
backlog | Games you own but haven't started |
playing | Games you're currently playing |
completed | Games you've finished |
Supported Platforms
NESSNESMega DriveGameboyPS1N64
๐ Environment Variables
| Variable | Description | Default |
|-|-||
| PORT | Server port | 3000 |
| NODE_ENV | Environment mode | local |
| DB_HOST | PostgreSQL host | localhost |
| DB_PORT | PostgreSQL port | 5432 |
| DB_NAME | Database name | - |
| DB_USERNAME | Database user | - |
| DB_PASSWORD | Database password | - |
๐ API Documentation
Interactive API documentation is available via Swagger UI at /api-docs when running in development mode.
You can also access the raw OpenAPI specification at /docs.json.
๐ Architecture Overview
The project follows a layered architecture pattern:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Routes โ
โ (Define endpoints & middlewares) โ
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Controllers โ
โ (Handle HTTP requests/responses) โ
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Services โ
โ (Business logic & validation) โ
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Repositories โ
โ (Data access layer) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโKey Principles
- Separation of Concerns: Each layer has a single responsibility
- Dependency Injection: Services and repositories are injected via factory functions
- Type Safety: Full TypeScript support with strict types
- Validation: All inputs validated at the middleware level using Joi
๐ TODO / Roadmap
- Integrate PostgreSQL: Replace in-memory storage with Sequelize models connected to PostgreSQL
- Create Docker Image: Add Dockerfile for the API and multi-container docker-compose setup
- Add More Operations:
- Get single game by ID (
GET /games/:id) - Update game details (
PUT /games/:id) - Bulk operations (add/delete multiple games)
- Pagination support for list endpoints
- Sorting and advanced filtering
- Get single game by ID (
- IGDB Integration: Integrate with the IGDB API to:
- Auto-fill game metadata (title, genres, platforms, cover art) by searching IGDB
- Validate game data against IGDB records on creation
- Sync additional game info (summary, release dates, ratings, screenshots)
- Additional Features:
- User authentication & authorization
- Game ratings and reviews
- Screenshots/cover art storage
- Export/import game lists
- Statistics dashboard (games by status, platform, etc.)
- Testing:
- Unit tests with Jest
- Integration tests
- E2E tests
- CI/CD:
- GitHub Actions pipeline
- Automated testing on PR
- Deployment automation
๐ค Author
Leonardo Silvatti