Skip to content

Commit e7cb936

Browse files
committed
Create new getting started guide
1 parent 9f13cc5 commit e7cb936

File tree

7 files changed

+417
-53
lines changed

7 files changed

+417
-53
lines changed

docs/README.md

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,11 @@
44
[Connect with our team!](https://www.harpersystems.dev/contact)
55
{% endhint %}
66

7-
## What is Harper? Performance, Simplicity, and Scale.
8-
9-
Harper is an all-in-one backend technology that fuses database technologies, caching, application hosting, and messaging functions into a single system. Unlike traditional architectures where each piece runs independently and incurs extra costs and latency from serialization and network operations between processes, Harper systems can handle workloads seamlessly and efficiently.
10-
11-
Harper simplifies scaling with clustering and native data replication. At scale, architectures tend to include 4 to 16 redundant, geo-distributed nodes located near every user population center. This ensures that every user experiences minimal network latency and maximum reliability in addition to the already rapid server responses.
12-
13-
<figure><img src="../images/harperstack.jpg" alt="Comparison of Harper&#x27;s all-in-one technology (left) versus traditional multi-system approaches (right), highlighting Harper&#x27;s speed, simplicity, and efficiency with no intermediary processes, against the latency and complexity of legacy strategies."><figcaption></figcaption></figure>
14-
15-
## Understanding the Paradigm Shift
16-
17-
Have you ever combined MongoDB with Redis, Next.js with Postgres, or perhaps Fastify with anything else? The options seem endless. It turns out that the cost of serialization, network hops, and intermediary processes in these systems adds up to 50% of the total system resources used (often more). Not to mention the hundreds of milliseconds of latency they can add.
18-
19-
What we realized is that networking systems together in this way is inefficient and only necessary because a fused technology did not exist. So, we built Harper, a database fused with a complete JavaScript application system. It’s not only orders of magnitude more performant than separated systems, but it’s also easier to deploy and manage at scale.
20-
21-
## Build With Harper
22-
23-
Start by running Harper locally with [npm](https://www.npmjs.com/package/harperdb) or [Docker](https://hub.docker.com/r/harperdb/harperdb).
24-
25-
Since technology tends to be built around the storage, processing, and transfer of data, start by [defining your schema](developers/applications/#creating-our-first-table) with the `schema.graphql` file in the root of the application directory.
26-
27-
If you would like to [query](developers/applications/#adding-an-endpoint) this data, add the `@export` directive to our data schema and test out the [REST](developers/rest.md), [MQTT](developers/real-time.md#mqtt), or [WebSocket](developers/real-time.md#websockets) endpoints.
28-
29-
When you are ready for something a little more advanced, start [customizing your application](developers/applications/#custom-functionality-with-javascript).
30-
31-
Finally, when it’s time to deploy, explore [replication](developers/replication/) between nodes.
32-
33-
If you would like to jump into the most advanced capabilities, learn about [components](developers/components/).
34-
35-
For a more comprehensive deep dive, take a look at our [Getting Started Guide](getting-started.md).
36-
37-
{% hint style="warning" %}
38-
Need help? Please don’t hesitate to [reach out](https://www.harpersystems.dev/contact).
39-
{% endhint %}
40-
41-
## Popular Use Cases
42-
43-
With so much functionality built in, the use cases span nearly all application systems. Some of the most popular are listed below, motivated by new levels of performance and system simplicity.
44-
45-
### Online Catalogs & Content Delivery
46-
47-
For use cases like e-commerce, real estate listing, and content-oriented sites, Harper’s breakthroughs in performance and distribution pay dividends in the form of better SEO and higher conversion rates. One common implementation leverages Harper’s [Next.js Component](https://github.com/HarperDB/nextjs) to host modern, performant frontend applications. Other implementations leverage the built-in caching layer and JavaScript application system to [server-side render pages](https://www.harpersystems.dev/development/tutorials/server-side-rendering-with-multi-tier-cache) that remain fully responsive because of built-in WebSocket connections.
48-
49-
### Data Delivery Networks
50-
51-
For use cases like real-time sports updates, flight tracking, and zero-day software update distribution, Harper is rapidly gaining popularity. Harper’s ability to receive and broadcast messages while simultaneously handling application logic and data storage streamlines operations and eliminates the need for multiple separate systems. To build an understanding of our messaging system function, refer to our [real-time documentation](developers/real-time.md).
52-
53-
### Edge Inference Systems
54-
55-
Capturing, storing, and processing real-time data streams from client and IoT systems typically requires a stack of technology. Harper’s selective data replication and self-healing connections make for an ideal multi-tier system where edge and cloud systems both run Harper, making everything more performant.
56-
57-
[We’re happy](https://www.harpersystems.dev/contact) to walk you through how to do this.
7+
Welcome to the Harper Documentation! Here, you'll find all things Harper, and everything you need to get started, troubleshoot issues, and make the most of our platform.
588

599
## Getting Started
6010

61-
<table data-column-title-hidden data-view="cards"><thead><tr><th></th><th></th><th data-hidden></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="getting-started.md"><strong>Getting Started Guide</strong></a></td><td>Get up and running with Harper</td><td></td><td><a href="getting-started.md">getting-started.md</a></td></tr><tr><td><a href="deployments/install-harper/"><strong>Quick Install Harper</strong></a></td><td>Run Harper on your on hardware</td><td></td><td><a href="deployments/install-harper/">install-harper</a></td></tr><tr><td><a href="deployments/harper-cloud/"><strong>Try Harper Cloud</strong></a></td><td>Spin up an instance in minutes to get going fast</td><td></td><td><a href="deployments/harper-cloud/">harper-cloud</a></td></tr></tbody></table>
11+
<table data-column-title-hidden data-view="cards"><thead><tr><th></th><th></th><th data-hidden></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="getting-started/install-harper.md"><strong>Install Harper</strong></a></td><td>Pick the installation method that best suits your environment</td><td></td><td><a href="getting-started/install-harper.md">install-harper</a></td></tr><tr><td><a href="getting-started/what-is-harper.md"><strong>What is Harper</strong></a></td><td>Learn about Harper, how it works, and some of its usecases</td><td></td><td><a href="getting-started/what-is-harper.md">what-is-harper</a></td></tr><tr><td><a href="getting-started/harper-concepts.md"><strong>Harper Concepts</strong></a></td><td>Learn about Harper's fundamental concepts and how they interact</td><td></td><td><a href="getting-started/harper-concepts.md">harper-concepts</a></td></tr></tbody></table>
6212

6313
## Building with Harper
6414

docs/SUMMARY.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Table of contents
22

33
* [Harper Docs](README.md)
4-
* [Getting Started](getting-started.md)
4+
* [Getting Started](getting-started/README.md)
5+
* [What is Harper](getting-started/what-is-harper.md)
6+
* [Install Harper](getting-started/install-harper.md)
7+
* [Harper Concepts](getting-started/harper-concepts.md)
8+
* [Create Your First Application](getting-started/first-harper-app.md)
59

610
## Developers
711

docs/getting-started/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Getting Started
2+
3+
If you're new to Harper, this section will guide you through the essential resources you need to get started.
4+
5+
Follow the steps in this documentation to discover how Harper can simplify your backend stack, eliminate many inter-process communication delays, and achieve a more predictable and performant application experience.
6+
7+
For more advanced concepts in Harper, see our [blog](https://www.harpersystems.dev/blog).
8+
9+
## Harper Basics
10+
<table data-column-title-hidden data-view="cards"><thead><tr><th></th><th></th><th data-hidden></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="getting-started/install-harper.md"><strong>Install Harper</strong></a></td><td>Pick the installation method that best suits your environment</td><td></td><td><a href="getting-started/install-harper.md">install-harper</a></td></tr><tr><td><a href="getting-started/what-is-harper.md"><strong>What is Harper</strong></a></td><td>Learn about Harper, how it works, and some of its usecases</td><td></td><td><a href="getting-started/what-is-harper.md">what-is-harper</a></td></tr><tr><td><a href="getting-started/harper-concepts.md"><strong>Harper Concepts</strong></a></td><td>Learn about Harper's fundamental concepts and how they interact</td><td></td><td><a href="getting-started/harper-concepts.md">harper-concepts</a></td></tr></tbody></table>
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Create Your First Application
2+
Now that you've set up Harper, let's build a simple Book API. Start by cloning the template:
3+
4+
```bash
5+
git clone https://github.com/HarperDB/application-template my-book-app
6+
cd my-book-app
7+
```
8+
9+
The template includes:
10+
- **schema.graphql** – Your GraphQL schema definition
11+
- **resources.js** – For custom application logic
12+
- **config.yaml** – Application-level settings
13+
14+
## Define a GraphQL Schema
15+
Edit your `schema.graphql` file to create a Book table:
16+
```graphql
17+
type Book @table @export {
18+
id: ID @primaryKey
19+
title: String!
20+
author: String!
21+
publishedYear: Int
22+
genre: String
23+
}
24+
```
25+
26+
The schema above does several important things:
27+
- Creates a `Book` table with the `@table` directive
28+
- Makes the table accessible via REST and GraphQL using the `@export` directive
29+
- Defines an `id` field as the primary key with the `@primaryKey` directive
30+
- Requires `title` and `author` fields (marked with `!`)
31+
- Adds optional `publishedYear` and `genre` fields
32+
33+
When you start your application, Harper will automatically create this table structure.
34+
35+
## Extend the Resource Class
36+
Now let's create the business logic for our Book API by implementing a custom resource class. Update your `resources.js` file:
37+
38+
```js
39+
export class Books extends Resource {
40+
// Get a book by ID or list all books
41+
async get() {
42+
console.log("GET request received");
43+
const id = this.getId();
44+
45+
if (id) {
46+
// Return a single book
47+
return await this.table.get(id);
48+
} else {
49+
// Return all books with optional genre filter
50+
const genre = this.getQueryParam("genre");
51+
const searchOptions = genre ? { genre } : {};
52+
return await this.table.search(searchOptions);
53+
}
54+
}
55+
56+
// Create a new book
57+
async post(data) {
58+
console.log("POST request received");
59+
60+
// Parse string data if needed
61+
if (typeof data === "string") {
62+
try {
63+
data = JSON.parse(data);
64+
} catch (err) {
65+
return { error: "Invalid JSON" };
66+
}
67+
}
68+
69+
// Validate required fields
70+
if (!data.title || !data.author) {
71+
return { error: "Title and author are required" };
72+
}
73+
74+
// Prevent primary key overriding
75+
if (data.id) delete data.id;
76+
77+
try {
78+
const result = await this.table.post(data);
79+
return result;
80+
} catch (error) {
81+
return { error: "Error creating book", details: error.message };
82+
}
83+
}
84+
}
85+
```
86+
Let's break down what this JavaScript file is doing:
87+
88+
### Resource Class Extension
89+
```js
90+
export class Books extends Resource {
91+
```
92+
93+
This line creates a custom `Books` class that extends Harper's built-in `Resource` class. By doing this, we inherit all the standard functionality while allowing us to customize behavior.
94+
95+
### GET Method
96+
```js
97+
async get() {
98+
console.log("GET request received");
99+
const id = this.getId();
100+
101+
if (id) {
102+
// Return a single book
103+
return await this.table.get(id);
104+
} else {
105+
// Return all books with optional genre filter
106+
const genre = this.getQueryParam("genre");
107+
const searchOptions = genre ? { genre } : {};
108+
return await this.table.search(searchOptions);
109+
}
110+
}
111+
```
112+
113+
The `get()` method handles HTTP GET requests to our Book endpoint. It:
114+
- Logs that a request was received (helpful for debugging)
115+
- Checks if an ID was provided in the URL path
116+
- If an ID exists, returns a single book by that ID
117+
- If no ID exists, checks for a `genre` query parameter
118+
- Returns all books, filtered by genre if specified
119+
120+
### POST Method
121+
```js
122+
async post(data) {
123+
console.log("POST request received");
124+
125+
// Parse string data if needed
126+
if (typeof data === "string") {
127+
try {
128+
data = JSON.parse(data);
129+
} catch (err) {
130+
return { error: "Invalid JSON" };
131+
}
132+
}
133+
134+
// Validate required fields
135+
if (!data.title || !data.author) {
136+
return { error: "Title and author are required" };
137+
}
138+
139+
// Prevent primary key overriding
140+
if (data.id) delete data.id;
141+
142+
try {
143+
const result = await this.table.post(data);
144+
return result;
145+
} catch (error) {
146+
return { error: "Error creating book", details: error.message };
147+
}
148+
}
149+
```
150+
151+
The `post()` method handles HTTP POST requests to create new books. It:
152+
- Handles both string and object data formats
153+
- Validates that required fields (`title` and `author`) are present
154+
- Removes any provided `id` field to prevent primary key conflicts
155+
- Creates the book record in the database
156+
- Returns the result or an error message if something goes wrong
157+
158+
## Run and Test
159+
1. Start your application:
160+
```bash
161+
harperdb dev .
162+
```
163+
2. Create a book:
164+
```bash\
165+
curl -X POST -H "Content-Type: application/json" \ -d '{"title": "The Great Gatsby", "author": "F. Scott Fitzgerald", "publishedYear": 1925, "genre": "Fiction"}' \ http://localhost:9926/Books
166+
```
167+
3. Retrieve a book by ID:
168+
```bash
169+
curl http://localhost:9926/Book/BOOK_ID_HERE
170+
```
171+
4. Get all books in a genre:
172+
```bash
173+
curl http://localhost:9926/Book?genre=Fiction
174+
```
175+
176+
This simple Book API demonstrates Harper's key features:
177+
- Schema-based table definitions with GraphQL
178+
- Custom resource extensions for business logic
179+
- Automatic REST endpoint generation
180+
- Built-in data validation and error handling
181+
182+
You can build on this foundation by adding more fields, implementing additional methods, or creating relationships to other tables.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Harper Concepts
2+
3+
As you begin your journey with Harper, there are a few concepts and definitions that you should understand.
4+
5+
## Components
6+
Harper components are a core Harper concept defined as flexible JavaScript based extensions of the highly extensible core Harper platform. They are executed by Harper directly and have complete access to the Harper [Global APIs](https://docs.harperdb.io/docs/technical-details/reference/globals) (such as Resource, databases, and tables).
7+
8+
A key aspect to components are their extensibility; components can be built on other components. For example, a [Harper Application](https://docs.harperdb.io/docs/developers/applications) is a component that uses many other components. The [application template](https://github.com/HarperDB/application-template) demonstrates many of Harper's built-in components such as [rest](https://docs.harperdb.io/docs/developers/components/built-in#rest) (for automatic REST endpoint generation), graphqlSchema (for table schema definitions), and many more.
9+
10+
## Applications
11+
Applications are a subset of components that cannot be used directly and must depend on other extensions. Examples include defining schemas (using [graphqlSchema](https://docs.harperdb.io/docs/developers/components/built-in#graphqlschema) built-in extension), defining custom resources (using jsResource built-in extension), hosting static files (using static built-in extension), enabling REST querying of resources (using rest built-in extension), and running Next.js, Astro, or Apollo applications through their respective extensions.
12+
13+
## Extensions
14+
A Harper Extension is an extensible component that is intended to be used by other components. The built-in components [graphqlSchema](https://docs.harperdb.io/docs/developers/components/built-in#graphqlschema) and [jsResource](https://docs.harperdb.io/docs/developers/components/built-in#jsresource) are both examples of extensions.
15+
16+
For now, there are two key types of Harper Extensions: Resource Extension and Protocol Extensions. The key difference is that a Protocol Extensions can return a Resource Extension.
17+
18+
### Resource Extension
19+
A resource extension is for processing file and directory entries. For example, the built-in jsResource extension handles executing JavaScript files, and the built-in graphql extension handles processing graphql schema files defining Harper resources.
20+
21+
### Protocol Extension
22+
A Protocol Extension is a more advanced form of a Resource Extension and is mainly used for implementing higher level protocols. For example, the [Harper Next.js Extension](https://github.com/HarperDB/nextjs) handles building and running a Next.js project by hooking the Next.js server into Harper's underlying HTTP and WS middleware system. A Protocol Extension is particularly useful for adding custom networking handlers (see the [server](https://docs.harperdb.io/docs/technical-details/reference/globals#server) global API documentation for more information).
23+
24+
## Resources
25+
Resources in Harper encompass databases, tables, and schemas that store and structure data within the system. The concept is central to Harper's data management capabilities, with custom resources being enabled by the built-in jsResource extension. Resources represent the data layer of the Harper ecosystem and provide the foundation for data operations across applications built with the platform.
26+
27+
## Networking
28+
Networking in Harper handles different communication protocols including HTTP, WebSocket, and MQTT, as well as event-driven systems. These networking capabilities enable Harper applications to communicate with other services, receive requests, send responses, and participate in real-time data exchange. The networking layer is fundamental to Harper's functionality as a versatile application platform.
29+
30+
## Authentication
31+
Authentication in Harper provides security mechanisms to verify user identities before granting access to system resources and functionality. This concept is essential for securing Harper deployments and ensuring that only authorized users can access sensitive data or perform privileged operations within applications built on the Harper platform.
32+
33+
## Roles
34+
Roles in Harper define permissions and access levels for different users within the system. They work in conjunction with authentication to create a comprehensive security model that controls what authenticated users can do once they access the system. Roles help implement principle of least privilege and segregation of duties within Harper applications.
35+
36+
__
37+
38+
As you go through Harper, you will pick up more knowledge of other advanced areas along the way, but with these concepts, you're now ready to create your first application.

0 commit comments

Comments
 (0)