How manojuio/noteflow works
1. Overall shape
- Noteflow is a two-tier collaborative editor: a React/Vite client talks to an Express/Socket.IO backend.
- The backend is the system of record for users, documents, and activity; the client is a thin UI that mirrors server state and streams edits in real time.
2. Client boundary
- The client/ app is organized into three user-facing screens: Auth, Dashboard, and Editor.
- App.jsx appears to act as the top-level coordinator, moving the user from login/register to document listing and then into the editing view.
- index.html and vite.config.js make this a Vite-based SPA with dev-time proxying to the backend.
3. Authentication flow
- Authentication is JWT-based.
- Auth.jsx handles register/login; tokens are persisted in browser storage and reused on later requests.
- The server signs and verifies tokens through server/middleware/auth.js and exposes auth endpoints in server/routes/auth.js.
4. Document management path
- Document CRUD is handled over HTTP in server/routes/documents.js.
- The Document model is the primary storage unit for title, content, share code, and collaboration metadata.
- The Dashboard component is the user’s entry point for listing, creating, joining, and deleting documents.
5. Real-time collaboration layer
- The Editor component is the live collaboration boundary and is the only client area that depends heavily on Socket.IO.
- Users join a document room, broadcast Quill text deltas, synchronize title changes, and receive presence/activity updates from the server.
- This is the central data flow in the app: local editor changes become socket events, which are fanned out to other connected clients.
6. Editing and persistence split
- The app separates transient collaboration from durable saves.
- Keystroke-level or delta-level updates are used for live syncing, while a fuller document payload is periodically saved back to the server via save-doc.
- The server then persists the canonical document state to MongoDB and confirms with save-ok.
7. Presence and activity tracking
- The Activity model and GET /api/documents/:id/activity route indicate a persisted audit trail of document events.
- Socket events such as room-users and activity support live sidebar feedback for who is online and what they are doing.
- This creates two parallel views of collaboration: ephemeral presence in sockets and historical activity in the database.
8. Data model boundary
- User, Document, and Activity are the core MongoDB-backed entities under server/models/.
- User supports identity and display metadata such as username and avatar color.
- Document holds share code and collaborators, which makes invite-based access part of the document domain rather than a separate service.
9. Sharing and access control
- Invite-by-code is a first-class flow: users can join a document by submitting a six-character code through /api/documents/join.
- Ownership matters for destructive actions such as delete and code regeneration.
- The auth middleware likely guards these routes so document actions are tied to the authenticated user identity.
10. Server composition
- server/server.js is the main composition root that likely mounts Express routes, configures middleware, and attaches Socket.IO to the same HTTP server.
- This makes HTTP APIs and websocket collaboration share the same deployment unit and authentication context.
- The server is the bridge between stateless REST operations and stateful room-based realtime sessions.
11. Storage and infrastructure
- MongoDB is the primary persistent store and is required for normal operation.
- init.sql suggests an optional PostgreSQL schema for additional logging or analytics, but the repository’s visible application models are MongoDB-centered.
- server/.env.example shows the system is configured by environment variables for ports, DB URIs, and JWT secret.
12. Important integration boundaries for a diagram
- UI boundary: Auth → Dashboard → Editor.
- API boundary: React app ↔ Express REST routes.
- Realtime boundary: Editor ↔ Socket.IO rooms.
- Persistence boundary: Express models ↔ MongoDB, with optional SQL logging outside the main path.
- For an architecture diagram, the critical arrows are: browser login to auth API, dashboard CRUD to document API, editor socket room joins and delta broadcasts, and server writes to MongoDB.
Main entry points: documents.js Docs API · server.js Server core · App.jsx App shell · auth.js Auth API
Components 16
Client UI
Vite/React single-page app for authentication, document management, and live editing.
- App shell · Top-level client coordinator that routes users between auth, dashboard, and editor screens.
client/src/App.jsx - Auth · Handles sign up, login, and token persistence.
client/src/components/Auth.jsx - Dashboard · Lists, creates, joins, and deletes documents.
client/src/components/Dashboard.jsx - Editor · Live editing surface that connects to Socket.IO for room joins, deltas, title sync, and presence updates.
client/src/components/Editor.jsx - Vite entry · Browser entry and Vite scaffold for the client application.
client/src/index.jsx - Vite config · Development configuration and backend proxying for the SPA.
client/vite.config.js
Server Runtime
Express and Socket.IO backend that owns auth, documents, collaboration, and persistence.
- Server core · Composition root that mounts middleware, routes, and realtime collaboration on one HTTP server.
server/server.js - Auth API · Authentication endpoints for registering, logging in, and issuing JWTs.
server/routes/auth.js - Docs API · Document CRUD, join-by-code, save, and activity endpoints.
server/routes/documents.js - Auth guard · Verifies bearer tokens and attaches authenticated user context to protected routes.
server/middleware/auth.js - Collab socket · Realtime collaboration layer for room membership, delta fanout, title sync, and presence/activity events.
server/server.js
Persistence
MongoDB-backed domain models and ancillary SQL schema.
- User · Identity and display metadata for authenticated users.
server/models/User.js - Document · Primary document record with title, content, share code, collaborators, and collaboration metadata.
server/models/Document.js - Activity · Persistent audit trail of document events and collaboration history.
server/models/Activity.js - MongoDB · Main persistent database for users, documents, and activity.
- SQL schema · Optional SQL initialization script for extra logging or analytics.
init.sql
Connections 22
- App shell → Auth: shows · Moves the user into authentication when no session is present.
- App shell → Dashboard: navigates · Routes authenticated users to the document dashboard.
- App shell → Editor: opens · Enters the live editor for a selected document.
- Vite entry → App shell: boots · Bootstraps the React application.
- Vite config → Server core: proxies · Dev-time API proxy to the backend.
- Auth → Auth API: login/register · Sends credentials and receives JWT auth responses.
- Dashboard → Docs API: crud · Creates, lists, joins, and deletes documents over HTTP.
- Editor → Collab socket: syncs edits · Joins rooms and streams deltas, title changes, and presence events.
- Server core → Auth API: mounts · Registers authentication routes.
- Server core → Docs API: mounts · Registers document routes.
- Server core → Collab socket: attaches · Hosts Socket.IO on the same server as HTTP.
- Auth API → Auth guard: protects · Uses JWT verification for protected operations.
- Auth API → User: uses · Creates and authenticates user records.
- Docs API → Auth guard: protects · Binds document actions to authenticated users.
- Docs API → Document: reads/writes · Persists and retrieves document state.
- Docs API → Activity: logs · Stores document activity and audit events.
- Collab socket → Document: updates · Applies live collaboration changes to the canonical document state.
- Collab socket → Activity: emits · Records or forwards collaboration activity signals.
- User → MongoDB: persists · User data is stored in MongoDB.
- Document → MongoDB: persists · Document data is stored in MongoDB.
- Activity → MongoDB: persists · Activity history is stored in MongoDB.
- Docs API → SQL schema: optional · Repository includes a secondary SQL schema outside the main path.