Getting Started
This guide walks you through setting up the Tower Defense project on your local machine.
Prerequisites
Install the following tools before you start:
- Node.js (latest LTS)
- pnpm (monorepo package manager)
- MySQL (local server, any recent version)
- smtp4dev (local mail sink for email testing — download)
1. Install Dependencies
git clone https://github.com/defkil/tower-defense.git
cd tower-defense
pnpm install
2. Configure Environment Variables
Create a .env file in the workspace root. All variables are loaded from this file at runtime.
# Database
MYSQL_HOST=localhost:3306
MYSQL_USER=your_mysql_user
MYSQL_PASSWORD=your_mysql_password
MYSQL_DB=tower_defense
# Better Auth
BETTER_AUTH_SECRET=a-long-random-secret-string
BETTER_AUTH_URL=http://localhost:3000
# SMTP (smtp4dev defaults)
SMTP_HOST=localhost
SMTP_PORT=25
SMTP_SECURE=false
SMTP_FROM=noreply@localhost
INCORRECT: DATABASE_URL=mysql://... — this project uses individual MYSQL_* variables.
CORRECT: Set MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, and MYSQL_DB separately.
INCORRECT: BETTER_AUTH_URL=http://localhost:4200 — this points at the Angular frontend.
CORRECT: BETTER_AUTH_URL=http://localhost:3000 — must point at the NestJS API.
3. Run Database Migrations
Ensure your MySQL server is running and the database tower_defense exists. Then apply migrations:
pnpm nx run db:migrate
db:push does not exist. Always use db:migrate to apply schema changes. Use db:generate first if you changed schema.ts.
4. Start the Development Environment
# Start both frontend and backend in parallel
pnpm nx run-many --targets=serve --projects=game,api
| Service | URL |
|---|---|
| Frontend (Angular) | http://localhost:4200 |
| Backend (NestJS) | http://localhost:3000 |
| Local Mail Sink (smtp4dev) | http://127.0.0.1:50463 |
The Angular dev server proxies all /api requests to http://localhost:3000. No CORS configuration is needed in local development.
5. Verify the Setup
- Open
http://localhost:4200 - Click Register and create an account
- Check
http://127.0.0.1:50463for the verification email - Click the verification link to activate the account