Quick Start

Quick Start

Viewing typescript

switch to python

Prerequisites:
  • Docker (opens in a new tab)
  • macOS or Linux (Windows is not supported at this time, but may work using WSL Windows Subsystem for Linux)

Check if these dependencies are installed:

Terminal
git --version && node --version && docker --version

First, initialize your Moose project

Run create-moose-app in your terminal

Terminal
npx create-moose-app@latest my-moose-app ts 

This will automatically create a new project folder and initialize a skeleton Moose app with the entire project structure you need to get started.

Terminal
cd my-moose-app && npm install

Spin up your Moose local development server

Make sure Docker is running.

Run docker info to check.

Terminal
npx moose-cli dev
What's happening?

The dev server dynamically configures and updates the infrastructure for your application, including a web server for data ingestion and consumption, a Redpanda platform for data buffering, and a Clickhouse database for data storage and querying.

Check that the infrastructure is set up correctly

Open a new terminal session

Make sure to cd into your Moose project directory before running the command.

Terminal
npx moose-cli ls 

You should see the following ouput, which shows the ingestion points and tables that have been created for your project:

moose-ls

Next, view and test your data models

Open Project in IDE

VSCode Users: Install Recommended Extensions

When you open your project, you'll be prompted to install the SQLTools (opens in a new tab) and SQLTools ClickHouse Driver (opens in a new tab) extensions. Moose auto-configures these for your local Clickhouse database, enabling you to explore and query your data immediately.

Open models.ts and inspect the data models (located in /app/datamodels)

/app/datamodels/models.ts
import { Key } from "@514labs/moose-lib";
 
export interface UserActivity {
  eventId: Key<string>;
  timestamp: string;
  userId: string;
  activity: string;
}
 
export interface ParsedActivity {
  eventId: Key<string>;
  timestamp: Date;
  userId: string;
  activity: string;
}
MooseTip:

The file defines UserActivity and ParsedActivity data models, which structure data for ingestion into your Moose infrastructure.

Moose automatically created database tables and ingestion points for these models, as seen in the moose-ls output.

Finally, ingest data into your application infrastructure

Send sample UserActivity data to the /ingest/UserActivity API endpoint on your local dev server (running on localhost:4000):

Terminal
  curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"eventId": "1234567890", "timestamp": "2019-01-01 00:00:01", "userId": "123456", "activity": "click"}' \
  http://localhost:4000/ingest/UserActivity

Check for confirmation messages in the CLI that the API endpoint received the data

Terminal
POST /ingest/UserActivity/0.0
SUCCESS /ingest/UserActivity/0.0
  • Click the SQLTools database icon in your extensions tab.
  • You should see the Clickhouse icon followed by the connection details for the database running on your local dev server: panda@localhost:18123/local. SQL Tools Setup
  • To create and run a new query, click the New SQL File icon.

Query your database to confirm the data landed

Navigate to your preferred database explorer tool and run the following query:

DB Explorer
SELECT * FROM local.UserActivity_0_0

You should see the data you ingested in the UserActivity table.

Next Steps

Congratulations!

You've successfully set up a Moose project, ingested data, and confirmed that it landed in your database. You're now ready to dive deeper and explore all the exciting capabilities that Moose has to offer. Here are some suggested next steps:

Learn Other Moose Primitives

Process Data with Streaming Functions

Learn how to process UserActivity data into ParsedActivity data using Streaming Functions

Add a New Data Model

Take a deeper dive into the Data Models primitive and how to add a new Data Model to your Moose project