Skip to content

Installation

Get up and running with Vla in minutes. This guide will walk you through installation, basic setup, and your first Action.

Install Vla using your preferred package manager:

Terminal window
npm install vla
Terminal window
pnpm add vla
Terminal window
yarn add vla
Terminal window
bun add vla

Vla works with any server-side JavaScript framework. The basic setup involves:

  1. Creating a Kernel
  2. Setting up the Kernel for invocation
  3. Creating your first classes

The Kernel is Vla’s dependency injection container. Create one in a central location:

src/data/kernel.ts
import { Vla } from "vla"
export const kernel = new Vla.Kernel()

Then setup the Kernel for invocation, so Vla knows what request context it’s in.

For any framework that supports middleware to wrap a request, often with a next() function:

src/app.ts
import { Vla } from "vla"
import { kernel } from "./data/kernel"
const app = express() // or anything else
app.use((req, res, next) => {
return Vla.withKernel(kernel.scoped(), () => next())
})

Actions are entry points to your data layer. They’re invoked from your framework’s route handlers, server actions, or API endpoints.

src/data/users.ts
import { Vla } from "vla"
export class GetUser extends Vla.Action {
repo = this.inject(UserRepo)
async handle(params: YourFrameworkParams) {
return this.repo.findById(params.id)
}
}
class UserRepo extends Vla.Repo {
db = this.inject(Db)
findById = this.memo((id: string) => {
return this.db.users[id]
})
}
class Db extends Vla.Resource {
// Mock database for this example
db = {
users: {
"1": { id: "1", name: "Alice", email: "[email protected]" },
"2": { id: "2", name: "Bob", email: "[email protected]" }
}
}
static readonly unwrap = "db"
}

Actions can be invoked from anywhere in your application:

app/users/[id]/page.tsx
import { GetUser } from "@/data/users.actions"
export default async function UserPage({ params }) {
const user = await GetUser.invoke(params)
return (
<div>
<h1>{user.name}</h1>
<p>{user.email}</p>
</div>
)
}

Now that you have Vla set up, learn about:

  • Adding Actions - Follow a step by step guide to work with Actions, Services, Repos and Resources
  • Why Vla? - Learn more about the benefits of using Vla in your app