How harsha-98h/storyflow works
Purpose and Active Entry Points
StoryFlow is an English-learning platform delivering daily, upward-scrolling reading lessons, tracking completion/streaks, showing analytics, and storing reminder preferences. The active system is a Next.js frontend plus TypeScript Express/MongoDB API; the Python FastAPI tree is legacy and safety-locked.
• Frontend application root: frontend/app/layout.tsx, frontend/app/page.tsx
• API process and route composition: backend/src/server.ts, backend/src/app.ts
• Legacy reference only: backend/app/main.py
Client Application and Navigation
Next.js App Router supplies public authentication, learning, dashboard, legal, and debug/operations views. Shared providers establish authentication and theme state; browser API access is centralized rather than embedded in individual pages.
• Main user surfaces: frontend/app/learn/page.tsx, frontend/app/dashboard/page.tsx, frontend/app/auth/page.tsx
• Shared session/UI boundaries: frontend/components/auth-provider.tsx, frontend/lib/api.ts
• Request-level frontend middleware: frontend/middleware.ts
Authentication and Security Boundary
The Express auth routes implement email/password registration, JWT access/refresh lifecycle, current-user lookup, verification, and password reset. Security controls include password hashing, CSRF double-submit tokens, request validation, rate limiting, CORS/cookie settings, and optional transactional-email providers.
• Auth API and token utilities: backend/src/routes/auth.ts, backend/src/utils/auth.ts
• Environment/database initialization: backend/src/config/env.ts, backend/src/config/database.ts
• Global API protection: backend/src/middleware/rateLimit.ts, backend/src/app.ts
Learning Content Delivery
Learning content is modeled and persisted in MongoDB, then selected by the content endpoint for daily lessons. A seed pipeline imports the frontend-owned JSON corpus into the learningContents collection; content structures are shared conceptually across the web app and backend.
• Content API/model: backend/src/routes/content.ts, backend/src/models/LearningContent.ts
• Canonical seed corpus and importer: frontend/data/learning_content.json, backend/src/scripts/seedContent.ts
• Reader UI: frontend/components/credits-reader.tsx, frontend/app/learn/page.tsx
Progress, Streaks, and Analytics Flow
After a reader marks material read, the API updates per-user progress and streak state. Summary/activity endpoints feed dashboard statistics, while analytics aggregates daily, weekly, monthly, and total reading views.
• Write/read progress flow: backend/src/routes/progress.ts, backend/src/models/UserProgress.ts, backend/src/models/Streak.ts
• Aggregated reporting: backend/src/routes/analytics.ts
• Dashboard presentation: frontend/app/dashboard/page.tsx, frontend/components/analytics-charts.tsx
Reminders and Notification Integration
Authenticated clients register Firebase push tokens and email reminder preferences through the reminders API. The frontend includes PWA/service-worker assets and Firebase initialization, while delivery remains optional infrastructure.
• Reminder persistence/API: backend/src/routes/reminders.ts, backend/src/models/UserReminder.ts
• Firebase/PWA client boundary: frontend/lib/firebase.ts, frontend/public/firebase-messaging-sw.js, frontend/public/sw.js
• Settings UI: frontend/components/reminder-settings.tsx
Runtime and Deployment Topology
The frontend is intended for Vercel; Express runs as a Node service, intended for Render, connected to MongoDB Atlas. CORS and cookie security bridge the separate browser/frontend/API origins. Optional external services are Firebase Cloud Messaging, Brevo or Resend email, and configured OpenAI moderation/fallback models.
• Backend deployment definition: backend/render.yaml
• Node dependencies/process definitions: backend/package.json, frontend/package.json
• Security CI gate: .github/workflows/security-smoke.yml
Main entry points: app.ts API composition and protection · page.tsx App Router surfaces · database.ts MongoDB Atlas · api.ts Browser API client
Components 22
Next.js frontend
- App Router surfaces · Learning, dashboard, authentication, legal, and operations views.
frontend/app/page.tsx - Request middleware
frontend/middleware.ts - Session and theme provider
frontend/components/auth-provider.tsx - Browser API client · Centralizes browser access to the Express API.
frontend/lib/api.ts - Lesson reader · Renders upward-scrolling reading lessons.
frontend/components/credits-reader.tsx - Dashboard and charts
frontend/app/dashboard/page.tsx - Reminder settings
frontend/components/reminder-settings.tsx - Firebase and PWA client · Firebase initialization plus service-worker assets.
frontend/lib/firebase.ts
Express API
- Node API process
backend/src/server.ts - API composition and protection · Composes routes with CORS, cookies, CSRF, validation, and rate limiting.
backend/src/app.ts - Authentication API · Registration, JWT lifecycle, verification, reset, and current-user lookup.
backend/src/routes/auth.ts - Daily content API
backend/src/routes/content.ts - Progress and streak API
backend/src/routes/progress.ts - Analytics API · Aggregates daily, weekly, monthly, and total reading activity.
backend/src/routes/analytics.ts - Reminders API
backend/src/routes/reminders.ts - Legacy FastAPI · Safety-locked and not part of the active runtime.
backend/app/main.py
Content and data
- MongoDB Atlas · Stores users, content, progress, streaks, and reminders.
backend/src/config/database.ts - Learning content corpus · Canonical frontend-owned lesson source.
frontend/data/learning_content.json - Content seed importer · Imports the corpus into learningContents.
backend/src/scripts/seedContent.ts
Deployment and integrations
- Vercel
frontend/package.json - Render
backend/render.yaml - Push and email providers · Firebase Cloud Messaging and Brevo or Resend delivery.
frontend/public/firebase-messaging-sw.js
Connections 28
- Vercel → App Router surfaces: hosts
- Request middleware → App Router surfaces: guards requests
- App Router surfaces → Session and theme provider: uses
- App Router surfaces → Lesson reader: learn view
- App Router surfaces → Dashboard and charts: dashboard view
- App Router surfaces → Reminder settings: settings view
- Session and theme provider → Browser API client: session requests
- Lesson reader → Browser API client: content and completion
- Dashboard and charts → Browser API client: statistics
- Reminder settings → Browser API client: preferences and tokens
- Firebase and PWA client → Push and email providers: registers push
- Reminder settings → Firebase and PWA client: configures push
- Browser API client → Node API process: cross-origin API calls · CORS and cookie security bridge frontend and API origins.
- Render → Node API process: hosts
- Node API process → API composition and protection: serves
- API composition and protection → Authentication API: routes
- API composition and protection → Daily content API: routes
- API composition and protection → Progress and streak API: routes
- API composition and protection → Analytics API: routes
- API composition and protection → Reminders API: routes
- Authentication API → MongoDB Atlas: users and tokens
- Daily content API → MongoDB Atlas: daily lessons
- Progress and streak API → MongoDB Atlas: progress and streaks
- Analytics API → MongoDB Atlas: aggregates activity
- Reminders API → MongoDB Atlas: preferences
- Reminders API → Push and email providers: optional delivery
- Learning content corpus → Content seed importer: source lessons
- Content seed importer → MongoDB Atlas: imports learningContents