Quickstarters

How to Build a CRUD App with ReactJS?

42min

Introduction

In this tutorial, you'll build a comprehensive CRUD (create, read, update, and delete) application using ReactJS.

This guide is designed to perform the basic operations of a software application by demonstrating how to build CRUD apps that effectively manage and update data.

You'll start by creating and configuring a Back4app project named Basic-CRUD-App-ReactJS, which acts as a robust backend system for your web application.

Next, you'll design a scalable database schema by defining detailed collections and fields—either manually or with the help of the Back4app AI Agent.

Then, you'll leverage the Back4app Admin App—a user-friendly management tool with a drag and drop interface—to easily data manage your collections.

This admin interface improves user experience and simplifies the user interface, enabling users to quickly perform CRUD operations.

Finally, you'll deploy your ReactJS frontend and integrate it with Back4app using REST/GraphQL (or the Parse SDK, where available), all while securing your backend with advanced access controls.

By the end of this guide, you'll have built a production-ready web application that not only supports basic CRUD operations but also includes user authentication and robust data update capabilities.

Key Takeaways

  • Learn how to build CRUD applications that efficiently manage data using a reliable database management system.
  • Gain practical insights into designing a scalable backend and integrating it with a ReactJS frontend to enhance user experience.
  • Discover how to use a drag and drop management tool (the Back4app Admin App) to simplify create, read, update, and delete operations.
  • Understand deployment techniques, including Docker containerization, to quickly launch your web application.


Prerequisites

Before you begin, ensure you have the following:

  • A Back4app account and a new project set up. If you need help, refer to Getting Started with Back4app.
  • A ReactJS development environment. Use Create React App or a similar tool. Make sure Node.js (version 14 or above) is installed.
  • Basic understanding of JavaScript, ReactJS, and REST APIs. Review the ReactJS documentation if necessary.


Step 1 – Project Setup

Creating a New Back4app Project

  1. Log in to your Back4app account.
  2. Click the “New App” button in your dashboard.
  3. Enter the project name: Basic-CRUD-App-ReactJS and follow the prompts to create your project.
Create New Project
Create New Project


Once created, your new project will appear on your Back4app dashboard, providing a solid foundation for your backend configuration and project management.



Step 2 – Database Schema Design

Designing Your Data Model

For the basic CRUD app, you will create several collections.

Below are some examples of the collections you will need, outlining the necessary fields and data types to help you set up your database schema effectively.

These collections are designed to perform the fundamental CRUD operations that enable users to create, read, update, and delete data.

1. Items Collection

This collection stores information about each item.

Field

Data Type

Description

_id

ObjectId

Automatically generated primary key.

title

String

The title of the item.

description

String

A brief description of the item.

created_at

Date

Timestamp when the item was created.

updated_at

Date

Timestamp when the item was last updated.

2. Users Collection

This collection stores user information and authentication details.

Field

Data Type

Description

_id

ObjectId

Automatically generated primary key.

username

String

Unique username for the user.

email

String

Unique email address.

password_hash

String

Hashed password for authentication.

created_at

Date

Timestamp when the user account was created.

updated_at

Date

Timestamp when the user account was updated.

You can set up these collections manually in the Back4app dashboard by creating a new class for each collection and adding columns to define the fields.

Create New Class
Create New Class


You can easily create fields for your database by selecting a data type, naming the field, setting a default value, and defining whether it's required.

Create Column
Create Column



Using the Back4app AI Agent for Schema Generation

The Back4app AI Agent is a powerful tool available directly from your Back4app dashboard.

It allows you to automatically generate your database schema based on a prompt that describes your desired collections and fields.

This functionality is a significant time-saver for project management and helps ensure that your database management system is set up to perform the basic operations required by your web application.

How to Use the AI Agent:

  1. Open the AI Agent: Log in to your Back4app dashboard and locate the AI Agent in the menu or within your project settings.
  2. Describe Your Data Model: In the AI Agent interface, paste a detailed prompt that outlines the collections and fields you need.
  3. Review and Apply: Once submitted, the AI Agent will generate the collections and field definitions. Review these suggestions and apply them to your project.

Example Prompt

Text


Using the AI Agent in this way saves time and ensures that your schema is consistent and optimized for your application's needs.



Step 3 – Enabling the Admin App & CRUD Operations

Overview of the Admin App

The Back4app Admin App is a powerful, no-code interface that allows you to manage your backend data.

This management tool provides a drag and drop user interface that enables users to easily perform CRUD operations such as create, read, update, and delete records.

Enabling the Admin App

  1. Navigate to the “More” menu in your Back4app dashboard.
  2. Click on “Admin App” and then on “Enable Admin App.”
  3. Configure your admin credentials by creating your first admin user. This process also sets up roles (e.g., B4aAdminUser) and system collections.
Enable Admin App
Enable Admin App


After enabling, log in to the Admin App to manage your data.

Admin App Dashboard
Admin App Dashboard


Using the Admin App for CRUD Operations

Within the Admin App you can:

  • Create Records: Click the “Add Record” button within a collection (e.g., Items) to create new entries.
  • Read/Update Records: Select any record to view its details or edit fields, ensuring smooth data update.
  • Delete Records: Use the delete option to remove records that are no longer needed. This easy-to-use management tool improves the overall user experience by providing a simple drag and drop interface for CRUD functions.


