Skip to content

docs(predict): add PredictNext architecture and migration plan#28702

Draft
matallui wants to merge 4 commits intomainfrom
predict/next-docs
Draft

docs(predict): add PredictNext architecture and migration plan#28702
matallui wants to merge 4 commits intomainfrom
predict/next-docs

Conversation

@matallui
Copy link
Copy Markdown
Contributor

Description

Architecture documentation and migration plan for redesigning the Predict feature from the ground up. This establishes the target architecture in a new PredictNext/ directory with comprehensive docs covering every aspect of the redesign.

Related issues

N/A — This is a documentation-only PR establishing the architecture plan.

Manual testing steps

N/A — Documentation only, no runtime changes.

Screenshots/Recordings

N/A

Pre-merge author checklist

  • I've followed MetaMask Contributor Docs
  • I've completed the PR template to the best of my ability
  • I've included tests if applicable
  • I've documented my code using JSDoc format if applicable
  • I've applied the right labels on the PR
  • I've properly set the title of this PR
  • If applicable, I've highlighted breaking changes using the "BREAKING" label.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and round trip)
  • I confirm that this PR addresses all acceptance criteria described in the linked issue and target all metrics in the ticket

What this PR contains

19 documentation files (5,597 lines) under app/components/UI/PredictNext/:

Foundational docs:

  • README.md — Feature overview, directory structure, public API
  • UBIQUITOUS_LANGUAGE.md — DDD glossary (Event/Market/Outcome canonical terms)

Architecture docs (docs/):

  • architecture.md — Master architecture doc (4-layer, deep modules, data flow)
  • services.md — 6 deep services + thin controller with TypeScript interfaces
  • adapters.md — Protocol adapter pattern for Polymarket/Kalshi
  • components.md — 3-tier component taxonomy with compound component patterns
  • hooks.md — 7 consolidated hooks (down from 37)
  • testing.md — Component view test strategy (~85-90% test code reduction)
  • state-management.md — BaseDataService integration, Redux, query keys
  • error-handling.md — PredictError class, 4 UI error categories

Migration plan (docs/migration/):

  • README.md — Strangler fig strategy, motivation, 8-phase overview
  • phase-1-foundation.md through phase-8-cleanup.md — Detailed per-phase plans with deliverables, acceptance criteria, and estimated PRs

Key architectural decisions

  1. 4-layer architecture (Components → Hooks → Controller/Services → Adapters)
  2. 6 deep services with slim interfaces replacing a 60+ method controller
  3. Canonical Event → Market → Outcome data model aligned with Polymarket/Kalshi
  4. BaseDataService for read services (shared cache between service and UI via TanStack Query)
  5. Compound components (Vercel-style) reducing 45 component dirs to ~7 primitives
  6. Component view tests as primary test surface
  7. Strangler fig migration via PredictNext/ directory

Introduce comprehensive architecture documentation for the Predict
feature redesign. The new PredictNext directory establishes the target
architecture with deep modules, slim interfaces, and a canonical
Event/Market/Outcome data model aligned with Polymarket and Kalshi.

Documents cover:
- 4-layer architecture (Components, Hooks, Controller/Services, Adapters)
- 6 deep services with BaseDataService integration
- 7 consolidated hooks (down from 37)
- 3-tier component taxonomy with compound component patterns
- Component view test strategy targeting 85-90% test code reduction
- DDD ubiquitous language glossary
- 8-phase strangler fig migration plan from Predict/ to PredictNext/
@matallui matallui self-assigned this Apr 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-predict Predict team label Apr 11, 2026
@matallui matallui changed the title docs: add PredictNext architecture and migration plan docs(predict): add PredictNext architecture and migration plan Apr 11, 2026
…lders

Replace monolithic useEvents/usePortfolio hooks with granular
per-query hooks organized in domain folders (hooks/events/,
hooks/portfolio/). Each data hook triggers exactly one query so
components only fetch what they need. Imperative hooks (trading,
transactions, live-data) stay deep.

Update architecture.md, hooks.md, and README.md to reflect the
folder-based organization with barrel exports.
Add 'Hook Usage by Component Tier' section to hooks.md explaining that
primitives are pure (no hooks), widgets wire data hooks to primitives,
and views compose widgets with imperative/guard hooks.

Update components.md widget descriptions with granular hook names
(useEventList, useBalance, etc. instead of monolithic useEvents) and
add code example for PredictHome view showing widget composition.

Update hook composition rules to reflect the tier boundaries.
…lices

Replace horizontal layer-by-layer migration (8 phases) with inside-out
approach (7 phases). New strategy hollows out old provider and controller
from the inside by delegating to new adapter and services, then migrates
UI as vertical slices per screen.

Key changes:
- Add compat/ translation layer for bidirectional type mapping
- Phase 2: Adapter replaces provider internals
- Phases 3-4: Services replace controller internals (parallelizable)
- Phase 5: New controller, old becomes pure shim
- Phase 6: UI migrates one screen at a time (vertical slices)
- Phase 7: Cleanup and rename (merged old phases 7+8)
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

⏭️ Smart E2E selection skipped - draft PR

All E2E tests pre-selected.

View GitHub Actions results

@github-actions
Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
11 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants