Docs
โœฆ

Spark

Social App - Technical Documentation

Generated: May 10, 2026
11 Features 19 API Routes 6 Socket Events 6 Pages

This document covers the complete Spark social app - built with Node.js,
Supabase Realtime, and a plain-HTML frontend. Re-run node generate_docs.js to update.

Contents

  1. Tech Stack
  2. How to Run
  3. Features
  4. API Endpoints
  5. Socket.io Events
  6. File Structure
  7. Credentials & Config
  8. Data Models
  9. Reasonix Setup
  10. Supabase Local Setup
  11. Database Access

1. Tech Stack

LayerTechnologyNotes
BackendNode.js + Express 4REST API + static file serving
Real-timeSupabase RealtimeInstant messaging via DB subscriptions
DatabaseSupabase (PostgreSQL)Cloud Postgres + Realtime + Storage
AuthJWT + bcryptjs7-day tokens stored in localStorage
File UploadsMulterProfile photos (5 MB), chat files (10 MB)
FrontendHTML + CSS + Vanilla JSNo framework - zero build step

2. How to Run

Prerequisites

First-time setup

Open a terminal in the project folder and run:

cd "C:\Users\andre\Documents\Deepseek\Code App" npm install

Start the server

node server.js

Open in browser

โš  Always use http://localhost:3000 - opening the HTML file directly via file:// will not work.

3. Features

3.1 Authentication

public/index.html · server.js

3.2 Profile

public/profile.html · server.js

3.3 Discover / Browse

public/browse.html · server.js · public/nav.js · public/style.css

3.4 Real-Time Chat

public/chat.html · server.js

3.5 Online / Offline Presence

public/global.js · public/nav.js · server.js · browse.html · chat.html

3.6 Unread Badges & Browser Notifications

public/chat.html · public/global.js

3.7 Admin Panel

public/admin.html · server.js

3.8 Error Logging

logger.js · server.js · public/logs.html

3.9 Contact Form

public/profile.html · server.js

4. API Endpoints

All routes are relative to http://localhost:3000. Auth = Bearer token required. Admin = admin JWT required.

MethodRouteAuth?Description
POST/api/registerNoCreate a new account
POST/api/loginNoLogin - returns JWT + userId
POST/api/forgot-passwordNoVerify email exists, return reset token (15 min TTL)
POST/api/reset-passwordNoSet new password using reset token
PUT/api/change-passwordYesChange password (current password required)
PUT/api/profileYesUpdate profile fields + optional photo upload
GET/api/profile/meYesGet own profile data
GET/api/membersYesList all members with complete profiles
GET/api/messages/:otherIdYesMessage history with another user
GET/api/conversationsYesConversation list with last-message preview
POST/api/chat/uploadYesUpload a file for use in chat
POST/api/admin/loginNoAdmin login - returns admin JWT
GET/api/admin/usersAdminAll users (passwords excluded)
GET/api/admin/messagesAdminFull message log with sender/receiver names
GET/api/admin/statsAdminAggregate stats (users, messages, etc.)
DELETE/api/admin/users/:idAdminDelete user and all their messages
DELETE/api/admin/messages/:idAdminDelete a single message
GET/api/logsAdminRead the server error log file
DELETE/api/logsAdminClear the error log file

5. Socket Events

Real-time messaging uses Supabase Realtime (PostgreSQL logical replication). No persistent WebSocket connections needed.

The following events are handled via REST API endpoints and Supabase Realtime subscriptions:

EventDirectionPayload FieldsDescription
send_messageClient → ServerreceiverId, content, type, fileNameSend message; server saves + routes it
new_messageServer → Clientid, sender_id, receiver_id, content, type, sender_nameDelivered to sender and receiver
edit_messageClient → ServermessageId, contentEdit own message
message_editedServer → ClientmessageId, contentBoth parties update the message text
delete_messageClient → ServermessageIdDelete own message
message_deletedServer → ClientmessageIdBoth parties remove the message
user_statusServer → AlluserId, online, lastSeenEmitted on every connect / disconnect

6. File Structure

PathPurpose
Code App/-- project root
  server.jsExpress API + Logger (all backend logic)
  logger.jsError logging module - writes timestamped entries to error.log
  error.logAuto-generated log file (created at runtime)
  database.jsSupabase client setup - exports @supabase/supabase-js instance
  db.jsonLegacy JSON database (fully migrated to Supabase โ€” kept for reference only)
  generate_docs.jsScript to regenerate this documentation
  package.jsonnpm dependency manifest
  public/-- static frontend files served by Express
    index.htmlLogin, Register, Forgot Password
    profile.htmlProfile editing + Change Password
    browse.htmlDiscover member grid
    chat.htmlReal-time chat UI
    admin.htmlAdmin dashboard
    logs.htmlError log viewer (admin-only, auto-refresh)
    documentation.htmlThis page - technical documentation
    nav.jsShared navbar chip (name + avatar)
    global.jsPresence heartbeat, Supabase Realtime notifications, tab-title flash
    style.cssAll styles for all pages
  uploads/Profile photos + chat files (exclude from git)

7. Credentials & Configuration

