SpellCast is a PROTOTYPE of a fully decentralized, peer-to-peer Twitter-like application that runs entirely in your web browser. Share messages (called "spells") directly with your connections without relying on any central servers. Your data stays with you!
SpellCast on itch.io: Spellcast
- Fully Decentralized: No central servers or databases - everything happens directly between peers
- Private & Secure: WebRTC's built-in encryption secures all peer connections
- Browser-Based: Runs entirely in your web browser - no installation required
- Cross-Platform: Works on desktop and mobile browsers (iOS, Android, iPad)
- Persistent Storage: Messages and connections are saved in your browser's storage
- Offline Capable: Create messages offline and they'll be sent when you reconnect
- QR Code Sharing: Connect with peers easily by scanning QR codes
SpellCast leverages WebRTC's built-in security mechanisms to protect your communications:
- DTLS (Datagram Transport Layer Security): All data channels between peers are encrypted using DTLS, similar to HTTPS encryption for websites
- Peer Authentication: During connection establishment, peers are authenticated to prevent man-in-the-middle attacks
- No Central Points of Compromise: Without central servers storing messages, there are no honeypots for attackers to target
- Private Connection Model: Messages only reach users you've directly or indirectly connected with
- No Account Required: Create an identity without providing email or phone number
- No Tracking: No central entity to track your connections or message content
- Local Storage Only: Your data is stored exclusively in your browser's local storage
- Selective Sharing: Messages only propagate to peers in your network
SpellCast works on all modern mobile browsers:
- iOS (iPhone & iPad): Works in Safari, Chrome, and Firefox
- Android: Compatible with Chrome, Firefox, and Samsung Internet
- Responsive Design: UI adapts to different screen sizes
- Connection Persistence: Reconnects automatically when switching networks
Note that on iOS, background tabs may disconnect due to browser limitations, but will reconnect when you return to the tab.
-
Clone this repository or download the files
git clone https://github.com/SiENcE/spellcast.git
-
Open the
index.html
file in a modern web browser- For best results, use Chrome, Firefox, Edge, or Safari
- You can use a local server if you prefer:
# Using Python python -m http.server # Using Node.js with http-server npx http-server
-
That's it! SpellCast runs entirely in your browser
- Click the "Create New Account" button
- Enter a username that others will see
- Click "Generate Your Credentials"
- Save your peer ID securely - you'll need it to log in from other devices
- Click "Continue to App"
There are several ways to connect with other SpellCast users:
- Go to the "Connect" tab
- Enter the peer ID of the person you want to connect with
- Click "Connect"
- Go to your "Profile" tab to display your QR code
- Have another SpellCast user scan your code using their device's camera
- Alternatively, scan their QR code using a QR code scanner app
SpellCast automatically saves your connections and will try to reconnect to known peers when you restart the app.
- In the "Feed" tab, type your message in the text area
- Click "Cast" to send your message
- Your message will be sent to all connected peers and displayed in your feed
- Go to the "Connect" tab to see all your connections
- Online peers will appear at the top
- You can disconnect from a peer by clicking the "Disconnect" button
- Remove saved peers by clicking "Remove"
- Go to the "Profile" tab
- Here you can see your username and peer ID
- Share your peer ID or QR code with others to connect
- Use the "Delete All Messages" button to clear your local message history
- Use the "Delete Account" button to completely reset your account
SpellCast creates a mesh network where:
- Direct Connections: You establish WebRTC connections with peers you know
- Message Propagation: When you send a message:
- It's stored in your local browser storage
- It's sent to all your directly connected peers
- They store it and forward it to their peers (who aren't already connected to you)
- The system tracks which peers have received each message to prevent duplicates
- Offline Handling: If a peer is offline, messages for them are queued and sent when they reconnect
This distributed approach means there's no central point of failure, and messages can still reach their destination through alternative paths in the network.
SpellCast is built with vanilla JavaScript and uses several key libraries:
- PeerJS: Handles WebRTC connections for peer-to-peer communication
- IndexedDB: Stores messages, media, and connection data persistently
- QR Code JS: Generates QR codes for easy peer ID sharing
The application is structured into several manager classes:
- SpellCastApp: Main application controller
- UserManager: Handles user credentials and authentication
- PeerManager: Manages peer connections and communication
- TweetManager: Handles message creation, storage, and distribution
- UIManager: Controls the user interface and event handling
- StorageManager: Manages persistent storage with IndexedDB
- MediaManager: -- unused, unfinished!! --
- RateLimiter: Prevents spam and abuse
SpellCast uses a sophisticated message distribution system:
- When a message is created, it's stored locally and broadcast to all connected peers
- The system tracks which peers have received which messages
- When new peers connect, only messages they haven't seen are sent
- This ensures efficient distribution without flooding the network
// Simplified example of the message distribution tracking
{
tweetRecipients: {
"message-123": ["peer1", "peer3"], // Peers that have this message
"message-456": ["peer1", "peer2", "peer3"]
},
unsentTweets: {
"peer1": [], // This peer has all messages
"peer2": ["message-123"], // This peer needs message-123
"peer3": []
}
}
SpellCast relies on WebRTC's built-in security features:
- DTLS Encryption: All data channels are encrypted using Datagram Transport Layer Security
- Connection Security:
- Each connection begins with a secure handshake
- Communication is encrypted end-to-end between directly connected peers
- Intermediary peers cannot read messages they relay if implemented correctly
Remember that while the transport is secure, the application itself doesn't implement additional encryption layers. For more security, you could add end-to-end encryption at the message level.
SpellCast uses IndexedDB for persistent storage with a fallback to localStorage:
- User credentials: Username and peer ID
- Messages: All created and received messages
- Media: Images attached to messages (stored as base64 data)
- Peers: Known connections and their status
- Distribution state: Which peers have received which messages
SpellCast actively monitors connection quality:
- Regular pings are sent to connected peers
- Response times are measured to determine connection quality
- Failed connections trigger automatic reconnection attempts
- Connection quality is displayed in the UI with simple indicators
We welcome contributions to SpellCast! Here's how you can help:
- Fork the repository: Create your own copy of the project
- Make your changes: Add features or fix bugs
- Test thoroughly: Ensure your changes work as expected
- Submit a pull request: Share your improvements with us
-
Clone the repository
git clone https://github.com/SiENcE/spellcast.git
-
Set up a local development server
# Using Python python -m http.server # Using Node.js with http-server npx http-server
-
Open
http://localhost:8000
(or whatever port your server uses) -
Make changes and refresh the browser to see them
- Use clear, descriptive variable and function names
- Add comments for complex logic
- Maintain the existing code structure and patterns
- Write clean, modular code
- Test your changes across different browsers
This project is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License - see the LICENSE file for details.
This means:
- You are free to share (copy and redistribute) and adapt (remix, transform, and build upon) this material
- You must give appropriate credit and indicate if changes were made
- You may not use the material for commercial purposes
- No additional restrictions — you may not apply legal terms or technological measures that legally restrict others from doing anything the license permits
Cast spells, not tweets. Be decentralized.