Giter Club home page Giter Club logo

sveltekit-soketi-fastify-prisma-demo's Introduction

Soketi-Fastify Chat App

A sample and kinda-unique Chat App build after peer-pressure from Twitter that (allegedly):

  • Fastify is faster than Express
  • Soketi is also faster than Pusher, Socket.io
  • Redis is...well, Redis!
  • Sveltekit performs arguably better than React,Next,Nuxt,Jquery (huh?!) with better syntax
  • Twitter is better than Masterdon

And oh-boy! Do I also have a 2016 Pc that barely notices the first 3 claims!

You're sure your new M1 MBP will notice it? As for React ....... they ain't lying!

Screenshot 1

Quick Docs

Node Server

Start the server by running:

node server

Prisma

Create migration

npx prisma migrate dev --name init

npx prisma studio 
npx prisma studio --browser none

Soketi

Install using Docker. Honestly, why would you not use docker?!

docker run -p 6001:6001 -p 9601:9601 quay.io/soketi/soketi:1.4-16-debian

S3 Uploads

For testing s3 uploads without necessarily creating an AWS account, here we use the s3rver testing library. Simply run

node backend/s3.js

All files are stored in the ./tmp/s3-test folder.

When deploying, you can use cheaper or self-hosted options that support S3-compatible API, e.g. minio

In-Thoughts & Architecture

  • Sveltekit handles the authentication/authorization in the SPA/SSR-side-of-life.
  • Fastify(Node) handles the API-side, that is the websockets/pusher side-of-life. To prevent multiple/redundant authentications, we pass the cookie from Sveltekit as an access_token header when sending messages to the node backend.
  • Arguably, the entire SSR can be made an SPA by just issuing JWT tokens / access_tokens from the node backend. I just prefer keeping the node backend light on its duties, and let Sveltekit do what its best at: everything else!.

After-thoughts

The nature of Pub/Sub is really not bad for small-to-medium scale apps as compared to Bidirectional Streaming. For faster authentication of websocket, short-lived JsonWebTokens are a perfect and fast authentication mechanism. Soketi is mostly advertised and/or used with Laravel, but has been proven to work with other projects. It is INSANELY fast when you test on your own.

However, for truly fast-paced live-chats, it would be better sticking to bidirectional Websockets, As explained here, and here, and this too.

.. or use a service such as Ably!

The Normal, Boring Docs

Boring is good Everything you need to build a Svelte project, powered by create-svelte.

Creating a project

If you're seeing this, you've probably already done this step. Congrats!

# create a new project in the current directory
npm create svelte@latest

# create a new project in my-app
npm create svelte@latest my-app

Developing

Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

Building

To create a production version of your app:

npm run build

You can preview the production build with npm run preview.

To deploy your app, you may need to install an adapter for your target environment.

Credits

Todo

  • Add Emojis
  • Add file and image uploads
  • Add Video chat (WebRTC)
  • Invite links to private chats
  • Hide private chats from non-members (participants)
  • Add limitations to chat rooms, e.g. max_members
  • Group admins can add and remove members
  • Chat creators can delete chat-rooms
  • Join private and group chats via QR code
  • Join private and group chats via PIN/code
  • Join private and group chats via Email

Screenshots

Screenshot 2 Screenshot 6 Screenshot 3 Screenshot 4 Screenshot 5

sveltekit-soketi-fastify-prisma-demo's People

Contributors

syntaxlexx avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.