Skip to main content

Overview

Maintaining high code quality standards ensures that Horse Trust remains maintainable, scalable, and reliable. This guide outlines our coding conventions and best practices.

TypeScript Guidelines

All code in Horse Trust is written in TypeScript for type safety and better developer experience.

Type Safety

Always use explicit types:
Avoid any type:

TypeScript Configuration

Backend (server/tsconfig.json)

Frontend (client/tsconfig.json)

Code Style

General Principles

  1. Write clean, readable code - Code is read more often than it’s written
  2. Be consistent - Follow existing patterns in the codebase
  3. Keep it simple - Avoid over-engineering solutions
  4. Document when necessary - Explain complex logic and business rules

Naming Conventions

Variables and Functions - Use camelCase:
Classes and Interfaces - Use PascalCase:
Constants - Use UPPER_SNAKE_CASE:
Private class members - Prefix with underscore:

File Naming

  • Components - PascalCase: UserProfile.tsx, DonationCard.tsx
  • Utilities - camelCase: formatDate.ts, validateEmail.ts
  • Constants - camelCase: apiConfig.ts, routePaths.ts

Frontend Standards (Next.js)

Component Structure

React Best Practices

  1. Use functional components with hooks
  2. Destructure props in function parameters
  3. Use TypeScript interfaces for props
  4. Keep components small and focused
  5. Extract reusable logic into custom hooks

ESLint Configuration

We use ESLint with Next.js configuration:
Run linting:

Backend Standards (Express.js)

API Route Structure

API Response Format

Success response:
Error response:

Error Handling

Security Best Practices

Environment Variables

NEVER commit sensitive data:

Input Validation

Always validate user input:

Authentication

Use JWT for authentication:

Testing Standards

Write Tests for:

  1. New features - Ensure functionality works as expected
  2. Bug fixes - Prevent regression
  3. Critical paths - Authentication, payments, data processing
  4. Utility functions - Pure functions are easy to test

Test Structure

Documentation Standards

Code Comments

Comment complex logic:
Use JSDoc for public APIs:

Performance Guidelines

Database Queries

React Performance

Pre-Commit Checklist

Before committing your code:
  • Code follows TypeScript standards
  • All tests pass
  • ESLint shows no errors
  • No console.log statements (use proper logging)
  • No commented-out code
  • Environment variables not hardcoded
  • Code is properly formatted
  • Complex logic is documented

Code Review Focus Areas

When reviewing code, pay attention to:
  1. Type safety - Proper TypeScript usage
  2. Error handling - Try-catch blocks, validation
  3. Security - No exposed credentials, proper authentication
  4. Performance - Efficient queries, proper caching
  5. Readability - Clear naming, good structure
  6. Testing - Adequate test coverage
Code quality is everyone’s responsibility. Take pride in your code and help maintain our high standards.

Resources

Getting Help

If you have questions about code standards:
  • Contact the repository maintainer
  • Reach out to the team: S02-26-Equipo-33-Web-App
  • Review existing code for examples