LivePad is a web-based real-time collaborative text editor. It allows multiple users to join a shared editing session and see each other's changes live. The project is built as a Single Page Application (SPA) using React and TypeScript for the frontend, leveraging Firebase for backend services including real-time data synchronization and hosting.
The primary goal of this project is to provide a simple and efficient platform for collaborative document editing, similar to Google Docs but potentially lighter weight. It utilizes Firepad on top of Firebase Realtime Database to handle the complexities of operational transforms required for seamless multi-user editing.
Here is an overview of the key directories and files within the project:
src/: Contains the core frontend source code for the React application.index.tsx: The main entry point for the React application.index.html.ejs: HTML template used by Webpack to generate the mainindex.html.App.tsx: The root React component, likely setting up routing and main layout.Router.tsx: Defines the application's client-side routing usingreact-router-dom.components/: Contains reusable React UI components (e.g.,JoinSession.tsx,History.tsx,StatusBar.tsx).utils/: Contains utility functions and modules (e.g.,Session.tsxfor session logic,LocalStore.tsxfor local storage interaction).assets/: Static assets like images, fonts, and SCSS stylesheets.favicon.ico: Application favicon.
public/: This directory typically holds the static files generated by the build process (Webpack). These are the files deployed to the web server or hosting service (Firebase Hosting in this case). Note: This directory might be cleaned and regenerated during builds.functions/: Contains the source code for Firebase Cloud Functions.src/index.ts: The entry point for cloud functions written in TypeScript.lib/: Compiled JavaScript output from the TypeScript functions source.package.json: Dependencies specific to the Cloud Functions.tsconfig.json: TypeScript configuration for the Cloud Functions.
configs/: Holds configuration files for various development tools.webpack/: Contains Webpack configuration files (common.js,dev.js,prod.js) for development and production builds.jest.json: Configuration for the Jest testing framework.jest.preprocessor.js: Preprocessor script for Jest.
scripts/: Contains utility scripts for development or maintenance tasks (e.g.,cleanup.js).tests/: Contains unit and integration tests for the frontend application, using Jest and potentially React Testing Library.__mocks__/: Directory for Jest mocks.
docs/: Contains project documentation files (e.g., planning documents in Markdown).README.md: This file, providing an overview of the project..firebaserc: Configuration linking the project to a specific Firebase project.firebase.json: Configuration for Firebase services like Hosting and Functions deployments.package.json: Defines project metadata, dependencies, and scripts for the frontend application.tsconfig.json: TypeScript configuration for the frontend application..eslintrc.js: Configuration for the ESLint linter..prettierrc.js: Configuration for the Prettier code formatter..gitignore: Specifies intentionally untracked files that Git should ignore.express.js: A simple Express server script used to serve the production build locally (yarn start-prod).LICENSE: Project license file (MIT).
Architecture:
- Frontend: A React-based Single Page Application (SPA) written in TypeScript. It handles user interface rendering, client-side routing (
react-router-dom), and interaction logic. Webpack is used for bundling assets, and Babel transpiles modern JavaScript/TypeScript for browser compatibility. Styling is done using SCSS/Sass. - Backend: Primarily leverages Firebase services:
- Realtime Database/Firestore: Used as the backend data store, particularly for synchronizing document content in real-time across clients via Firepad.
- Firebase Hosting: Hosts the static frontend assets (HTML, CSS, JavaScript bundles).
- Firebase Cloud Functions: Provides serverless backend logic (if any specific logic beyond Firepad's capabilities is needed). The
functions/directory suggests their use.
- Collaboration Engine: Firepad library integrates with Firebase Realtime Database to manage collaborative text editing, handling operational transformations to merge changes from multiple users concurrently.
Data Flow:
- Input:
- User navigates to the application URL.
- User interacts with the UI (e.g., types in the editor, clicks buttons).
- User joins a specific session, potentially via a URL parameter (handled by
react-router-domandquery-string).
- Processing:
- Client-Side:
- React renders the UI based on application state.
react-router-domhandles navigation between views (e.g., joining screen, editor screen).- User input in the editor is captured.
- Firepad library intercepts editor changes, calculates the necessary operational transforms, and sends them to the Firebase Realtime Database.
- Firepad listens for changes from Firebase originating from other users, applies the transforms to the local editor state, and updates the UI.
- Session management logic (
Session.tsx) handles joining/leaving sessions. - Local storage (
LocalStore.tsx) might be used to persist user preferences or session information locally.
- Backend-Side (Firebase):
- Firebase Realtime Database receives changes from clients via Firepad and broadcasts them to other connected clients in the same session.
- Firebase Cloud Functions (
functions/src/index.ts) might execute specific backend logic triggered by database events or HTTP requests (e.g., session cleanup, user authentication if implemented).
- Client-Side:
- Output:
- The updated document content is rendered in the editor for all participants in the session in near real-time.
- UI elements (like status bars, user lists) are updated based on application state.
- Data is persisted in Firebase Realtime Database.
External Dependencies/Integrations:
- Firebase: Core platform for backend services (Database, Hosting, Functions).
- Firepad: Library enabling collaborative text editing on top of Firebase.
- CodeMirror/Other Editor: Firepad typically integrates with a code editor library (CodeMirror is common, suggested by
@convergencelabs/codemirror-collab-extdependency, though Firepad can work with others).
- Real-time Collaborative Editing: Multiple users can edit the same document simultaneously, seeing changes live.
- Dependencies: React, Firebase, Firepad.
- Interaction: User types in the editor; changes are synced via Firebase.
- Session Management: Users can join specific editing sessions.
- Input: Session ID (likely via URL).
- Dependencies:
react-router-dom,query-string,Session.tsx. - Interaction: Frontend parses URL, connects to the corresponding Firepad session via Firebase.
- Basic Text Editor Interface: Provides a text area for editing.
- Dependencies: React, potentially a base editor library integrated with Firepad.
- Revision History (Potential): The
History.tsxcomponent suggests there might be functionality to view past versions, although the exact implementation isn't detailed here.- Dependencies: React, Firebase (Firepad stores revision history).
- Local State Persistence (Potential):
LocalStore.tsxsuggests some user or session details might be saved in the browser's local storage.- Dependencies: React, Browser Local Storage API.
- Starter Kit Basis: As the original
package.jsondescription indicates it's a "starter kit," it might lack advanced features, comprehensive error handling, or optimizations found in mature production applications. - Scalability: Performance and cost are tied to Firebase usage limits and pricing tiers. Very large documents or a high number of concurrent users might require optimization or plan upgrades.
- Authentication/Authorization: The current structure doesn't explicitly detail user authentication or authorization mechanisms. Access control might be basic or non-existent unless implemented separately (e.g., using Firebase Authentication).
- Offline Support: Likely requires an active internet connection to Firebase for real-time collaboration. Offline editing capabilities might be limited or absent.
- Cleanup Requirement: The presence of
scripts/cleanup.jssuggests that manual or scheduled cleanup of old sessions or data in Firebase might be necessary.
Prerequisites:
- Node.js and Yarn (or npm) installed.
- Firebase account and a Firebase project set up.
- Firebase CLI tools installed (
npm install -g firebase-toolsoryarn global add firebase-tools).
Installation:
- Clone the repository:
git clone <repository-url> - Navigate to the project directory:
cd livepad - Install frontend dependencies:
yarn install - Navigate to the functions directory and install dependencies:
cd functions && yarn install && cd ..
Configuration:
- Firebase Setup:
- Log in to Firebase CLI:
firebase login - Configure the project to use your Firebase project:
firebase use --addand select your project. - You will likely need to create a Firebase Realtime Database instance.
- Update Firebase configuration details within the frontend source code (
src/) if they are hardcoded (ideally, use environment variables or Firebase SDK initialization snippets). Check wherefirebase.initializeAppis called. - Ensure the
firebase.jsonfile correctly points to your build output directory (likelypublic) for hosting and specifies any cloud functions.
- Log in to Firebase CLI:
- Environment Variables: Check if any
.envfiles or specific environment variable configurations are required, especially for API keys or Firebase config details (not explicitly shown, but common practice).
Running the Application:
-
Development Mode (with Hot Module Replacement):
yarn start # or yarn start-devThis will start a local development server (usually at
http://localhost:8080or similar). -
Production Mode (local simulation):
yarn start-prod
This builds the application for production and serves it using the local
express.jsserver. -
Building for Production:
yarn build
This creates optimized static assets in the
public/directory.
Testing:
- Run tests:
yarn test
Linting:
- Check code quality:
yarn lint
Deployment:
- Deploy to Firebase Hosting (and Functions, if configured):
yarn deploy # or firebase deploy
Manual Cleanup:
- Run the cleanup script (ensure you understand what it does first):
yarn cleanup:manual
- Programming Languages: TypeScript, JavaScript, SCSS/Sass
- Frontend Framework/Libraries: React, React Router DOM, React Bootstrap / Material-UI (potentially), FontAwesome
- Backend Services: Firebase (Realtime Database, Hosting, Cloud Functions), Firepad
- Build Tools: Webpack, Babel, Sass Loader, TypeScript Loader
- Development Tools:
webpack-dev-server, ESLint, Prettier, Express (for local prod serving) - Testing: Jest
- Package Manager: Yarn