Skip to content

Cleanup: Codebase Decoupling and Legacy Code Removal#8

Merged
Isaiahriveraa merged 7 commits into
mainfrom
cleanup/remove-dead-code
Dec 24, 2025
Merged

Cleanup: Codebase Decoupling and Legacy Code Removal#8
Isaiahriveraa merged 7 commits into
mainfrom
cleanup/remove-dead-code

Conversation

@Isaiahriveraa

@Isaiahriveraa Isaiahriveraa commented Dec 24, 2025

Copy link
Copy Markdown
Owner

Summary

This PR cleans up redundant legacy code and refines the authentication flow by fixing potential redirect issues. It also stabilizes the CI/CD pipeline by providing a correctly formatted mock environment for Clerk.

What problem does it solve?

  1. Redundancy: Removes unused components and legacy pages.
  2. Auth Reliability: Fixes a UX issue where the SignUpPage ignored redirect parameters. Wraps auth pages in <Suspense> to prevent de-opting to client-side rendering during build.
  3. Database Stability: Improves Mongoose model registration to be robust in serverless/hot-reload environments.
  4. CI/CD Fix: Resolves a critical build failure (InvalidCharacterError) in CI caused by an incorrectly formatted dummy Clerk Publishable Key.

Context / Background

The project has already transitioned to a minimalist design. This PR represents the final cleanup phase to remove code that is no longer in use and to stabilize the development workflow.

Changes

  • Auth Fixes: Updated SignUpPage to respect ?redirect= param. Wrapped LoginPage and SignUpPage in <Suspense>.
  • CI/CD: Updated .github/workflows/ci.yml with a syntactically valid mock Clerk key to satisfy the SDK's Base64 decoder during build.
  • Database: Updated registerModels to check mongoose.models existence.
  • Cleanup: Removed dead code (CardStyleC, GameCalendar, etc.).

Tests

  • Verified SignUpPage respects redirect param.
  • Verified build passes locally with CI dummy variables.
  • Verified model registration logic.

How to test:

  1. Run npm test.
  2. Verify npm run build succeeds with mock environment variables.

Impact / Risk

  • Low Risk: Fixes are isolated to auth pages, dead code removal, and build-time configuration.

Checklist

  • Code builds
  • Tests pass locally
  • CI build error resolved

Changed:
- Converted model registration function to async/await to ensure all schemas are loaded before database connection returns
- Updated connection logic to await registration in both new and cached connection paths

Files:
- src/server/models/index.js
- src/server/db.js

Why:
In serverless environments (Vercel/Netlify), the previous synchronous implementation could return the database connection before models were registered, leading to 'Schema hasn't been registered' errors when executing queries. Moving to async registration ensures reliable model availability across all execution environments.
Changed:
- Added GitHub Actions workflow (ci.yml) for automated linting and testing
- Updated .gitignore to exclude local development artifacts and temporary files

Files:
- .github/workflows/ci.yml
- .gitignore

Why:
Establishes a baseline CI process to enforce code quality on every push. Excluding local environment artifacts ensures the shared repository remains clean and environment-agnostic.
Changed:
- Deleted redundant UI components (BettingModal, UWRecord, etc.) replaced by new design system
- Removed unused historical data files and legacy HTML/CSS pages
- Cleaned up deprecated API endpoints and service methods

Files:
- src/app/change-password/page.jsx (deleted)
- src/app/change-username/page.jsx (deleted)
- src/app/contexts/DarkModeContext.jsx (deleted)
- src/app/daily-tasks/page.html (deleted)
- src/app/daily-tasks/style.css (deleted)
- src/app/data/games.js (deleted)
- src/app/data/users.js (deleted)
- src/components/BettingModal.jsx (deleted)
- src/components/BiscuitIcon.jsx (deleted)
- src/components/CardStyleC.jsx (deleted)
- src/components/DarkModeToggle.jsx (deleted)
- src/components/ErrorState.jsx (deleted)
- src/components/FireIcon.jsx (deleted)
- src/components/GameCalendar.jsx (deleted)
- src/components/GameDetailsModal.jsx (deleted)
- src/components/UWRecord.jsx (deleted)
- src/components/animation/AnimatedCard.jsx (deleted)
- src/components/animation/FadeInView.jsx (deleted)
- src/components/animation/variants.js (deleted)
- src/components/betting/BetConfirmation.jsx (deleted)
- src/components/charts/BettingDistributionChart.jsx (deleted)
- src/components/charts/BettingTrendChart.jsx (deleted)
- src/components/charts/SportActivityChart.jsx (deleted)
- src/components/charts/index.js (deleted)
- src/components/dashboard/BettingChart.jsx (deleted)
- src/components/dashboard/StatsGrid.jsx (deleted)
- src/components/game/index.js (deleted)
- src/components/leaderboard/Podium.jsx (deleted)
- src/components/shared/index.js (deleted)
- src/pages/api/bets/settle-all.js (deleted)
- src/pages/api/bets/settle-game.js (deleted)
- src/hooks/useKeyboardNav.js (deleted)

