How tanavposwal/chess works
Main Components
• Frontend Application:
• Located under apps/frontend and built with Next.js.
• Handles page routing (e.g., chess game UI, user pages, authentication endpoints) and static asset management.
• Uses a custom UI package (located in packages/ui) to provide reusable components like buttons, cards, and chess board interfaces.
• Integrates with a backend API layer (found in apps/frontend/src/app/api) and global styling, configuration (tailwind.config.ts) and TypeScript settings.
• WebSocket (WS) Server:
• Found under apps/ws – serves as the real-time game engine backend.
• Implements the game logic with files such as Game.ts, GameManager.ts and exchange messages (messages.ts).
• Listens on PORT:8080 for client connections.
• Database Component:
• Located within packages/db and manages the database schema (Prisma schema) and migrations.
• Responsible for data persistence including authentication, user data, game persistence, etc.
• Shared Utilities & Configurations:
• TypeScript and ESLint configs (in packages/typescript-config and packages/eslint-config) ensure code quality and consistency.
• The UI library (packages/ui) centralizes design components used by the frontend.
• Other support libraries and generators (e.g., turbo generators within packages/ui) streamline maintenance.
Relationships and Interactions
• The Frontend communicates with the WS server:
• The user interface, running on PORT:3000, establishes WebSocket connections to the WS server to send/receive real-time game actions.
• The Frontend communicates with its own API endpoints:
• Next.js API routes (e.g., for user authentication, game actions) interact with the database and perform server-side functions.
• The WS server communicates with the Database:
• It could be interacting indirectly with persistence functionalities (for example, updating game states or user activity) or directly using shared modules.
• Shared Libraries:
• Both frontend and possibly the WS server depend on the UI and configuration packages to stay aligned with the overall design principles and coding standards.
Architectural Patterns & Design Principles
• Monorepo Architecture:
• The project is structured to enable shared resources (such as UI, ESLint, and TypeScript settings) across multiple apps (frontend and ws).
• Layered Architecture:
• The separation into frontend (presentation layer), WS (real-time communication and business logic), and database/persistence layers (data storage) is clear.
• API and WebSocket Integration:
• Clear separation between HTTP-based API calls (for non-real-time operations) and WebSocket communications (for gameplay interactions).