Skip to content

๐ŸŽญ Stateful serverless framework for Rivet, Cloudflare Workers, Bun, and Node.js. Build AI agents, realtime apps, game servers, and more.

License

Notifications You must be signed in to change notification settings

rivet-gg/actor-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

90 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ActorCore

The Stateful Serverless Framework

Build AI agents, realtime apps, game servers, and more.
Supports Rivet, Cloudflare Workers, Bun, and Node.js.

GitHub Discussions Discord Rivet Twitter Rivet Bluesky License Apache-2.0

Code snippets

Intro

Features

  • ๐Ÿ”‹ Batteries Included: State, RPC, events, & scheduling included out of the box.
  • ๐Ÿ’พ Persistent & In-Memory: Supports storing actor state in-memory that's automatically persisted for high-performance workloads.
  • โšก Multiplayer & Realtime: Build realtime or multiplayer applications on top of actors. ๐Ÿ’พ
  • โš™๏ธ Serverless & Scalable: Built on your serverless runtime of choice to make deploying, scaling, and cost management easy. :microchip:

Supported Platforms

Use Cases

ActorCore is ideal for applications that need coordinated state across multiple clients. Some common use cases include:

  • AI agents
  • Game Servers
  • Collaborative applications
  • Local-first apps
  • Discord Activities
  • Chat Apps
  • Yjs Sync & Storage
  • Sandboxed Code Execution

By handling the complexities of state management and coordination, ActorCore lets you focus on building your application logic rather than wrestling with distributed systems primitives.

Getting Started

Step 1: Installation

# npm
npm add actor-core

# pnpm
pnpm add actor-core

# Yarn
yarn add actor-core

# Bun
bun add actor-core

Step 2: Create an Actor

import { Actor, type Rpc } from "actor-core";

export interface State {
    messages: { username: string; message: string }[];
}

export default class ChatRoom extends Actor<State> {
    // initialize this._state
    _onInitialize() {
        return { messages: [] };
    }

    // receive an remote procedure call from the client
    sendMessage(rpc: Rpc<ChatRoom>, username: string, message: string) {
        // save message to persistent storage
        this._state.messages.push({ username, message });

        // broadcast message to all clients
        this._broadcast("newMessage", username, message);
    }
}

Step 3: Connect to Actor

import { Client } from "actor-core/client";
import type ChatRoom from "../src/chat-room.ts";

const client = new Client(/* manager endpoint */);

// connect to chat room
const chatRoom = await client.get<ChatRoom>({ name: "chat" });

// listen for new messages
chatRoom.on("newMessage", (username: string, message: string) =>
    console.log(`Message from ${username}: ${message}`),
);

// send message to room
await chatRoom.sendMessage("william", "All the world's a stage.");

Step 4: Deploy

Deploy to your platform of choice:

Community & Support

License

Apache 2.0