Skip to content

refactor: align codebase with architectural standards and thin routing pattern - #283

Merged
O2sa merged 9 commits into
mainfrom
refactor/architecture-and-codebase-standards
Nov 22, 2026
Merged

O2sa merged 9 commits into
mainfrom
refactor/architecture-and-codebase-standards

Conversation

@O2sa

@O2sa O2sa commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Summary

This PR addresses architectural anomalies, misplaced files, and boundary leaks across the codebase to strictly align with the design principles defined in ARCHITECTURE.md. It standardizes module encapsulation, isolates server-only services from client bundles, introduces thin page controllers, and cleans up deep subpath imports.


Key Changes

1. 📁 Misplaced Files & Directory Structural Realignment

  • signal-metrics.ts: Relocated from src/features/developer/ to src/features/developer/services/signal-metrics.ts.
  • format-comparison-to-markdown.ts: Relocated from src/features/comparison/ to src/features/comparison/services/format-comparison-to-markdown.ts.
  • DashboardSkeleton: Moved from src/components/layout/skeletons.tsx to src/features/comparison/components/dashboard-skeleton.tsx.
  • Avatar Primitive: Moved from src/components/layout/avatar.tsx to src/components/ui/avatar.tsx (with backwards-compatible re-export in components/layout/index.ts).
  • Global Types Barrel: Added src/types/index.ts re-exporting api.ts and models.ts to satisfy @/types import paths.

2. 🛡️ Server vs. Client Boundary Isolation

  • Fixed Next.js Turbopack build failure caused by server-only modules (user-service.ts, schedule-background.ts with after() from next/server, PostgreSQL pg) leaking into client component bundles.
  • Feature barrels (@/features/developer and @/features/comparison) now strictly export client-safe code (UI components, domain types, client helpers), while server-only database and calculation pipelines remain cleanly isolated in @/features/<feature>/services.

3. 🧩 Domain Types Encapsulation

  • Relocated CalculateUserScoreResult, TopRepo, TopPullRequest, TopCommunityContribution, TopLanguageRepo, TopLanguagePullRequest, and LanguageScores from score-engine.ts into src/features/scoring/types.ts.
  • Updated external consumers (user-service.ts, user-persistence.ts, db-store.ts) to import directly from public feature barrel @/features/scoring.

4. 🪶 Thin Routing Layer (Page Controller Refactoring)

  • Home Route (src/app/[locale]/page.tsx): Extracted 50-line inline fallback skeleton into src/features/comparison/components/home-page-fallback.tsx.
  • User Profile Route (src/app/[locale]/user/[username]/page.tsx): Extracted 80 lines of inline JSON-LD schemas into src/features/developer/services/developer-seo.ts (buildUserProfileSchema, buildUserBreadcrumbSchema).
  • Leaderboard Route (src/app/[locale]/leaderboard/[country]/page.tsx): Extracted inlined country formatting and metadata helpers into src/features/leaderboard/services/leaderboard-helpers.ts.

5. 🧹 Standardized Deep Subpath Imports

  • Eliminated deep subpath imports across src/components/cards/, src/features/comparison/, and src/features/developer/.
  • Replaced deep paths (@/components/ui/button, @/components/providers/language-provider, @/utils/cn, @/utils/github, @/features/developer/types) with clean barrel paths (@/components/ui, @/components/providers, @/utils, @/features/developer).

O2sa added 9 commits November 14, 2026 02:16
- Route directory restructured from src/app/ to src/app/[locale]/ with generateStaticParams() pre-rendering static HTML (SSG) for English and Arabic.
- Middleware transparently rewrites unprefixed URLs (/, /leaderboard, etc.) directly to localized pages with zero URL redirect flicker.
- Bypasses static assets, metadata files (manifest.webmanifest, robots, sitemap), and API routes from rewrite.
- Retains inline blocking script in head for 0ms initial theme FOUC prevention and keeps client-side language switching reactive without router.refresh() to avoid theme flashing.
- Adds darkreader-lock to suppress browser extension hydration mismatches and disables unused logo preload.
- Adds comprehensive unit test suite in src/lib/i18n/tests/middleware.test.ts.
@O2sa
O2sa merged commit 964508b into main Nov 22, 2026
5 of 6 checks passed
@O2sa

O2sa commented Nov 22, 2026

Copy link
Copy Markdown
Owner Author

✨ Thank you, @O2sa! Another great contribution merged! 🚀

You've been a fantastic contributor! We truly appreciate your continued support.

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.

1 participant