How to Build a Basic CRUD App with Riot.js: A Step-by-Step Guide
In this guide, you'll learn to create a CRUD (create, read, update, and delete) application using Riot.js.
We’ll walk through setting up a Back4app project—named Basic-CRUD-App-RiotJS—to serve as your backend, and then integrate it with a Riot.js frontend.
This tutorial covers everything from designing your database schema and managing data with the Back4app Admin App to integrating your frontend using either the SDK (if applicable) or REST/GraphQL API calls.
By the end, you'll have a fully operational, production-ready web application featuring user authentication and secure data handling.
- Master CRUD operations using a scalable backend system.
- Gain insights on integrating a Riot.js frontend with Back4app.
- Utilize the intuitive Back4app Admin App for effortless data management.
- Learn deployment strategies, including Docker containerization.
Before you start, make sure you have:
- A development setup for Riot.js. You can use the Riot CLI or include Riot via a script tag. Ensure Node.js (v14 or later) is installed.
- Basic knowledge of JavaScript, Riot.js, and REST APIs. If needed, consult the Riot.js documentation for additional insights.
- Sign in to your Back4app account.
- Click “New App” on your dashboard.
- Name your project: Basic-CRUD-App-RiotJS and follow the setup instructions.

Your project will now appear on your Back4app dashboard, serving as the backbone for your application's data.
For our CRUD application, you will define multiple collections. Below are sample collections and fields to help you structure your database for efficient CRUD operations.
This collection holds details about each item.
Field | Type | Description |
---|---|---|
_id | ObjectId | Auto-generated unique identifier. |
title | String | Item title. |
description | String | Brief item description. |
created_at | Date | Timestamp when the item was added. |
updated_at | Date | Timestamp when the item was modified. |
This collection contains user details and authentication info.
Field | Type | Description |
---|---|---|
_id | ObjectId | Auto-generated unique identifier. |
username | String | Unique username. |
String | Unique email address. | |
password_hash | String | Encrypted password. |
created_at | Date | Account creation timestamp. |
updated_at | Date | Last account update timestamp. |
You can configure these collections manually on the Back4app dashboard by creating new classes and defining columns.

You can add fields by selecting a data type, assigning a name, setting defaults, and marking if the field is mandatory.

The Back4app AI Agent, accessible from your dashboard, can automatically generate your schema by processing a detailed prompt describing your required collections and fields.
- Open the AI Agent: Find it in your project settings or menu.
- Input Your Data Model: Paste a prompt outlining your collections and their fields.
- Review and Confirm: Validate the generated schema and apply it to your project.
This tool expedites the process and ensures a consistent schema setup.
The Back4app Admin App offers a no-code, drag-and-drop interface for effortless backend management, letting you execute CRUD operations quickly.
- Open the “More” menu in your Back4app dashboard.
- Select “Admin App” and click “Enable Admin App.”
- Set up your admin account by creating the initial admin user, which also establishes default roles.

Once enabled, log in to the Admin App to manage your backend data.

Within this interface, you can:
- Add Records: Use the “Add Record” button within a collection (e.g., Items) to create new entries.
- Edit Records: Click on any record to view and modify its details.
- Remove Records: Delete any record that is no longer necessary.
This tool streamlines your workflow by offering a straightforward interface for managing data.
Now that your backend is set up, it’s time to connect your Riot.js frontend to Back4app.
Install the Parse SDK:
- Initialize Parse in Your Riot.js Project: Create a file (e.g., src/parseConfig.js):
- Use Parse in a Riot Tag: Create a Riot tag (e.g., items.riot) to fetch and display items:
If the Parse SDK is unsuitable, execute CRUD operations via API calls. For instance, to retrieve items using REST:
Integrate these API calls within your Riot.js tags as required.
Secure your data by setting ACLs on your objects. For instance, to create a private item:
Within your Back4app dashboard, configure CLPs for each collection to ensure that only authenticated or authorized users access sensitive data.
Riot.js applications can handle user registration and login using Back4app’s built-in Parse User class. Below is an example Riot tag for user signup:
A similar strategy can be applied for login and session management. Additional features like social login, email verification, or password recovery can be set up in your Back4app dashboard.
Back4app’s Web Deployment feature lets you host your Riot.js app by linking your GitHub repository. Follow these steps to deploy your production build:
- Open your project directory in a terminal.
Run your build command:
- Confirm the build: Verify that the build folder includes an index.html and required asset directories.
Your repository should contain the complete Riot.js frontend source. A typical structure could be:
Initialize a Git repo (if not done):
Add your files:
Commit your changes:
Create a GitHub repository (e.g., Basic-CRUD-App-RiotJS-Frontend) and push your code:
- Open Web Deployment: Sign in to your Back4app dashboard, select your project (Basic-CRUD-App-RiotJS), and click on Web Deployment.
- Connect to GitHub: Follow the prompts to link your GitHub account and repository.
- Choose Your Repo and Branch: Select your repository (e.g., Basic-CRUD-App-RiotJS-Frontend) and the appropriate branch (like main).
- Build Command: If your repository lacks a pre-built build folder, specify the build command (e.g., npm run build). Back4app will execute it.
- Output Directory: Set this to build to indicate where your static files reside.
- Environment Variables: Include any necessary variables (such as API keys) in your configuration.
If you prefer containerized deployment, add a Dockerfile to your project:
Select the Docker option in your Web Deployment settings if you choose this route.
- Deploy: Click the Deploy button after configuring your settings.
- Monitor the Process: Back4app will fetch your code, execute the build command, and deploy your app in a container.
- Get Your URL: Once deployed, Back4app provides a URL where your Riot.js application is hosted.
- Visit the URL: Open the provided URL in your browser.
- Test the App: Confirm that all routes and assets (CSS, JavaScript, images) are functioning correctly.
- Troubleshoot: Use browser developer tools and Back4app logs if any issues arise.
Congratulations! You've built a fully functional CRUD app using Riot.js and Back4app.
You set up a project called Basic-CRUD-App-RiotJS, designed a robust database schema for Items and Users, and managed your data with the Admin App.
You integrated your Riot.js frontend and implemented security measures like ACLs.
Next Steps:
- Enhance the Frontend: Add features like detailed views, search capabilities, and real-time updates.
- Expand Functionality: Explore advanced backend operations such as Cloud Functions or integrate third-party APIs.
- Deepen Your Learning: Visit the Back4app documentation and other resources to optimize and expand your application.
With these steps, you now have the expertise to build scalable CRUD applications using Riot.js and Back4app. Happy coding!
