Common Tasks & Solutions
This document provides step-by-step guides for common tasks you'll encounter as an intern on the ViBe project. Use these as reference when working on assignments.
Frontend Tasks
Creating a New Component
-
Plan your component
- Define props and state
- Sketch the component structure
-
Create component file
touch src/components/ui/index.tsx
-
Implement the component
import React from 'react';
interface YourComponentProps {
title: string;
// Add other props as needed
}
export function YourComponent({ title }: YourComponentProps) {
return (
<div className="p-4 bg-white rounded shadow">
<h2 className="text-xl font-bold">{title}</h2>
{/* Your component content */}
</div>
);
} -
Document your component
- Add TSDoc comments
- Create usage examples if complex
Adding a New Page
-
Create page file
touch src/pages/YourNewPage.tsx
-
Implement the page
import React from 'react';
import { Layout } from '@/components/Layout';
export default function YourNewPage() {
return (
<Layout>
<div className="container mx-auto py-8">
<h1 className="text-2xl font-bold">Your New Page</h1>
{/* Page content */}
</div>
</Layout>
);
} -
Add route to the page
- Navigate to the router configuration
- Add your new route
Backend Tasks
Creating a New API Endpoint
-
Identify the module
- Determine which module your endpoint belongs to
- If it's a new feature, consider creating a new module
-
Create input types
// src/modules/your-module/classes/your-input-types.ts
import { IsString, IsNotEmpty } from 'class-validator';
export class CreateYourResourceBody {
@IsString()
@IsNotEmpty()
name: string;
// Add other properties with validation
}
// For query parameters
export class GetYourResourceQueryParams {
// Query params properties
}
// For route parameters
export class GetYourResourceParams {
// Route params properties
} -
Create or update controller
// src/modules/your-module/controllers/your-controller.ts
import { Controller, Post, Body } from 'routing-controllers';
import { Service } from 'typedi';
import { CreateYourResourceBody } from '../classes/your-input-types';
@Controller('/your-endpoint')
@Service()
export class YourController {
constructor(private yourService: YourService) {}
@Post('/')
async createSomething(@Body() body: CreateYourResourceBody) {
return this.yourService.createSomething(body);
}
} -
Implement the service
// src/modules/your-module/services/your-service.ts
import { Service } from 'typedi';
import { CreateYourResourceBody } from '../classes/your-input-types';
@Service()
export class YourService {
async createSomething(body: CreateYourResourceBody) {
// Implementation
return { success: true, data: body };
}
} -
Write tests
- Create unit tests for your service
- Create integration tests for your API endpoint
Documentation Tasks
Updating Existing Documentation
-
Locate the documentation
- Find the relevant Markdown file in the
/docs
directory
- Find the relevant Markdown file in the
-
Make your changes
- Update content as needed
- Follow the existing formatting style
-
Test locally
cd docs
pnpm start -
Create a PR
- Follow the PR Guide
- Use
doc
as the type in your commit message
Creating New Documentation
-
Determine the appropriate location
- Choose the right section for your documentation
- Create a new file with
.md
extension
-
Add frontmatter
---
title: Your Documentation Title
sidebar_position: X
--- -
Write your content
- Use clear headings and subheadings
- Include code examples where helpful
- Add links to related documentation
-
Test and submit
- Preview locally
- Create a PR with descriptive title and body
Troubleshooting Common Issues
Frontend Build Errors
Problem: TypeScript errors during build
Solution:
- Check error messages carefully
- Fix type definitions or add proper typing
- If using third-party libraries, check if types are installed:
pnpm add -D @types/library-name
Backend Server Won't Start
Problem: Server crashes on startup
Solution:
- Check logs for specific error messages
- Verify environment variables are set correctly
- Make sure database connection is properly configured
- Check port conflicts (another service might be using the same port)
Git Issues
Problem: Merge conflicts
Solution:
- Pull latest changes from the main branch
- Resolve conflicts in each file
- Test your changes after resolving conflicts
- Commit the resolved conflicts
Reference
If you encounter issues not covered here, don't hesitate to ask your mentor or teammates for assistance!