Skip to content

Latest commit

 

History

History
747 lines (507 loc) · 20.6 KB

File metadata and controls

747 lines (507 loc) · 20.6 KB

Redezeit - Project Improvements

This document outlines recommended improvements to make the Redezeit project more maintainable, robust, and production-ready.

Status Overview

  • Total Lines of Code: ~4,587 (TypeScript/TSX)
  • Current Type Errors: 0 ✅ (Fixed in PR #332)
  • Current Lint Errors: 2
  • Test Coverage: Minimal (1 test file)
  • Outdated Dependencies: 37+
  • Security Vulnerabilities: 9 ✅ (all moderate, dev-only) - Fixed in PR #[TBD], reduced from 22
  • Node Version: >=22.2.0

🔴 Critical Priority

1. ✅ Fix TypeScript Errors (COMPLETED)

Status: ✅ Completed in PRs #331 and #332

Impact: High - Type safety is compromised, potential runtime errors

Completed Tasks:

  • Fix null assignment type errors in SpeakingTimeContent.tsx:275-279
  • Fix Document type mismatches in SpeakingTimeContent.tsx:283
  • Add proper type guards for page property in route loaders
  • Fix meta function type signature in blog post route
  • Add proper type assertions for Contentful fields that are currently typed as any
  • Fix array iteration type issues in tag filtering
  • Remove unused app/utils/i18n.ts file

Actual effort: ~4 hours


1b. ✅ Fix Security Vulnerabilities (COMPLETED - Reduced from 22 to 9)

Status: ✅ Completed in PR #[TBD]

Impact: High - Security risks, potential exploits

Completed Tasks:

  • Ran npm audit fix to auto-update vulnerable dependencies
  • Fixed 13 vulnerabilities automatically (all critical, high, and low severity issues)
  • Verified TypeScript compilation passes
  • Verified production build succeeds
  • All tests pass

Results:

  • Before: 22 vulnerabilities (1 critical, 4 high, 11 moderate, 6 low)
  • After: 9 moderate severity vulnerabilities
  • Fixed: All critical and high severity vulnerabilities ✅

Remaining vulnerabilities (all moderate, development-only):

  • esbuild (8 instances) - Only affects development server, not production. Fix requires breaking change to Vitest v4.
  • remark-mdx-frontmatter (1 instance) - Remix dependency, will be fixed in future Remix updates.

Packages updated:

  • @babel/helpers, @babel/runtime (fixed RegExp complexity)
  • @remix-run/express, @remix-run/node, @remix-run/serve (fixed URL manipulation)
  • brace-expansion (fixed ReDoS)
  • on-headers (fixed header manipulation)
  • tar-fs (fixed path traversal)
  • undici (fixed random values and certificate issues)
  • vitest (fixed critical RCE - updated to 2.1.9)

Actual effort: ~1.5 hours


2. ✅ Migrate to Biome for Linting and Formatting (COMPLETED)

Status: ✅ Completed in PR #334

Impact: High - Currently no working linter for project files, plus faster tooling

Issue: ESLint parsing errors in getContentfulEnvironment.js and tailwind.config.js suggest missing or misconfigured setup. Biome is significantly faster than ESLint (10-100x) and can replace both ESLint and Prettier.

Completed Tasks:

  • Install Biome: npm install --save-dev --save-exact @biomejs/biome
  • Initialize Biome: npx @biomejs/biome init
  • Configure biome.json with:
    • TypeScript and React support
    • JSX accessibility rules
    • Import sorting
    • Formatting rules
  • Remove ESLint and Prettier dependencies
  • Remove .prettierrc and .prettierignore files
  • Update npm scripts:
    • "lint": "biome check ."
    • "lint:fix": "biome check --write ."
    • "format": "biome format --write ."
  • Run auto-fix (fixed 128 files automatically)
  • Verify TypeScript compilation passes
  • Verify production build succeeds
  • Add pre-commit hook using Biome (husky + lint-staged) - deferred to future PR
  • Update CI/CD to use Biome - deferred to future PR

Results:

  • Auto-fixed: 128 files
  • Identified Issues: 44 errors, 62 warnings (mostly accessibility and code quality improvements)
  • TypeScript: ✅ All type checks pass
  • Production Build: ✅ Build succeeds

Remaining Work (for follow-up PRs):

  • Fix accessibility issues (missing alt text, button types, etc.)
  • Remove as any type assertions (see task #4)
  • Add pre-commit hooks
  • Update CI/CD pipeline

Actual effort: ~2 hours


3. Create Missing .env.template

Impact: Medium - New developers cannot easily set up the project

Issue: README.md references .env.template but file doesn't exist.

Tasks:

  • Create .env.template with all required variables:
    CONTENTFUL_SPACE=
    CONTENTFUL_ACCESSTOKEN=
    CONTENTFUL_ENVIRONMENT=master
    CONTENTFUL_MANAGEMENT_API_ACCESS_TOKEN=
    
  • Ensure .env is in .gitignore (✓ already done)
  • Add comments explaining where to find each value

Estimated effort: 15 minutes


4. Remove Type Assertions (as any)

Impact: High - Type safety bypass, defeats TypeScript purpose

Issue: Extensive use of as any in ContentBlocks.tsx (lines 39, 52, 64, 77, 98, 114, 130, 142, 154, 159, 171, 185, 199)

Tasks:

  • Create proper TypeScript discriminated union types for content blocks
  • Use type guards instead of as any assertions
  • Create helper functions with proper type narrowing
  • Consider using Contentful's generated types more effectively

Example refactor:

// Instead of: const { content } = item!.fields as any;
// Use proper type narrowing:
if (
  id === "centeredContent" &&
  item.sys.contentType.sys.id === "centeredContent"
) {
  const block = item as Entry<TypeCenteredContentSkeleton>;
  const { content, bgcolor } = block.fields;
  // ... rest of logic
}

Estimated effort: 6-8 hours


🟡 High Priority

5a. Set Up Test Infrastructure

Impact: High - Foundation for all future tests

Current state: Only 1 test file, Vitest has issues

Tasks:

  • Create vitest.config.ts with proper setup
  • Fix Vitest hanging issue (pool settings, environment config)
  • Add test setup file with React Testing Library
  • Add test utilities and mocks for Contentful
  • Set coverage targets (70% utilities, 60% components)
  • Update npm scripts for test workflows

Estimated effort: 3-4 hours


5b. Add Utility Function Tests

Impact: High - Test business logic

Tasks:

  • contentful.ts - Test data fetching functions
    • Test getPage, getPageById
    • Test getCoaches with filtering
    • Test getBlogposts, getBlogpost
    • Test error handling
  • getSearchPageContents.ts - Test coach filtering
  • getFlagCodes.ts - Test flag mapping
  • documentToSimpleString.ts - Expand existing test

Estimated effort: 6-8 hours


5c. Add Component Tests

Impact: Medium-High - Catch UI regressions

Tasks:

  • CoachCard.tsx - Test rendering and contact methods
  • ContentBlocks.tsx - Test block type rendering
  • CoachFilterTag.tsx - Test filter interactions
  • CookieBanner.tsx - Test consent management

Estimated effort: 6-8 hours


5d. Add Analytics and Route Tests

Impact: Medium - Ensure tracking and navigation work

Tasks:

  • gtag.client.ts - Test analytics tracking
  • Coach search route - Test filtering logic
  • Blog routes - Test rendering and navigation
  • Sitemap generation - Test XML output

Estimated effort: 5-6 hours


6a. Migrate from Remix v2 to React Router v7

Impact: High - Major architectural change, future-proofs the app

Context: React Router v7 is the successor to Remix. The Remix team recommends migrating to React Router v7 as it combines the best of both frameworks with better performance and a more streamlined API.

⚠️ REQUIRED READING: Before starting this migration, read and follow the official guide:

Tasks:

  • Read the entire migration guide: https://reactrouter.com/upgrading/remix
  • Install React Router v7 packages (follow guide for exact versions)
  • Update file-based routing (likely minimal changes per guide)
  • Migrate from Remix loaders/actions to React Router loaders/actions
  • Update data fetching patterns
  • Replace @remix-run/* imports with react-router equivalents (use codemod if available)
  • Update entry.client.tsx and entry.server.tsx (follow guide examples)
  • Update Netlify adapter (check for @react-router/netlify or follow deployment guide)
  • Update vite.config.ts to use React Router plugin
  • Update package.json scripts if needed
  • Test all routes thoroughly (especially loaders, actions, and error boundaries)
  • Update documentation and CLAUDE.md

Benefits:

  • Modern framework with active development
  • Better performance characteristics
  • Simplified mental model
  • Official successor to Remix

Notes:

  • The migration guide includes codemods to automate many changes
  • File-based routing conventions are largely compatible
  • Most breaking changes are in package names, not APIs

Estimated effort: 8-10 hours


6a2. Update Patch and Minor Dependencies

Impact: Medium - Quick security and bug fixes

Tasks:

  • Update TypeScript 5.7.2 → 5.9.3
  • Update Remix 2.15.2 → 2.17.1 (all packages)
  • Update all other patch/minor versions
  • Remove ESLint/Prettier if Biome is adopted
  • Run tests and build
  • Fix any breaking changes

Estimated effort: 2-3 hours


6b. Update React to v19

Impact: High - Major version with breaking changes

Tasks:

  • Create separate branch for React 19 upgrade
  • Update React and React-DOM to 19.2.0
  • Update @types/react and @types/react-dom
  • Review React 19 migration guide
  • Update deprecated APIs (if any)
  • Test thoroughly (especially forms and suspense)
  • Fix any type errors

Estimated effort: 3-4 hours


6c. Update Tailwind to v4

Impact: High - Major version with new engine

Tasks:

  • Create separate branch for Tailwind 4 upgrade
  • Review Tailwind v4 migration guide
  • Update Tailwind CSS and related plugins
  • Update configuration file format (if needed)
  • Test all components for styling regressions
  • Update custom CSS if needed

Estimated effort: 3-4 hours


6e. Update Other Major Dependencies

Impact: Medium - Gradual modernization

Tasks:

  • Update i18next 23.16.8 → 25.6.0
  • Update Contentful 10.15.1 → 11.8.7
  • Update Vite 5.4.11 → 7.1.11
  • Review migration guides for each
  • Test after each update
  • Fix breaking changes

Estimated effort: 4-6 hours


7. Improve Type Safety in Contentful Integration

Impact: Medium - Current type usage is incomplete

Issues:

  • Type assertions in contentful.ts (e.g., as string, as any)
  • Inconsistent use of generated Contentful types
  • Manual type casting of field values

Tasks:

  • Review and regenerate Contentful types
  • Add proper error handling for missing/invalid content
  • Create type guard functions for Contentful entries
  • Add JSDoc comments for complex type unions
  • Consider using Entry<T, 'WITHOUT_UNRESOLVABLE_LINKS'> consistently

Estimated effort: 4-6 hours


8. Add Error Boundary Improvements

Impact: Medium - Better user experience on errors

Tasks:

  • Add error tracking/logging (e.g., Sentry)
  • Improve BasicErrorBoundary component with:
    • Localized error messages
    • Different error states (404, 500, network errors)
    • User-friendly error UI
    • Retry mechanisms
  • Add error boundaries at route level for better isolation
  • Log errors to external service for monitoring

Estimated effort: 4-6 hours


🟠 Medium Priority

9. Improve Documentation

Impact: Medium - Helps onboarding and maintenance

Tasks:

  • Expand README with:
    • Architecture overview
    • Development workflow
    • Deployment process
    • Troubleshooting guide
    • Contributing guidelines
  • Document Contentful content model structure
  • Add JSDoc comments to complex functions
  • Create architecture decision records (ADRs) for major decisions
  • Document environment-specific configurations
  • Add component documentation (Storybook or similar)

Estimated effort: 6-8 hours


10. Resolve TODO Comments

Impact: Low-Medium - Clean up technical debt

Found in:

  • app/utils/contentful.ts:201 - "TODO: getGender requires lang due to getCoaches requires it"

Tasks:

  • Review TODO in contentful.ts about gender/language coupling
  • Search for any FIXMEs or XXX comments
  • Create issues for unresolved TODOs
  • Either fix or document why they exist

Estimated effort: 2-3 hours


11a. Component Performance Optimizations

Impact: Medium - Faster rendering

Tasks:

  • Add React.memo to expensive components (CoachCard, ContentBlocks children)
  • Implement virtual scrolling for coach list (react-window or react-virtual)
  • Memoize expensive calculations in filters
  • Add useMemo/useCallback where beneficial

Estimated effort: 3-4 hours


11b. Image and Asset Optimizations

Impact: Medium - Faster page loads

Tasks:

  • Add proper sizes attributes to all images
  • Review Contentful image CDN parameters
  • Lazy load images below the fold
  • Consider WebP/AVIF fallbacks (already partially done)
  • Optimize font loading (font-display already set)

Estimated effort: 3-4 hours


11c. Bundle and Caching Optimizations

Impact: Medium - Better performance metrics

Tasks:

  • Add route-level code splitting
  • Implement caching strategy for Contentful requests
  • Review and optimize bundle size (currently 1.8MB)
  • Add performance monitoring (Web Vitals)
  • Set up performance budgets

Estimated effort: 4-5 hours


12. Improve Analytics & Tracking

Impact: Medium - Better understanding of user behavior

Current state: GTM and GA4 setup, but tracking could be improved

Tasks:

  • Audit existing tracking events
  • Add TypeScript types for all GA events
  • Document all tracked events
  • Add conversion tracking
  • Implement event validation/testing
  • Consider adding privacy-focused analytics (Plausible, Fathom)
  • Review GDPR compliance

Estimated effort: 4-6 hours


13. Accessibility Improvements

Impact: Medium - Better UX for all users

Tasks:

  • Run accessibility audit (axe, Lighthouse)
  • Add proper ARIA labels throughout
  • Ensure keyboard navigation works everywhere
  • Add focus management in modals/filters
  • Test with screen readers
  • Add skip links
  • Ensure color contrast meets WCAG AA standards
  • Add alt text validation for images from Contentful

Estimated effort: 6-8 hours


14. Improve i18n Implementation

Impact: Medium - Better localization support

Tasks:

  • Audit translation completeness across all locales
  • Add missing translations
  • Implement translation fallbacks
  • Add pluralization support where needed
  • Consider using Contentful localization features more effectively
  • Add RTL support preparation
  • Document translation workflow for contributors

Estimated effort: 4-6 hours


🟢 Low Priority

15. Code Quality Improvements

Impact: Low-Medium - Better maintainability

Tasks:

  • If not using Biome: Add Prettier configuration (currently empty .prettierrc)
  • Configure import sorting (Biome handles this automatically)
  • Add consistent file naming convention
  • Extract magic strings to constants
  • Remove unused imports/variables (Biome can auto-fix this)
  • Standardize component prop interfaces naming
  • Add consistent error handling patterns
  • Remove commented-out code

Estimated effort: 4-6 hours


16. Developer Experience Improvements

Impact: Low-Medium - Faster development

Tasks:

  • Add VS Code recommended extensions and settings
  • Create debug configurations
  • Add npm scripts for common tasks:
    • npm run check-all - Run all checks
    • npm run clean - Clean build artifacts
    • npm run validate - Type check + lint + test
  • Document local development tips

Estimated effort: 3-4 hours


17. CI/CD Improvements

Impact: Low-Medium - Better deployment confidence

Current state: Only CodeQL analysis workflow exists

Tasks:

  • Add GitHub Actions for:
    • Run tests on PR
    • Type checking on PR
    • Biome check on PR (linting + formatting)
    • Build verification
    • Lighthouse CI for performance
    • Dependency vulnerability scanning
  • Add PR preview deployments (Netlify already supports this)
  • Add automatic changelog generation
  • Set up branch protection rules

Estimated effort: 4-6 hours


18. Security Improvements

Impact: Medium - Better security posture

Tasks:

  • Add security headers in netlify.toml:
    • Content-Security-Policy
    • X-Frame-Options
    • X-Content-Type-Options
    • Referrer-Policy
  • Audit third-party scripts (GTM, Brevo)
  • Implement subresource integrity (SRI) for external scripts
  • Add rate limiting for form submissions
  • Review cookie security settings
  • Add dependency vulnerability scanning in CI

Estimated effort: 3-4 hours


19. Content Management Improvements

Impact: Low - Better content workflow

Tasks:

  • Document Contentful content model
  • Create content entry templates/examples
  • Add content validation in loaders
  • Implement preview mode for unpublished content
  • Add webhook handlers for cache invalidation
  • Consider implementing incremental static regeneration (ISR)

Estimated effort: 4-6 hours


20. Clean Up Unused Code

Impact: Low - Reduced maintenance burden

Tasks:

  • Remove unused dependencies (check with knip)
  • Remove commented-out code in routes and components
  • Remove unused icons if any
  • Clean up .DS_Store files (add to .gitignore)
  • Remove remix-development-tools from production build

Estimated effort: 2-3 hours


📊 Summary

Effort Estimation

Priority Total Estimated Hours Number of Tasks
Critical 16-20 hours 4 tasks
High 40-59 hours 9 tasks
Medium 32-44 hours 9 tasks
Low 16-23 hours 6 tasks
Total 104-146 hours 28 tasks

Note: Tasks are now broken down into ≤10 hour chunks for easier PR review and implementation.

Recommended Approach

Phase 1: Critical Fixes (Sprint 1-2)

  1. Fix TypeScript errors
  2. Migrate to Biome for linting and formatting
  3. Create .env.template
  4. Remove as any type assertions

Phase 2: Foundation (Sprint 3-5)

  1. Set up test infrastructure (5a)
  2. Add utility function tests (5b)
  3. Add component tests (5c)
  4. Add analytics/route tests (5d)
  5. Update patch/minor dependencies (6a)
  6. Improve type safety in Contentful integration
  7. Add error boundary improvements

Phase 3: Major Updates (Sprint 6-9)

  1. Update React to v19 (6b)
  2. Update Tailwind to v4 (6c)
  3. Migrate from Remix v2 to React Router v7 (6d)
  4. Update other major dependencies (6e)

Phase 4: Quality & Performance (Sprint 10-12)

  1. Documentation improvements
  2. Component performance optimizations (11a)
  3. Image/asset optimizations (11b)
  4. Bundle/caching optimizations (11c)
  5. Accessibility improvements
  6. Analytics improvements
  7. i18n improvements

Phase 5: Polish (Sprint 13+)

  1. Code quality improvements
  2. Developer experience improvements
  3. CI/CD improvements
  4. Security improvements
  5. Content management improvements
  6. Clean up unused code
  7. Resolve TODO comments

🎯 Quick Wins

If time is limited, focus on these high-impact, low-effort tasks first:

  1. ✅ Create .env.template (15 min)
  2. ✅ Install and configure Biome (1-2 hours) - replaces ESLint + Prettier
  3. ✅ Fix critical TypeScript errors (3-4 hours)
  4. ✅ Update patch-level dependencies (1-2 hours)
  5. ✅ Add pre-commit hooks with Biome (1-2 hours)

Total: ~7-11 hours for significant improvement


📝 Notes

  • This analysis was performed on branch feat/adjust-filter-display
  • Last commit: 73d4b81 - chore: first bit of setting up Claude for the repo
  • Some improvements may uncover additional issues
  • Prioritize based on your team's capacity and project goals
  • Consider pairing junior and senior developers for knowledge transfer during refactoring

Generated: 2025-10-22 Codebase size: ~4,587 lines of TypeScript/TSX Node version: >=22.2.0