How himanijha/foldednotes works
1. Overall shape
- This is a Next.js Pages Router application with both UI pages and backend API routes in the same repo.
- The architecture is split into:
- Client-facing pages/components under src/pages and src/components
- Server-side API endpoints under src/pages/api
- Shared domain/infrastructure helpers under src/lib
- A small custom server layer under src/server plus server.js
2. Primary product flow
- The app is built around anonymous voice messages: users record audio, submit it for transcription/processing, and then consume or generate content from that transcript.
- The README also calls out a notes feed where users can post short notes, including a side-panel “write a note” workflow.
3. Frontend entry points
- Main UI screens live in:
- src/pages/index.tsx and src/pages/home.tsx for landing/home
- src/pages/record.tsx for audio capture
- src/pages/generate.tsx for transcript-driven generation
- src/pages/memories.tsx for saved/archived content
- src/pages/login.tsx and src/pages/settings.tsx
- _app.tsx and _document.tsx provide shared app-level wiring and document setup.
- Styling is page/component-scoped via CSS modules in src/styles plus global styles.
4. Client components and UX boundaries
- AudioRecorder.tsx is the main recording UI component; it likely owns microphone capture, recording state, and upload/submit actions.
- GenerateFromTranscript.tsx appears to handle turning a transcript into generated content or follow-up artifacts.
- These components are the primary bridge from user interaction into the API layer.
5. API layer as the backend boundary
- The app uses Next.js API routes as its server boundary. Key endpoints include:
- POST /api/auth/login, signup, me
- POST /api/notes
- POST /api/transcribe
- POST /api/summary
- POST /api/classify
- POST /api/speech
- GET/POST /api/voices, /api/pick-voice
- GET/POST /api/recordings
- This means the browser never talks directly to MongoDB or third-party AI services; it goes through these routes.
6. Identity and session subsystem
- src/lib/auth.ts and the auth API routes indicate a dedicated authentication subsystem.
- The presence of /api/auth/me suggests the frontend can hydrate the current user/session state from the backend.
- The repo supports authenticated flows for some actions while still emphasizing anonymous contributions as a product concept.
7. Persistence layer
- MongoDB is the main database, with connection helpers in src/lib/mongodb.ts and src/server/mongodb.ts.
- Data likely persisted here includes:
- Users/auth records
- Notes/feed items
- Recordings and transcript metadata
- Possibly summaries, classifications, and selected voice preferences
- src/pages/api/recordings.ts and src/pages/api/notes.ts are the clearest persistence-facing endpoints.
8. AI/LLM processing subsystem
- src/lib/gemini.ts and src/lib/prompt.ts show an LLM-backed generation layer, likely used for summarization, rewriting, or content generation from transcripts.
- /api/summary and /api/classify are the service boundaries for turning raw transcript content into structured outputs.
- src/lib/emotions.ts and src/types/emotion.ts suggest a dedicated emotion/labeling model used in classification or content tagging.
9. Audio and speech subsystem
- src/lib/audio.ts handles audio-specific transformations or transport concerns.
- The README documents POST /api/transcribe as an ElevenLabs Speech-to-Text integration using base64-encoded audio.
- POST /api/speech, /api/voices, and /api/pick-voice indicate a text-to-speech / voice-selection pipeline, also likely external-service-backed.
- This makes audio an explicit data pipeline:
- browser recording → API upload → transcription → transcript processing → optional speech/voice output
10. External service dependencies
- ElevenLabs is a required external service for transcription, and likely also voice generation.
- Gemini is used for AI text processing/generation.
- MongoDB is the persistence backend.
- These are the main off-repo dependencies that affect architecture and deployment configuration.
11. Custom server and runtime
- server.js plus src/server/index.ts suggest there is a custom Node server entrypoint or server bootstrap in addition to Next.js defaults.
- This is relevant because it may control startup behavior, database initialization, or route mounting beyond standard Next.js deployment.
- The project still remains fundamentally a Next.js app, but with server-side bootstrap logic layered on top.
12. End-to-end data flow summary
- Typical flow:
- User records audio in the browser
- Client submits audio to /api/transcribe
- Transcript may then be sent to /api/summary, /api/classify, or /api/speech
- Results and/or notes are persisted through MongoDB-backed API routes
- The UI retrieves user state and content through API routes like /api/me, /api/notes, and /api/recordings
13. Architectural boundaries to show in a diagram
- Presentation layer: pages + reusable React components
- API layer: Next.js route handlers under /api/*
- Domain helpers: auth, audio, prompts, emotions, AI integration
- Data layer: MongoDB
- External AI services: ElevenLabs and Gemini
- Static assets/styles: public and src/styles
Main entry points: summary.ts AI API · transcribe.ts Speech API · mongodb.ts MongoDB · _app.tsx App shell
Components 27
Presentation
UI pages and shared app shell
- App shell · Global app and document setup
src/pages/_app.tsx - Landing · Entry and home screens
src/pages/index.tsx - Record · Audio capture workflow
src/pages/record.tsx - Generate · Transcript-driven generation screen
src/pages/generate.tsx - Memories · Saved and archived content
src/pages/memories.tsx - Account · Login and settings screens
src/pages/login.tsx
Components
Reusable client interactions
- AudioRecorder · Microphone capture and upload control
src/components/AudioRecorder.tsx - Transcript UI · Turns transcripts into follow-up content
src/components/GenerateFromTranscript.tsx
API Layer
Next.js route handlers
- Auth API · Login, signup, and session lookup
src/pages/api/auth/login.ts - Notes API · Create and read notes feed items
src/pages/api/notes.ts - Recordings API · Persist recording metadata and history
src/pages/api/recordings.ts - Speech API · Transcription and voice synthesis endpoints
src/pages/api/transcribe.ts - AI API · Summaries and classification endpoints
src/pages/api/summary.ts - Voices API · Voice listing and selection endpoints
src/pages/api/voices.ts - Hello · Basic health or sample endpoint
src/pages/api/hello.ts
Domain
Shared auth, audio, and AI helpers
- Auth core · Session and identity logic
src/lib/auth.ts - Audio core · Audio processing and transport utilities
src/lib/audio.ts - Prompting · Prompt templates and generation helpers
src/lib/prompt.ts - Emotions · Emotion and classification vocabulary
src/lib/emotions.ts - Gemini client · AI integration for text generation
src/lib/gemini.ts
Persistence
MongoDB access and server bootstrap
- MongoDB · Database connection helper
src/lib/mongodb.ts - Server bootstrap · Custom server entrypoint and startup logic
server.js - Server Mongo · Server-side database wiring
src/server/mongodb.ts - Server core · Custom server implementation
src/server/index.ts
External Services
Off-repo AI, speech, and database dependencies
- ElevenLabs · Transcription and voice generation
- Gemini · LLM-backed text processing
- MongoDB · Persistent data store
Connections 29
- App shell → Landing: wraps · Shared app-level setup for pages
- App shell → Record: wraps · Shared app-level setup for pages
- App shell → Generate: wraps · Shared app-level setup for pages
- Landing → AudioRecorder: uses · Landing and recording flows surface recorder UI
- Record → AudioRecorder: uses · Primary capture interaction
- Generate → Transcript UI: uses · Transcript-driven generation UI
- Account → Auth API: calls · Login and session management
- AudioRecorder → Speech API: submits audio · Uploads recorded audio for transcription
- Transcript UI → AI API: requests output · Uses transcript processing endpoints
- Transcript UI → Notes API: may save · Generated content can become notes
- Memories → Notes API: loads · Reads stored notes and memories
- Record → Recordings API: persists · Stores recording history
- Auth API → Auth core: implements · Auth route handlers use shared auth logic
- Notes API → MongoDB: stores · Persists notes data
- Recordings API → MongoDB: stores · Persists recording metadata
- Speech API → Audio core: uses · Audio encoding and transport helpers
- Speech API → ElevenLabs: calls · Transcription and voice services
- Voices API → ElevenLabs: calls · Voice catalog and selection data
- AI API → Prompting: uses · Builds prompts for AI tasks
- AI API → Gemini client: calls · LLM-backed summary and classification
- AI API → Emotions: uses · Emotion labels for classification
- MongoDB → MongoDB: connects · Primary persistence backend
- Server bootstrap → Server core: starts · Custom runtime entrypoint
- Server core → Server Mongo: initializes · Server-side Mongo wiring
- Server Mongo → MongoDB: connects · Database connection used by server bootstrap
- Auth API → MongoDB: stores · Auth records and session state
- Speech API → MongoDB: may persist · Transcript or recording metadata
- AI API → MongoDB: may persist · Generated summaries or labels
- Hello → Server core: served by · Example or health route in the API surface