-
Notifications
You must be signed in to change notification settings - Fork 0
Frontend migration foundation: Read-only React Contexts + Server Action mutations across all services with NextJS page structure #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
12
commits into
main
Choose a base branch
from
copilot/analyze-frontend-app-design
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d475257
Initial plan
Copilot 1d66989
Add React contexts and page structure for frontend migration
Copilot b893cbb
Add comprehensive frontend migration documentation
Copilot 557d450
Add architecture comparison diagram
Copilot f4a81c4
Refactor contexts to use Immutable.js and integrate with server actions
Copilot 2b36bdf
wip: dream context patterning
mlynam 0e99ea0
feat: add context pattern
mlynam 2017b6b
Refactor contexts to match DreamContext pattern
Copilot 4f2804a
Refactor contexts to be read-only with server action mutations
Copilot fbf31e1
Refactor dream services: one export per file, FormData for saveYearVi…
Copilot e7488b2
Apply form action pattern to all services (weeks, connects, scoring, …
Copilot 76ddc18
Fix withAuth usage: use as function wrapper not inside body
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,327 @@ | ||
| # Dreamspace Architecture: Legacy vs New | ||
|
|
||
| ## Legacy Architecture (src/) | ||
|
|
||
| ``` | ||
| ┌─────────────────────────────────────────────────────────────┐ | ||
| │ Browser (Client Only) │ | ||
| ├─────────────────────────────────────────────────────────────┤ | ||
| │ │ | ||
| │ ┌──────────────┐ ┌─────────────────────┐ │ | ||
| │ │ React Router │────────▶│ Page Components │ │ | ||
| │ └──────────────┘ └──────────┬──────────┘ │ | ||
| │ │ │ | ||
| │ ┌──────────▼──────────┐ │ | ||
| │ │ AppContext │ │ | ||
| │ │ (Redux-like) │ │ | ||
| │ │ │ │ | ||
| │ │ • Dreams │ │ | ||
| │ │ • Goals │ │ | ||
| │ │ • User │ │ | ||
| │ │ • Connects │ │ | ||
| │ │ • Scoring │ │ | ||
| │ │ • Team │ │ | ||
| │ │ │ │ | ||
| │ │ 30+ Actions │ │ | ||
| │ │ 315 LOC Reducer │ │ | ||
| │ └──────────┬──────────┘ │ | ||
| │ │ │ | ||
| │ ┌──────────▼──────────┐ │ | ||
| │ │ Custom Hooks │ │ | ||
| │ │ (32 hooks) │ │ | ||
| │ └──────────┬──────────┘ │ | ||
| │ │ │ | ||
| │ ┌──────────▼──────────┐ │ | ||
| │ │ Services Layer │ │ | ||
| │ │ (21 services) │ │ | ||
| │ └──────────┬──────────┘ │ | ||
| └──────────────────────────────────────┼──────────────────────┘ | ||
| │ | ||
| │ HTTP/REST | ||
| │ | ||
| ┌──────────▼──────────┐ | ||
| │ Azure Functions │ | ||
| │ (50+ functions) │ | ||
| └──────────┬──────────┘ | ||
| │ | ||
| ┌──────────▼──────────┐ | ||
| │ Cosmos DB │ | ||
| └─────────────────────┘ | ||
| ``` | ||
|
|
||
| ## New Architecture (apps/web/) | ||
|
|
||
| ``` | ||
| ┌─────────────────────────────────────────────────────────────┐ | ||
| │ Server (NextJS) │ | ||
| ├─────────────────────────────────────────────────────────────┤ | ||
| │ │ | ||
| │ ┌──────────────┐ ┌─────────────────────┐ │ | ||
| │ │ App Router │────────▶│ Server Components │ │ | ||
| │ │ │ │ (Pages - RSC) │ │ | ||
| │ └──────────────┘ └──────────┬──────────┘ │ | ||
| │ │ │ | ||
| │ │ fetch data │ | ||
| │ │ │ | ||
| │ ┌──────────▼──────────┐ │ | ||
| │ │ Server Actions │ │ | ||
| │ │ (70+ actions) │ │ | ||
| │ │ │ │ | ||
| │ │ • users/ │ │ | ||
| │ │ • dreams/ │ │ | ||
| │ │ • weeks/ │ │ | ||
| │ │ • teams/ │ │ | ||
| │ │ • scoring/ │ │ | ||
| │ │ • connects/ │ │ | ||
| │ │ │ │ | ||
| │ └──────────┬──────────┘ │ | ||
| │ │ │ | ||
| │ ┌──────────▼──────────┐ │ | ||
| │ │ Database Client │ │ | ||
| │ │ (@dreamspace/db) │ │ | ||
| │ └──────────┬──────────┘ │ | ||
| └──────────────────────────────────────┼──────────────────────┘ | ||
| │ | ||
| ┌──────────▼──────────┐ | ||
| │ Cosmos DB │ | ||
| └─────────────────────┘ | ||
|
|
||
| ┌─────────────────────────────────────────────────────────────┐ | ||
| │ Browser (Client) │ | ||
| ├─────────────────────────────────────────────────────────────┤ | ||
| │ │ | ||
| │ ┌──────────────────────────────────────────────────┐ │ | ||
| │ │ Client Components (Interactive) │ │ | ||
| │ │ │ │ | ||
| │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ | ||
| │ │ │ Dream │ │ Goal │ │ User │ │ │ | ||
| │ │ │ Context │ │ Context │ │ Context │ │ │ | ||
| │ │ └──────────┘ └──────────┘ └──────────┘ │ │ | ||
| │ │ │ │ | ||
| │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ | ||
| │ │ │ Connect │ │ Team │ │ Scoring │ │ │ | ||
| │ │ │ Context │ │ Context │ │ Context │ │ │ | ||
| │ │ └──────────┘ └──────────┘ └──────────┘ │ │ | ||
| │ │ │ │ | ||
| │ │ (Contexts only for UI state) │ │ | ||
| │ └──────────────────────────────────────────────────┘ │ | ||
| │ │ | ||
| └─────────────────────────────────────────────────────────────┘ | ||
| ``` | ||
|
|
||
| ## Key Differences | ||
|
|
||
| | Aspect | Legacy | New | | ||
| |--------|--------|-----| | ||
| | **Rendering** | Client-side only | Server + Client | | ||
| | **State** | Centralized Redux | Distributed Contexts | | ||
| | **Data Flow** | Client → API → DB | Server → DB → Client | | ||
| | **Routing** | React Router (client) | NextJS (server) | | ||
| | **API Layer** | Azure Functions | Server Actions | | ||
| | **Bundle Size** | Large (all client) | Small (server-first) | | ||
| | **SEO** | Poor | Excellent | | ||
| | **Performance** | Slower initial load | Faster initial load | | ||
| | **Complexity** | 30+ actions, 1 reducer | 6 contexts, focused | | ||
|
|
||
| ## Data Flow Comparison | ||
|
|
||
| ### Legacy: Client-Heavy | ||
| ``` | ||
| User Action | ||
| ↓ | ||
| React Component | ||
| ↓ | ||
| Dispatch Action → Reducer → Context Update | ||
| ↓ | ||
| useEffect triggered | ||
| ↓ | ||
| Service Layer (client) | ||
| ↓ | ||
| HTTP Request → Azure Function | ||
| ↓ | ||
| Cosmos DB | ||
| ↓ | ||
| Response → State Update | ||
| ↓ | ||
| localStorage sync | ||
| ↓ | ||
| Component Re-render | ||
| ``` | ||
|
|
||
| ### New: Server-First | ||
| ``` | ||
| Page Load | ||
| ↓ | ||
| Server Component | ||
| ↓ | ||
| Server Action (direct DB access) | ||
| ↓ | ||
| Cosmos DB | ||
| ↓ | ||
| Render HTML | ||
| ↓ | ||
| Send to Client | ||
|
|
||
| User Interaction | ||
| ↓ | ||
| Client Component | ||
| ↓ | ||
| Server Action (mutation) | ||
| ↓ | ||
| Cosmos DB | ||
| ↓ | ||
| revalidatePath | ||
| ↓ | ||
| Server Component re-fetches | ||
| ↓ | ||
| Render updated HTML | ||
| ``` | ||
|
|
||
| ## Component Architecture | ||
|
|
||
| ### Legacy Three-Layer Pattern | ||
| ``` | ||
| ┌─────────────────────────────────┐ | ||
| │ DashboardLayout.jsx │ ◀─── Orchestrator | ||
| │ - State management │ | ||
| │ - Side effects │ | ||
| │ - Event handlers │ | ||
| └──────────┬──────────────────────┘ | ||
| │ | ||
| ┌──────▼─────────┐ | ||
| │ useDashboard │ ◀─── Business Logic Hook | ||
| │ Hook │ | ||
| │ - Data fetch │ | ||
| │ - Calculations │ | ||
| └──────┬─────────┘ | ||
| │ | ||
| ┌──────▼─────────┐ | ||
| │ Presentational │ ◀─── Pure UI Components | ||
| │ Components │ | ||
| │ - No state │ | ||
| │ - Props only │ | ||
| └────────────────┘ | ||
| ``` | ||
|
|
||
| ### New Server-First Pattern | ||
| ``` | ||
| ┌─────────────────────────────────┐ | ||
| │ page.tsx (Server) │ ◀─── Server Component | ||
| │ - Auth check │ | ||
| │ - Data fetching │ | ||
| │ - Render │ | ||
| └──────────┬──────────────────────┘ | ||
| │ | ||
| │ Pass data as props | ||
| │ | ||
| ┌──────▼─────────┐ | ||
| │ Client │ ◀─── Client Component | ||
| │ Components │ | ||
| │ - Interactive │ | ||
| │ - Use contexts │ | ||
| │ - Event handlers│ | ||
| └──────┬─────────┘ | ||
| │ | ||
| │ Mutations | ||
| │ | ||
| ┌──────▼─────────┐ | ||
| │ Server Actions │ ◀─── Server-side logic | ||
| │ - Validation │ | ||
| │ - DB updates │ | ||
| │ - Revalidation │ | ||
| └────────────────┘ | ||
| ``` | ||
|
|
||
| ## File Organization | ||
|
|
||
| ### Legacy | ||
| ``` | ||
| src/ | ||
| ├── pages/ | ||
| │ ├── Dashboard.jsx (thin wrapper) | ||
| │ └── dashboard/ | ||
| │ ├── DashboardLayout.jsx (orchestrator) | ||
| │ ├── DashboardHeader.jsx | ||
| │ ├── WeekGoalsWidget.jsx | ||
| │ └── week-goals/ | ||
| │ ├── index.js | ||
| │ ├── GoalItem.jsx | ||
| │ └── AddGoalForm.jsx | ||
| ├── context/ | ||
| │ ├── AppContext.jsx (global state) | ||
| │ └── AuthContext.jsx | ||
| ├── state/ | ||
| │ ├── appReducer.js (315 LOC) | ||
| │ └── actionTypes.js | ||
| ├── hooks/ | ||
| │ ├── useDashboard.js | ||
| │ ├── useDreamActions.js | ||
| │ └── ... (32 hooks) | ||
| └── services/ | ||
| ├── apiClient.js | ||
| ├── dreamService.js | ||
| └── ... (21 services) | ||
| ``` | ||
|
|
||
| ### New | ||
| ``` | ||
| apps/web/ | ||
| ├── app/ | ||
| │ ├── dashboard/ | ||
| │ │ └── page.tsx (server component) | ||
| │ ├── dream-book/ | ||
| │ │ └── page.tsx | ||
| │ └── layout.tsx (with providers) | ||
| ├── components/ | ||
| │ ├── dashboard/ | ||
| │ │ ├── DashboardHeader.tsx | ||
| │ │ ├── WeekGoalsWidget.tsx | ||
| │ │ └── DashboardDreamCard.tsx | ||
| │ └── shared/ | ||
| │ └── Navigation.tsx | ||
| ├── lib/ | ||
| │ └── contexts/ (6 focused contexts) | ||
| │ ├── DreamContext.tsx | ||
| │ ├── GoalContext.tsx | ||
| │ ├── UserContext.tsx | ||
| │ ├── ConnectContext.tsx | ||
| │ ├── TeamContext.tsx | ||
| │ ├── ScoringContext.tsx | ||
| │ └── AppProviders.tsx | ||
| └── services/ (70+ server actions) | ||
| ├── dreams/ | ||
| ├── users/ | ||
| ├── weeks/ | ||
| └── ... | ||
| ``` | ||
|
|
||
| ## Migration Benefits | ||
|
|
||
| 1. **Performance** | ||
| - ⚡ Faster initial page load (server rendering) | ||
| - 📦 Smaller client bundle (no Redux, less JS) | ||
| - 🎯 Automatic code splitting (NextJS) | ||
| - 🔄 Parallel data fetching | ||
|
|
||
| 2. **Developer Experience** | ||
| - 📝 Type-safe throughout (TypeScript) | ||
| - 🎨 Clearer separation of concerns | ||
| - 🧪 Easier to test (isolated contexts) | ||
| - 📚 Better documentation | ||
|
|
||
| 3. **Maintainability** | ||
| - 🔍 Easier to understand (smaller contexts) | ||
| - 🔧 Easier to modify (focused responsibilities) | ||
| - 🚀 Easier to deploy (NextJS built-in) | ||
| - 📊 Better error tracking | ||
|
|
||
| 4. **User Experience** | ||
| - 🌐 SEO-friendly (server rendering) | ||
| - ♿ More accessible (progressive enhancement) | ||
| - 📱 Better mobile performance | ||
| - 🔒 More secure (server-side auth) | ||
|
|
||
| --- | ||
|
|
||
| **Migration Status**: Phase 1 Complete ✅ | ||
| **Next Phase**: Component Stubbing (80+ components) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's cleanup this go-forward architecture:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored architecture to match this pattern (4f2804a):
✅ Read-only contexts - All 6 contexts now only provide data via immutable Lists, no mutation methods
✅ Form actions with FormData - Created
saveDreamFormActionanddeleteDreamFormActionusing Zod + FormData, compatible withuseActionState✅ Non-form mutations - Created
reorderDreams(dreams[])andupdateYearVision(vision)with simple signatures✅ Revalidation cascade - All server actions call
revalidatePath()to refresh context dataExample: