# manojuio/noteflow architecture

> Architecture diagram of the GitHub repository manojuio/noteflow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/manojuio/noteflow
- Repository: https://github.com/manojuio/noteflow

## Overview

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: [`server/routes/documents.js`](https://github.com/manojuio/noteflow/blob/main/server/routes/documents.js) (Docs API), [`server/server.js`](https://github.com/manojuio/noteflow/blob/main/server/server.js) (Server core), [`client/src/App.jsx`](https://github.com/manojuio/noteflow/blob/main/client/src/App.jsx) (App shell), [`server/routes/auth.js`](https://github.com/manojuio/noteflow/blob/main/server/routes/auth.js) (Auth API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client UI"]
  node_client_app["App shell<br/>react coordinator<br/>[App.jsx]"]
  node_client_auth["Auth<br/>login/register UI<br/>[Auth.jsx]"]
  node_client_dashboard["Dashboard<br/>document hub<br/>[Dashboard.jsx]"]
  node_client_editor["Editor<br/>[Editor.jsx]"]
  node_client_entry["Vite entry<br/>spa bootstrap<br/>[index.jsx]"]
  node_client_vite["Vite config<br/>dev proxy<br/>[vite.config.js]"]
end

subgraph group_server["Server Runtime"]
  node_server_main["Server core<br/>express/socket.io host<br/>[server.js]"]
  node_server_auth_routes["Auth API<br/>rest routes<br/>[auth.js]"]
  node_server_doc_routes["Docs API<br/>rest routes<br/>[documents.js]"]
  node_server_auth_mw["Auth guard<br/>jwt middleware<br/>[auth.js]"]
  node_server_socket(("Collab socket<br/>socket.io rooms<br/>[server.js]"))
end

subgraph group_data["Persistence"]
  node_model_user[("User<br/>mongo model<br/>[User.js]")]
  node_model_doc[("Document<br/>mongo model<br/>[Document.js]")]
  node_model_activity[("Activity<br/>mongo model<br/>[Activity.js]")]
  node_mongo[("MongoDB<br/>primary store")]
  node_sql_schema["SQL schema<br/>optional postgres<br/>[init.sql]"]
end

node_client_app -->|"shows"| node_client_auth
node_client_app -->|"navigates"| node_client_dashboard
node_client_app -->|"opens"| node_client_editor
node_client_entry -->|"boots"| node_client_app
node_client_vite -.->|"proxies"| node_server_main
node_client_auth -->|"login/register"| node_server_auth_routes
node_client_dashboard -->|"crud"| node_server_doc_routes
node_client_editor -->|"syncs edits"| node_server_socket
node_server_main -->|"mounts"| node_server_auth_routes
node_server_main -->|"mounts"| node_server_doc_routes
node_server_main -->|"attaches"| node_server_socket
node_server_auth_routes -->|"protects"| node_server_auth_mw
node_server_auth_routes -->|"uses"| node_model_user
node_server_doc_routes -->|"protects"| node_server_auth_mw
node_server_doc_routes -->|"reads/writes"| node_model_doc
node_server_doc_routes -->|"logs"| node_model_activity
node_server_socket -->|"updates"| node_model_doc
node_server_socket -->|"emits"| node_model_activity
node_model_user -->|"persists"| node_mongo
node_model_doc -->|"persists"| node_mongo
node_model_activity -->|"persists"| node_mongo
node_server_doc_routes -.->|"optional"| node_sql_schema

click node_client_app "https://github.com/manojuio/noteflow/blob/main/client/src/App.jsx"
click node_client_auth "https://github.com/manojuio/noteflow/blob/main/client/src/components/Auth.jsx"
click node_client_dashboard "https://github.com/manojuio/noteflow/blob/main/client/src/components/Dashboard.jsx"
click node_client_editor "https://github.com/manojuio/noteflow/blob/main/client/src/components/Editor.jsx"
click node_client_entry "https://github.com/manojuio/noteflow/blob/main/client/src/index.jsx"
click node_client_vite "https://github.com/manojuio/noteflow/blob/main/client/vite.config.js"
click node_server_main "https://github.com/manojuio/noteflow/blob/main/server/server.js"
click node_server_auth_routes "https://github.com/manojuio/noteflow/blob/main/server/routes/auth.js"
click node_server_doc_routes "https://github.com/manojuio/noteflow/blob/main/server/routes/documents.js"
click node_server_auth_mw "https://github.com/manojuio/noteflow/blob/main/server/middleware/auth.js"
click node_server_socket "https://github.com/manojuio/noteflow/blob/main/server/server.js"
click node_model_user "https://github.com/manojuio/noteflow/blob/main/server/models/User.js"
click node_model_doc "https://github.com/manojuio/noteflow/blob/main/server/models/Document.js"
click node_model_activity "https://github.com/manojuio/noteflow/blob/main/server/models/Activity.js"
click node_sql_schema "https://github.com/manojuio/noteflow/blob/main/init.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_app,node_client_auth,node_client_dashboard,node_client_editor,node_client_entry,node_client_vite toneBlue
class node_server_main,node_server_auth_routes,node_server_doc_routes,node_server_auth_mw,node_server_socket toneAmber
class node_model_user,node_model_doc,node_model_activity,node_mongo,node_sql_schema toneMint
```

## Components

### Client UI

Vite/React single-page app for authentication, document management, and live editing.

- [App shell](https://github.com/manojuio/noteflow/blob/main/client/src/App.jsx): react coordinator · Top-level client coordinator that routes users between auth, dashboard, and editor screens. · `client/src/App.jsx`
- [Auth](https://github.com/manojuio/noteflow/blob/main/client/src/components/Auth.jsx): login/register UI · Handles sign up, login, and token persistence. · `client/src/components/Auth.jsx`
- [Dashboard](https://github.com/manojuio/noteflow/blob/main/client/src/components/Dashboard.jsx): document hub · Lists, creates, joins, and deletes documents. · `client/src/components/Dashboard.jsx`
- [Editor](https://github.com/manojuio/noteflow/blob/main/client/src/components/Editor.jsx): collab 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](https://github.com/manojuio/noteflow/blob/main/client/src/index.jsx): spa bootstrap · Browser entry and Vite scaffold for the client application. · `client/src/index.jsx`
- [Vite config](https://github.com/manojuio/noteflow/blob/main/client/vite.config.js): dev proxy · 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](https://github.com/manojuio/noteflow/blob/main/server/server.js): express/socket.io host · Composition root that mounts middleware, routes, and realtime collaboration on one HTTP server. · `server/server.js`
- [Auth API](https://github.com/manojuio/noteflow/blob/main/server/routes/auth.js): rest routes · Authentication endpoints for registering, logging in, and issuing JWTs. · `server/routes/auth.js`
- [Docs API](https://github.com/manojuio/noteflow/blob/main/server/routes/documents.js): rest routes · Document CRUD, join-by-code, save, and activity endpoints. · `server/routes/documents.js`
- [Auth guard](https://github.com/manojuio/noteflow/blob/main/server/middleware/auth.js): jwt middleware · Verifies bearer tokens and attaches authenticated user context to protected routes. · `server/middleware/auth.js`
- [Collab socket](https://github.com/manojuio/noteflow/blob/main/server/server.js): socket.io rooms · 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](https://github.com/manojuio/noteflow/blob/main/server/models/User.js): mongo model · Identity and display metadata for authenticated users. · `server/models/User.js`
- [Document](https://github.com/manojuio/noteflow/blob/main/server/models/Document.js): mongo model · Primary document record with title, content, share code, collaborators, and collaboration metadata. · `server/models/Document.js`
- [Activity](https://github.com/manojuio/noteflow/blob/main/server/models/Activity.js): mongo model · Persistent audit trail of document events and collaboration history. · `server/models/Activity.js`
- **MongoDB**: primary store · Main persistent database for users, documents, and activity.
- [SQL schema](https://github.com/manojuio/noteflow/blob/main/init.sql): optional postgres · Optional SQL initialization script for extra logging or analytics. · `init.sql`

## Connections

- 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.
