Contribution Guidelines
8. Contribution Guidelines
8.1. Code Style & Best Practices
Coding Standards
-
TypeScript Guidelines
// Use explicit types interface User { id: string; email: string; role: UserRole; metadata?: Record<string, unknown>; } // Use enums for fixed values enum UserRole { ADMIN = 'admin', USER = 'user', GUEST = 'guest', } // Use meaningful variable names const userSubscription: Subscription; // β const sub: Subscription; // β
-
React Components
// Use functional components const UserProfile: React.FC<UserProfileProps> = ({ user, onUpdate }) => { // Use hooks at the top level const [isEditing, setIsEditing] = useState(false); const { data, loading } = useQuery(USER_QUERY); // Group related state const { name, email } = user; return ( <div className="user-profile"> {/* JSX */} </div> ); };
-
File Organization
src/ βββ components/ β βββ common/ # Shared components β βββ features/ # Feature-specific components β βββ layouts/ # Layout components βββ hooks/ β βββ useAuth.ts # Authentication hook β βββ useForm.ts # Form handling hook βββ utils/ βββ api.ts # API utilities βββ validation.ts # Validation helpers
[!NOTE] πΈ Screenshot Needed: Code style guide examples and linting configuration
Git Workflow
-
Branch Naming
# Feature branches feature/user-authentication feature/payment-integration # Bug fixes fix/login-error fix/database-connection # Documentation docs/api-documentation docs/setup-guide
-
Commit Messages
# Format: <type>(<scope>): <description> feat(auth): implement OAuth2 authentication fix(db): resolve connection timeout issues docs(api): update endpoint documentation style(ui): improve button component styling
-
Pull Request Template
## Description Brief description of the changes ## Type of Change - [ ] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Documentation update ## Testing Steps to test the changes ## Screenshots If applicable, add screenshots
[!NOTE] πΈ Screenshot Needed: Git workflow and PR process visualization
8.2. Development Workflow
Setting Up Development Environment
-
Local Setup
# Clone repository git clone https://github.com/your-username/daas-boilerplate.git # Install dependencies yarn install # Set up environment cp .env.example .env # Start development servers yarn dev
-
Development Tools
{ "devDependencies": { "eslint": "^8.0.0", "prettier": "^2.0.0", "husky": "^7.0.0", "lint-staged": "^12.0.0" }, "scripts": { "lint": "eslint . --ext .ts,.tsx", "format": "prettier --write \"**/*.{ts,tsx,json,md}\"" } }
Testing Guidelines
-
Unit Tests
describe('UserService', () => { it('should create a new user', async () => { const user = await UserService.create({ email: 'test@example.com', password: 'password123', }); expect(user).toBeDefined(); expect(user.email).toBe('test@example.com'); }); });
-
Integration Tests
describe('Authentication Flow', () => { it('should authenticate user and return token', async () => { const response = await request(app) .post('/api/auth/login') .send({ email: 'test@example.com', password: 'password123', }); expect(response.status).toBe(200); expect(response.body.token).toBeDefined(); }); });
[!NOTE] πΈ Screenshot Needed: Test coverage and reporting interface
8.3. Documentation Standards
Code Documentation
-
Function Documentation
/** * Processes a user subscription payment * @param userId - The ID of the user * @param planId - The ID of the subscription plan * @param paymentMethod - Payment method details * @returns Promise<PaymentResult> * @throws PaymentError if processing fails */ async function processSubscription( userId: string, planId: string, paymentMethod: PaymentMethod ): Promise<PaymentResult> { // Implementation }
-
Component Documentation
/** * Displays user profile information and allows editing * @component * @example * ```tsx * <UserProfile * user={currentUser} * onUpdate={handleUpdate} * editable={true} * /> * ``` */ interface UserProfileProps { /** The user object containing profile information */ user: User; /** Callback function when profile is updated */ onUpdate: (user: User) => void; /** Whether the profile is editable */ editable?: boolean; }
API Documentation
- Endpoint Documentation
/** * @api {post} /api/users Create User * @apiName CreateUser * @apiGroup Users * @apiVersion 1.0.0 * * @apiParam {String} email User's email * @apiParam {String} password User's password * @apiParam {String} [name] User's full name * * @apiSuccess {String} id User's unique ID * @apiSuccess {String} email User's email * @apiSuccess {String} name User's name * @apiSuccess {Date} createdAt Account creation date */
[!NOTE] πΈ Screenshot Needed: API documentation portal
8.4. Review Process
Code Review Guidelines
-
Review Checklist
- [ ] Code follows style guidelines - [ ] Tests are included and passing - [ ] Documentation is updated - [ ] No security vulnerabilities - [ ] Performance impact considered - [ ] Breaking changes documented
-
Review Comments
// Good comment // Consider using optional chaining here to handle undefined values const userName = user?.profile?.name; // Bad comment // This is wrong
Continuous Integration
- CI Pipeline
name: CI on: push: branches: [main, develop] pull_request: branches: [main, develop] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install dependencies run: yarn install - name: Run tests run: yarn test - name: Run linting run: yarn lint
[!NOTE] π Diagram Needed: CI/CD pipeline workflow