Thank you for your interest in contributing! This guide will help you get started.
# Fork the repository on GitHub, then clone your fork
git clone https://github.com/YOUR_USERNAME/Nextjs-Ecommerce.git
cd Nextjs-Ecommerce
# Add upstream remote
git remote add upstream https://github.com/ORIGINAL_OWNER/Nextjs-Ecommerce.gitFollow the complete setup guide in DEV_SETUP.md.
Quick setup:
# Install dependencies
npm install
# Copy environment file
cp .env.example .env
# Set up database
docker-compose up -d postgres
npx prisma migrate dev
npm run db:seed
# Start development server
npm run dev# Update your main branch
git checkout main
git pull upstream main
# Create a feature branch
git checkout -b feature/your-feature-name
# or
git checkout -b fix/bug-description- Write clean, readable code
- Follow the existing code style
- Add tests for new features
- Update documentation as needed
# Run all tests
npm test
# Run specific test suites
npm run test:unit
npm run test:a11y
npm run test:e2e:open
# Type checking
npm run type-check
# Linting
npm run lintWe follow conventional commits:
# Format: <type>(<scope>): <description>
git commit -m "feat(auth): add Google OAuth integration"
git commit -m "fix(cart): resolve quantity update bug"
git commit -m "docs(readme): update installation steps"
git commit -m "test(products): add product filtering tests"Commit Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style/formatting (no code change)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasksperf: Performance improvements
# Push to your fork
git push origin feature/your-feature-name
# Go to GitHub and create a Pull Request- Use TypeScript for all new code
- Avoid
anytypes - use proper typing - Use interfaces for object shapes
- Export types that may be reused
// ✅ Good
interface ProductProps {
name: string;
price: number;
inStock: boolean;
}
// ❌ Avoid
const product: any = { ... };- Use functional components with hooks
- Prefer server components unless you need client-side features
- Use
"use client"directive only when necessary - Keep components small and focused
// Server Component (default)
export default function ProductGrid({ products }: Props) {
return <div>...</div>;
}
// Client Component (only when needed)
"use client";
import { useState } from 'react';
export function AddToCart({ productId }: Props) {
const [loading, setLoading] = useState(false);
// ...
}- Components:
PascalCase.tsx(e.g.,ProductCard.tsx) - Utilities:
kebab-case.ts(e.g.,format-currency.ts) - Routes:
page.tsx,layout.tsx,route.ts - Tests:
*.test.tsor*.test.tsx
// 1. External imports
import { useState } from 'react';
import { Button } from '@/components/ui/button';
// 2. Internal imports - absolute paths
import { formatCurrency } from '@/lib/utils';
import { getProducts } from '@/server/queries/products';
// 3. Relative imports
import { ProductCard } from './product-card';
// 4. Types
import type { Product } from '@prisma/client';We use Prettier for consistent formatting:
# Format all files
npm run format
# Check formatting
npm run format:checkSettings (automatically applied):
- Single quotes
- 2 space indentation
- Trailing commas
- Semicolons required
- Line width: 80 characters
All new features should include tests:
// Unit Test Example
describe('formatCurrency', () => {
it('should format USD correctly', () => {
expect(formatCurrency(29.99)).toBe('$29.99');
});
});
// Component Test Example
describe('AddToCart', () => {
it('should add product to cart', async () => {
render(<AddToCart productId="123" />);
await userEvent.click(screen.getByRole('button'));
expect(mockAddToCart).toHaveBeenCalledWith('123');
});
});When modifying the database schema:
# 1. Edit prisma/schema.prisma
# 2. Create a migration
npx prisma migrate dev --name add_user_preferences
# 3. Update seed file if needed
# Edit: prisma/seed.ts
# 4. Test migration
npm run db:seedBefore submitting, ensure:
- All tests pass (
npm test) - No TypeScript errors (
npm run type-check) - No linting errors (
npm run lint) - Code is formatted (
npm run format) - New features have tests
- Documentation is updated
- Commit messages follow conventions
- PR description clearly explains changes
## Description
Brief description of what this PR does
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
How to test these changes:
1. Step 1
2. Step 2
## Screenshots (if applicable)
Add screenshots here
## Checklist
- [ ] Tests pass
- [ ] Code is formatted
- [ ] Documentation updated- Submit your PR
- A maintainer will review within 1-3 days
- Address any feedback
- Once approved, your PR will be merged!
Nextjs-Ecommerce/
├── app/ # Next.js App Router
│ ├── (store)/ # Store pages (marketing layout)
│ ├── (account)/ # User account pages
│ ├── admin/ # Admin dashboard
│ └── api/ # API routes
├── components/ # React components
│ └── ui/ # Reusable UI components
├── lib/ # Utility functions
├── server/ # Server-side code
│ ├── actions/ # Server actions
│ └── queries/ # Database queries
├── prisma/ # Database schema & migrations
├── tests/ # Test files
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ ├── a11y/ # Accessibility tests
│ └── e2e/ # End-to-end tests
└── docs/ # Documentation
Server Actions vs API Routes:
- Prefer server actions for mutations (in
server/actions/) - Use API routes only for webhooks or third-party integrations
Data Fetching:
- Server queries in
server/queries/for data fetching - Cache with
unstable_cachewhen appropriate - Use React Server Components for automatic caching
Styling:
- Tailwind CSS for all styling
- Use
cn()utility for class merging - shadcn/ui components for UI elements
- 📖 Read the Development Setup Guide
- 📋 Check existing Issues
- 💬 Start a Discussion
- 📧 Contact maintainers
Be respectful and professional. We're all here to learn and build together!
Thank you for contributing! 🎉