InstaKG is a secure, real-time messaging application focused on uncompromising privacy. It features a custom End-to-End Encryption (E2EE) protocol utilizing a unique "degenerative tree" architecture for scalable group messaging, backed by a high-performance WebAssembly math engine.
- Custom E2EE Degenerative Tree: Unlike standard paired ratchets, InstaKG chains group participants cryptographically based on their join order. This allows secure, scalable group key distribution without compromising zero-knowledge principles.
- High-Performance Cryptography: A custom C++ math engine (
math_engine.cpp) handles intensive modular exponentiation, compiled to WebAssembly (Wasm) to run natively in the browser. - Real-Time Communication: Instant message delivery via WebSockets (Socket.io), including live reactions, read receipts, and role-based group management.
- Built-in AI Assistant:
ikg_botis an integrated Small Language Model (SLM) powered by Ollama, ready to assist users directly within their chats.
graph TD
A[Client UI - React] -->|Message Input| B(Wasm Math Engine)
B -->|Encrypt payload using Group Key| C[Encrypted Payload]
C -->|Socket.io / HTTP| D(Backend API - Node.js)
D -->|Verify Auth & Store Log| E[(PostgreSQL Database)]
D -->|Socket.io Emit| F[Recipient Client]
F -->|Wasm Math Engine| G[Decrypt Message]
G --> H[Render in UI]
subgraph "IKG Bot Integration"
D -->|If @ikg_bot triggered| I[Ollama SLM]
I -->|Generate response| D
end
- Frontend: React, Vite, WebAssembly (C++ via Emscripten), Socket.io-client
- Backend: Node.js, Express, Socket.io, Multer, DOMPurify
- Database: PostgreSQL (pg)
- AI Integration: Ollama (gemma2:2b)
To run this project locally, you must configure two separate .env files for the frontend and backend.
Create a .env file in the backend/ directory:
PORT=5000
JWT_SECRET=your_jwt_secret_here
CRYPT_SALT=12
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_password
PG_USER=postgres
PG_PASSWORD=your_db_password
PG_HOST=localhost
PG_PORT=5432
PG_DATABASE=instakgCreate a .env file in the react-frontend/ directory. These variables act as the base parameters for the cryptographic math engine:
VITE_SEED=98
VITE_BASE=19
VITE_MODULUS=4294967291-
Database Setup
- Ensure PostgreSQL is running locally.
- Create a database named
instakg(or match yourPG_DATABASEenv variable).
-
Backend Setup
cd backend npm install npm startNote: The backend starts via
node src/main.js. Ensure Ollama is running locally if you want to use theikg_bot. -
Frontend Setup
cd react-frontend npm install npm run devNote: If you make changes to the cryptographic logic in
math_engine.cpp, you will need to recompile it to WebAssembly using Emscripten (emcc) before restarting the frontend development server.