This guide outlines the development workflow and best practices for contributing to FocusMaster.
We follow a feature branch workflow with the following branch structure:
main → Production-ready code
├── develop → Integration branch (future)
├── feature/* → New features
├── fix/* → Bug fixes
├── hotfix/* → Critical production fixes
└── maintenance → Maintenance and updates
feature/add-dark-mode-toggle
feature/spotify-integration
fix/session-api-500-error
fix/timer-countdown-bug
hotfix/critical-security-patch
maintenance/update-dependencies
We follow Conventional Commits for clear and consistent commit history.
<type>(<scope>): <subject>
<body>
<footer>
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, no logic change)refactor: Code refactoringperf: Performance improvementstest: Adding or updating testschore: Maintenance tasksci: CI/CD changes
# Feature
git commit -m "feat(timer): add customizable session durations"
# Bug fix
git commit -m "fix: add missing session CRUD endpoints
Add GET, PATCH, DELETE routes for /api/sessions/:id
Fixes 500 error when updating sessions from frontend"
# Documentation
git commit -m "docs: add API reference for sessions endpoint"
# Refactor
git commit -m "refactor(auth): simplify token validation logic"# Make sure you're on main and up to date
git checkout main
git pull origin main
# Create your feature branch
git checkout -b feature/your-feature-name# Make code changes
# ...
# Stage your changes
git add .
# Commit with a meaningful message
git commit -m "feat: add your feature description"# Fetch latest changes from main
git fetch origin main
# Rebase your branch on top of main
git rebase origin/main
# Or merge main into your branch
git merge origin/main# First push
git push -u origin feature/your-feature-name
# Subsequent pushes
git push- Go to GitHub repository
- Click "Compare & pull request"
- Fill in the PR template:
- Title: Clear, concise description
- Description: What, why, and how
- Screenshots: If UI changes
- Testing: Steps to test
- Request reviews
- Address feedback
- Merge when approved
# Run linter
npm run lint
# Format code
npm run format
# Run tests
npm test-
Write test first
// session.test.js describe('Session API', () => { it('should update session mood', async () => { // Test implementation }); });
-
Run test (it should fail)
npm test -
Write code to make it pass
-
Refactor while keeping tests green
- Code follows project style guide
- All tests pass
- No console.log or debug code
- Documentation updated if needed
- Commit messages are clear
- PR description is complete
Focus on:
- Logic: Does the code do what it's supposed to?
- Security: Any vulnerabilities?
- Performance: Any bottlenecks?
- Readability: Is it easy to understand?
- Testing: Are there adequate tests?
// Good: Use descriptive names
const getUserSessions = async (userId: string) => {
// ...
};
// Bad: Unclear names
const getData = async (id: string) => {
// ...
};
// Good: Early returns
const validateUser = (user) => {
if (!user) return false;
if (!user.email) return false;
return true;
};
// Bad: Nested conditions
const validateUser = (user) => {
if (user) {
if (user.email) {
return true;
}
}
return false;
};// Good: Named exports, clear props
interface TimerProps {
duration: number;
onComplete: () => void;
}
export const Timer: React.FC<TimerProps> = ({ duration, onComplete }) => {
// Implementation
};
// Good: Extract complex logic to custom hooks
const useTimer = (duration: number) => {
const [timeLeft, setTimeLeft] = useState(duration);
// Hook logic
return { timeLeft, start, pause, reset };
};{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"bradlc.vscode-tailwindcss",
"ms-vscode.vscode-typescript-next",
"mongodb.mongodb-vscode"
]
}// .vscode/settings.json
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}MAJOR.MINOR.PATCH
1.0.0 → 1.0.1 (Patch: Bug fixes)
1.0.1 → 1.1.0 (Minor: New features, backward compatible)
1.1.0 → 2.0.0 (Major: Breaking changes)
- All tests passing
- Documentation updated
- Changelog updated
- Version bumped in package.json
- Tagged in Git
- Deployed to production
- Smoke tests on production
# Create a test that reproduces the bug
describe('Bug: Session update fails', () => {
it('should update session without error', async () => {
// Test that currently fails
});
});git checkout -b fix/session-update-500-error// Fix the issue
// Make sure the test now passesgit commit -m "fix: add missing session CRUD endpoints
Fixes #123"# Use React DevTools Profiler
# Use Chrome DevTools Performance tab
# Check Network tab for slow requestsconsole.time('fetchSessions');
await fetchSessions();
console.timeEnd('fetchSessions');
// fetchSessions: 1234ms// Example: Add memoization
const MemoizedComponent = React.memo(ExpensiveComponent);
// Example: Use pagination
const sessions = await Session.find()
.limit(20)
.skip(page * 20);console.time('fetchSessions');
await fetchSessions();
console.timeEnd('fetchSessions');
// fetchSessions: 234ms Improved!- Never commit
.envfiles - Sanitize user inputs
- Use parameterized queries
- Implement rate limiting
- Keep dependencies updated
- Use HTTPS in production
- Implement CSRF protection
- Validate JWT tokens properly
# Check for vulnerabilities
npm audit
# Fix automatically if possible
npm audit fix
# Force fix (may have breaking changes)
npm audit fix --force- Adding new API endpoints → Update
docs/api/ - Changing database schema → Update
docs/architecture/database-schema.md - Adding new features → Update relevant guides
- Fixing bugs → Update troubleshooting guide if needed
- Use clear, concise language
- Include code examples
- Add diagrams where helpful (Mermaid)
- Keep examples up to date
- Link related documentation
- Comment on PRs promptly
- Be respectful and constructive
- Ask questions when unclear
- Explain your reasoning
# Share your branch
git push origin feature/your-feature
# Pull someone else's branch
git fetch origin
git checkout their-branch-name# .github/workflows/ci.yml (planned)
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Run linter
run: npm run lintRemember: Good code is not just working code, it's maintainable, tested, and well-documented code! 🚀