An open API service indexing awesome lists of open source software.

https://github.com/jonathas/realtime-notes-pad

A self-hosted real-time collaborative note-taking app built with React, FastAPI, and WebSockets. Inspired by Google Docs, but designed for privacy-first local networks.
https://github.com/jonathas/realtime-notes-pad

Last synced: about 1 year ago
JSON representation

A self-hosted real-time collaborative note-taking app built with React, FastAPI, and WebSockets. Inspired by Google Docs, but designed for privacy-first local networks.

Awesome Lists containing this project

README

          

# ๐Ÿ“ Real-Time Notes Pad (WIP)

A **self-hosted** real-time collaborative note-taking app built with **React**, **FastAPI**, and **WebSockets**. Inspired by Google Docs, but designed for privacy-first local networks.

Perfect for families, small teams, and privacy-conscious users who want to keep their notes completely under their control.

![Web version](/docs/images/web.png)

## ๐Ÿ”„ Data Flow

```mermaid
sequenceDiagram
participant U1 as User 1
(Desktop)
participant U2 as User 2
(Mobile)
participant WS as WebSocket
Manager
participant API as FastAPI Server
participant DB as SQLite
Database

Note over U1,U2: Real-time Collaboration

U1->>WS: Edit note content
WS->>API: Process change
API->>DB: Save to database
API->>WS: Broadcast change
WS-->>U2: Live update

Note over U1,U2: Metadata Updates
U2->>API: Change note title
API->>DB: Update metadata
API-->>U1: Title updated

Note over API,DB: All data stays local
```

### Real-Time vs REST API

- **๐Ÿ“ก WebSocket**: Real-time content changes, cursors, typing indicators
- **๐Ÿ”„ REST API**: Initial load, metadata (title, tags), note management
- **๐Ÿ’พ Database**: Single source of truth for all data

## ๐Ÿ  Self-Hosted Architecture

- ๐Ÿ“ **Raspberry Pi friendly**: Runs efficiently on ARM devices
- ๐Ÿ”’ **Privacy-first**: Your notes never leave your network
- ๐ŸŒ **Multi-platform**: Web, desktop, and mobile apps
- ๐Ÿ“ฑ **Local network**: Fast, low-latency collaboration
- ๐Ÿ’พ **SQLite database**: Simple, reliable, zero-config storage

---

## ๐Ÿš€ Features

- [x] Real-time collaborative editing via WebSocket
- [x] Firebase Authentication (works with self-hosted setup)
- [x] Auto-saving with intelligent debouncing
- [x] Multiple notes management
- [x] Cross-platform clients (Web, Desktop, Mobile)
- [x] Simple backup (single SQLite file)
- [x] Docker deployment
- [ ] Electron desktop app
- [ ] React Native mobile app

---

## ๐Ÿ“ฆ Tech Stack

### Backend (Self-Hosted Server)

- **FastAPI** (Python) - High-performance API
- **SQLite** - Lightweight, serverless database
- **WebSocket** - Real-time communication
- **Firebase Auth** - User management

### Frontend (Multi-Platform)

- **React + TypeScript** - Web application
- **Tailwind CSS** - Styling
- **Electron** - Desktop wrapper
- **React Native** - Mobile apps (planned)

### Deployment

- **Docker** - Containerized deployment
- **Docker Compose** - Single-command setup

---

## ๐Ÿ›  Quick Start

### Option 1: Docker (Recommended)

```bash
# Clone the repository
git clone https://github.com/jonathas/realtime-notes-pad.git
cd realtime-notes-pad

# Start with Docker Compose
docker-compose up -d

# Access your notes at http://localhost:8000
```

### Option 2: Manual Setup

```bash
# 1. Start the backend
cd backend
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
fastapi dev app/main.py

# 2. Start the frontend
cd frontend
npm i
npm run dev
```

### Option 3: Desktop App (Electron)

```bash
# Clone and setup
git clone https://github.com/jonathas/realtime-notes-pad.git
cd realtime-notes-pad

# Install frontend dependencies
cd frontend
npm install

# Run in development mode (starts both web server and Electron)
npm run electron-dev

# Build for production
npm run build-electron

# Create distributable packages
npm run dist
```

---

## ๐Ÿงช Testing

### Backend API Tests

The backend includes comprehensive tests covering:

- **Unit tests** - NoteService business logic
- **API tests** - REST endpoints
- **WebSocket tests** - Real-time functionality

```bash
# Navigate to backend directory
cd backend

# Run all tests
pytest

# Run with verbose output
pytest -v

# Run specific test categories
pytest -v -m "not slow" # Skip performance tests
pytest -v -m "slow" # Only performance tests
pytest -v -k "websocket" # Only WebSocket tests

# Run with coverage report
pytest --cov=app --cov-report=html
```

**Test Categories:**

- ๐Ÿ”ง **Unit Tests**: Core business logic (NoteService)
- ๐ŸŒ **API Tests**: REST endpoint validation
- ๐Ÿ“ก **WebSocket Tests**: Real-time communication

All tests use isolated in-memory databases for fast, reliable testing.

---

## ๐Ÿ“ Project Structure

