The Dutch Learning App uses a centralized constants system to eliminate magic numbers and ensure consistency across both the React Native application and Supabase Edge Functions.
- Location:
src/constants/directory - Files:
AppConfig.ts- Main app configuration (re-exports from supabase)Colors.ts- Centralized color constants
- Usage:
import { REVIEW_CONSTANTS } from '@/constants/AppConfig' - Colors Usage:
import { Colors } from '@/constants/Colors'
- Location:
supabase/functions/_shared/constants.ts - Purpose: Contains ALL application constants for Edge Functions
- Usage:
import { IMAGE_CONFIG, TOUCH_CONFIG } from '../_shared/constants.ts'
- Edge Functions Limitation: Cannot import from root project folders
- Separation of Concerns: Different environments, different needs
- Maintainability: Clear organization by feature and environment
MOBILE_WIDTH/MOBILE_HEIGHT: Optimized image dimensions for mobile (400x300)SELECTOR_OPTIONS_COUNT: Number of image options in selector (6)DEFAULT_QUERY_COUNT: Default count for multiple image queries (6)UNSPLASH: Unsplash API configuration (preferred size, orientation)PICSUM_ID_RANGE: Range for Lorem Picsum random IDs (1000)
MAX_TAP_DURATION: Maximum tap duration (300ms)MAX_TAP_DISTANCE: Maximum tap distance (10px)
CARD_MIN_HEIGHT: Minimum review card height (500px)ANIMATION_DURATION_*: Various animation durationsTOAST_DURATION_*: Toast notification durations
- Spaced Repetition System default values
- Easiness factor bounds
RATE_LIMIT_DELAY_MS: Delay between API calls (200ms)
MIN_CONTEXT_WORD_LENGTH: Minimum word length for context (3)STOP_WORDS: Common words to filter from search queries
When constants are modified, the system automatically:
- Git Hook Detection: Pre-commit hook detects changes to
constants.ts - User Notification: Displays deployment reminder with specific commands
- Manual Deploy: Developer runs appropriate NPM script
# Deploy all Edge Functions
npm run deploy:constants
# Deploy specific functions
npm run deploy:gemini # gemini-handler only
npm run deploy:images # get-multiple-images only
npm run deploy:edge-functions # All functions (no notification)- Always use constants instead of magic numbers
- Run deployment after constants changes
- Add descriptive comments for new constants
- Group related constants together
- Hardcode values in components or Edge Functions
- Forget to deploy after constants changes
- Duplicate constants across files
- Use inconsistent naming patterns
import { TOUCH_CONFIG, UI_CONFIG } from '@/constants/AppConfig'
import { Colors } from '@/constants/Colors'
// In component
const isQuickTap =
touchDuration < TOUCH_CONFIG.MAX_TAP_DURATION &&
touchDistance < TOUCH_CONFIG.MAX_TAP_DISTANCE
const styles = StyleSheet.create({
card: {
minHeight: UI_CONFIG.CARD_MIN_HEIGHT,
backgroundColor: Colors.background,
borderColor: Colors.primary,
},
})import { IMAGE_CONFIG, SEARCH_CONFIG } from '../_shared/constants.ts'
// In function
const imageUrl = `https://picsum.photos/${IMAGE_CONFIG.MOBILE_WIDTH}/${IMAGE_CONFIG.MOBILE_HEIGHT}`
const contextWords = words.filter(
word =>
word.length >= SEARCH_CONFIG.MIN_CONTEXT_WORD_LENGTH &&
!SEARCH_CONFIG.STOP_WORDS.includes(word.toLowerCase())
)Problem: Edge Functions still use old constant values after changes
Solution: Redeploy Edge Functions using npm run deploy:constants
Problem: No deployment reminder when committing constants changes
Solution: Ensure .husky/check-constants is executable (chmod +x .husky/check-constants)
Problem: Cannot import constants in React Native components
Solution: Use import { CONSTANT_NAME } from '@/constants/AppConfig' format
Consider adding automatic Edge Function deployment:
- GitHub Actions on constants file changes
- Webhook-triggered deployments
- Environment-specific constant management
- Runtime constant validation
- Type safety for constant values
- Configuration schema validation