Step 4 – Integrating ReactJS with Back4app

Now that your backend is set up and managed via the Admin App, it’s time to connect your ReactJS frontend to Back4app.

Option A: Using the Parse SDK

  1. Install the Parse SDK:

    Bash
    
  2. Initialize Parse in Your React App: Create a file (e.g., src/parseConfig.js):

    JS
    
  3. Use Parse in a React Component: For example, create a component to fetch and display items:

    JS
    

Option B: Using REST or GraphQL

If your environment does not support the Parse SDK, you can perform CRUD operations using REST or GraphQL. For example, to fetch items using REST:

JS


Integrate these API calls into your React components as needed.



Step 5 – Securing Your Backend

Access Control Lists (ACLs)

Secure your data by assigning ACLs to objects. For example, to create a private item:

JS


Class-Level Permissions (CLPs)

In the Back4app dashboard, configure CLPs for each collection to set default access rules. This ensures that only authenticated or authorized users can access sensitive data.



Step 6 – User Authentication

Setting Up User Accounts

Back4app leverages Parse’s User class for authentication. In your React app, handle user registration and login as follows:

JS


A similar approach can be used for login and session management. Additional features such as social logins, email verification, and password resets can be configured in the Back4app dashboard.



Step 7 – Deploying Your ReactJS Frontend with Web Deployment

Back4app’s Web Deployment feature allows you to host your ReactJS frontend seamlessly by deploying your code from a GitHub repository.

In this section, you’ll learn how to prepare your production build, commit your source code to GitHub, integrate your repository with Web Deployment, and deploy your site.

7.1 Prepare Your Production Build

  1. Open your project folder in a terminal.
  2. Run the build command:

    Bash
    

    This command creates a build folder containing all the optimized static files (including index.html, JavaScript, CSS, and images).

  3. Verify the Build: Ensure that the build folder contains an index.html file along with necessary asset subdirectories.


7.2 Organize and Upload Your Source Code

Your repository should include the full source code for your ReactJS frontend. A typical file structure might look like this:

Text


Sample Source Code Files

src/parseConfig.js

JS


src/App.js

JS

  1. Add your source files:

    Bash
    
  2. Commit your changes:

    Bash
    
  3. Create a GitHub repository: For example, create a repository named Basic-CRUD-App-ReactJS-Frontend on GitHub.
  4. Push your code to GitHub:

    Bash
    


7.3 Integrate Your GitHub Repository with Web Deployment

  1. Access Web Deployment: Log in to your Back4app dashboard, navigate to your project (Basic-CRUD-App-ReactJS), and click on the Web Deployment feature.
  2. Connect to GitHub: If you haven’t already, integrate your GitHub account by following the on-screen prompts. This connection allows Back4app to access your repository.
  3. Select Your Repository and Branch: Choose the repository you created (e.g., Basic-CRUD-App-ReactJS-Frontend) and select the branch (e.g., main) that contains your ReactJS code.


7.4 Configure Your Deployment

Provide additional configuration details:

  • Build Command: If your repository does not include a pre-built build folder, specify the build command (e.g., npm run build). Back4app will run this command during deployment.
  • Output Directory: Set the output directory to build so that Back4app knows which folder contains your static site files.
  • Environment Variables: If your application depends on any environment variables (e.g., API keys), add them in the configuration settings.


7.5 Dockerize Your ReactJS Application Project

If you prefer using Docker for deployment, you can containerize your ReactJS application. Include a Dockerfile in your repository with content similar to the following:

Dockerfile


Include this Dockerfile in your repository. Then, in your Web Deployment configuration, select the Docker deployment option to build and deploy your containerized application.



7.6 Deploy Your Application

  1. Click the Deploy Button: Once you have configured the deployment settings, click the Deploy button.
  2. Monitor the Build Process: Back4app will pull your code from GitHub, execute the build command (if configured), and deploy your app within a container.
  3. Obtain Your URL: After the deployment completes, Back4app will provide a URL where your ReactJS application is hosted.


7.7 Verify Your Deployment

  1. Visit the Provided URL: Open the URL in your web browser to view your deployed site.
  2. Test the Application: Verify that your application loads correctly, all routes work as expected, and all assets (CSS, JavaScript, images) are properly served.
  3. Troubleshoot if Needed: Use your browser’s developer tools to check for any errors. If issues arise, review the deployment logs in Back4app and verify your GitHub integration and build settings.


Step 8 – Conclusion and Next Steps

Congratulations! You have built a complete basic CRUD app using ReactJS and Back4app.

You configured a project named Basic-CRUD-App-ReactJS, designed detailed database collections for Items and Users, and managed your data via the powerful Admin App.

You also integrated your ReactJS frontend with your backend and secured your data with robust access controls.

Next Steps:

  • Enhance Your Frontend: Extend your ReactJS app with features such as detailed item views, search functionality, and real-time notifications.
  • Integrate Additional Features: Consider adding more advanced backend logic (e.g., Cloud Functions), third-party API integrations, or role-based access controls.
  • Explore Further Resources: Review the Back4app documentation and additional tutorials for deeper dives into performance optimization and custom integrations.

By following this tutorial, you now have the skills to create a robust, scalable CRUD backend for your ReactJS application using Back4app. Happy coding!