Development Workflows¶
Common development workflows and best practices for working with the Petfolio monorepo.
Daily Development Flow¶
flowchart TD
A[Pull latest main] --> B[Create feature branch]
B --> C[Make changes]
C --> D[Run affected tests]
D --> E{Tests pass?}
E -->|No| C
E -->|Yes| F[Commit changes]
F --> G[Push to remote]
G --> H[Create PR]
H --> I[CI Pipeline]
I --> J{All checks pass?}
J -->|No| C
J -->|Yes| K[Code review]
K --> L[Merge to main]
Getting Latest Changes¶
Always start with the latest code:
Creating a Feature Branch¶
Use descriptive branch names:
# Feature
git checkout -b feature/add-user-profile
# Bug fix
git checkout -b fix/login-validation-error
# Refactor
git checkout -b refactor/simplify-theme-provider
# Documentation
git checkout -b docs/update-architecture-guide
Making Changes¶
Affected Commands¶
Nx intelligently detects affected projects:
# Test only affected
npx nx affected:test
# Lint only affected
npx nx affected:lint
# Build only affected
npx nx affected:build
# See what's affected
npx nx affected:graph
Running Individual Projects¶
# Serve app
npx nx serve petfolio-business
# Test specific library
npx nx test ui-component-library --watch
# Lint and fix
npx nx lint petfolio-business --fix
Testing Workflow¶
Unit Tests¶
# Run all tests
npx nx run-many --target=test --all
# Test with coverage
npx nx test ui-component-library --coverage
# Watch mode for development
npx nx test ui-component-library --watch
E2E Tests¶
# Run all e2e tests
npx nx e2e petfolio-ui-tests
# Run specific test file
npx nx e2e petfolio-ui-tests --spec=login.spec.ts
# Debug mode
npx nx e2e petfolio-ui-tests --debug
Visual Testing with Storybook¶
# Start Storybook
npx nx storybook ui-component-library
# Build static Storybook
npx nx build-storybook ui-component-library
Committing Changes¶
Commit Message Format¶
Follow Conventional Commits:
Types:
feat: New featurefix: Bug fixdocs: Documentation onlystyle: Code style (formatting, missing semi-colons)refactor: Code change that neither fixes a bug nor adds a featureperf: Performance improvementtest: Adding or updating testsbuild: Build system or dependenciesci: CI configuration changeschore: Other changes that don't modify src or test files
Examples:
git commit -m "feat(ui): add Button component with variants"
git commit -m "fix(auth): resolve JWT token expiration issue"
git commit -m "docs: update installation guide with Python setup"
git commit -m "refactor(theme): simplify palette structure"
Pre-commit Checks¶
The repository may have pre-commit hooks that run:
- Linting
- Formatting
- Type checking
If commits are blocked, fix the issues and try again.
Pull Request Workflow¶
Creating a PR¶
# Push your branch
git push origin feature/my-new-feature
# Create PR via GitHub CLI (optional)
gh pr create --title "Add new feature" --body "Description of changes"
PR Checklist¶
Before creating a PR, ensure:
- All tests pass locally
- Code is linted and formatted
- No TypeScript errors
- Added tests for new features
- Updated documentation if needed
- Followed module boundary rules
CI Pipeline¶
The CI pipeline automatically runs:
- Affected detection: Determines what changed
- Lint: ESLint checks
- Test: Jest unit tests
- Build: Production build
- E2E: Playwright tests (if app changed)
- Security: Trivy vulnerability scan
- Docker: Container build (if applicable)
PR Review Process¶
- Automated checks: Must pass before review
- Code review: Team member reviews code
- Feedback: Address review comments
- Approval: Get approval from reviewer
- Merge: Squash and merge to main
Working with Dependencies¶
Adding Dependencies¶
# Add to main app
npm install --save package-name
# Add dev dependency
npm install --save-dev package-name
# Add to specific project (not common in Nx)
npm install --save package-name --workspace=apps/petfolio-business
Updating Dependencies¶
# Check outdated packages
npm outdated
# Update all to latest (be careful!)
npm update
# Update specific package
npm update package-name
Working with Components¶
Creating a New Component¶
# Create directory
mkdir -p libs/ui-component-library/src/lib/atoms/NewComponent
# Create files
touch libs/ui-component-library/src/lib/atoms/NewComponent/NewComponent.tsx
touch libs/ui-component-library/src/lib/atoms/NewComponent/NewComponent.spec.tsx
touch libs/ui-component-library/src/lib/atoms/NewComponent/NewComponent.stories.tsx
Component Template¶
NewComponent.tsx
import { FC } from 'react';
export interface NewComponentProps {
label: string;
onClick?: () => void;
}
export const NewComponent: FC<NewComponentProps> = ({ label, onClick }) => {
return <button onClick={onClick}>{label}</button>;
};
Export Component¶
Add to libs/ui-component-library/src/index.ts:
Using the Component¶
import { NewComponent } from '@ui-component-library';
export function MyPage() {
return <NewComponent label="Click me" />;
}
Debugging¶
VS Code Configuration¶
Use the provided launch configurations:
- Open VS Code
- Go to Run and Debug (Ctrl+Shift+D)
- Select configuration:
- "Next.js: debug server-side"
- "Next.js: debug client-side"
- "Next.js: debug full stack"
Browser DevTools¶
Access React DevTools for debugging:
# Install React DevTools extension
# Chrome: https://chrome.google.com/webstore/detail/react-developer-tools
Nx Console¶
Use Nx Console extension for VS Code:
- Install "Nx Console" extension
- View available commands in sidebar
- Run commands with UI
Hot Reload Issues¶
If hot reload stops working:
Performance Tips¶
Nx Caching¶
Nx caches computation results:
Parallel Execution¶
Run tasks in parallel:
# Lint all projects in parallel
npx nx run-many --target=lint --all --parallel=3
# Test in parallel
npx nx run-many --target=test --all --parallel=2
Troubleshooting¶
"Cannot find module" Errors¶
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
# Clear Nx cache
npx nx reset
TypeScript Errors¶
# Restart TypeScript server in VS Code
# Ctrl+Shift+P -> "TypeScript: Restart TS Server"
# Or rebuild
npx nx build petfolio-business
Port Already in Use¶
# Find process using port 4200
lsof -i :4200 # macOS/Linux
netstat -ano | findstr :4200 # Windows
# Kill process
kill -9 <PID> # macOS/Linux
taskkill /PID <PID> /F # Windows
Next Steps¶
- Testing Guide - Deep dive into testing strategies
- Docker Development - Container-based development
- Component Library - Working with UI components