Refactor: Modularize Scoring Engine, Unify Persistence Pipeline, and Streamline Comparison State - #215
Merged
Conversation
…umentation - Reorganized codebase under `src/` following a Feature-Driven Scalable Next.js Architecture: - `src/features/` (domain modules: comparison, developer, leaderboard, scoring with colocated components, services, tests, types, and barrel exports) - `src/lib/` (infrastructure adapters: cache, db, geo, github, i18n, logger, seo) - `src/components/` (shared domain-agnostic UI: ui, layout, providers, seo) - `src/app/` (thin routing controllers, layouts, and API routes) - `src/locales/`, `src/data/`, `src/types/`, `src/utils/` - Updated path aliases in `tsconfig.json`, `tailwind.config.ts`, and `vitest.config.ts` (`@/features/*`, `@/lib/*`, `@/components/*`, etc.). - Updated script paths in `scripts/calculate-next-country.ts`, `scripts/init-db.ts`, and `scripts/validate-locales.js`. - Created comprehensive `ARCHITECTURE.md` documentation detailing system design, sequence flows, encapsulation rules, and step-by-step contributor cookbooks. - Updated `README.md`, `CONTRIBUTING.md`, and `algorithm.md` to align with the new architecture. - Replaced hardcoded machine/absolute paths in markdown files with relative paths.
…ize responsive layout - Move and unify shared work cards (RepoCardItem, PullRequestCardItem, CommunityCardItem, ScoreCard) under global src/components/cards/ - Fix client/server barrel boundary separation in feature index exports to avoid leaking server-only dependencies (pg, redis, dns) into client bundles - Restructure Profile Top Work section into a responsive 1-column (mobile) and max 2-column (desktop) grid with balanced community card spanning - Enable text wrapping with break-words leading-snug for repository and PR titles to prevent awkward truncation - Add GitHub Linguist language color palette supporting 150+ programming languages with alias normalization and deterministic HSL fallback - Update LanguageBreakdown and SelectedLanguageRow components to render official GitHub color bars and indicators - Add comprehensive unit test suite for language colors (15 suites / 117 tests passing)
…streamline comparison state - Core Domain Pipeline: - Introduce `persistUserScores` in `user-persistence.ts` as the canonical persistence pipeline - Eliminate duplicate DB upsert and Redis invalidation logic across `user-service`, `compare-service`, and `calculate-leaderboard` - Remove cross-boundary dynamic imports of `db` and `score-engine` from `github-client` - Scoring Engine Modularization: - Decompose monolithic 1,230-line `score-engine.ts` into focused sub-calculators (`repo-scoring`, `pr-scoring`, `community-scoring`, `scoring-constants`, `scoring-helpers`) - Preserve 100% backward compatibility and exact mathematical output - API & Routes: - Unify API error handling and search parameter parsing into `src/lib/api` - Reduce route handler boilerplate by ~70% across `/api/user/[username]` and `/api/compare` - Remove `initializeSchema()` DDL overhead from hot read path in `leaderboard-service` - Add strong generic typing to `db-store` rows and upsert params - Frontend State & Polish: - Extract comparison orchestration into `useComparisonController` hook, slimming `home-page-client.tsx` from 545 to 125 lines - Introduce reusable `useClipboardCopy` hook with timeout cleanup in profile and comparison dashboards - Fix template placeholder replacement in `provider-hook.ts` - Deduplicate SSR profile fetches between `generateMetadata` and `UserProfilePage` using `React.cache()`
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Owner
Author
|
✨ Thank you, @O2sa! Another great contribution merged! 🚀 You've been a fantastic contributor! We truly appreciate your continued support. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
This PR executes a full architectural refactoring to remove duplicate logic, isolate domain boundaries, and improve maintainability while preserving 100% backward compatibility:
Unified Scoring & Persistence Pipeline:
persistUserScoresinsrc/features/developer/services/user-persistence.tsto coordinate canonical score computation, PostgreSQL upserts, and Redis cache invalidation in a single place.github-client.tsby removing cross-boundary dynamic imports of database and scoring internals.user-service.ts,compare-service.ts, andcalculate-leaderboard.tsto usepersistUserScores.Scoring Engine Modularization:
score-engine.tsinto isolated modules:scoring-constants.ts: Weights, thresholds, and explanationsscoring-helpers.ts: Math utilities (safeLog,roundScore, date normalization)repo-scoring.ts: Repository score breakdown and language weightspr-scoring.ts: Pull request decay, size penalties, and author association logiccommunity-scoring.ts: Issues and discussions scoringscore-engine.ts: Lightweight coordinator (~320 lines)API Boilerplate Deduplication:
@/lib/apihelpers (formatApiErrorResponse,parseSelectedLanguagesFromSearchParams)./api/user/[username](105 → 30 lines) and/api/compare(101 → 36 lines).await db.initializeSchema()DDL operations fromleaderboard-service.tshot read path.raw_dataandscoresindb-store.ts.Frontend State Architecture:
useComparisonControllerhook to handle comparison requests, race conditions, in-flight promises, duplicate fetch prevention, and URL sync.home-page-client.tsxfrom 545 lines down to 125 lines.useClipboardCopyhook with automatic timeout cleanup and integrated it intouser-profile-client.tsxandresult-dashboard.tsx.provider-hook.ts.React.cache()forgenerateMetadataand page component deduplication.Verification
npx tsc --noEmitpassed with 0 errors.npx vitest runpassed with all 15 test files and 117 tests green.