This document defines the mandatory standards that must be followed throughout the project to maintain consistency, scalability, and facilitate maintenance.
CRITICAL: The response system is locked and CANNOT be modified. All endpoints MUST use the standard format.
{
"success": true,
"data": {
// Response data
},
"message": "Operation successful"
}{
"success": false,
"error": {
"type": "ValidationError",
"message": "Error message here",
"code": 400
}
}All controllers MUST:
- Import strict types:
import type { ControllerResponse } from '../core/types';
import { createSuccessResponse, createErrorResponse } from '../core/responses';- Use
ControllerResponse<T>as return type:
async function getPlayer(address: string): Promise<ControllerResponse<Player>> {
// ...
}- Use
createSuccessResponse()for successful responses:
return createSuccessResponse(player, 'Player retrieved successfully');- Use
createErrorResponse()for errors or let the middleware catch them:
try {
// ...
} catch (error) {
return createErrorResponse(error);
}TypeScript will prevent compilation of code that doesn't follow these standards.
- kebab-case:
fish.service.ts,player.controller.ts,api-response.ts
- camelCase:
feedFishBatch(),getPlayerByAddress(),createSuccessResponse()
- PascalCase:
FishService,PlayerController,ApiResponse,ValidationError
- RESTful + descriptive:
GET /api/player/:addressPOST /api/fish/feedPUT /api/tank/:id
/src
├── api/ # Routes grouped by resource
├── controllers/ # Controllers per endpoint
├── services/ # Game logic
├── models/ # Domain entities
└── core/
├── types/ # Shared types (LOCKED)
├── errors/ # Custom error classes
├── responses/ # Response helpers (LOCKED)
├── middleware/ # Global middleware
├── utils/ # Pure helpers
└── config/ # Configuration
All errors MUST use custom error classes:
ValidationError- For input validation (400)NotFoundError- For resources not found (404)ConflictError- For state conflicts (409)OnChainError- For on-chain operation errors (500)
Example:
if (!address) {
throw new ValidationError('Address is required');
}
if (!player) {
throw new NotFoundError(`Player with address ${address} not found`);
}The error middleware will automatically catch these errors and transform them to the standard format.
- Extract parameters from request
- Call corresponding service
- Return standardized responses
- DO NOT contain business logic
- Input validation
- Game logic
- Supabase calls
- Dojo/Starknet action execution
- Throw custom errors
- Define entity structures
- Define DTOs (Data Transfer Objects)
- DO NOT contain logic
- All files must have a
@fileoverviewJSDoc - Public functions must have JSDoc comments
- Use comments in English
- Document parameters and return values
- Strict mode enabled (
strict: true) - All types must be explicit
- Do not use
any(useunknownif necessary) - Validate types at compile time
- Descriptive commits using Conventional Commits
- One commit per file
- Messages in English by default
- All variables must be in
.env.example - Sensitive variables NEVER in code
- Validate required variables when starting the application
Remember: These standards are designed to keep the code scalable and maintainable. Following them is mandatory for all developers.