Skip to content

Commit 3bdb631

Browse files
DOCS-3472: Add documentation for Viam Apps (#4335)
1 parent 2b4e70c commit 3bdb631

File tree

11 files changed

+356
-7
lines changed

11 files changed

+356
-7
lines changed

assets/scss/_styles_project.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3364,6 +3364,10 @@ div.tablestep > table td, div.tablestep table td {
33643364
margin-left: 1.0rem;
33653365
}
33663366

3367+
.td-content > ol li {
3368+
margin-bottom: 0.5rem;
3369+
}
3370+
33673371
.td-content > ul {
33683372
padding-left: 1rem;
33693373
}
-61.8 KB
Loading

docs/dev/reference/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ date: "2024-09-18"
4242
# updated: "" # When the content was last entirely checked
4343
---
4444

45+
{{% changelog color="added" title="Build custom Viam applications" date="2025-07-17" %}}
46+
47+
You can now create and use Viam applications to build custom applications that interact with your Viam-powered machines through the Viam SDKs.
48+
For more information, see [Viam applications](/operate/control/viam-applications/).
49+
50+
{{% /changelog %}}
51+
4552
{{% changelog color="added" title="Start modules with a TCP connection" date="2025-07-14" %}}
4653

4754
You can now configure to start modules with a TCP connection. See [Module Configuration](/operate/get-started/other-hardware/module-configuration/) for more information.
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
---
2+
title: "Create a Viam application"
3+
linkTitle: "Create a Viam application"
4+
weight: 5
5+
layout: "docs"
6+
type: "docs"
7+
description: "Create and deploy a custom web interface for your machines without managing hosting and authentication."
8+
---
9+
10+
Create and deploy a custom web interface for your machines without managing hosting and authentication.
11+
Once deployed, your application is accessible from a dedicated URL (`appname_publicnamespace.viamapplications.com`), and hosting and authentication is handled for you.
12+
13+
Users log into your application and select a machine they have access to.
14+
The application then renders your custom interface for interacting with the user's machine.
15+
16+
{{<gif webm_src="/spa.webm" mp4_src="/spa.mp4" alt="Sample web application" max-width="500px">}}
17+
18+
## Requirements
19+
20+
{{< expand "Install the Viam CLI and authenticate." >}}
21+
Install the Viam CLI using the option below that matches your system architecture:
22+
23+
{{< readfile "/static/include/how-to/install-cli.md" >}}
24+
25+
Then authenticate your CLI session with Viam using one of the following options:
26+
27+
{{< readfile "/static/include/how-to/auth-cli.md" >}}
28+
29+
{{< /expand >}}
30+
31+
## Build a custom web interface
32+
33+
You can build a custom web interface to access your machines using your preferred framework like React, Vue, Angular, or others.
34+
35+
### Access machines from your application
36+
37+
When logging into a Viam application and selecting a machine to use it with, the machine's API key is stored as a cookie.
38+
You can access the data from your browser's cookies as follows:
39+
40+
```ts {class="line-numbers linkable-line-numbers" data-line=""}
41+
import Cookies from "js-cookie";
42+
43+
let apiKeyId = "";
44+
let apiKeySecret = "";
45+
let host = "";
46+
let machineId = "";
47+
48+
// Extract the machine identifier from the URL
49+
const machineCookieKey = window.location.pathname.split("/")[2];
50+
({
51+
apiKey: { id: apiKeyId, key: apiKeySecret },
52+
machineId: machineId,
53+
hostname: host,
54+
} = JSON.parse(Cookies.get(machineCookieKey)!));
55+
```
56+
57+
### Local development
58+
59+
For developing your application on localhost:
60+
61+
1. Run your web server.
62+
1. Run the following command specifying the address where your app is running on localhost and a machine to test on.
63+
The command will proxy your local app and open a browser window and navigate to `http://localhost:8000/machine/<machineHostname>` for the machine provided with --machine-id.
64+
65+
{{< tabs >}}
66+
{{% tab name="Template" %}}
67+
68+
```sh {class="command-line" data-prompt="$" data-output="2-10"}
69+
viam login
70+
viam module local-app-testing --app-url http://localhost:<PORT> --machine-id <MACHINE-ID>
71+
```
72+
73+
{{% /tab %}}
74+
{{% tab name="Example" %}}
75+
76+
```sh {class="command-line" data-prompt="$" data-output="2-10"}
77+
viam login
78+
viam module local-app-testing --app-url http://localhost:3000 --machine-id a1b2c3d4-e5f6-7890-abcd-ef1234567890
79+
```
80+
81+
{{% /tab %}}
82+
{{< /tabs >}}
83+
84+
### Configure routing
85+
86+
When using your deployed application, static files will be accessible at `https://your-app-name_your-public-namespace.viamapplications.com/machine/<machineHostname>/`.
87+
If your HTML file loads other files, use relative paths to ensure your files are accessible.
88+
89+
## Deploy your web interface as a Viam application
90+
91+
To deploy your application with Viam you must package it as a module and upload it using the Viam CLI.
92+
93+
{{< table >}}
94+
{{% tablestep number=1 %}}
95+
96+
**Create a <FILE>meta.json</FILE>** file for your module using this template:
97+
98+
{{< tabs >}}
99+
{{% tab name="Template" %}}
100+
101+
```json
102+
{
103+
"module_id": "your-namespace:your-module",
104+
"visibility": "public",
105+
"url": "https://github.com/your-org/your-repo",
106+
"description": "Your module description",
107+
"applications": [
108+
{
109+
"name": "your-app-name",
110+
"type": "single_machine",
111+
"entrypoint": "dist/index.html"
112+
}
113+
]
114+
}
115+
```
116+
117+
{{% /tab %}}
118+
{{% tab name="Example" %}}
119+
120+
```json
121+
{
122+
"module_id": "acme:dashboard",
123+
"visibility": "public",
124+
"url": "https://github.com/acme/dashboard",
125+
"description": "An example dashboard for a fictitious company called Acme.",
126+
"applications": [
127+
{
128+
"name": "dashboard",
129+
"type": "single_machine",
130+
"entrypoint": "dist/index.html"
131+
}
132+
]
133+
}
134+
```
135+
136+
{{% /tab %}}
137+
{{< /tabs >}}
138+
139+
This file specifies the contents of the module.
140+
It is required for your module.
141+
142+
{{% expand "Click to view more information on attributes." %}}
143+
144+
<!-- prettier-ignore -->
145+
| Name | Type | Inclusion | Description |
146+
|------|------|-----------|-------------|
147+
| `module_id` | string | **Required** | The module ID, which includes the organization name and the module name. `module_id` uniquely identifies your module. |
148+
| `visibility` | string | **Required** | Must be `"public"`. |
149+
| `description` | string | **Required** | A description of your module and what it provides. |
150+
| `url` | string | Optional | The URL of the GitHub repository containing the source code of the module. |
151+
| `applications` | array | Optional | Objects that provide information about the [applications](/operate/control/viam-applications/) associated with the module. |
152+
| `models` | array | Optional | Empty unless you are shipping the app alongside models. For information on how to add models, see [Integrate other hardware](/operate/get-started/other-hardware/). |
153+
154+
{{% /expand%}}
155+
156+
The `applications` field is an array of application objects with the following properties:
157+
158+
<!-- prettier-ignore -->
159+
| Property | Type | Description |
160+
| ------------ | ------ | ----------- |
161+
| `name` | string | The name of your application, which will be a part of the application's URL (`name_publicnamespace.viamapplications.com`). For more information on valid names see [Valid application identifiers](/operate/reference/naming-modules/#valid-application-identifiers). |
162+
| `type` | string | The type of application (currently only `"single_machine"` is supported). |
163+
| `entrypoint` | string | The path to the HTML entry point for your application. The `entrypoint` field specifies the path to your application's entry point. For example: <ul><li><code>"dist/index.html"</code>: Static content rooted at the `dist` directory</li><li><code>"dist/foo.html"</code>: Static content rooted at the `dist` directory, with `foo.html` as the entry point</li><li><code>"dist/"</code>: Static content rooted at the `dist` directory (assumes `dist/index.html` exists)</li><li><code>"dist/bar/foo.html"</code>: Static content rooted at `dist/bar` with `foo.html` as the entry point</li></ul> |
164+
165+
{{% /tablestep %}}
166+
{{% tablestep number=2 %}}
167+
**Register your module** with Viam:
168+
169+
{{< tabs >}}
170+
{{% tab name="Template" %}}
171+
172+
```sh {class="command-line" data-prompt="$" data-output="3-10"}
173+
viam module create --name="app-name" --public-namespace="namespace"
174+
```
175+
176+
{{% /tab %}}
177+
{{% tab name="Example" %}}
178+
179+
```sh {class="command-line" data-prompt="$" data-output="3-10"}
180+
viam module create --name="air-quality" --public-namespace="naomi"
181+
```
182+
183+
{{% /tab %}}
184+
{{< /tabs >}}
185+
186+
{{% /tablestep %}}
187+
{{% tablestep number=3 %}}
188+
189+
**Package your static files and your <FILE>meta.json</FILE> file and upload them** to the Viam Registry:
190+
191+
```sh {class="command-line" data-prompt="$" data-output="3-10"}
192+
tar -czvf module.tar.gz <static-website-files> meta.json
193+
viam module upload --upload=module.tar.gz --platform=any --version=0.0.1
194+
```
195+
196+
For subsequent updates run these commands again with an updated version number.
197+
198+
{{% /tablestep %}}
199+
{{< /table >}}
200+
201+
## Access your application
202+
203+
After uploading your module with the application configuration, your application will be available at:
204+
205+
```txt
206+
https://your-app-name_your-public-namespace.viamapplications.com
207+
```
208+
209+
Users will be prompted to authenticate with their Viam credentials before accessing your application:
210+
211+
1. User navigates to `your-app-name_your-public-namespace.viamapplications.com`.
212+
1. User authenticates with Viam credentials.
213+
1. User selects an organization, location, and machine.
214+
1. User is redirected to `your-app-name_your-public-namespace.viamapplications.com/machine/<machineHostname>`.
215+
1. Your application is rendered with access to the selected machine.
216+
The credentials for that one machine are provided in the cookies.
217+
218+
## Example
219+
220+
<!-- For a TypeScript example see [Monitor Air Quality with a Fleet of Sensors](/tutorials/control/air-quality-fleet/). -->
221+
222+
For a React application that shows camera feeds for a machine, see [Viam Camera Viewer](https://github.com/viam-labs/viam-camera-viewer).
223+
224+
## Limitations
225+
226+
- Applications currently only support single-machine applications.
227+
- All modules with applications must have public visibility.
228+
- The page will always render the latest version.
229+
- Browsers with cookies disabled are not supported.
230+
- Viam applications serve static files.
231+
If you are building an application with server-side rendering or need other back-end capabilities, Viam applications is not the right choice.
232+
233+
## Security considerations
234+
235+
- Customer applications are stored publicly on the internet, so avoid uploading sensitive information in your application code or assets.
236+
- API keys and secrets are stored in the browser's cookies.
237+
- Users authenticate with FusionAuth.
238+
239+
## FAQ
240+
241+
### Can I use a custom domain?
242+
243+
Viam does not currently support using custom domains (for example: `app.mycustomdomain.com/machine/<machineHostname>`) to serve your Viam application.
244+
You can, however, redirect from your domain to your Viam application (`app.mycustomdomain.com` -> `your-app-name_your-public-namespace.viamapplications.com`).
245+
You can configure a redirect (HTTP 301) on your web server or hosting provider from `app.mycustomdomain.com/*` to `your-app-name_your-public-namespace.viamapplications.com/*`.

docs/operate/control/web-app.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ The TypeScript SDK includes:
1313
- Implementation of the standard component and service APIs to control your hardware and software
1414
- Authentication tools so users can log in securely
1515

16+
{{< alert title="Tip: Host your application on Viam" color="tip" >}}
17+
You can host most apps by [deploying them as Viam applications](/operate/control/viam-applications/).
18+
If your application requires server-side rendering or other back-end functionality, self-host your application instead.
19+
{{< /alert >}}
20+
1621
## Install the TypeScript SDK
1722

1823
Run the following command in your terminal to install the Viam TypeScript SDK:

docs/operate/get-started/other-hardware/module-configuration.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,64 @@ For any version type other than **Patch (X.Y.Z)**, the module will upgrade as so
242242
If, for example, the module provides a motor component, and the motor is running, it will stop while the module upgrades.
243243
{{% /alert %}}
244244

245+
### Module meta.json configuration
246+
247+
When creating a module, you'll need to create a `meta.json` file that defines the module's properties. This file includes information about the module's ID, visibility, models, and other features.
248+
249+
Here's an example of a `meta.json` file:
250+
251+
```json
252+
{
253+
"module_id": "your-namespace:your-module",
254+
"visibility": "public",
255+
"url": "https://github.com/your-org/your-repo",
256+
"description": "Your module description",
257+
"models": [
258+
{
259+
"api": "rdk:component:base",
260+
"model": "your-namespace:your-module:your-model"
261+
}
262+
],
263+
"entrypoint": "run.sh",
264+
"first_run": "setup.sh"
265+
}
266+
```
267+
268+
For modules that include [Viam applications](/operate/control/viam-applications/), you can add the `applications` field:
269+
270+
```json
271+
{
272+
"module_id": "your-namespace:your-module",
273+
"visibility": "public",
274+
"url": "https://github.com/your-org/your-repo",
275+
"description": "Your module description",
276+
"models": [
277+
{
278+
"api": "rdk:component:base",
279+
"model": "your-namespace:your-module:your-model"
280+
}
281+
],
282+
"entrypoint": "run.sh",
283+
"applications": [
284+
{
285+
"name": "your-app-name",
286+
"type": "web",
287+
"entrypoint": "dist/index.html"
288+
}
289+
]
290+
}
291+
```
292+
293+
The `applications` field is an array of application objects with the following properties:
294+
295+
| Property | Type | Description |
296+
| ------------ | ------ | ------------------------------------------------------------------------------------------------- |
297+
| `name` | string | The name of your application, which will be used in the URL (`name.publicnamespace.viamapps.com`) |
298+
| `type` | string | The type of application (currently only `"web"` is supported) |
299+
| `entrypoint` | string | The path to the HTML entry point for your application |
300+
301+
For more information about Viam applications, see the [Viam applications documentation](/operate/control/viam-applications/).
302+
245303
### Environment variables
246304

247305
Each module has access to the following default environment variables.

docs/operate/reference/naming-modules.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description: "Add support for a new component or service model by writing a modu
99
languages: ["c++"]
1010
viamresources: []
1111
platformarea: ["registry"]
12-
toc_hide: true
12+
toc_hide: false
1313
---
1414

1515
Each modular resource has two associated triplets: an API namespace triplet to indicate which [API](/dev/reference/apis/) it implements, and a model namespace triplet to uniquely identify the modular resource {{< glossary_tooltip term_id="model" text="model" >}}.
@@ -95,6 +95,30 @@ More requirements:
9595

9696
Determine the model name you want to use based on these requirements, then proceed to the next section.
9797

98+
## Valid application identifiers
99+
100+
If your module includes a [Viam app](/operate/control/viam-applications/), you need to define the application name in your module's `meta.json` file.
101+
Application names have the following requirements:
102+
103+
- Application names must be all-lowercase.
104+
- Application names may only use alphanumeric (`a-z` and `0-9`) and hyphen (`-`) characters.
105+
- Application names may not start or end with a hyphen.
106+
- Application names must be unique within your organization's namespace.
107+
108+
The URL for accessing your Viam app will contain your application name:
109+
110+
```txt
111+
https://app-name_your-public-namespace.viamapps.com
112+
```
113+
114+
For example, if your organization namespace is `acme` and your application name is `dashboard`, your application will be accessible at:
115+
116+
```txt
117+
https://dashboard_acme.viamapps.com
118+
```
119+
120+
For more information about Viam apps, see the [Viam apps documentation](/operate/control/viam-applications/).
121+
98122
## Create a namespace for your organization
99123

100124
When uploading modules to the Viam Registry, you must set a unique namespace for your organization to associate your module with.

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
[plugins.inputs]
5858

5959
# change this key to a new one any time you need to restart from scratch
60-
cacheKey = ["July102025"]
60+
cacheKey = ["July172025"]
6161
# either "warn" or "error"
6262
failBuildOnError = true
6363

0 commit comments

Comments
 (0)