Notification System Example
This example shows how to break a complex feature (a notification system) into small, focused stories that Ralph can execute autonomously. The key challenge is splitting work into stories completable in one context window.The Challenge
Original requirement: “Add user notifications to the app” This is far too big for one story. Let’s break it down properly.Story Breakdown Strategy
Identify Layers
Split by technical layer:
- Data layer: Database schema
- Logic layer: Services and actions
- UI layer: Components and pages
- Integration: Connecting the pieces
Order by Dependencies
Later stories depend on earlier ones:
- Schema (nothing works without this)
- Write operations (creating notifications)
- Read operations (fetching notifications)
- Display (showing notifications)
- Interactions (marking as read, etc.)
Complete prd.json
Story-by-Story Walkthrough
US-001: Database Schema (Iteration 1)
US-001: Database Schema (Iteration 1)
Focus: Just the data modelRalph implements:
- Create
notificationstable migration - Add columns: id, userId, type, message, read, createdAt
- Add index on userId
- Run migration
- Single file: one migration
- Clear scope: just database
- Fast verification: migration runs or fails
feat: add notifications tableprogress.txt update:US-002: Notification Service (Iteration 2)
US-002: Notification Service (Iteration 2)
Focus: Just the creation logicRalph implements:
- Create
lib/services/notification.ts - Implement
create()function - Add unit tests
- Export from services index
- Single file: one service
- Clear interface: one public function
- Testable: unit tests verify behavior
feat: add notification serviceprogress.txt update:US-003: Bell Icon (Iteration 3)
US-003: Bell Icon (Iteration 3)
Focus: Just the indicatorRalph implements:
- Add bell icon to
components/Header.tsx - Query for unread count
- Display badge with count
- Style badge to match design system
- Single component modification
- Simple query (just count)
- Visual verification with dev-browser
feat: add notification bell to headerprogress.txt update:US-004: Dropdown Panel (Iteration 4)
US-004: Dropdown Panel (Iteration 4)
Focus: Just the display panelRalph implements:
- Create
components/NotificationPanel.tsx - Fetch recent notifications (limit 10)
- Render list with message, icon, timestamp
- Style unread vs read differently
- Add click-outside-to-close behavior
- Single new component
- Read-only (no mutations)
- Self-contained UI logic
feat: add notification dropdown panelprogress.txt update:US-005: Mark as Read (Iteration 5)
US-005: Mark as Read (Iteration 5)
Focus: Just the interactionRalph implements:
- Create server action
markNotificationRead(id) - Add onClick handler to notification items
- Optimistically update UI
- Decrement badge count
- Single interaction flow
- One server action
- Clear success criteria
feat: add mark-as-read functionalityprogress.txt update:US-006: Preferences Page (Iteration 6)
US-006: Preferences Page (Iteration 6)
Focus: Just the settings UIRalph implements:
- Create
app/settings/notifications/page.tsx - Query user preferences from database
- Render toggles for each notification type
- Create server action for saving preferences
- Add to settings navigation
- Single page component
- Standard CRUD pattern
- Independent from other stories
feat: add notification preferences pageprogress.txt update:What Made This Work
- Right-Sized Stories
- Dependency Order
- Verifiable Criteria
- Separation of Concerns
Each story was small enough to complete in one iteration:US-001: One migration file
US-002: One service file + tests
US-003: One component modification
US-004: One new component
US-005: One interaction + server action
US-006: One page componentNone required touching more than 2-3 files.
Common Mistakes to Avoid
Adapting This Pattern
Use this breakdown strategy for any complex feature:- Authentication system: Schema → Middleware → Login UI → Session handling
- Search feature: Schema → Indexing → API endpoint → Search UI → Filters
- File uploads: Schema → Upload service → UI component → Progress tracking
The notification system example demonstrates production patterns for breaking down features. Use it as a reference when creating your own
prd.json files.
