This guide provides detailed information for developers working on KeepWiz.
- Prerequisites
- Development Environment Setup
- Project Structure
- Development Workflow
- Testing
- Code Style and Standards
- Common Development Tasks
- Debugging
- Performance Optimization
Before you begin, ensure you have the following installed:
- Node.js: v18.0.0 or higher
- npm: v9.0.0 or higher (comes with Node.js)
- Git: For version control
- MongoDB: v7.0 or higher (or use Docker)
- Docker & Docker Compose: (Optional) For containerized development
- VS Code: With recommended extensions:
- ESLint
- Prettier
- ES7+ React/Redux/React-Native snippets
- MongoDB for VS Code
- Docker
git clone https://github.com/jkrumboe/wizard-tracker.git
cd wizard-trackerCopy the example environment file and configure it:
cp .env.example .envGenerate a secure JWT secret:
npm run setup-envStart all services (MongoDB, Backend, Frontend):
docker compose upAccess points:
- Frontend: http://localhost:8088
- Backend API: http://localhost:5000
- MongoDB Admin: http://localhost:8081
Backend Development:
cd backend
npm install
npm run devThe backend will run on http://localhost:5000 with hot reload.
Frontend Development:
cd frontend
npm install
npm run devThe frontend will run on http://localhost:3000 with hot module replacement (HMR).
Run backend and MongoDB in Docker, frontend locally:
# Start backend services
docker compose up -d backend mongodb
# In a separate terminal
cd frontend
npm install
npm run devThis provides the best of both worlds: stable backend services and fast frontend development.
wizard-tracker/
├── backend/ # Node.js/Express backend
│ ├── models/ # MongoDB models (Mongoose)
│ ├── routes/ # API route handlers
│ ├── middleware/ # Express middleware (auth, error handling)
│ ├── tests/ # Backend tests
│ └── server.js # Entry point
├── frontend/ # React frontend (Vite)
│ ├── src/
│ │ ├── app/ # App initialization and routing
│ │ ├── components/ # Reusable UI components
│ │ ├── pages/ # Page components
│ │ ├── shared/ # Shared utilities and logic
│ │ │ ├── api/ # API client and endpoints
│ │ │ ├── contexts/ # React contexts
│ │ │ ├── db/ # IndexedDB/Dexie setup
│ │ │ ├── hooks/ # Custom React hooks
│ │ │ ├── schemas/ # Data schemas and validation
│ │ │ ├── sync/ # Sync engine (online/offline)
│ │ │ └── utils/ # Utility functions
│ │ └── styles/ # CSS/SCSS styles
│ └── public/ # Static assets
├── scripts/ # Build and utility scripts
└── docker-compose.yml # Docker orchestration
Create a new branch for your feature:
git checkout -b feature/your-feature-name- Backend: Edit files in
backend/, server auto-restarts with nodemon - Frontend: Edit files in
frontend/src/, HMR updates the browser automatically - Models: Changes to MongoDB models require backend restart
Backend Tests:
cd backend
npm testFrontend Tests:
cd frontend
npm testRun linting:
# Frontend
cd frontend
npm run lint
# Backend
cd backend
npm run lintFix linting issues automatically:
npm run lint:fixFollow conventional commit messages:
git add .
git commit -m "feat: add new game mode"
git commit -m "fix: resolve sync conflict issue"
git commit -m "docs: update API documentation"Commit types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasks
The backend uses Jest for testing:
cd backend
npm test # Run all tests
npm test -- --watch # Run tests in watch mode
npm test -- --coverage # Run tests with coverage reportThe frontend uses Vitest and React Testing Library:
cd frontend
npm test # Run all tests
npm test -- --watch # Run tests in watch mode
npm test -- --coverage # Run tests with coverage reportTest the application manually by:
- Creating test users
- Creating and playing games
- Testing online/offline transitions
- Testing sync conflicts
- Testing PWA features (offline mode, install prompt)
- Use ES6+ syntax
- Use functional components with hooks
- Use async/await for asynchronous code
- Follow React hooks best practices
- Use prop-types or TypeScript for type checking
- One component per file
- Co-locate related files (component + styles + tests)
- Use index.js for clean exports
- Keep components small and focused
- Components: PascalCase (e.g.,
GameCard.jsx) - Hooks: camelCase with 'use' prefix (e.g.,
useGameState.js) - Utils: camelCase (e.g.,
formatDate.js) - Constants: UPPER_SNAKE_CASE (e.g.,
API_BASE_URL)
- Use CSS Modules or styled-components
- Follow BEM methodology for class naming
- Use CSS custom properties for theming
- Mobile-first responsive design
- Create route handler in
backend/routes/ - Add validation middleware if needed
- Update API documentation
- Add tests for the endpoint
- Update frontend API client in
frontend/src/shared/api/
- Create component in
frontend/src/pages/ - Add route in
frontend/src/app/App.jsx - Update navigation in
frontend/src/components/layout/Navbar.jsx - Add tests for the page
- Create model in
backend/models/ - Add any necessary indexes
- Update related API endpoints
- Add migration if needed
- Update documentation
cd frontend
npm run update-versionThis script updates version numbers in:
package.jsonmanifest.json- README badges
Using VS Code Debugger:
- Set breakpoints in your code
- Start the debugger with Node.js configuration
- Send requests to the API
Console Logging:
console.log('Debug info:', variable);
console.error('Error occurred:', error);React DevTools:
Install the React DevTools browser extension for component inspection.
Redux DevTools: (if using Redux)
Install Redux DevTools extension for state debugging.
Console Debugging:
console.log('State:', state);
console.table(arrayData);Network Tab:
Monitor API calls in browser DevTools Network tab.
MongoDB Compass:
Connect to mongodb://localhost:27017 to browse and query data.
Mongo Express:
Access MongoDB admin interface at http://localhost:8081
View container logs:
docker compose logs -f # All containers
docker compose logs -f backend # Specific containerEnter a running container:
docker exec -it wizard-backend sh- Code Splitting: Use dynamic imports for route-based splitting
- Lazy Loading: Load components and images on demand
- Memoization: Use
React.memo,useMemo,useCallback - Virtual Scrolling: For large lists
- Image Optimization: Use WebP format, lazy loading
- Bundle Analysis: Run
npm run build -- --analyze
- Database Indexing: Add indexes to frequently queried fields
- Query Optimization: Use projection to limit returned fields
- Caching: Implement Redis for frequently accessed data
- Connection Pooling: Configure MongoDB connection pool
- Compression: Use gzip compression middleware
- API Response Compression: Enable gzip on backend
- Request Batching: Combine multiple API calls
- Debouncing: Debounce search and input handlers
- Service Worker: Cache static assets and API responses
Port Already in Use:
# Windows
netstat -ano | findstr :5000
taskkill /PID <PID> /F
# Linux/Mac
lsof -ti:5000 | xargs killDocker Issues:
docker compose down -v # Remove volumes
docker system prune -f # Clean up
docker compose build --no-cache # Rebuild without cacheNode Modules Issues:
rm -rf node_modules package-lock.json
npm installHot Reload Not Working:
- Check if files are saved
- Restart the dev server
- Clear browser cache
- Check file watchers limit (Linux)
- Check existing documentation first
- Search GitHub issues for similar problems
- Create a new issue with detailed description
- Join the project discussions on GitHub