Local Database & State Management

In Novyse, the local database is the absolute core of the application experience. The application is built from the ground up to be Offline-First, ensuring a seamless and responsive UI regardless of network availability.

Data Persistence & Single Source of Truth

While the UI is highly reactive, the Single Source of Truth for persistence is exclusively the local SQLite database.

  • Persistent Home: Every piece of data received from the backend is persisted in SQLite before it is considered "received."
  • No Direct API Reads: The application does not fetch data from REST APIs to render the interface; it reads from the local database or the reactive state.

Reactive UI & Zustand

To provide a "real-time" feel, Novyse does not rely solely on polling the database.

  • Live Updates: When the app is in the foreground, it listens for events via Socket.io.
  • Zustand Context: These incoming events are immediately processed by a Zustand store. The UI subscribes to this Zustand context for instantaneous updates without waiting for database I/O.
  • Background Persistence: While Zustand handles the live UI, the Sync Engine ensures that every change is simultaneously written to the local SQLite database to guarantee data integrity.

What is Stored Locally?

The local SQLite database is organized to mirror the server's materialized state while providing additional structures for local queue management.

1. Identity & Social Graph

TableDescription
userProfiles for registered users including names, bios, and location.
botAutomated entities with descriptions and profile picture references.
handleUnique identifier lookup (e.g., @username) for users, bots, or chats.
memberRelational mapping of user-to-chat membership and join timestamps.

2. Conversations & Structure

TableDescription
chatCore container for all conversations (DM, Group, Channel, Forum).
chat_typeDefinition of supported conversation modes and their characteristics.
pinned_chatUser-specific persistent sorting and priority for the chat list.
chat_pinSpecific positioning data for pinned conversations.

3. The Messaging Engine

TableDescription
messageThe primary store for all text-based and system-action content.
edited_messageTracks which messages have been modified (maintains integrity).
deleted_messageSoft-deletion registry to synchronize removals across clients.
reaction_messageStores emojis and metadata for message reactions per user.
pinned_messageRegistry of specific messages highlighted within a chat.
message_replyHandles complex threading and range-based text replies.
message_readReal-time status of which users have seen specific messages.

4. Media & Assets

TableDescription
fileCentral registry for metadata (size, mime-type, waveforms, duration).
message_filesMany-to-many mapping of files attached to specific messages.

5. Persistence Queue (Offline-First Engine)

TableDescription
pending_messageLocal queue of messages waiting for network or upload completion.
pending_fileTemporary registry for file URIs and active S3 transfer states.

By storing this entire relational structure locally, Novyse can recover from crashes, survive network loss, and provide a desktop-class snappy experience.

    Local Database Design - Novyse Architecture | Novyse