Technical Architecture
This section describes the high-level architecture of the Tower Defense project, following the C4 model.
System Context
The following diagram illustrates the primary components of the Tower Defense ecosystem and their interactions.
Core Components
1. Frontend: Angular Game Client
The frontend is built using Angular and provides the primary user interface and game logic. It communicates with the backend API to handle authentication, profile management, and game data persistence.
- Location:
apps/game - Key Technologies: Angular, RxJS, Tailwind CSS (optional).
2. Backend: NestJS API Gateway
The backend is powered by NestJS and serves as the central hub for the application. It handles business logic, security, and data persistence.
- Location:
apps/api - Key Technologies: NestJS, Webpack.
3. Identity and Access: Better Auth
We use Better Auth v1 for secure authentication and account management. This handles session management, email verification, and password resets.
- Location: Integrated as a library and service within the API.
4. Persistence: MySQL & Drizzle ORM
Data is stored in a MySQL database. We use Drizzle ORM for type-safe database interactions and automated migrations.
- Location:
libs/api/db - Key Technologies: MySQL, Drizzle ORM.
Communication Protocols
- HTTP/REST: Primary protocol for authentication and standard business logic.
- WebSockets: (Planned) For real-time game state synchronization.
- SMTP: For outgoing transactional emails.
Scaling Strategy
The architecture is designed to be highly scalable:
- Stateless API: The NestJS backend is largely stateless, allowing for horizontal scaling behind a load balancer.
- Micro-Services Ready: The monorepo structure allows for easy extraction of specific logic into dedicated micro-services if needed.
- Game Server Provisioning: (Future) Dynamically instantiated game servers for high-performance multiplayer sessions.
For detailed component-level documentation, see the API Docs and Game Docs sections.
For the end-to-end authentication and profile change flow, see Auth Flow End to End.