Architecture
The Horse Trust backend is built with Express.js and TypeScript, providing a RESTful API and real-time communication via Socket.io.Tech Stack
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (JSON Web Tokens)
- Real-time: Socket.io
- Security: Helmet, CORS, Rate Limiting
Server Setup
The application is initialized in two main files:app.ts
Configures the Express application with middleware and routes:Rate Limiting
Two rate limiters protect the API:Routes
API routes are organized by domain:Error Handling
index.ts
Creates the HTTP server and initializes Socket.io:Environment Variables
Required environment variables:PORT- Server port (default: 3000)CORS_ORIGINS- Comma-separated allowed originsJWT_SECRET- Secret for signing JWT tokensRATE_LIMIT_WINDOW_MS- Rate limit window in millisecondsRATE_LIMIT_MAX- Maximum requests per windowBCRYPT_SALT_ROUNDS- Salt rounds for password hashingNODE_ENV- Environment (development, production, test)

