// GitHub Clean Code Guidelines
// Author: {{AUTHOR_NAME}} ({{GITHUB_USERNAME}})

// What you can build with this ruleset:
A maintainable and professional GitHub codebase with:
- Clean, readable code structure
- Consistent naming conventions
- Efficient code organization
- Proper documentation
- Reusable components
- Testable functions

// Project Structure
src/
  components/      # Reusable code components
    constants/     # Named constants
    utils/         # Utility functions
    validators/    # Input validation
  core/            # Core business logic
    services/      # Business services
    models/        # Data models
  tests/           # Test suites
    unit/          # Unit tests
    integration/   # Integration tests
  docs/            # Documentation
    guides/        # Usage guides
    api/           # API documentation

// Development Guidelines
1. Code Organization:
   - Use meaningful and descriptive names
   - Write short, focused functions
   - Follow single responsibility principle
   - Avoid code duplication (DRY)
   - Encapsulate complex logic
   - Use proper indentation

2. Code Standards:
   - Follow language conventions
   - Use consistent formatting
   - Apply proper spacing
   - Implement naming patterns
   - Structure files consistently
   - Document public interfaces

3. Code Quality:
   - Write self-documenting code
   - Avoid hard-coded values
   - Use meaningful comments
   - Handle errors properly
   - Write testable code
   - Refactor regularly

// Dependencies
Core:
- eslint: "^8.0.0"
- prettier: "^2.0.0"
- jest: "^27.0.0"
- typescript: "^4.0.0"

Optional:
- husky: "^7.0.0"
- commitlint: "^13.0.0"
- lint-staged: "^11.0.0"
- typedoc: "^0.22.0"

// Code Examples:

1. Clean Function Pattern:
```typescript
// Before
function calc(p: number): number {
  const d = p * 0.1;
  return p - d;
}

// After
function calculateDiscount(productPrice: number): number {
  const TEN_PERCENT_DISCOUNT = 0.1;
  const discountAmount = productPrice * TEN_PERCENT_DISCOUNT;
  return productPrice - discountAmount;
}
```

2. Single Responsibility Pattern:
```typescript
// Before
function processData(data: any) {
  // Validate
  if (!data.user) throw new Error('Invalid user');
  
  // Calculate
  const total = data.items.reduce((sum, item) => sum + item.price, 0);
  
  // Format
  return `Total: $${total.toFixed(2)}`;
}

// After
function validateUserData(data: any): void {
  if (!data.user) throw new Error('Invalid user');
}

function calculateTotal(items: Item[]): number {
  return items.reduce((sum, item) => sum + item.price, 0);
}

function formatCurrency(amount: number): string {
  return `Total: $${amount.toFixed(2)}`;
}

function processData(data: any): string {
  validateUserData(data);
  const total = calculateTotal(data.items);
  return formatCurrency(total);
}
```

3. Encapsulation Pattern:
```typescript
// Before
if (user.age >= 18 && user.country === 'US' && !user.restricted) {
  // Allow access
}

// After
function canAccessService(user: User): boolean {
  return (
    isAdult(user.age) &&
    isFromSupportedCountry(user.country) &&
    !isRestricted(user)
  );
}

function isAdult(age: number): boolean {
  return age >= 18;
}

function isFromSupportedCountry(country: string): boolean {
  return country === 'US';
}

function isRestricted(user: User): boolean {
  return user.restricted;
}
```

// Best Practices:
1. Use descriptive variable names
2. Keep functions small and focused
3. Follow DRY principle
4. Write self-documenting code
5. Use proper error handling
6. Implement consistent formatting
7. Write comprehensive tests
8. Refactor regularly
9. Use version control effectively
10. Document complex logic

// Security Considerations:
1. Validate all inputs
2. Sanitize user data
3. Handle errors securely
4. Use proper authentication
5. Implement authorization
6. Avoid security anti-patterns
7. Keep dependencies updated
8. Use secure configurations
9. Implement proper logging
10. Follow security guidelines