Building Your First App
Step-by-step tutorial for building your first app on the LegionEdge Platform
This tutorial walks you through building a simple project management tool on the LegionEdge Platform. By the end, you will have a working application that creates projects, manages team members, and allocates resources.
Prerequisites
- Node.js 18+
- A LegionEdge account with an API key
- The
@legionedge/sdkpackage installed
Project Setup
mkdir le-project-manager && cd le-project-manager
npm init -y
npm install @legionedge/sdk dotenv typescript tsxCreate a .env file:
LEGIONEDGE_API_KEY=le_live_your_key_here
LEGIONEDGE_ORG_ID=org_your_org_idStep 1: Initialize the Client
Create src/client.ts:
import { LegionEdge } from "@legionedge/sdk";
import "dotenv/config";
export const client = new LegionEdge({
apiKey: process.env.LEGIONEDGE_API_KEY!,
});
export const ORG_ID = process.env.LEGIONEDGE_ORG_ID!;Step 2: Create a Project
Create src/create-project.ts:
import { client, ORG_ID } from "./client";
export async function createProject(name: string, description: string) {
const project = await client.projects.create({
organizationId: ORG_ID,
name,
description,
settings: {
defaultEnvironment: "development",
autoScaling: false,
notificationsEnabled: true,
},
});
console.log(`Project "${project.name}" created with ID: ${project.id}`);
return project;
}Step 3: Add Team Members
Create src/manage-team.ts:
import { client } from "./client";
export async function addTeamMember(
projectId: string,
email: string,
role: "admin" | "member"
) {
// Look up the user by email
const users = await client.users.list({
organizationId: process.env.LEGIONEDGE_ORG_ID!,
search: email,
});
const user = users.data.find((u) => u.email === email);
if (!user) {
throw new Error(`User with email ${email} not found in organization`);
}
await client.projects.addMember(projectId, {
userId: user.id,
role,
});
console.log(`Added ${user.name} as ${role} to project ${projectId}`);
}
export async function listTeamMembers(projectId: string) {
const members = await client.projects.listMembers(projectId);
console.log(`\nTeam members (${members.data.length}):`);
for (const m of members.data) {
console.log(` ${m.user.name} <${m.user.email}> - ${m.role}`);
}
return members.data;
}Step 4: Allocate Resources
Create src/resources.ts:
import { client } from "./client";
export async function allocateDatabase(projectId: string) {
const resource = await client.resources.allocate({
projectId,
type: "database",
name: "primary-db",
config: {
engine: "postgresql",
version: "16",
size: "small",
region: "us-east-1",
},
});
console.log(`Database resource allocated: ${resource.id} (${resource.status})`);
return resource;
}Step 5: Bring It All Together
Create src/main.ts:
import { createProject } from "./create-project";
import { addTeamMember, listTeamMembers } from "./manage-team";
import { allocateDatabase } from "./resources";
async function main() {
// Create the project
const project = await createProject(
"my-first-app",
"A demo application built on LegionEdge"
);
// Add a team member
await addTeamMember(project.id, "colleague@example.com", "member");
// List the team
await listTeamMembers(project.id);
// Allocate a database
await allocateDatabase(project.id);
console.log("\nYour first app is set up and ready to go!");
}
main().catch(console.error);Running the App
npx tsx src/main.tsExpected output:
Project "my-first-app" created with ID: proj_x1y2z3
Added Alice Engineer as member to project proj_x1y2z3
Team members (2):
Jane Developer <jane@example.com> - admin
Alice Engineer <colleague@example.com> - member
Database resource allocated: res_a1b2c3 (provisioning)
Your first app is set up and ready to go!Next Steps
- Deploy your app to production.
- Review best practices for production readiness.
- Explore the API reference for additional capabilities.