Letschat / CONTRIBUTING.md
HonzaH's picture
Upload 171 files
9853b20 verified
|
Raw History Blame Contribute Delete
7.96 kB

Contributing to Let's Chat

Přehled

Vítejte v příspěvcích k Let's Chat! Tento dokument obsahuje všechny potřebné informace pro efektivní přispívání do projektu.

Rychlé odkazy: docs/REQUIREMENTS.md (funkční zadání), doc/design/ (UI), docs/DATAMODEL.md (data), docs/GITHUB_INSTRUCTIONS.md (workflow), docs/DEV-ONBOARDING.md (lokální setup).

Zásady přispívání

Senior Developer Mindset

  • Architektura-first: Před implementací navrhni řešení, zvaž alternativy
  • Kvalita před rychlostí: Kód musí být udržitelný, testovatelný, dokumentovaný
  • Code review jako standard: Každý PR musí projít review od senior developera

Best Practices

  • SOLID principles: Single responsibility, Open/closed, Liskov substitution, Interface segregation, Dependency inversion
  • DRY (Don't Repeat Yourself): Žádné duplicity kódu, konfigurací nebo instrukcí
  • KISS (Keep It Simple, Stupid): Jednoduchá řešení pro komplexní problémy
  • Clean Code: Srozumitelné názvy, malé funkce, dobré komentáře
  • Alignment: Každá změna musí odpovídat docs/REQUIREMENTS.md, doc/design/ a docs/DATAMODEL.md.

Technické standardy

  • TypeScript: Strict mode, žádné any, comprehensive types
  • Testing: Unit testy pro všechnu business logiku, integration testy pro API
  • Performance: Optimalizace queries, lazy loading, code splitting
  • Security: Input validation, SQL injection prevention, XSS protection

Vývojový workflow

1. Příprava

# Fork repository
# Clone your fork
git clone https://github.com/your-username/letschat2.git
cd letschat2

# Install dependencies
npm ci

# Setup local database (optional)
npm run db:local:init

2. Vývoj

# Create feature branch
git checkout -b feature/your-feature-name

# Run development server
npm run dev

# Run tests continuously
npm run test -- --watch

3. Testování

# Run all tests
npm test

# Run with coverage
npm test -- --coverage

# Run linting
npm run lint

# Run build
npm run build

4. Commit a Push

# Add changes
git add .

# Commit with conventional format
git commit -m "feat: add user authentication"

# Push to your fork
git push origin feature/your-feature-name

5. Pull Request

  • Vytvoř PR z vaší feature branche do master
  • Vyplň PR template kompletně
  • Požádej o review od senior developera
  • Adresuj všechny code review komentáře

Code Standards

TypeScript

// ✅ Good
interface User {
  id: string;
  email: string;
  createdAt: Date;
}

function createUser(data: CreateUserInput): Promise<User> {
  // Implementation
}

// ❌ Bad
function createUser(data: any): any {
  // Implementation
}

React Components

// ✅ Good
interface ButtonProps {
  children: React.ReactNode;
  variant?: 'primary' | 'secondary';
  onClick: () => void;
}

export function Button({ children, variant = 'primary', onClick }: ButtonProps) {
  return (
    <button
      className={clsx('btn', `btn-${variant}`)}
      onClick={onClick}
    >
      {children}
    </button>
  );
}

// ❌ Bad
export function Button({ children, ...props }) {
  return <button {...props}>{children}</button>;
}

API Routes

// ✅ Good
import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';

const schema = z.object({
  email: z.string().email(),
  password: z.string().min(8),
});

export async function POST(request: NextRequest) {
  try {
    const body = await request.json();
    const validated = schema.parse(body);
    
    // Business logic
    const result = await createUser(validated);
    
    return NextResponse.json(result);
  } catch (error) {
    return NextResponse.json(
      { error: 'Invalid input' },
      { status: 400 }
    );
  }
}

// ❌ Bad
export async function POST(request: NextRequest) {
  const body = await request.json();
  const user = await createUser(body);
  return NextResponse.json(user);
}

Testování

// ✅ Good
import { describe, it, expect, vi } from 'vitest';

describe('createUser', () => {
  it('should create user with valid data', async () => {
    const mockUser = { id: '1', email: 'test@example.com' };
    vi.mocked(createUserInDb).mockResolvedValue(mockUser);
    
    const result = await createUser({
      email: 'test@example.com',
      password: 'password123',
    });
    
    expect(result).toEqual(mockUser);
    expect(createUserInDb).toHaveBeenCalledWith({
      email: 'test@example.com',
      passwordHash: expect.any(String),
    });
  });
});

// ❌ Bad
describe('createUser', () => {
  it('works', async () => {
    const result = await createUser({ email: 'test' });
    expect(result).toBeDefined();
  });
});

Architektura

File Structure

src/
├── app/                 # Next.js app router
│   ├── api/            # API routes
│   ├── (auth)/         # Auth pages
│   └── (dashboard)/    # Protected pages
├── components/         # Reusable components
│   ├── ui/            # Base UI components
│   ├── forms/         # Form components
│   └── layout/        # Layout components
├── lib/               # Business logic
│   ├── supabase/      # Supabase utilities
│   ├── validations/   # Zod schemas
│   └── utils/         # Helper functions
├── hooks/             # Custom React hooks
├── types/             # TypeScript definitions
└── db/                # Database schemas

State Management

  • Local state: React useState/useReducer
  • Server state: SWR/React Query (plánováno)
  • Global state: Zustand stores
  • Form state: React Hook Form

Error Handling

// ✅ Good
try {
  const result = await riskyOperation();
  return { success: true, data: result };
} catch (error) {
  console.error('Operation failed:', error);
  return { success: false, error: error.message };
}

// ❌ Bad
const result = await riskyOperation();
return result;

Performance Guidelines

Frontend

  • Používej React.memo pro expensive komponenty
  • Implementuj lazy loading pro routes a komponenty
  • Optimalizuj images s Next.js Image component
  • Minimalizuj re-renders s useMemo/useCallback

Backend

  • Používej database indexes na časté queries
  • Implementuj pagination pro velké datasets
  • Cache expensive operations
  • Používej connection pooling

Bundle Size

  • Monitoruj bundle size s npm run build
  • Používej dynamic imports pro code splitting
  • Tree-shake unused dependencies
  • Optimalizuj third-party libraries

Security Checklist

  • Input validation na všech API endpoints
  • SQL injection prevention s parameterized queries
  • XSS protection s proper escaping
  • CSRF protection na state-changing operations
  • Rate limiting na sensitive endpoints
  • Proper error messages (bez sensitive info)
  • Secure headers (CSP, HSTS, etc.)
  • Dependency vulnerability scanning

Code Review Checklist

Must-haves

  • TypeScript strict mode bez chyb
  • Unit testy pro business logiku
  • ESLint bez warnings/errors
  • Build passes
  • Dokumentace aktualizována

Should-haves

  • Performance optimalizace
  • Accessibility compliance
  • Mobile responsiveness
  • Error boundaries
  • Loading states

Nice-to-haves

  • Integration testy
  • E2E testy
  • Performance benchmarks
  • Bundle size monitoring

Kontakt

Máte otázky? Kontaktujte maintainer team přes GitHub Issues nebo Discussions.