-
Notifications
You must be signed in to change notification settings - Fork 0
Development Guide
This guide provides information for developers who want to contribute to or modify the MIND Diet Tracker PWA.
- Git for version control
- Node.js (version 18 or higher) for both client and server development
- Modern web browser with developer tools (Chrome, Firefox, Safari, Edge)
- Text editor or IDE (VS Code recommended)
- Docker and Docker Compose (optional, for container-based development)
-
Clone the repository
git clone https://github.com/NateEaton/mind-pwa.git cd mind-pwa -
Set up Git hooks (recommended)
cp scripts/pre-commit.example .git/hooks/pre-commit chmod +x .git/hooks/pre-commit
The pre-commit hook automatically updates
version.jsonwith commit information. -
Install dependencies
# Install root dependencies npm install # Install server dependencies (if working on cloud sync features) cd server npm install cd ..
-
Generate version file
npm run generate-version
Choose the appropriate development mode based on what you're working on:
Best for UI work, tracking logic, themes, and import/export features:
# Configure environment
echo "VITE_SERVER_FEATURES_ENABLED=false" > .env
echo "VITE_DEV_MODE=true" >> .env
# Start development server
cd client
npm run devAccess at: http://localhost:5173
Required when working on cloud synchronization, OAuth flows, or server components:
# Configure environment
echo "VITE_SERVER_FEATURES_ENABLED=true" > .env
echo "VITE_DEV_MODE=true" >> .env
echo "APP_BASE_URL=http://localhost:8080" >> .env
# Start OAuth server (Terminal 1)
cd server
npm run dev
# Start client development server (Terminal 2)
cd client
npm run devAccess at: http://localhost:8080
For environment variable details and OAuth provider setup, see the Installation Guide.
For detailed information about the codebase architecture and module organization, see the Technical Documentation.
Client Core (client/src/core/):
-
stateManager.js- Application state and data flow -
dataService.js- Local storage and data persistence -
trackingEngine.js- Date handling and tracking logic -
setupWizard.js- First-time user experience
User Interface (client/src/ui/):
-
renderer.js- UI rendering and state updates -
components.js- Reusable UI components -
templates.js- HTML template system
Cloud Sync (client/src/cloudSync/):
-
cloudSync.js- Main synchronization coordinator -
mergeStrategies.js- Conflict resolution logic - Cloud provider implementations in
cloudProviders/
Server (server/):
-
server.js- Express OAuth server (see Technical Documentation for architecture details)
-
Create a feature branch
git checkout -b feature/description-of-change
-
Make focused commits
- Keep commits small and focused on a single change
- Write descriptive commit messages
- The pre-commit hook will automatically update version information
-
Test thoroughly
- Test across multiple browsers (Chrome, Firefox, Safari, Edge)
- Test PWA installation behavior
- Test offline functionality
- For cloud sync changes, test OAuth flows with both providers
- Test both deployment modes if your changes affect feature gating
-
Create a pull request
- Include a clear description of changes
- Document any new dependencies or breaking changes
- Note which deployment modes you've tested
JavaScript Style:
- Use ES6+ features while maintaining browser compatibility
- Follow existing naming conventions and module patterns
- Add JSDoc comments for functions and classes
- Use feature gating (
if (__SERVER_FEATURES_ENABLED__)) for cloud sync code
Module Organization:
- Follow the established module structure
- Keep modules focused on single responsibilities
- Use explicit imports and exports
- Maintain clear dependencies between modules
Error Handling:
- Add appropriate logging using the logger system
- Handle both online and offline scenarios
- Provide graceful fallbacks for optional features
Client-Side Testing:
- Test core functionality without internet connection
- Verify state persistence across browser sessions
- Test date transitions using developer tools
- Validate PWA installation and offline behavior
Cloud Sync Testing:
- Test authentication flows with both providers
- Verify conflict resolution with multiple devices
- Test network constraint scenarios (Wi-Fi only mode)
- Validate sync behavior with various data states
Cross-Browser Testing:
- Chrome/Chromium (primary development target)
- Firefox (secondary target)
- Safari (iOS/macOS compatibility)
- Edge (Windows compatibility)
The application includes debugging tools accessible through the About dialog when developer mode is enabled.
- Set
VITE_DEV_MODE=truein your.envfile, or - In the browser console:
localStorage.setItem('devMode', 'true') - Refresh the application
- Open the About dialog to access developer controls
Simulate date transitions for testing:
- Open About dialog → Developer Controls
- Set a custom test date
- App will use the test date instead of system date
- Reset by clearing the override
Use cases:
- Testing day/week boundary transitions
- Validating reset and archival logic
- Testing historical data scenarios
For cloud sync development:
- Use multiple browser profiles or incognito windows to simulate multiple devices
- Monitor network requests in browser developer tools
- Check server logs for OAuth and token refresh issues
- Use the sync status indicators in Settings dialog
Console Debugging:
- The logger system provides module-based debug output
- Use
stateManager.getState()to inspect current application state - Check for errors in the console during state transitions
Storage Inspection:
- localStorage: Current state, preferences, and settings
- IndexedDB: Historical weekly data and large datasets
- Clear storage to test fresh installation scenarios
Network Monitoring:
- Monitor OAuth flows and token refresh requests
- Check for proper CORS handling
- Validate API request/response formats
# Start server with auto-restart
cd server
npm run dev
# Start server without auto-restart
npm start
# Check server logs (if using Docker)
docker-compose logs serverTesting Authentication Flows:
- Configure OAuth redirect URIs in cloud provider consoles for development URLs
- Test complete auth flow through setup wizard or settings
- Verify token refresh operations work correctly
- Monitor server logs for authentication issues
For OAuth architecture details, see Technical Documentation.
Food groups are defined in client/src/app.js. For the complete data structure and requirements, see Technical Documentation.
Steps:
- Add the new food group to the
foodGroupsarray - Update UI templates if needed for layout
- Test with existing user data to ensure compatibility
- Update color coding logic if required
The core tracking logic is in trackingEngine.js and stateManager.js. For architecture details, see Technical Documentation.
Development Considerations:
- Modify
checkDateAndReset()for new transition behaviors - Update week calculation logic if changing week definitions
- Test edge cases like timezone changes and system clock adjustments
- Add new action types to
ACTION_TYPESif needed - Update state schema version if changing data structure
For cloud sync architecture details, see Technical Documentation.
Adding New Providers:
- Create provider class in
client/src/cloudProviders/ - Implement the required interface methods
- Add OAuth endpoints to
server/server.js - Update setup wizard and settings UI
- Test complete authentication and sync flows
Modifying Sync Logic:
- Update merge strategies in
mergeStrategies.js - Modify conflict resolution rules
- Add new sync metadata fields if needed
- Test across multiple devices and network conditions
Component Development:
- Follow existing component patterns in
components.js - Use the template system in
templates.js - Test responsive behavior across device sizes
Theme System:
- Theme logic is in
themeManager.js - CSS variables are defined in
style.css - Test light, dark, and auto theme modes
State Management Problems:
- Check state structure matches expected schema
- Verify action dispatching and reducer logic
- Use
stateManager.getState()to inspect current state
Date Transition Issues:
- Use test date override to simulate specific scenarios
- Check
trackingEngine.jslogic for edge cases - Verify timezone handling and date string formatting
Storage Issues:
- Clear browser storage to test fresh installations
- Check for storage quota limitations
- Verify localStorage and IndexedDB operations
OAuth Flow Problems:
- Verify redirect URIs match cloud provider configuration
- Check environment variables are correctly set
- Monitor server logs for authentication errors
- Test with different browsers and incognito mode
Token Management Issues:
- Check token refresh logic in server code
- Verify client secret configuration
- Monitor network requests for token operations
CORS Configuration:
- Ensure proper origin configuration in server
- Check for preflight request handling
- Verify CORS headers in responses
Build Problems:
- Check environment variable configuration
- Verify feature gating is working correctly
- Ensure all dependencies are installed
Development Server Issues:
- Check port conflicts (client: 5173, server: 3000)
- Verify proxy configuration for full-stack mode
- Clear browser cache and restart servers
For development purposes, you can build manually to test specific configurations:
# Development build - client-only
cd client
VITE_SERVER_FEATURES_ENABLED=false npm run build
# Development build - server-enabled
cd client
VITE_SERVER_FEATURES_ENABLED=true npm run buildNote: For production deployment, use the deployment scripts documented in the Installation Guide rather than manual builds.
Before submitting changes that affect deployment:
-
Test both deployment modes
- Build and test client-only deployment
- Build and test server-enabled deployment
-
Verify feature gating
- Ensure cloud sync code is excluded from client-only builds
- Test that features are properly disabled/hidden
-
Test PWA functionality
- Verify installation works correctly
- Test offline behavior
- Check service worker caching
For complete deployment instructions, see the Installation Guide.
- All changes should go through pull request review
- Include testing notes and affected deployment modes
- Document any new dependencies or configuration requirements
- Update relevant documentation for user-facing changes
When making changes that affect:
- User experience: Update User Guide
- Installation/deployment: Update Installation Guide
- Cloud sync behavior: Update Cloud Sync Guide
- Architecture/internals: Update Technical Documentation
- The pre-commit hook automatically updates
version.json - Version information is displayed in the About dialog
- Build timestamp and commit hash are included for debugging
When reporting issues:
- Include browser and device information
- Note which deployment mode you're using
- Provide steps to reproduce the issue
- Include relevant console errors or logs
Main Topics
Technical Topics