Modus Serverless Framework
repository·main·Indexed 19 days ago
https://github.com/hypermodeinc/modusAn open-source serverless framework for building agentic systems and AI applications. Modus allows developers to write functions in Go or AssemblyScript that are transformed into scalable, sandboxed GraphQL endpoints using WebAssembly (Wasm). It includes a CLI (@hypermode/modus-cli) for local development and a runtime for executing modules with integrated access to AI models, vector support, and various databases including Dgraph, Neo4j, PostgreSQL, and MySQL.
What's inside Modus
- The Modus CLI is the primary tool for the local developer experience when working with Modus. Modus itself is an open-source, serverless framework designed for building intelligent functions and APIs using WebAssembly (Wasm).
Use the Modus SDK for AssemblyScript
mainThe Modus SDK for AssemblyScript is designed for developers building Modus applications using AssemblyScript. It provides the necessary interfaces to access Modus platform features, utilize Modus-specific build scripts and tooling, and leverage specialized AssemblyScript APIs tailored for the Modus environment.How Modus works: From function to API
mainModus is a serverless framework that turns functions into scalable, AI-ready GraphQL endpoints. It uses WebAssembly (Wasm) to provide a sandboxed execution environment.
The Workflow
- Development: You write a function in a supported language (Go or AssemblyScript).
- Compilation: Modus extracts metadata, optimizes the code for the host environment, and caches the compiled module.
- Deployment/Activation: Modus reads the app's manifest to extract connections, models, and configuration, then generates a GraphQL API schema.
- Execution: When a GraphQL query is received, Modus loads the Wasm module into a sandboxed environment with dedicated memory, runs the code using host functions for AI/data access, and returns the result.
// Example AssemblyScript function export function sayHello(name: string): string { return `Hello, ${name}!`; } // Example GraphQL query to call the function query SayHello { sayHello(name: "World") }Understand the role of the Modus Runtime
mainThe Modus Runtime is the core component responsible for loading and executing Modus applications.
Note for Users: You generally do not need to interact with the runtime source code directly. The Modus CLI handles the installation of the appropriate platform-specific binary in your development environment, and the runtime is used automatically when hosting Modus apps in production.
Quickstart: Install and initialize Modus
mainTo start building with Modus, install the CLI globally, initialize a new project, and run it locally in development mode.
- Install the Modus CLI: Use npm to install the
@hypermode/modus-clipackage. - Initialize a project: Run
modus newto scaffold a new Modus application. - Run locally: Use
modus devto start your app with fast refresh enabled.
# Install the CLI npm install -g @hypermode/modus-cli # Initialize a new app modus new # Run locally with fast refresh modus dev- Install the Modus CLI: Use npm to install the
Getting started with Modus
mainTo begin using Modus, follow the official quickstart guide at: https://docs.hypermode.com/modus/quickstartClean up the Secrets example environment
mainTo remove the local
kindcluster created during the setup of the Secrets example, run theteardown.shscript.# Delete the kind cluster bash teardown.shUse Modus shared libraries in external projects
mainThe libraries located in thelib/directory are designed to be used both within the Modus ecosystem and in external projects. They are primarily utilized by the Modus runtime and Hypermode hosting infrastructure, but they can be integrated into any application subject to the Modus LICENSE.Run the Modus app with Kubernetes secrets
mainTo run a Modus application using a Kubernetes secret for secret management, use the
modus_runtimecommand with the-useKubernetesSecretflag and specify the secret name using-kubernetesSecretName. The secret name should follow thenamespace/secret-nameformat.modus_runtime -appPath ./build -useKubernetesSecret -kubernetesSecretName default/exampleSet up and run the Secrets example
mainThis guide demonstrates how to set up a local environment using
kindto test the Modus secrets implementation.Prerequisites
A running Kubernetes cluster is required. This example uses
kindfor local testing.Steps
- Initialize the cluster: Run the provided setup script to create a local
kindcluster. - Build the application: Compile the Modus app using the build script.
- Execute the runtime: Run the application using
modus_runtimewith Kubernetes secret flags.
Verification
To verify the implementation is working correctly:
- Call the
GetSecretValue()function with the input argument"foo". - Confirm that the function returns
"bar".
# Setup local kind cluster for testing bash setup.sh # Build the Modus app bash build.sh # Run the Modus app modus_runtime -appPath ./build -useKubernetesSecret -kubernetesSecretName default/example- Initialize the cluster: Run the provided setup script to create a local
Install Modus shared libraries via Go modules
mainModus shared libraries are organized into independent Go modules. Each module is versioned separately using a tag scheme that corresponds to its directory path. To install a specific library, use its unique module path. For example, to install the
manifestlibrary, use the pathgithub.com/hypermodeinc/modus/lib/manifest.go get -u github.com/hypermodeinc/modus/lib/manifestUnderstand the output of the Modus Keygen Tool
mainWhen executed, the
modus-keygentool produces both standard output (stdout) and local files.Standard Output (stdout)
The tool prints a JSON-encoded object and a JWT token:
- RSA Public Key (JSON): A JSON object containing an RSA public key. This is intended to be passed to the
MODUS_PEMSenvironment variable. - JWT Token: A bearer token signed with the generated RSA key. It has a 1-year expiration date and no additional claims. This is used for authorization.
Generated Files
The tool creates two files in your current working directory:
private-key.pem: A 2048-bit RSA private key. IMPORTANT: Keep this secret and do not lose it. You need this file to issue new JWT tokens that can be validated by the public key.public-key.pem: The corresponding public key (this matches the JSON output provided to stdout).
Note on persistence: If
private-key.pemalready exists in the working directory, the tool will re-use it instead of generating a new key pair. This allows you to run the tool multiple times to generate additional JWTs from the same existing key pair.- RSA Public Key (JSON): A JSON object containing an RSA public key. This is intended to be passed to the