Phase 2: Shared Extraction Implementation Plan
For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Create shared/ folder and consolidate cross-cutting utilities, lib, and types.
Architecture: Move utils/, lib/, and types/ into shared/ subfolder. Update all imports from @/utils/ to @/shared/utils/, etc. No functional changes - pure reorganization.
Tech Stack: TypeScript, Next.js path aliases
Pre-Flight Check
Before starting, ensure:
- On
mainbranch with latest changes:git checkout main && git pull - Create feature branch:
git checkout -b ghostmonk/phase-2-shared-extraction - Frontend builds:
cd frontend && npm run build
Task 1: Create Shared Directory Structure
Files:
- Create:
frontend/src/shared/ - Create:
frontend/src/shared/utils/ - Create:
frontend/src/shared/lib/ - Create:
frontend/src/shared/types/
Step 1: Create directories
mkdir -p frontend/src/shared/utils frontend/src/shared/lib frontend/src/shared/typesStep 2: Commit
git add frontend/src/shared/
git commit -m "chore: create shared/ directory structure"Task 2: Move Utils
Files:
- Move:
frontend/src/utils/*→frontend/src/shared/utils/
Step 1: Move all utils files
git mv frontend/src/utils/* frontend/src/shared/utils/
rmdir frontend/src/utilsStep 2: Create barrel export
Create frontend/src/shared/utils/index.ts:
export * from './extractImageFromContent';
export * from './formatDate';
export * from './logger';
export * from './sanitizer';
export * from './uploadUtils';
export * from './urls';Step 3: Commit
git add -A
git commit -m "refactor: move utils/ to shared/utils/"Task 3: Move Lib
Files:
- Move:
frontend/src/lib/*→frontend/src/shared/lib/
Step 1: Move all lib files
git mv frontend/src/lib/* frontend/src/shared/lib/
rmdir frontend/src/libStep 2: Create barrel export
Create frontend/src/shared/lib/index.ts:
export * from './api-client';
export * from './auth';
export * from './keep-alive';
export * from './navigation';
export * from './logging';Step 3: Commit
git add -A
git commit -m "refactor: move lib/ to shared/lib/"Task 4: Move Types
Files:
- Move:
frontend/src/types/*→frontend/src/shared/types/
Step 1: Move all types files
git mv frontend/src/types/* frontend/src/shared/types/
rmdir frontend/src/typesStep 2: Create barrel export
Create frontend/src/shared/types/index.ts:
export * from './api';
export * from './error';
// Note: next-auth.d.ts is a declaration file, not exportedStep 3: Commit
git add -A
git commit -m "refactor: move types/ to shared/types/"Task 5: Create Shared Index
Files:
- Create:
frontend/src/shared/index.ts
Step 1: Create main barrel export
Create frontend/src/shared/index.ts:
// Re-export all shared modules
export * from './utils';
export * from './lib';
export * from './types';Step 2: Commit
git add frontend/src/shared/index.ts
git commit -m "chore: add shared/ barrel exports"Task 6: Update Utils Imports
Files to modify (13 files):
frontend/src/pages/api/engagement/[...path].tsfrontend/src/pages/api/stories.tsfrontend/src/pages/stories/[slug].tsxfrontend/src/hooks/uploads/useVideoUpload.tsfrontend/src/pages/api/projects/index.tsfrontend/src/pages/api/projects/[slug].tsfrontend/src/pages/api/pages/[pageType].tsfrontend/src/hooks/uploads/useImageUpload.tsfrontend/src/hooks/uploads/useFileUpload.tsfrontend/src/hooks/editor/useStoryEditor.tsfrontend/src/pages/_app.tsxfrontend/src/services/errorService.tsfrontend/src/pages/api/upload-proxy.ts
Step 1: Find and replace all utils imports
For each file, replace:
from '@/utils/...'With:
from '@/shared/utils/...'Step 2: Verify no remaining old imports
grep -r "from '@/utils/" frontend/src/Expected: No results
Step 3: Commit
git add -A
git commit -m "refactor: update utils imports to @/shared/utils/"Task 7: Update Lib Imports
Files to modify (15 files):
frontend/src/hooks/useEngagement.tsfrontend/src/components/Stories.tsxfrontend/src/components/BottomNav.tsxfrontend/src/pages/projects/[slug].tsxfrontend/src/pages/projects.tsxfrontend/src/pages/contact.tsxfrontend/src/pages/about.tsxfrontend/src/hooks/useActiveSection.tsfrontend/src/hooks/stories/useStoryMutations.tsfrontend/src/hooks/stories/useFetchStory.tsfrontend/src/hooks/stories/useFetchStories.tsfrontend/src/hooks/editor/useStoryEditor.tsfrontend/src/pages/_app.tsxfrontend/src/utils/logger.ts(now atshared/utils/logger.ts)frontend/src/lib/logging/index.ts(now atshared/lib/logging/index.ts)
Step 1: Find and replace all lib imports
For each file, replace:
from '@/lib/...'With:
from '@/shared/lib/...'Step 2: Verify no remaining old imports
grep -r "from '@/lib/" frontend/src/Expected: No results
Step 3: Commit
git add -A
git commit -m "refactor: update lib imports to @/shared/lib/"Task 8: Update Types Imports
Files to modify (21 files):
frontend/src/pages/index.tsxfrontend/src/components/engagement/CommentThread.tsxfrontend/src/components/engagement/ReactionBar.tsxfrontend/src/pages/stories/[slug].tsxfrontend/src/lib/api-client.ts(now atshared/lib/api-client.ts)frontend/src/hooks/useEngagement.tsfrontend/src/components/engagement/EngagementProvider.tsxfrontend/src/components/engagement/CommentSection.tsxfrontend/src/components/Stories.tsxfrontend/src/pages/projects/[slug].tsxfrontend/src/pages/projects.tsxfrontend/src/pages/contact.tsxfrontend/src/pages/about.tsxfrontend/src/hooks/uploads/useFileUpload.tsfrontend/src/hooks/stories/useStoryMutations.tsfrontend/src/hooks/stories/useFetchStory.tsfrontend/src/hooks/stories/useFetchStories.tsfrontend/src/hooks/editor/useStoryEditor.tsfrontend/src/services/errorService.tsfrontend/src/utils/uploadUtils.ts(now atshared/utils/uploadUtils.ts)frontend/src/components/ErrorDisplay.tsx
Step 1: Find and replace all types imports
For each file, replace:
from '@/types/...'With:
from '@/shared/types/...'Step 2: Verify no remaining old imports
grep -r "from '@/types/" frontend/src/Expected: No results
Step 3: Commit
git add -A
git commit -m "refactor: update types imports to @/shared/types/"Task 9: Verify Build
Step 1: Run TypeScript check
cd frontend && npx tsc --noEmitExpected: No errors
Step 2: Run build
npm run buildExpected: Build succeeds
Step 3: Run lint
npm run lintExpected: No new errors (existing warnings acceptable)
Step 4: Commit any fixes
If any issues found:
git add -A
git commit -m "fix: resolve import issues after shared extraction"Task 10: Run E2E Tests
Step 1: Start backend (if not running)
# In separate terminal
make dev-backendStep 2: Run E2E tests
cd frontend && npm run test:e2eExpected: All tests pass
Step 3: Commit any fixes
If any issues found:
git add -A
git commit -m "fix: resolve test issues after shared extraction"Task 11: Create PR
Step 1: Push branch
git push -u origin ghostmonk/phase-2-shared-extractionStep 2: Create PR
gh pr create --title "Phase 2: Shared Extraction" --body "$(cat <<'EOF'
## Summary
Consolidates cross-cutting code into `shared/` directory:
- Moves `utils/` → `shared/utils/`
- Moves `lib/` → `shared/lib/`
- Moves `types/` → `shared/types/`
- Updates all imports (49 files)
- Adds barrel exports for clean imports
## Phase 2 of Frontend Architecture Refactor
See `docs/plans/2026-01-03-frontend-architecture-refactor.md` for full plan.
## No Functional Changes
This is a pure reorganization. No behavior changes.
## Test Plan
- [x] TypeScript compiles without errors
- [x] Build succeeds
- [x] Lint passes
- [x] E2E tests pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
EOF
)"Completion Checklist
- Task 1: Directory structure created
- Task 2: Utils moved
- Task 3: Lib moved
- Task 4: Types moved
- Task 5: Shared index created
- Task 6: Utils imports updated (13 files)
- Task 7: Lib imports updated (15 files)
- Task 8: Types imports updated (21 files)
- Task 9: Build verified
- Task 10: E2E tests pass
- Task 11: PR created