Why:
Reduces technical debt and codebase size by removing obsolete features and experimental UI components. This streamlines the project structure and ensures only the current design language and active features remain, making maintenance and onboarding easier.
Changed:
- Updated import paths in all active pages to resolve references to deleted legacy components
- Refactored remaining components (AppShell, GameCards) to fully adopt the 'MinimalLayout' patterns
- Standardized authentication routing in middleware and hooks (removing hash routing)
- Centralized icon components into src/components/icons

Files:
- src/app/betting-history/page.jsx
- src/app/dashboard/page.jsx
- src/app/games/page.jsx
- src/app/layout.jsx
- src/app/leaderboard/page.jsx
- src/app/tasks/page.jsx
- src/app/hooks/useKeyboardNav.js
- src/components/experimental/layout/AppShell.jsx
- src/components/game/OddsDisplay.jsx
- src/components/game/PlaceholderCard.jsx
- src/components/game/PlayerStat.jsx
- src/components/game/PlayerStatCard.jsx
- src/components/icons/BiscuitIcon.jsx
- src/components/icons/FireIcon.jsx
- src/components/ui/Card.jsx
- src/components/ui/LoadingSpinner.jsx
- src/middleware.ts
- src/pages/api/bets/auto-settle-user.js
- src/pages/api/games/sync-from-espn.js
- src/server/services/StatisticsService.js

Why:
To stabilize the application build after the removal of legacy artifacts. This ensures all active code correctly references the new architecture, eliminating dead dependencies and ensuring that the remaining features—like authentication and navigation—function correctly within the unified design system.
Copilot AI review requested due to automatic review settings December 24, 2025 09:52
@netlify

netlify Bot commented Dec 24, 2025

Copy link
Copy Markdown

Deploy Preview for huskybids ready!

Name Link
🔨 Latest commit da413f0
🔍 Latest deploy log https://app.netlify.com/projects/huskybids/deploys/694c473665248f0008c097f8
😎 Deploy Preview https://deploy-preview-8--huskybids.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR performs a comprehensive cleanup of the HuskyBids codebase, removing over 20 legacy files and components that are no longer aligned with the project's minimal design direction. It also strengthens the development workflow with CI improvements and resolves authentication routing issues.

Key changes include:

  • Dead Code Removal: Eliminated unused components (Podium, StatsGrid, BettingModal, CardStyleC, GameCalendar, etc.), chart components, animation utilities, and legacy pages
  • Database Stability: Converted model registration to use async/await with dynamic imports for better race condition handling
  • CI/CD Integration: Removed the || true workaround from the lint step, enforcing stricter code quality checks

Reviewed changes

Copilot reviewed 49 out of 53 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/server/models/index.js Converted registerModels to async function using dynamic imports instead of require
src/server/db.js Added await calls for registerModels to ensure proper initialization timing
src/server/services/StatisticsService.js Removed unused Game import and sortField logic
src/pages/api/games/sync-from-espn.js Removed unused wasCompleted variable
src/pages/api/bets/settle-game.js Deleted entire legacy bet settlement endpoint
src/pages/api/bets/settle-all.js Deleted entire legacy batch settlement endpoint
src/pages/api/bets/auto-settle-user.js Removed unused Game import
src/middleware.ts Removed /change-password and /change-username from protected routes
src/components/ui/LoadingSpinner.jsx Added displayName properties to Skeleton and UWSpinner sub-components
src/components/ui/Card.jsx Added displayName properties to CardHeader, CardBody, and CardFooter sub-components
src/components/shared/index.js Deleted empty export file
src/components/leaderboard/Podium.jsx Deleted legacy podium visualization component
src/components/icons/FireIcon.jsx New fire icon component with variants and animations
src/components/icons/BiscuitIcon.jsx New biscuit icon component with balance display and rain effect
src/components/game/index.js Deleted empty export file
src/components/game/PlayerStatCard.jsx Removed unused opponentAbbrev parameter
src/components/game/PlayerStat.jsx Removed unused User import
src/components/game/PlaceholderCard.jsx Removed unused team parameter
src/components/game/OddsDisplay.jsx Updated BiscuitIcon import path
src/components/experimental/layout/AppShell.jsx Updated useKeyboardNav import path
src/components/dashboard/StatsGrid.jsx Deleted legacy stats grid component
src/components/dashboard/BettingChart.jsx Deleted legacy chart component
src/components/charts/* Deleted all legacy chart components and index
src/components/betting/BetConfirmation.jsx Deleted legacy bet confirmation modal
src/components/animation/* Deleted all animation variant utilities and wrapper components
src/components/UWRecord.jsx Deleted UW team record display component
src/components/GameDetailsModal.jsx Deleted legacy game details modal
src/components/GameCalendar.jsx Deleted legacy game calendar component
src/components/ErrorState.jsx Deleted legacy error state component
src/components/DarkModeToggle.jsx Deleted dark mode toggle (dark mode removed)
src/components/CardStyleC.jsx Deleted legacy card style variant
src/components/BettingModal.jsx Deleted legacy betting modal
src/app/tasks/page.jsx Updated import paths and spelling fix
src/app/leaderboard/page.jsx Removed unused ActionBar import and React import
src/app/layout.jsx Removed DarkModeProvider and related inline script
src/app/hooks/useKeyboardNav.js New keyboard navigation hook implementation
src/app/games/page.jsx Updated import path
src/app/data/* Deleted legacy sample data files
src/app/dashboard/page.jsx Updated import paths
src/app/daily-tasks/* Deleted legacy HTML/CSS daily tasks page
src/app/contexts/DarkModeContext.jsx Deleted dark mode context
src/app/change-username/page.jsx Deleted placeholder page
src/app/change-password/page.jsx Deleted legacy page
src/app/betting-history/page.jsx Removed unused useEffect import
.gitignore Added exclusions for Gemini agent files
.github/workflows/ci.yml Removed `

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/server/models/index.js
Fix auth page redirects and prevent build errors with Suspense

Changed:
- Wrapped LoginPage and SignUpPage in Suspense to handle useSearchParams correctly
- Updated SignUpPage to respect the redirect URL parameter

Files:
- src/app/login/[[...sign-in]]/page.js
- src/app/sign-up/[[...sign-up]]/page.jsx
- src/app/sign-up/__tests__/redirect.test.jsx

Why:
Next.js requires components using useSearchParams to be wrapped in a Suspense boundary to avoid de-opting entire pages to client-side rendering during build. Additionally, the sign-up flow was ignoring the post-auth redirect destination, causing UX issues where users were not sent to their intended protected route.
Improve Mongoose model registration check for serverless and hot-reload environments

Changed:
- Updated registerModels to check for existing models in mongoose.models alongside the modelsRegistered flag.

Files:
- src/server/models/index.js

Why:
In serverless environments or during hot reloads in development, the module-level modelsRegistered flag might persist while the internal Mongoose model cache is cleared. Verifying both ensures that models are always correctly registered before use, preventing 'Schema hasn't been registered' errors.
Fix CI build error caused by invalid Clerk publishable key format

Changed:
- Updated the dummy NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY in the CI workflow to a syntactically valid mock key (pk_test_Y2xlcmsuY29tJA).

Files:
- .github/workflows/ci.yml

Why:
The Clerk SDK performs a Base64 decoding on the publishable key during Next.js's static page generation. Using a non-base64 string like 'pk_test_dummy' caused a DOMException [InvalidCharacterError], breaking the build in CI environments.
@Isaiahriveraa Isaiahriveraa merged commit bb34434 into main Dec 24, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants