Skip to main content

d-back

Last Commit Open Pull Requests License: MIT Stars Contributors Build Status PyPI Documentation Documentation Status Crowdin Sync

📚 Documentation

Comprehensive documentation is available online in English, Spanish (Español), and German (Deutsch), including API reference, user guides, and examples.

Translations are automatically synchronized with Crowdin. The Crowdin Sync workflow uploads source files and downloads completed translations.

Quick Links

The documentation is available in multiple languages. Use the language selector in the navigation to switch between languages.

Building Documentation Locally

# Install documentation dependencies
pip install -e .[docs]

# Serve documentation locally with live reload (all languages)
mkdocs serve

# Build documentation (generates site/ directory with all languages)
mkdocs build

After running mkdocs serve, access the documentation at:

  • English: http://127.0.0.1:8000/
  • Spanish: http://127.0.0.1:8000/es/
  • German: http://127.0.0.1:8000/de/

Note: The documentation uses mkdocs-static-i18n for multilingual support with the Material for MkDocs theme.

Welcome to d-back – the backend service that powers the magical d-zone ambient life simulation!

🎯 Project Overview

d-zone is an ambient life simulation where the presence and activity of users in a Discord server subtly influence a living digital environment. Think of it as a digital terrarium that reacts to your community's energy!

d-back serves as the intelligent bridge between Discord servers and the beautiful d-zone frontend. It provides real-time user data through WebSocket connections, creating an immersive experience where every Discord user becomes part of a living, breathing digital ecosystem.

Currently, d-back uses sophisticated mock data to simulate user activity, making it perfect for development, testing, and demonstration purposes.

✨ Features

  • 🔌 WebSocket Server: Real-time communication with the d-zone frontend
  • 👥 User Activity Simulation: Mock Discord user data with realistic presence states
  • 🎨 Role Color Support: Beautiful user representation with Discord role colors
  • 🌐 Multi-Server Support: Handle multiple Discord servers simultaneously
  • 📊 Status Tracking: Monitor online, idle, DND, and offline user states
  • 🔒 OAuth2 Ready: Built-in support for Discord OAuth2 authentication
  • 📁 Static File Serving: Serve frontend assets directly from the backend
  • 🚀 Easy Configuration: Simple command-line options and programmatic setup
  • 🧪 Development Friendly: Comprehensive mock data for testing and development

🛠️ Installation

Step-by-Step Setup

  1. Clone the repository:

    git clone https://github.com/NNTin/d-back.git
    cd d-back
    
  2. Create a virtual environment (recommended):

    # On Windows
    python -m venv .venv
    .venv\Scripts\activate
    
    # On macOS/Linux
    python3 -m venv .venv
    source .venv/bin/activate
    
  3. Install the package:

    # Install in development mode (recommended for contributors)
    pip install -e .
    
    # Or install directly from requirements
    pip install -r requirements.txt
    
  4. Verify installation:

    d_back --version
    

🚀 Usage

Quick Start

The simplest way to get d-back running:

# Start the server with default settings (localhost:3000)
d_back

# Or run as a Python module
python -m d_back

Command Line Options

# Custom host and port
d_back --host 0.0.0.0 --port 8080

# Serve custom static files
d_back --static-dir ./my-frontend-build

# Get help
d_back --help

Programmatic Usage

Use d-back in your Python projects:

import asyncio
from d_back.server import WebSocketServer

async def main():
    # Create server instance
    server = WebSocketServer(port=3000, host="localhost")
    
    # Optional: Set up custom callbacks
    server.on_get_user_data = my_user_data_callback
    server.on_get_server_data = my_server_data_callback
    
    # Start the server
    print("Starting d-back server...")
    await server.start()

# Run the server
asyncio.run(main())

Testing the WebSocket Connection

You can test the server using any WebSocket client:

// JavaScript example for testing
const socket = new WebSocket('ws://localhost:3000');

socket.onopen = () => {
    console.log('Connected to d-back!');
    // Request user data for a mock server
    socket.send(JSON.stringify({
        type: 'get_user_data',
        serverId: '232769614004748288'
    }));
};

socket.onmessage = (event) => {
    const data = JSON.parse(event.data);
    console.log('Received:', data);
};

⚙️ Configuration

Command Line Arguments

Option Default Description
--port 3000 Port to run the WebSocket server on
--host localhost Host to bind the server to
--static-dir Built-in Directory to serve static files from
--version - Show version information

Mock Server Configuration

d-back comes with pre-configured mock Discord servers for testing:

  • d-world server (232769614004748288): Main development server with active users
  • docs server (482241773318701056): Documentation server
  • oauth2 server (123456789012345678): Protected server for OAuth testing
  • my repos server (987654321098765432): Repository showcase server

Environment Variables

While d-back doesn't currently use environment variables for configuration, you can extend it easily:

import os
from d_back.server import WebSocketServer

# Example: Use environment variables
port = int(os.getenv('D_BACK_PORT', 3000))
host = os.getenv('D_BACK_HOST', 'localhost')

server = WebSocketServer(port=port, host=host)

Custom Data Providers

Replace mock data with your own:

from d_back.server import WebSocketServer

async def my_user_data_provider(server_id):
    # Your custom logic here
    return {
        "user123": {
            "uid": "user123",
            "username": "MyUser",
            "status": "online",
            "roleColor": "#ff6b6b"
        }
    }

server = WebSocketServer()
server.on_get_user_data = my_user_data_provider

📜 License

This project is licensed under the MIT License. See LICENSE for details.

Release files for d-back 0.0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for d-back 0.0.18
File Size Uploaded
d_back-0.0.18.tar.gz 32.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for d-back 0.0.18
File Interpreter ABI Platform
d_back-0.0.18-py3-none-any.whl Python 3 none any Details

Total release size: 61.1 kB

Release files / d_back-0.0.18.tar.gz

Download URL d_back-0.0.18.tar.gz
Size 32.9 kB
Tags Source
SHA-256 checksum
How to use checksums
af0642b894ee701eee809e704efd3300324e879665faf4c1c174226c220dd55a
BLAKE2b-256 checksum
How to use checksums
4b9f7b645eee5f93f23f78207e13f413eb408be94e7320b5507ff0d78bf35a9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.14

Release files / d_back-0.0.18-py3-none-any.whl

Download URL d_back-0.0.18-py3-none-any.whl
Size 28.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ae71132f69e95e6f7e858aaec60fc188a476f4b9143be5b59bb9e6abeef1cd8
BLAKE2b-256 checksum
How to use checksums
abad13d4c5cc57ec3f0a1596a6c8db976636cf1a7517eae4b7719d5763d654f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.14

Release history Release notifications | RSS feed

This release

0.0.18 This release

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page