```bash
realtime-notes-pad/
โ”œโ”€โ”€ frontend/ # React web application
โ”‚ โ”œโ”€โ”€ src/
โ”‚ โ”‚ โ”œโ”€โ”€ components/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Editor/ # Real-time text editor
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ Toolbar/ # Navigation and controls
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ Modals/ # Settings and note selection
โ”‚ โ”‚ โ”œโ”€โ”€ services/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ storage.ts # API client
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ firebase.ts # Authentication
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ websocket.ts # Real-time communication
โ”‚ โ”‚ โ””โ”€โ”€ hooks/ # React hooks
โ”‚ โ”œโ”€โ”€ electron/ # Desktop app wrapper
โ”‚ โ”‚ โ””โ”€โ”€ main.js # Electron main process
โ”‚ โ”œโ”€โ”€ public/
โ”‚ โ””โ”€โ”€ package.json
โ”œโ”€โ”€ backend/ # FastAPI server
โ”‚ โ”œโ”€โ”€ app/
โ”‚ โ”‚ โ”œโ”€โ”€ routers/ # API endpoints
โ”‚ โ”‚ โ”œโ”€โ”€ services/ # Business logic
โ”‚ โ”‚ โ”œโ”€โ”€ models/ # Database models
โ”‚ โ”‚ โ””โ”€โ”€ auth/ # Authentication
โ”‚ โ”œโ”€โ”€ tests/ # Comprehensive test suite
โ”‚ โ”‚ โ”œโ”€โ”€ test_note_service.py # Unit tests
โ”‚ โ”‚ โ”œโ”€โ”€ test_notes_api.py # API tests
โ”‚ โ”‚ โ”œโ”€โ”€ test_websockets.py # WebSocket tests
โ”‚ โ”œโ”€โ”€ data/ # SQLite database
โ”‚ โ””โ”€โ”€ requirements.txt
โ”œโ”€โ”€ docker-compose.yml # Development setup
โ””โ”€โ”€ README.md
```

---

## ๐ŸŒ Client Applications

### Web App

- Access via any modern browser
- Works on desktop and mobile
- Real-time collaboration

### ๐Ÿ–ฅ๏ธ Desktop App (Electron) - โš ๏ธ Work in Progress

A native desktop wrapper for the web app with enhanced features.

![Desktop version](/docs/images/electron.png)

#### โš ๏ธ Current Status: Not Ready for Production

The Electron app is currently **under development** and missing critical authentication features:

- โŒ **Firebase Authentication**: Google sign-in doesn't work properly in Electron
- โŒ **OAuth Flow**: Browser-based auth redirects don't return to the app
- โŒ **Custom Protocol Handler**: Not yet implemented for auth callbacks

**Built Apps Location:**

- **Development**: Runs from `http://localhost:5173`
- **Production**: Packaged in `dist-electron/` folder

**Planned Features:**

- ๐Ÿ–ฅ๏ธ **Native window**: Proper desktop integration
- ๐Ÿ“ฑ **Cross-platform**: Windows, macOS, and Linux
- ๐Ÿ” **Embedded auth**: In-app Google authentication
- ๐Ÿ”„ **Auto-updater ready**: Built-in update mechanism

**For now, please use the web app** at `http://localhost:8000` which has full authentication support.

### ๐ŸŒ PWA Features (Connection-Required)

This app is designed as a **connected-only** PWA that requires real-time WebSocket connection:

- ๐Ÿ“ฑ **App-like experience**: Installs like a native app
- ๐Ÿš€ **Fast loading**: Static assets cached locally
- ๐Ÿ”„ **Smart reconnection**: Automatically reconnects when server available
- ๐Ÿ“ก **Connection awareness**: Shows connection status and graceful degradation
- ๐Ÿ’พ **No offline storage**: Notes require server connection (by design)

#### Why No Offline Mode?

- Real-time collaboration requires active connections
- Notes are stored securely on your self-hosted server
- Prevents sync conflicts and data loss
- Simpler architecture and better security

### Mobile Apps (Planned)

- React Native for iOS/Android

---

## ๐Ÿ”ง Configuration

### Environment Variables

```bash
# Frontend (.env)
# Firebase Configuration
VITE_FIREBASE_API_KEY=your_api_key_here
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=123456789
VITE_FIREBASE_APP_ID=1:123456789:web:abcdef123456

# API Configuration
VITE_API_URL=http://localhost:8000
```

---

## ๐Ÿ”’ Privacy & Security

### Data Privacy

- โœ… **Local storage**: Notes never leave your network
- โœ… **No cloud dependencies**: Works completely offline
- โœ… **Your data, your control**: Easy backups and migrations
- โœ… **Firebase auth only**: User accounts, not note data

### Security Features

- ๐Ÿ” **JWT authentication**: Secure user sessions
- ๐Ÿ›ก๏ธ **CORS protection**: Configurable origins
- ๐Ÿ”„ **Automatic backups**: SQLite file copying
- ๐Ÿšซ **No telemetry**: No tracking or analytics

---

## ๐Ÿ”„ Backup & Restore

### Backup Your Notes

```bash
# Simple file copy
cp data/notes.db backups/notes-$(date +%Y%m%d).db
```

### Restore from Backup

```bash
# Stop the service
docker-compose down

# Restore database
cp backups/notes-20240105.db data/notes.db

# Restart
docker-compose up -d
```

---

## ๐Ÿค Use Cases

### Perfect For

- ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ **Families**: Shared grocery lists, vacation planning
- ๐Ÿข **Small teams**: Meeting notes, project planning
- ๐Ÿ”’ **Privacy-conscious users**: Keep sensitive notes local
- ๐Ÿ  **Home labs**: Self-hosted enthusiasts
- ๐Ÿ“š **Students**: Collaborative study notes
- โœ๏ธ **Writers**: Draft sharing and feedback

### Why Self-Hosted?

- **No subscription fees** - One-time setup
- **Complete privacy** - Your data stays home
- **Fast performance** - Local network speed
- **Works offline** - No internet required
- **Customizable** - Modify to fit your needs

---

### Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. **Run tests**: `cd backend && pytest`
5. Test on Raspberry Pi if possible
6. Submit a pull request

---

## ๐Ÿ“œ License

MIT ยฉ Jonathas Ribeiro

**Built for self-hosters, by self-hosters** ๐Ÿ