- Architectural Plan: Complete Node.js/TypeScript backend design
- Database Schema: Full PostgreSQL schema with Prisma
- PRD v2.0: Backend-focused with testing requirements
- Testing Strategy: 200+ tests, 90% coverage target
- Context Archival: Frontend PRD moved to
.context/archive/
REVISED_BACKEND_ARCHITECTURE.md- Detailed backend planprd.json- New backend PRD with testing requirements.context/archive/prd-frontend-...- Archived frontend PRD.context/archive/TESTING_STRATEGY.md- Testing guide
- Next.js 14 (App Router) - Frontend + API
- NextAuth.js v5 - Authentication
- PostgreSQL - Primary database (self-hosted)
- Redis - Cache + queues (self-hosted)
- BullMQ - Background jobs
- OpenAI - AI features with local fallback
- Socket.io - Real-time features
docker-compose up -d # Start DB + Redis
npm run dev # Start Next.jsPhase 1 (Week 1): Setup
- Next.js 14 + Docker + Prisma + NextAuth
Phase 2 (Week 2): Core API
- Tasks, Micro-steps, Sessions
Phase 3 (Week 3): Intelligence
- AI breakdown, Pattern analysis
Phase 4 (Week 4): Social
- Partners, Sharing, Notifications
Phase 5 (Week 5): Emergency + Polish
- Emergency mode, Reminders, Monitoring
Phase 6 (Week 6): Production
- Deployment, Migration tools, Documentation
- 200+ tests across 4 categories
- 90% coverage requirement
- Unit: 70% (140+ tests)
- Integration: 20% (40+ tests)
- E2E: 10% (20+ tests)
- Security: 100% coverage
This repo includes a small, explicit lifecycle state machine for Cards, exposed via a REST surface in the Express backend and mirrored in a simple React component.
initial->loading->active->completedloading/activecan also go todiscardedcompletedanddiscardedare terminal
The shared type lives in shared/src/types.d.ts as CardLifecycleState.
Base path: POST /api/cards (mounted in backend/src/index.ts). All endpoints require Authorization: Bearer <access_token>.
POST /api/cards/:id/open- Creates the card record if it does not exist (creates directly in
loading) - Otherwise attempts to transition to
loading
- Creates the card record if it does not exist (creates directly in
POST /api/cards/:id/readytransitions toactivePOST /api/cards/:id/finishtransitions tocompleted(setscompletedAt)POST /api/cards/:id/closetransitions todiscarded(fails with 400 if already discarded)
Responses are a CardRecord JSON payload:
{
"id": "card-123",
"userId": "user-abc",
"state": "active",
"createdAt": "2026-02-07T12:00:00.000Z",
"updatedAt": "2026-02-07T12:01:00.000Z",
"completedAt": null
}Quick test (default backend port is 7101):
TOKEN=... # access token
curl -sS -X POST "http://localhost:7101/api/cards/card-123/open" \
-H "Authorization: Bearer $TOKEN"Note: the current implementation uses an in-memory store (backend/src/routes/cardRoutes.ts) keyed by userId:cardId.
src/components/Card.tsx is a minimal React component that demonstrates the same transition rules. It currently takes no props and exposes helpers you can reuse:
initialCardLifecycleStatecardAllowedTransitionscanTransition(from, to)nextCardState(current, desired)
- Run
npm installto install dependencies - Run
docker-compose up -dto start infrastructure - Run
npx prisma migrate devto setup database - Start implementing Phase 1 features
- Write tests alongside code (TDD recommended)
# Infrastructure
docker-compose up -d # Start PostgreSQL + Redis
docker-compose down # Stop infrastructure
docker-compose logs -f # View logs
# Development
npm run dev # Start Next.js (port 3000)
npx prisma studio # Database GUI (port 5555)
# Testing
npm run test:unit # Unit tests with coverage
npm run test:integration # Integration tests
npm run test:e2e # E2E tests
npm run test:all # Run everything
# Database
npx prisma migrate dev # Create migration
npx prisma db push # Sync schema
npx prisma generate # Generate client
# Production
npm run build # Build for production
npm start # Start production server- Frontend is still in localStorage mode - Backend needs to be built
- Migration script needed - For moving existing user data
- All features are planned - Ready for implementation
- Tests are specified - Ready to write
- Cost-effective - Uses free/low-cost services
REVISED_BACKEND_ARCHITECTURE.md- Complete technical planprd.json- Backend user stories & testing requirements.context/archive/TESTING_STRATEGY.md- Testing guide
Ready to start implementation! 🚀