How Offline Works
The app uses a local SQLite database to store all your notes, tags, and settings directly on your device. This means:- Create new notes offline
- Edit existing notes offline
- Search through your notes offline
- Organize with tags offline
- Archive and delete notes offline
Local Storage
Database Technology
Anchor uses Drift (SQLite) for local storage:- Persistent: Data survives app restarts
- Fast: Instant search and retrieval
- Reliable: ACID-compliant transactions
- Isolated: Separate database per user account
What’s Stored Locally
Your local database contains:- Notes: Title, content, metadata (pinned, archived, background color)
- Tags: Tag names, colors, and note associations
- State: Sync status, last modified timestamps
- Relationships: Note-tag mappings, sharing information
Authentication tokens are stored securely using Flutter Secure Storage, separate from the notes database.
Storage Location
Data is stored in your device’s application documents directory:Creating Notes Offline
When you create a note without internet:Create Note
Tap the + button and create your note as usual. The note is immediately saved to your local database.
Local UUID
The app generates a unique ID (UUID) for the note locally. This ID remains the same when synced to the server.
Sync Flag
The note is marked as “unsynced” in the local database, indicating it needs to be sent to the server.
Editing Notes Offline
Editing works the same offline as online:- Open any note from your local database
- Make changes to title, content, tags, or formatting
- Changes are saved locally with updated timestamps
- Sync flag is set to trigger server update when online
There’s no visual difference between editing online and offline. The app handles sync transparently.
Automatic Synchronization
Anchor uses bidirectional sync to keep your data consistent:When Sync Happens
Sync is triggered automatically:- On connect: When internet connection is restored
- After changes: When you create, edit, or delete a note
- On app launch: When you open the app while online
- Periodic: Background sync while the app is open and online
Sync Process
Detect Connection
The app uses the
connectivity_plus package to monitor network status.When connection is restored, the sync manager is notified automatically.Sync Tags First
Tags are synced before notes to ensure tag IDs are resolved correctly.This prevents issues where a note references a tag that doesn’t exist on the server yet.
Receive Server Changes
The server responds with:
- Notes modified on the server since last sync
- Notes shared with you by other users
- Revoked sharing permissions (notes removed from your access)
- Deleted notes (tombstones)
- New sync timestamp
Resolve Conflicts
If the same note was modified both locally and on the server:
- Compare timestamps (
updatedAt) - Server wins if timestamps are equal or server is newer
- Local changes are overwritten to maintain server as source of truth
Manual Sync
You can manually trigger sync:- Pull down on the notes list to refresh
- The app will sync immediately if you’re online
Offline Features
Full Functionality
These features work completely offline:- Create, edit, and delete notes
- Add and remove tags
- Pin and unpin notes
- Archive and unarchive notes
- Move notes to trash and restore them
- Search notes by title and content
- Format text with rich text editor
- Change note background colors
- View note edit history (local changes)
Limited Functionality
These features require internet connection:- Sharing notes: Requires server to manage permissions
- User search: Needs server to look up other users
- Profile updates: Syncs to server for other users to see
- OIDC authentication: Requires identity provider connection
Offline Indicators
The app shows your connection status:- No indicator: You’re online and synced
- Sync icon: Sync in progress
- Warning: Sync failed (will retry automatically)
The app is designed to feel the same whether you’re online or offline. There’s no degraded experience.
Data Persistence
App Restart
Your data persists across app restarts:- Close the app with unsaved changes
- Reopen the app
- All changes are still there, waiting to sync
Cache Management
The app doesn’t use a traditional cache that expires:- All notes are considered primary data, not cached
- Data only changes through sync or user actions
- No automatic data deletion
Storage Limits
The only limit is your device’s available storage:- SQLite databases can grow very large (gigabytes)
- Rich text content is stored efficiently
- Images are referenced by URL, not embedded
Conflict Resolution
Timestamp-Based Resolution
Conflicts are resolved using timestamps:Conflict Scenarios
Scenario 1: Edit on phone while offline- You edit a note at 2:00 PM
- Server was last synced at 1:00 PM
- When you sync, your changes go to the server
- You edit on phone at 2:00 PM
- You edit on web at 2:05 PM
- When phone syncs, server’s 2:05 PM version wins
- Your 2:00 PM changes are lost
Deleted Notes
When a note is deleted:- It’s marked as
state: 'deleted'(tombstone) - Tombstone syncs to server
- Server confirms deletion
- Local tombstone is removed from database
Sync Failure Handling
If sync fails (network error, server down, etc.):- Changes remain marked as unsynced
- Sync will retry on next connection event
- No data is lost
- You can continue working offline
Retry Strategy
The app automatically retries sync:- When connectivity is restored
- When app returns to foreground
- After any new local changes
- No exponential backoff (immediate retry)
Multi-Account Support
Each user account has isolated storage:- Previous account’s database is closed
- New account’s database is opened
- No data mixing between accounts
Privacy and Security
Local Encryption
Note content in the SQLite database is not encrypted by default. The database is protected by:- Android/iOS app sandboxing
- Device-level encryption (if enabled)
- Secure storage for authentication tokens
Authentication Tokens
JWT tokens are stored separately usingflutter_secure_storage:
- Encrypted using platform keychain (iOS) or Keystore (Android)
- Not accessible to other apps
- Wiped when app is uninstalled
Clearing Local Data
To delete all local data:- Open Settings
- Scroll to Account section
- Tap Sign Out
- Choose Sign out and delete local data
Best Practices
Maximize Offline Reliability
- Sync regularly: Open the app while online to keep data fresh
- Avoid conflicts: Don’t edit the same note on multiple devices
- Check sync status: Ensure notes sync before switching devices
- Keep app updated: Updates improve sync reliability
Troubleshooting Sync Issues
Notes not syncing:- Check internet connection
- Verify server is reachable
- Pull down to manually trigger sync
- Check server logs for errors
- Likely due to conflict resolution (server won)
- Check note’s “Updated” timestamp
- Avoid editing on multiple devices simultaneously
- Extremely rare with SQLite
- Sign out and re-sync from server
- Report issue if persistent
Technical Details
Dependencies
Offline functionality uses:- Drift: SQLite ORM and query builder
- sqlite3_flutter_libs: Native SQLite library
- path_provider: Find database storage location
- connectivity_plus: Monitor network status
- flutter_secure_storage: Encrypted token storage
Database Schema
The notes table structure:Sync Endpoint
The sync API endpoint:lib/features/notes/data/repository/notes_repository.dart:345 for implementation details.
Next Steps
Learn more about using Anchor’s mobile app:Rich Text Editing
Format notes with the Flutter Quill editor
Tags & Organization
Organize notes with tags and search