.cursorrules
.llmrules
Always use Yarn for dependencies.
Sign in to like and favorite skills
.llmrules
Code Style and Structure
Here are some pieces of information you need to know about this project:
Always use Yarn for dependencies.
This file outlines the coding rules and best practices for the MMO RPG server project. These guidelines ensure clarity, maintainability, scalability, and performance in the codebase. They are intended for both developers and AI/LLM assistance.
Use WebAssembly (WASM) for CPU-Intensive Tasks
WebAssembly.instantiate.Leverage Worker Threads with SharedArrayBuffer
SharedArrayBuffer for efficient data access across threads.Maintain Thread Safety
Atomics to synchronize access to shared memory and prevent race conditions.Batch WASM Calls
Avoid Blocking the Main Thread
Use Efficient Data Structures
Int32Array, Float32Array) with SharedArrayBuffer.Implement Scalable Architecture
Monitor and Optimize Performance
--prof or external services.Ensure Compatibility and Stability
Document and Comment Code
yarn add, yarn install).yarn.lock for consistent installations.Use TypeScript Exclusively
.ts file extensions..js files to .ts and add type annotations for parameters, return types, and variables.const x = 5 instead of const x: number = 5).tsconfig.json with strict type checking enabled.Define Interfaces for Abstraction
interface Player { id: string; position: number }).Type Safety Best Practices
any type.Minimize Code Size
() => x, optional chaining ?., destructuring { a, b }).Optimize Algorithm Efficiency
Set for unique items, typed arrays for numeric data).Single Responsibility Principle (SRP)
LobbyManager only manages lobbies, not game logic).server.ts into separate I/O and logic handlers if it grows too complex.Open-Closed Principle (OCP)
LobbyManager.Liskov Substitution Principle (LSP)
VIPPlayer class should work wherever Player is expected).Interface Segregation Principle (ISP)
Movable and Damageable interfaces for entities).Dependency Inversion Principle (DIP)
Logger interface into classes).Minimize Token Count
pos instead of playerPosition) where readability is not compromised.// Init lobby instead of a multi-line explanation).Balance Readability and Conciseness
x for position).Folder Organization
File Naming
.ts extension for all TypeScript files.camelCase for files, PascalCase for classes).Testing Requirements
Code Quality
SharedArrayBuffer for concurrent processing.Organize the project as follows:
project-root/ ├── src/ │ ├── core/ │ │ ├── lobby/ │ │ │ ├── lobbyManager.ts │ │ │ └── lobbyWorker.ts │ │ └── game/ │ │ ├── player.ts │ │ └── world.ts │ ├── utils/ │ │ ├── logger.ts │ │ └── helpers.ts │ ├── config/ │ │ ├── env.ts │ │ └── constants.ts │ ├── wasm/ │ │ ├── procedural_generator.cpp │ │ ├── lobby_generator.wasm │ │ └── proceduralGenerator.ts │ ├── server/ │ │ └── server.ts │ └── index.ts ├── tests/ │ ├── core/ │ │ └── lobbyManager.test.ts │ └── utils/ │ └── helpers.test.ts ├── scripts/ │ └── build_wasm.sh ├── docs/ │ └── architecture.md ├── package.json ├── tsconfig.json └── .env
Naming Conventions
camelCase (e.g., lobbyManager.ts)PascalCase (e.g., LobbyManager)camelCase (e.g., createLobby)UPPER_CASE (e.g., MAX_PLAYERS)Modularization
import/export) for dependency management.Error Handling
try-catch blocks.utils/logger.ts.Comments and Documentation
@param, @returns).Asynchronous Code
async/await over callbacks or raw promises for readability.Testing
tests/.Linting and Formatting
Version Control
main, develop, feature branches).