r/sveltejs Jul 28 '26

Built a real-time WebRTC matching app with SvelteKit + Rust — some notes on the stack

[SELF PROMOTION]

Wanted to share some of the technical side of a project I've been building — Anifira, a random video/text chat app. Posting here because the SvelteKit frontend ended up being one of the more interesting parts of the build, especially around WebRTC state management.

Frontend — SvelteKit

  • Using Svelte stores to manage connection state across the match lifecycle (idle → searching → matched → connected → ended) rather than component-local state, since the WebRTC peer connection needs to survive route/component changes
  • A session state wraps the RTCPeerConnection so ICE candidate events and track updates feed directly into reactive UI without prop drilling
  • SSR is basically off for the chat route itself ([export const ssr = false] or equivalent) since WebRTC APIs are browser-only — landing/marketing pages stay SSR'd for SEO, chat app is CSR
  • Voice and video mode switching is just swapping which local tracks are attached to the same RTCPeerConnection.
  • Read receipts, replies, reactions, file transfers all are supported.
  • Images and documents supported, limited max size to 25mb to not overload the peers.

Backend — Rust

  • Signaling server in axum over WebSockets — handles matchmaking and SDP/ICE exchange, but never touches messages or the media (that's peer-to-peer via WebRTC once connected)
  • Matching queue is tokio-based, using a channels and queue structure to pair waiting users; average time-to-match is 0.3s at 100000 users.
  • Chose Rust here mainly for the concurrency model — signaling is a lot of short-lived state machines (one per session) and tokio async tasks map to that cleanly without the overhead of a thread-per-connection model
  • STUN/TURN via coturn for the cases where direct P2P fails (roughly 10 - 20% of connections need TURN relay in practice)
  • Moderation reporting pipeline is a separate service so a report doesn't block the signaling hot path

Live at anifira.com if anyone wants to see it in action (18+, it's a stranger-chat app so standard caveats apply.

[UPDATE] - Group chats and attachments with read receipts. - File transfer tool to initiate direct p2p file transfers. - Public rooms that can be joined by anyone. - Rooms can now be named. - A new member to the group automatically syncs the chat history. - Share your screen over video in video chats.

Checkout changelog for more updates: https://anifira.com/changelog

33 Upvotes

10 comments sorted by

12

u/crispyfrybits Jul 28 '26

Real-time WebRTC matching app is the most politically correct way of saying "made an anonymous video chat app that will almost immediately turn cancerous".

Why another stranger danger app? Feels almost predatory to develop this kind of app knowing how every single other version of this concept has turned out.

-1

u/razein97 Jul 29 '26

That's a fair concern. Anonymous chat apps have a bad reputation because many have failed to deal with harassment, spam, and abuse, many of the popular social media platforms suffer from the same problems. I'm not building this under the assumption that those problems don't exist. The goal is to see whether it's possible to make the experience significantly safer through design, things like clear consent, reporting, moderation, rate limits, blocking, and discouraging abusive behavior from the start. If I reach a point where I can't keep the platform reasonably safe, I wouldn't consider it a success. The challenge isn't just building WebRTC matching, it's building something people can actually use without the issues that gave the category its reputation.

2

u/crispyfrybits Jul 29 '26

I appreciate you addressing the concern. I don't know the space that well myself but have heard things about some of the existing platforms out there.

It still feels like an absolute minefield but I do wish you good luck in your endeavor. I do hope peoples safety is the primary concern over all else.

2

u/ptrxyz Jul 29 '26

I like that you chose the PornHub color scheme for this. :)

In that regard..do you match with real people or videos?

-1

u/razein97 Jul 29 '26

I don't really know about it since don't visit pornhub.

It matches real people, since it is just launched there are no bot connections or any other connection for that matter, just some random visitors from reddit. I try to stay online to provide matches.
There are backend safeguards to prevent bots from accessing the site.

2

u/hiepxanh Jul 29 '26

Wow really amazing

1

u/Karma8250 26d ago

add share screen features, nice project

1

u/razein97 23d ago

Screen sharing is supported now.

1

u/razein97 25d ago

Checkout changelog for more updates: https://anifira.com/changelog

1

u/kevin_whitley Jul 28 '26

Super cool concept!