Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Latest commit

 

History

History
250 lines (179 loc) · 4.14 KB

File metadata and controls

250 lines (179 loc) · 4.14 KB

Development Guide

Development Environment Setup

Required Tools

  • Node.js >= 18.0.0
  • MongoDB >= 5.0
  • Git
  • npm or yarn
  • VS Code or Zed (recommended)

VS Code Extensions

  • ESLint
  • Prettier
  • MongoDB for VS Code
  • REST Client
  • GitLens

Code Style Guide

JavaScript Style Guide

  1. Variables

    • Use const for values that won't be reassigned
    • Use let for values that will be reassigned
    • Never use var
    • Use meaningful variable names
  2. Functions

    • Use arrow functions for callbacks
    • Use regular functions for methods
    • Use async/await for asynchronous operations
  3. Objects

    • Use object destructuring
    • Use object shorthand notation
    • Use computed property names when appropriate
  4. Arrays

    • Use array destructuring
    • Use array methods (map, filter, reduce)
    • Use spread operator for array operations

Naming Conventions

  1. Files

    • Use kebab-case for file names
    • Use .js extension for JavaScript files
    • Use .test.js for test files
  2. Variables and Functions

    • Use camelCase for variables and functions
    • Use PascalCase for classes and components
    • Use UPPER_CASE for constants
  3. Database

    • Use snake_case for database fields
    • Use plural form for collection names
    • Use singular form for model names

Testing

Unit Tests

  • Test individual functions and components
  • Mock external dependencies
  • Use Jest for testing framework
  • Aim for high test coverage

Integration Tests

  • Test API endpoints
  • Test database operations
  • Test authentication flows
  • Test error handling

Running Tests

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

# Run specific test file
npm test -- path/to/test.js

# Run tests in watch mode
npm test -- --watch

Database

Schema Design

  • Use Mongoose schemas
  • Define indexes for frequently queried fields
  • Use appropriate data types
  • Add validation rules

Migrations

  • Use migrations for schema changes
  • Version control migration files
  • Test migrations before applying

Seeding

  • Create seed data for development
  • Include test cases
  • Document seed data structure

API Development

Endpoint Structure

  • Use RESTful conventions
  • Version APIs
  • Use appropriate HTTP methods
  • Include proper status codes

Request Validation

  • Validate all inputs
  • Use Joi for validation
  • Return clear error messages
  • Handle edge cases

Response Format

{
  "success": true,
  "data": {},
  "meta": {
    "page": 1,
    "limit": 10,
    "total": 100
  }
}

Error Handling

Error Types

  • ValidationError
  • AuthenticationError
  • AuthorizationError
  • NotFoundError
  • DatabaseError

Error Response Format

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Error message",
    "details": {}
  }
}

Logging

Log Levels

  • ERROR: For errors that need immediate attention
  • WARN: For potentially harmful situations
  • INFO: For general operational information
  • DEBUG: For detailed debugging information

Log Format

{
  "timestamp": "2024-01-01T00:00:00.000Z",
  "level": "info",
  "message": "Operation completed",
  "context": {
    "userId": "123",
    "operation": "create_report"
  }
}

Performance Optimization

Database

  • Use appropriate indexes
  • Implement pagination
  • Use lean queries when possible
  • Cache frequently accessed data

API

  • Implement rate limiting
  • Use compression
  • Enable caching headers
  • Optimize response payload

Security

Authentication

  • Use JWT for authentication
  • Implement refresh tokens
  • Secure password storage
  • Rate limit login attempts

Authorization

  • Use role-based access control
  • Validate permissions
  • Sanitize user inputs
  • Prevent SQL injection

Deployment

Environment Variables

  • Use .env for local development
  • Use environment variables in production
  • Never commit sensitive data
  • Document all required variables

Build Process

  • Use production build
  • Minify assets
  • Optimize images
  • Enable compression

Monitoring

  • Set up error tracking
  • Monitor performance
  • Track user activity
  • Set up alerts