How jake-purton/towertech works
Main Components
a. Client/Frontend
• The base of the UI is in the Next.js “app” directory, which includes pages for login, register, profile, game display, game control, leaderboards (game and player), and additional components like joining or hosting a game.
• The “public” folder holds game assets (images etc.) used by the front-end.
b. API Layer / Backend
• The “app/api” directory holds subdirectories for each API endpoint (Register, checkToken, endGame, gameleaderboard, etc.). These endpoints are responsible for handling RESTful operations such as authentication, game logic updates, and data retrieval.
• The server.js file and additional files in “src” (like eventHandlers.js and rooms.js) indicate further backend logic, possibly for managing game events and room/session state.
c. Game Engine & Components
• The “components” folder (and its "src") contains the game engine’s core logic with modules for game controllers, rendering (PhaserGame.js), player management, enemy behavior, waves, UI widgets, and more. These represent the dynamic aspects of the game world.
d. Additional Services & Configuration
• Authentication is handled using JWTs (as indicated by the secret generation instructions).
• Database connectivity to PostgreSQL for persisting game data, user profiles, and leaderboards.
• Supporting libraries and frameworks like Tailwind (tailwind.config.ts), ESLint, and the Next.js config denote underlying tech choices.
Relationships and Interactions
• The Client (Next.js pages and assets) communicates with the API endpoints hosted under “app/api” to manage user sessions (registration, login, token validation) and to perform game-related operations (like retrieving leaderboards, updating game status, etc.).
• The API layer often orchestrates interactions between the client and the game engine logic. For example, playing a game or hosting a session may trigger functionality in the game components, which manage game state and events.
• Both real-time and regular HTTP communication may be in use. Files like “app/src/socket.ts” suggest use of WebSockets for real-time game interactions, while the REST API endpoints handle standard HTTP requests.
• The backend communicates with the PostgreSQL database to store persistent data, authentication details, and game statistics.
Architectural Patterns and Design Principles
• Separation of Concerns: Clear separation among presentation (Next.js pages and UI assets), game logic (components and Phaser integration), and business logic (API endpoints and service logic in “src/”).
• Modular Design: Both the API endpoints and game engine components are designed modularly (with individual directories for each API route and detailed organization for game entities, enemies, UI widgets, etc.).
• Client-Server Communication: Use of RESTful API endpoints and WebSocket connections facilitates real-time communication which is essential for interactive online gaming.
• Configuration Driven: Use of environment variables (JWT secrets, database tokens) emphasizes secure configuration practices.
Final Advice for the Principal Software Engineer
• Given the modular nature observed (with each API route and game module being separated into its own folder), aim to represent this modular breakdown in the system design so that every key functionality point (like user authentication, game logic, and leaderboard management) is individually highlighted.