SettingValueWhere to change
Server port3000server.js - const PORT
JWT secretsocial-app-secret-key-change-in-prodserver.js - const JWT_SECRET
JWT expiry7 daysserver.js - jwt.sign expiresIn
Admin passwordadmin1234server.js - const ADMIN_PASSWORD
Profile photo limit5 MBserver.js - upload multer config
Chat file limit10 MBserver.js - uploadChat multer config
DatabaseSupabase PostgreSQLdatabase.js - Supabase client config
Supabase URLhttp://127.0.0.1:54321Local Supabase API endpoint
Supabase Studiohttp://127.0.0.1:54323Web UI for database management
Security note: Change JWT_SECRET and ADMIN_PASSWORD before deploying to any public server.

8. Data Models (Supabase PostgreSQL)

User

FieldTypeDescription
idnumberAuto-incrementing primary key
usernamestringUnique; chosen at registration
emailstringUnique email address
passwordstringbcrypt hash - never returned by any API route
namestring | nullDisplay name set on Profile page
agenumber | nullAge set on Profile page
genderstring | nullGender set on Profile page
biostring | nullShort bio, max 300 characters
photostring | nullServer path, e.g. /uploads/photo.jpg
created_atISO stringRegistration timestamp
lastSeenISO stringUpdated via heartbeat every 30-45s + on tab close/logout

Message

FieldTypeDescription
idnumberAuto-incrementing primary key
sender_idnumberID of the sending user
receiver_idnumberID of the recipient
contentstringMessage text or /uploads/... path for files
type"text" | "image" | "file"Defaults to "text"
fileNamestring | nullOriginal filename for attachments
editedbooleantrue if the sender edited this message
created_atISO stringSend timestamp (server time)

9. Reasonix Setup

Reasonix is a DeepSeek-native coding agent that runs in the terminal. It's designed around DeepSeek's API directly - cache-first loop, flash-first cost control, and automatic tool-call repair.

Prerequisites

Step-by-Step Setup

  1. Open Command Prompt - press Win + R, type cmd, press Enter
  2. Navigate to project folder - cd C:\Users\andre\Documents\Deepseek\Code App
  3. Run Reasonix - npx reasonix@latest code (first run prompts for your API key)
  4. Enter your API key when prompted - it's saved automatically to C:\Users\andre\.reasonix\config.json
  5. (Optional) Customise config - notepad C:\Users\andre\.reasonix\config.json

Cost Comparison

ModelCost / TurnTurns for $4.98Best For
Flash (default)~$0.0006~8,000Quick edits, exploration
Pro (/preset max)~$0.01–0.03~200Complex reasoning tasks

Key Commands

Shortcut / CommandAction
Ctrl + LClear terminal
Ctrl + CExit Reasonix
Shift + TabAuto-apply all suggestions
y / nAccept or discard a change
/preset maxSwitch to DeepSeek Pro model
/statsShow token/cost statistics
/costShow running cost
/clearClear conversation context
/helpShow all commands
Tip: Use Flash for quick exploration and iterative work; switch to Pro with /preset max when you need deep reasoning. In v0.28.0, the model/preset fields in config.json are ignored - you must run /preset max manually each session.

Quick-Start Cheat Sheet

Every session, run these four lines:

cd C:\Users\andre\Documents\Deepseek\Code App npx reasonix@latest code /preset max /stats

10. Supabase Local Setup

Spark has migrated from lowdb (JSON file) to Supabase (PostgreSQL) for better scalability and Vercel deployment readiness.

Prerequisites

Local Setup

cd C:\Users\andre\Documents\Deepseek\Code App npx supabase init npx supabase start

This spins up PostgreSQL + Supabase Studio + all supporting services locally via Docker.

Local URLs

ServiceURL
Supabase Studio (web UI)http://127.0.0.1:54323
API Endpointhttp://127.0.0.1:54321
Database URLpostgresql://postgres:postgres@127.0.0.1:54322/postgres
Mailpit (test emails)http://127.0.0.1:54324

Cloud Supabase

Spark uses a cloud Supabase project (CWD) at https://hpezaqvtufrvvczyixwc.supabase.co for production data. The local Supabase instance is used for development and testing.

Migration Complete

All phases completed! Spark now runs entirely on Supabase PostgreSQL.
  1. Phase 1 - Set up Supabase locally โœ…
  2. Phase 2 - Create tables (users, messages, contacts) โœ…
  3. Phase 3 - Migrated 5 users, 19 messages, 2 contacts from db.json โœ…
  4. Phase 4 - Replaced all lowdb queries with Supabase โœ…
  5. Phase 5 - File uploads moved to Supabase Storage โœ…
  6. Phase 6 - Deploy to Vercel โœ… - live at cebuspark.com

11. Database Access

Access your Supabase PostgreSQL database two ways:

Supabase Dashboard (Web UI)

Direct PostgreSQL Connection

SettingValue
Hostaws-0-ap-southeast-1.pooler.supabase.com
Port6543
Databasepostgres
Usernamepostgres.hpezaqvtufrvvczyixwc
PasswordDatabase password set during project creation