Skip to main content

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:
Reference: app.ts:1-34

Rate Limiting

Two rate limiters protect the API:
Reference: app.ts:36-51

Routes

API routes are organized by domain:
Reference: app.ts:71-74

Error Handling

Reference: app.ts:53-85

index.ts

Creates the HTTP server and initializes Socket.io:
Reference: index.ts:1-142

Environment Variables

Required environment variables:
  • PORT - Server port (default: 3000)
  • CORS_ORIGINS - Comma-separated allowed origins
  • JWT_SECRET - Secret for signing JWT tokens
  • RATE_LIMIT_WINDOW_MS - Rate limit window in milliseconds
  • RATE_LIMIT_MAX - Maximum requests per window
  • BCRYPT_SALT_ROUNDS - Salt rounds for password hashing
  • NODE_ENV - Environment (development, production, test)

Health Check

Health check endpoint to verify server status:
Reference: app.ts:65-67