@magland/dango
v0.2.6
Published
A self-hosted team chat with the shape of Slack: channels, threads, direct messages, reactions, uploads, and search, from one small server with no database.
Maintainers
Readme
dango
A self-hosted team chat, Slack-shaped: channels, threads, direct messages, reactions, file attachments, and search. One Node process, no database, nothing installed beside it but Node.
dango is built from the same parts as Mochi Forge, its sibling project (checked out in the next directory for development), and makes the same kinds of decisions: state is plain files in one directory, pages are server-rendered HTML with no client framework and no build step, every write is authorized by a token, and users are created by an administrator rather than registering themselves. Where mochi has a vault of repositories, dango has a workspace of channels.
Unlike a mochi vault, a workspace has no anonymous surface beyond the one a member opens on purpose, a meeting's guest link (see below): reading otherwise requires signing in, a private channel is visible only to its members (the site admin included in the exclusion), and a direct conversation only to its participants. The exclusion is what the interface enforces, not a guarantee against a site admin who sets out to read: an admin can issue a sign-in token for any person, and a backup, which needs an admin's token, copies every room. The operator can of course read the files on disk. Both are true of everything here and worth knowing rather than pretending away; a site admin should be someone trusted as the operator would be.
Try it locally
mkdir mychat
npx @magland/dango serve mychatThe server initializes the workspace and prints an owner token once (only its hash is stored). Open http://127.0.0.1:3000, sign in at /login with the token, and create channels and users from there, or from the CLI:
dango login http://127.0.0.1:3000
dango user add alice
dango channel create general --topic "Everything and nothing"
dango send general "Hello."
dango meeting create Weekly review --with alice # prints the guest linkPut it on the internet
With a Fly.io account and flyctl installed, one command creates the app, the volume, and the machine:
npm install -g @magland/dango
dango deploy fly my-workspace-name # -> https://my-workspace-name.fly.dev
dango login https://my-workspace-name.fly.dev
dango user add aliceThe same command deploys updates, and dango backup ~/backups/chat --snapshot keeps an incremental copy of a hosted workspace on your own disk. From a checkout, --from-source builds the image from your own dango and mochiforge instead of pulling the published one. See Deploying a workspace for Docker, self-hosting with Caddy, and a domain of your own, and Backing up a workspace.
What it does
- Channels, public to every member or private to a member list. Messages are markdown with KaTeX and emoji, with lines typed one under another shown on their own lines, as Slack and GitHub comments show them; links out of the workspace open in a new tab.
- @mentions, completed as you type; a message naming you is marked in the room and counted in the sidebar.
- Unread counts in the sidebar, the tab title, and a dot on the tab's icon, kept on the server per person, so reading a room on one device clears it on the others.
- Threads hung off any message, reactions toggled per person (a dozen at hand, or any emoji, typed or named as
:tada:), pinned messages per room, editing your own messages in place for two hours after sending them (Up in an empty composer edits the last one), and deleting them after a confirmation (a deletion leaves a tombstone, so a thread keeps its anchor). - Direct messages, one conversation per set of up to nine people, and one of your own for notes to self, seen by nobody else.
- File attachments, up to 20 MB and fifty files per message, chosen with the paperclip, dropped onto the room, or pasted into the composer (a screenshot becomes an image named for when it was pasted) and shown there one by one, each removable before sending, stored in the workspace and served only to who could read the message, each shown with its size. Images, audio, and video show or play in place; everything else is a download, under a sandbox policy so an uploaded page is never a page of ours.
- Sending that survives trouble: an upload shows its progress, the composer locks until it finishes, and a send that fails keeps the message and says why. Each send carries a nonce, so sending again after a failure whose outcome was unclear never makes a second message.
- Rate limits per person, sized for someone typing: 20 messages a minute, 300 an hour, 200 MB of uploads an hour, 60 other writes (reactions, edits, deletions, pins, topics, members, settings) a minute, 20 new channels and conversations an hour, and 20 searches a minute. Starting a call counts as sending a message, since it puts an entry in the room and, in a direct conversation, a notification. A refusal says how long to wait. They are settings in
config.json(limits.messagesPerMinute,messagesPerHour,uploadMbPerHour,actionsPerMinute,roomsPerHour,searchesPerMinute; 0 turns one off, and a change takes effect on restart) and apply to the API as well, so a script cannot go around them. Beside these, fixed bounds that are not settings: a reaction is one emoji and a message gathers at most 50 different ones; a person may have two large uploads arriving at once; a person is pushed at most 10 notifications a minute, from all rooms together (the rest wait in the unread counts); and an event stream whose reader has stopped reading is closed rather than buffered, and the page opens it again. - Notifications on the desktop and on phones, through the browsers' own Web Push, so no app store is involved and nothing runs beside the server. Each person chooses, on their Account page, between what is addressed to them (direct messages, @mentions, and replies in their threads; the default), everything, or nothing, whether a notification shows the text, and quiet hours in their own time zone, when nothing is sent and nothing is saved up for later. A bell in each room's header mutes that room, and the sidebar marks the rooms muted. When a notification arrives and a workspace tab is open, the tab plays a soft chime and the notification is shown silently, since the system's own sound is often off and a web page cannot choose it; each browser can turn the chime off on the Account page. A push waits a few seconds and is dropped if the message was read meanwhile on some other screen, and messages inside the wait become one notification. The text is encrypted for the receiving browser, so the push service (Google's, Apple's, Mozilla's, or Microsoft's, whichever the browser uses) sees that a notification was sent and when, but not what it says. On iPhone and iPad this needs iOS 16.4 or later and the workspace added to the Home Screen, which is Apple's condition for any web page; installed there, the workspace also shows the unread total on its icon. Notifications need HTTPS (or a browser on the same machine at localhost).
- Calls in any channel, direct conversation, or meeting, with video, audio, and screen sharing, for up to eight at once, each person in at most two of those places (a laptop and a phone, say). Anyone who can see the room can join at any time. The call sits as a strip of small tiles under the room's header, can be expanded to the full page and collapsed again, and floats in a corner while you read and write in other rooms. Its audio and video go directly between the browsers in it (WebRTC); the workspace only introduces them to each other, and an admin can give the workspace a TURN relay for people whose networks will not connect directly. The admin page tests the STUN and TURN servers from the admin's browser and lists how each connection in each call went; a call's own panel shows its connections live and copies the details for whoever has to diagnose them. The timeline records each call, who was in it, and for how long; a call in a direct conversation or a meeting is notified like a message, and a call in a channel is marked beside the channel's name. See Calls.
- Meetings, for calls with people outside the workspace. A meeting is a room like a private channel, visible to the members added to it, with a guest link. Whoever opens the link gives a name and asks to join; any member of the meeting sees them waiting, on whatever page they have open (and on their phone, if they take notifications), and lets them in or turns them away. A meeting can instead let guests in on the link alone. A guest can join the meeting's call once a member has started it and read and write in the meeting, under the name they gave and marked as a guest; they reach nothing else in the workspace, cannot attach files, and have no account, only a cookie for that meeting. A call left with guests alone ends after 45 seconds. Making a new link shuts out the old one and everyone let in with it. A member of the workspace who opens the link joins as themselves. A site admin can turn guest links off for the whole workspace. See Calls.
- Who is typing, shown under the composer to the others in the room (or thread), as Slack shows it. A page says so every few seconds while its composer has text in it, and the line clears when the message is sent, the composer is emptied, or seven seconds pass without word. It is kept in memory only.
- Live delivery over server-sent events, and moving between rooms without reloading the page, which is what lets a call go on while you do. Every form also works with no script at all; the page script only makes things quieter.
- Search across everything you can read, walked from the files when asked.
- Invite links: adding someone gives a link that signs them in with one press of a button, the token carried in its fragment so it never reaches a server log.
- CLI and JSON API covering the same operations, bearer-token only, with
--jsoneverywhere and the exit codes scripts want.
The workspace
A workspace is one directory. No database, no state outside it; backup is cp -a, and dango backup <dir> pulls the same copy over HTTP where you have no shell.
<workspace>/
workspace.json users and hashed tokens
config.json name, theme, limits, how calls connect
.secret session-cookie signing key
.vapid the key pair notifications are signed with
.turn the TURN relay's credentials, for calls
call-log.json recent call connections, for diagnosing them
channels/
general/
channel.json topic, private flag, members
messages/1.md ... one markdown file per message, YAML frontmatter
threads/4/ replies to message 4, holding its own messages/
files/4/photo.png uploads attached to message 4
dms/
1/
conversation.json participants, and the same layout as a channel
(each room also keeps pins.json, its pinned messages)
meetings/
1/
meeting.json title, members, whether guests wait, the guests
let in (by the name each gave); then as a channel
users/
alice/
read.json the newest message she has seen in each room
notify.json what she wants to be notified of
push.json the browsers her notifications go toEvery message is a markdown file a person can read, grep, and edit with ordinary tools, the way mochi stores issues. Message numbers are allocated by exclusive create, so concurrent writers cannot collide.
Relationship to mochiforge
dango imports mochiforge's modules directly from the sibling checkout (../mochiforge): the identity store, sessions and CSRF, the escaping-by-type HTML templates, markdown rendering, themes, rate limiting, the CLI framework, the Fly deploy procedure, and the backup protocol and client are the forge's own code, not copies. A small naming module in mochiforge lets the shared code spell dango's names, so a workspace mints dango_ tokens, sets a dango_session cookie, and keeps identity in workspace.json; the deploy and backup modules take a profile for what differs beyond names (the image, the volume, the backup's exclusions). With the defaults, mochiforge behaves exactly as before.
The trade-off is stated rather than hidden: dango does not build without the sibling checkout present, and its CI and image workflows check out both. What it ships does not share that coupling: the compiler emits the mochiforge modules dango uses into its own dist, so the npm package and the container image are self-contained. Pinning to a published mochi package would remove the build-time coupling, at the cost of the two drifting; for two projects developed side by side, the checkout wins.
Posts
- Embracing the non-scalability - why a workspace (and a Mochi vault) is one directory and one process
Development
npm install
npm run example # creates example-root/ with sample users and messages
npm run dev # serves example-root/ at http://127.0.0.1:3000
npm run test:unit # the pure modules, in milliseconds
npm run smoke # end to end, against the compiled output
npm run test:browser # the page script in headless Chrome (Node 22+, Chrome installed)
npm run test:phones # the layout on emulated phones: corners, camera, status bar, home indicatornpm run test:phones -- --shots /tmp/phones also writes a screenshot of each phone and page, with the phone's corners, camera, status bar, and home indicator drawn over it, and an index.html to look through them; --device "iPhone 16" limits it to one phone. The check emulates the phones in Chrome, with their sizes and safe-area insets, so it catches a layout that runs under the edges of the screen on every build, but it is not Safari. Before a change to the mobile layout ships, it is worth a look in the iOS Simulator (Xcode, on a Mac) in a Safari tab and as a Home Screen app: run npm run dev -- --host 0.0.0.0 or serve on the Mac itself, then xcrun simctl openurl booted http://<address>:3000.
A release is a version bump pushed to main: npm run bump (patch, or minor, major, or a version) commits the new version, and .github/workflows/publish.yml tests it, publishes it to npm through trusted publishing, tags it, and builds its image, which is what dango deploy fly deploys.
The example workspace has site admin dev with token dango_example_dev_token_000000 (example workspace only), and users alice and bob with tokens spelled the same way.
Limitations and roadmap
- One process serves the workspace. Events are delivered in-process, so a second server on the same directory would render correct pages but not push the other's messages.
- Unread counts cover what arrives in a room, not replies inside its threads; a thread is read from its message. Nothing reaches you by email.
- Signing in takes the token each time on a new browser. Passkeys and GitHub sign-in exist in the shared modules and are the natural next step.
- Whether someone is reading is judged from the page: it must be visible and have been used (a key, a click, a scroll, the pointer moving over it) within the last five minutes, or two when the window lacks the focus. A room left open on an unattended desktop therefore stops counting as read after a few minutes and the phone is notified, while someone who watches a busy room longer than that without touching anything is notified of messages they saw. Notification settings are not yet in the CLI or the JSON API.
- On iPhone and iPad the Home Screen app keeps its own cookies, apart from Safari's, so it has to be signed into separately, with the token; an invite link opens in Safari, not in the app.
- A call connects every browser in it to every other, with no media server, so each person's upload grows with the call; eight is the cap. This is what bounds meetings as a replacement for a video-conferencing service: they suit a small group, and a larger one would need a media server (an SFU).
- A meeting's guest is known by a cookie that lasts a day from its last use, so someone who comes back to a weekly meeting asks to be let in again, under a new identity. The lobby is held in memory, and a restart empties it; a waiting guest's page knocks again by itself. The guest link is derived from
.secret, so replacing.secret(which also signs everyone out) makes every meeting's link new. A call's roster is held in memory, and a restart of the server loses it but not the call, whose browsers stay connected and join again by themselves. Reloading or closing the page is leaving the call; moving between the workspace's own pages is not. - Search walks the files on every query, which is fine well past the point where a workspace is large; an index can come later without changing what is stored.
License
Apache License 2.0.
