0.3.5 • Published 2 years ago

rtag v0.3.5

Weekly downloads
124
License
MIT
Repository
github
Last release
2 years ago

rtag - realtime app generator

Overview

Rtag is a framework for building realtime applications with a focus on development experience.

Features

Rtag comes out of the box with the following features so that developers don't have to think about them:

  • Networking (state synchronization and RPC, efficient binary serialization)
  • Authentication
  • Automatic persistence
  • Declarative API format with client generation
  • Development server with hot reloading and built in debug UI

Application spec

The foundation of an rtag application is the rtag.yml file, which defines various aspects of the application's behavior. One of the primary components the developer includes in this file is a fully typed API, which lists the server methods as well as the client state tree.

From this specification, rtag automatically generates the following:

  • server side method stubs that set up the entire server code structure and just need to be filled in with the application's business logic
  • clients for frontends to communicate with the rtag server in a typesafe manner
  • a web-based debug application that allows for testing backend logic right away without writing any frontend code

Installation

Requirements

  • node v16.12.0+

Install rtag from the npm registry:

npm install -g rtag

Example

First, create a directory for your application and create a rtag.yml file inside the directory with the following contents:

# rtag.yml

types:
  Username: string
  Message:
    text: string
    sentAt: int
    sentBy: Username
    sentTo: Username?
  RoomState:
    name: string
    createdBy: Username
    messages: Message[]

methods:
  createRoom:
    name: string
  sendPublicMessage:
    text: string
  sendPrivateMessage:
    to: Username
    text: string

auth:
  anonymous:
    separator: "-"

userState: RoomState
initialize: createRoom
error: string

Next, run rtag init to initialize your project. Then run rtag dev to start the debug server. Visit http://localhost:3000 where you see the following Prototype UI view:

image

We then fill in the methods in server/impl.ts with our desired implementation:

import { Methods, Context } from "./.rtag/methods";
import { UserData, Response } from "./.rtag/base";
import { RoomState, ICreateRoomRequest, ISendPublicMessageRequest, ISendPrivateMessageRequest } from "./.rtag/types";

export class Impl implements Methods<RoomState> {
  createRoom(user: UserData, ctx: Context, request: ICreateRoomRequest): RoomState {
    return { name: request.name, createdBy: user.name, messages: [] };
  }
  sendPublicMessage(state: RoomState, user: UserData, ctx: Context, request: ISendPublicMessageRequest): Response {
    state.messages.push({ text: request.text, sentAt: ctx.time(), sentBy: user.name });
    return Response.ok();
  }
  sendPrivateMessage(state: RoomState, user: UserData, ctx: Context, request: ISendPrivateMessageRequest): Response {
    state.messages.push({ text: request.text, sentAt: ctx.time(), sentBy: user.name, sentTo: request.to });
    return Response.ok();
  }
  getUserState(state: RoomState, user: UserData): RoomState {
    return {
      name: state.name,
      createdBy: state.createdBy,
      messages: state.messages.filter(
        (msg) => msg.sentBy === user.name || msg.sentTo === user.name || msg.sentTo === undefined
      ),
    };
  }
}

Note that currently, the only backend language supported is typescript. More language support is planned for the future.

Finally, we can see our working application in action:

image

Here are some example apps built with rtag:

Additional resources

For a high level overview of rtag concepts and goals, see concepts. For more details on how to implement an rtag application, check out the reference docs.

If you have any questions/suggestions or want to report a bug, please feel free to file an issue or start a discussion on Github!

0.3.0

2 years ago

0.3.5

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.2.6

2 years ago

0.2.3

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

2 years ago

0.2.2

2 years ago

0.2.0

3 years ago

0.1.35

3 years ago

0.1.32

3 years ago

0.1.33

3 years ago

0.1.34

3 years ago

0.1.31

3 years ago

0.1.30

3 years ago

0.1.27

3 years ago

0.1.28

3 years ago

0.1.29

3 years ago

0.1.26

3 years ago

0.1.24

3 years ago

0.1.25

3 years ago

0.1.21

3 years ago

0.1.22

3 years ago

0.1.23

3 years ago

0.1.20

3 years ago

0.1.19

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.16

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.4

3 years ago

0.1.5

3 years ago

0.1.2

3 years ago

0.1.3

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.84

3 years ago

0.0.85

3 years ago

0.0.86

3 years ago

0.0.80

3 years ago

0.0.81

3 years ago

0.0.82

3 years ago

0.0.83

3 years ago

0.0.74

3 years ago

0.0.75

3 years ago

0.0.76

3 years ago

0.0.77

3 years ago

0.0.78

3 years ago

0.0.79

3 years ago

0.0.73

3 years ago

0.0.70

3 years ago

0.0.71

3 years ago

0.0.72

3 years ago

0.0.69

3 years ago

0.0.68

3 years ago

0.0.67

3 years ago

0.0.66

3 years ago

0.0.65

3 years ago

0.0.62

3 years ago

0.0.63

3 years ago

0.0.64

3 years ago

0.0.60

3 years ago

0.0.61

3 years ago

0.0.59

3 years ago

0.0.58

3 years ago

0.0.53

3 years ago

0.0.54

3 years ago

0.0.55

3 years ago

0.0.56

3 years ago

0.0.57

3 years ago

0.0.52

3 years ago

0.0.51

3 years ago

0.0.49

3 years ago

0.0.48

3 years ago

0.0.47

3 years ago

0.0.46

3 years ago

0.0.45

3 years ago

0.0.44

3 years ago

0.0.43

3 years ago

0.0.42

3 years ago

0.0.41

3 years ago

0.0.39

3 years ago

0.0.37

3 years ago

0.0.38

3 years ago

0.0.36

3 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.26

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.11

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago