Skip to main content

Backend API Overview

The Tower Defense backend is a NestJS application (apps/api). It handles authentication, account management, and data persistence for the game.

Architecture

Three shared libraries power the API:

  • @tower-defense/auth — Better Auth integration and profile management
  • @tower-defense/db — Drizzle ORM + MySQL schema
  • @tower-defense/mail — Nodemailer transactional email delivery

Runtime Shape

  • Entry point: apps/api/src/main.ts
  • Global prefix: /api
  • Port: reads from PORT env var, defaults to 3000
  • CORS: enabled for https://td.traitor.app with credentials

What Each Library Owns

LibraryResponsibility
authSession management, confirmation-token flows, blocked mutation policy
dbMySQL schema, connection pool, migration tooling
mailSMTP transport, all outgoing email templates

Documentation Map

GoalPage
Understand how auth and profile flows workAuthentication
Look up endpoint payloads and responsesEndpoints
Find required env vars and runtime settingsConfiguration
Inspect the database schemaDatabase
See which mail is sent and whenMail Service
Understand the complete client-to-API auth flowAuth Flow End to End
New to the backend?

Read Getting Started for local setup instructions.