Skip to content

Database

Aorux01 edited this page Jan 31, 2026 · 1 revision

Database

Neodyme supports multiple database backends. All data access goes through the DatabaseManager abstraction layer, ensuring consistent behavior regardless of the storage engine.

Supported Databases

Type Status Config Value Requirements
JSON Stable json None (default)
MongoDB Stable mongodb npm install mongodb mongoose
SQLite Planned sqlite npm install better-sqlite3
MySQL Planned mysql npm install mysql2
PostgreSQL Planned postgresql npm install pg

JSON Database (Default)

The simplest option. All data is stored in JSON files in the data/ directory.

Configuration

databaseType=json
databasePath=data/
getJsonSpacing=true    # Pretty-print for readability

Data Files

data/
  clients.json          # User accounts
  friends.json          # Friend relationships
  tickets.json          # Support tickets
  creator-codes.json    # Creator codes and requests
  audit-log.json        # Audit log entries
  reports.json          # User reports

Characteristics

  • No external dependencies
  • Human-readable data files
  • Atomic writes with temp files for safety
  • File locking to prevent corruption
  • Suitable for small to medium servers

MongoDB

Production-ready database with high scalability.

Setup

  1. Install MongoDB on your system or use a cloud provider (MongoDB Atlas)
  2. Install the Node.js driver:
npm install mongodb mongoose
  1. Configure server.properties:
databaseType=mongodb
databasePath=mongodb://localhost:27017/neodyme

Connection String Examples

# Local MongoDB:
databasePath=mongodb://localhost:27017/neodyme

# MongoDB with authentication:
databasePath=mongodb://user:password@localhost:27017/neodyme

# MongoDB Atlas (cloud):
databasePath=mongodb+srv://user:password@cluster.mongodb.net/neodyme

Collections

MongoDB stores data in the following collections:

  • accounts - User accounts and profiles
  • friends - Friend relationships
  • tickets - Support tickets
  • creatorcodes - Creator codes
  • creatorcoderequests - Creator code requests
  • auditlogs - Audit log entries

Characteristics

  • High performance and scalability
  • Built-in replication and sharding
  • Suitable for large production servers
  • Automatic indexing

Architecture

DatabaseManager

All database operations go through DatabaseManager, which delegates to the active database implementation:

Service Layer (TicketService, AuditService, etc.)
       |
  DatabaseManager (abstraction layer)
       |
  JsonDatabase  OR  MongoDatabase
       |                  |
  JSON files         MongoDB

Services never access the database directly. This means switching from JSON to MongoDB only requires changing databaseType in server.properties.

Data Entities

Entity Description
Accounts User accounts with credentials, roles, profiles
Friends Friend relationships and requests
Tickets Support tickets with messages
Creator Codes Affiliate codes and requests
Audit Logs Administrative action history
Cloud Storage User and system cloud storage files

Backup System

The backup system works with JSON and SQLite databases.

Configuration

databaseBackup=true              # Enable backups
databaseBackupInterval=60        # Backup every 60 minutes
databaseBackupExpiryDays=7       # Delete backups older than 7 days

Console Commands

/backup create              # Create manual backup
/backup list                # List available backups
/backup stats               # Backup statistics
/backup restore <name>      # Restore a backup (requires confirmation)
/backup delete <name>       # Delete a backup (requires confirmation)
/backup cleanup             # Force cleanup of expired backups

Backup Contents

Backups include all data files in the data/ directory. Backups are stored in data/backups/ with timestamped folder names.

Restore Process

  1. Run /backup restore <backup-name>
  2. Confirm with /confirm restore
  3. Restart the server after restoration

Migrating Between Databases

JSON to MongoDB

  1. Install MongoDB and the driver: npm install mongodb mongoose
  2. Ensure MongoDB is running
  3. Update server.properties:
databaseType=mongodb
databasePath=mongodb://localhost:27017/neodyme
  1. Restart the server
  2. Existing JSON data will need to be imported manually (create accounts through the interface or import scripts)

MongoDB to JSON

  1. Update server.properties:
databaseType=json
databasePath=data/
  1. Restart the server
  2. MongoDB data will need to be exported/imported manually

Redis Cache (Optional)

Redis can be used alongside any database for caching.

Configuration

redisEnabled=false
redisHost=127.0.0.1
redisPort=6379
redisPassword=

Setup

npm install ioredis

What Redis Caches

  • Authentication tokens
  • Profile data
  • Session information

Redis improves performance by reducing database queries on frequently accessed data.

Clone this wiki locally