Building a User Dashboard with Redwood

Banner for a MediaJam post


There's a dashboard for just about every application you log in to these days. Most of them are built with modern frameworks like React or Angular and they have some kind of back-end to support them. Users depend on these dashboards to check their account info, make updates to their businesses, and handle a number of other actions.

In this tutorial, we'll be making a user dashboard for a management system with Redwood. It'll have a few actions that a user can take to add other users to the account with different roles. The dashboard will also let a user add new items to their inventory and the items will be attached to different locations.

Let's kick it off with a little background on Redwood.

What is Redwood

Redwood is a full-stack framework built with Prisma, React, and GraphQL. It comes with a lot of features with a few commands that we'll be using to make this app quickly. If you're interested in learning more about Redwood, make sure to check out their docs.

Set up the project

Now let's jump into getting our dashboard set up. We'll bootstrap this app by running the following command. Just a heads up, it might take a few minutes for it to finish, but it'll be worth the wait.

yarn create redwood-app ./redwood-dashboard

When the command has finished executing, you'll notice you have quite a few folders and files. The most important folders are the api directory and the web directory. The api directory holds all of the code for the back-end and database while the web directory holds everything for the front-end.

Before we start working on the app, you should run it to see how it works first. Use the following command to start both the front-end and back-end.

yarn rw dev

Here's what you should see in your browser.

base Redwood app

Defining the dashboard model

Since you've seen the app in action, let's start taking advantage of some Redwood commands to work on the back-end. We'll start by making a Prisma model for the dashboard. This is how our app will connect to a Postgres database. Inside of the api > db, open the schema.prisma file.

This is where we'll make the schema for the tables we want in our database using a few different kinds of relations. You'll see that Redwood already has a few configs set and an example of a user model.

We'll be changing the datasource db provider to postgresql which you can see in the code snippet below.

1datasource db {
2 provider = "postgresql"
3 url = env("DATABASE_URL")

Then we'll remove the TODO and update the example user model.

1model User {
2 id Int @id @default(autoincrement())
3 email String @unique
4 name String
5 role String

Our updated User model has a few columns for information we want to store about a user. The email field has a constraint that it always has to be a unique value. The same email address can't be in the database multiple times. Next, we'll add a new model for our Item and Location tables. These need to be created at the same time because they have a relationship with each other.

1model Item {
2 id Int @id @default(autoincrement())
3 sku String @unique
4 name String
5 location Location @relation(fields: [locationId], references: [id])
6 locationId Int
9model Location {
10 id Int @id @default(autoincrement())
11 name String
12 district Int
13 Item Item[]

Then we'll update the seed.js file so that there are a few values present before we start our app. This is common on product dashboards for populating dropdown options or initializing tags that users can add to different settings. We'll be adding a user, an item, and one location to seed our database. Just a heads up, I've deleted a lot of comments from this file.

1/* eslint-disable no-console */
2const { PrismaClient } = require('@prisma/client')
3const dotenv = require('dotenv')
6const db = new PrismaClient()
8async function main() {
9 console.warn('Please define your seed data.')
11 await db.user.create({
12 data: { name: 'Kaiya', email: '', role: 'inventory' },
13 })
15 await db.location.create({
16 data: { name: 'Compound North', district: 1 },
17 })
19 await db.item.create({
20 data: {
21 name: 'Morning Glory',
22 sku: 'hf8029ht8942ht8429pht8p942p',
23 locationId: 1,
24 },
25 })
29 .catch((e) => console.error(e))
30 .finally(async () => {
31 await db.$disconnect()
32 })

With the schema and seed data in place, we're almost ready to run our first migration. Before we do that, we need to be connected to the database. So in the .env file at the root of the project, update the DATABASE_URL to match your Postgres instance. It'll look similar to this.


If you don't have a local Postgres instance to work with, you can download it here pretty quickly.

Now we're going to run the migration with:

yarn rw prisma migrate dev

This will prompt you for a migration name, create the database and the tables, and add the seed data. If you look at your database through pgAdmin, you'll see something like this.

seeded database in pgAdmin

Now that you have your database ready to store and send the values we need, let's move on to our back-end and front-end.

Adding the back-end and front-end

Redwood has one particular command that does a lot of work for us. It will create the entire CRUD for a table from the front-end components and routes to the back-end GraphQL queries, types, and mutations. We're going to take advantage of that to make most of our dashboard. Let's start with the following command.

yarn rw g scaffold user

This will generate several pages and components and GraphQL files to handle all of the CRUD actions for the user's portion of the dashboard. Take a look in web > pages. You should see a new directory called User. This has all of the pages we need to handle everything about users.

Now take a look in web > components. There will be another User folder. This one contains the components we use to interact with the GraphQL server. Most of the data is fetched in these components and requests are sent from these components.

The web > layouts folder will also have a new directory containing a layout file for your User pages. This is how you can create styles for a specific set of pages.

In the Routes.js file, you'll see there is a new set of routes for users wrapped in the UserLayout. All of the pages generate also have their routes automatically added to this file inside of their parent layout.

There were also some new files generated in the api directory. If you look inside api > src > graphql, you'll find the GraphQL schema for all the CRUD operations you need and the types have been defined by the model in the schema.prisma file.

Then inside api > src > services, you'll find all of the GraphQL resolvers for the queries and mutations defined in the schema.

All of these pages, components, types, and resolvers were generated by that one Redwood command. Let's run the app with yarn rw dev so you can see all of this working. If you go to the users page in the browser, you should see something similar to this.

The home page will return a 404 right now because we haven't added a component for that route. We'll do that a bit later, but the /users page will still work.

users CRUD in browser

You can add a new user, update the current user, or delete the current user with the buttons on the page.

We're going to run that scaffold command two more times to generate the CRUD for the items and locations.

1yarn rw g scaffold location
2yarn rw g scaffold item

Now we have all of the actions we need for our user dashboard. There are a couple of things we need to do to give this dashboard a more realistic feel. We'll add a home page and a layout to help us navigate between parts of the dashboard.

Making the home page

Let's start by adding the styled-components package because we're going to use it to style a few things. First, go to the web directory in your terminal. That's where this package will need to be installed.

yarn add styled-components

Now let's run one of those magic Redwood commands to generate the home page and its routing.

yarn rw g page home /

This will create a new directory in web > src > pages for the HomePage component and it'll add a new route to Routes.js. You can re-run your app here to see the new home page. It'll look like this in the browser.

new home page

Now that we have a home page in place, let's make a layout that will apply to this and all the other pages we have so far. Of course, there's a Redwood command to handle that.

yarn rw g layout home

This will create a new folder in web > src > layouts for our home page. We're going to use a few styled components in the HomeLayout component to create a side navigation menu and give the dashboard a little definition. We'll also be using Redwood routing to add links to the other pages in the side navigation.

1import { Link, routes } from '@redwoodjs/router'
2import styled from 'styled-components'
4const HomeLayout = ({ children }) => {
5 return (
6 <FlexBox>
7 <SideNav>
8 <LinkContainer>
9 <Link to={routes.users()}>Users</Link>
10 </LinkContainer>
11 <LinkContainer>
12 <Link to={routes.locations()}>Locations</Link>
13 </LinkContainer>
14 <LinkContainer>
15 <Link to={routes.items()}>Items</Link>
16 </LinkContainer>
17 </SideNav>
18 <FullPage>{children}</FullPage>
19 </FlexBox>
20 )
23const FlexBox = styled.div`
24 display: flex;
27const FullPage = styled.div`
28 height: 100vh;
29 width: 100%;
32const LinkContainer = styled.div`
33 padding: 12px;
35 > * {
36 color: #000;
37 font-family: sans-serif;
38 font-size: 18px;
39 text-decoration: none;
40 }
42 > *:hover {
43 color: #5b5b5b;
44 }
47const SideNav = styled.nav`
48 border-right: 1px solid;
49 width: 250px;
52export default HomeLayout

Next, we need to apply this layout to all of the pages in our app. We'll do that in the Routes.js file. This means adding a <Set> component around all of the existing routes like below.

3 <Set wrap={HomeLayout}>
4 <Route path="/" page={HomePage} name="home" />
5 <Set wrap={ItemsLayout}>
6 <Route path="/items/new" page={ItemNewItemPage} name="newItem" />
7 <Route path="/items/{id:Int}/edit" page={ItemEditItemPage} name="editItem" />
8 <Route path="/items/{id:Int}" page={ItemItemPage} name="item" />
9 <Route path="/items" page={ItemItemsPage} name="items" />
10 </Set>
11 <Set wrap={LocationsLayout}>
12 <Route path="/locations/new" page={LocationNewLocationPage} name="newLocation" />
13 <Route path="/locations/{id:Int}/edit" page={LocationEditLocationPage} name="editLocation" />
14 <Route path="/locations/{id:Int}" page={LocationLocationPage} name="location" />
15 <Route path="/locations" page={LocationLocationsPage} name="locations" />
16 </Set>
17 <Set wrap={UsersLayout}>
18 <Route path="/users/new" page={UserNewUserPage} name="newUser" />
19 <Route path="/users/{id:Int}/edit" page={UserEditUserPage} name="editUser" />
20 <Route path="/users/{id:Int}" page={UserUserPage} name="user" />
21 <Route path="/users" page={UserUsersPage} name="users" />
22 </Set>
23 <Route notfound page={NotFoundPage} />
24 </Set>

Now if you run yarn rw dev, you'll see something like this.

dashboard with global layout applied

If you go any of the links in the side navigation, you'll see something like this.

users in the dashboard with layout

I'll leave the extra styling to you. Styling this could be a completely separate tutorial!

This might feel like a cliffhanger since we didn't actually write much code, but that's what I like about Redwood. You can get big apps up and running quickly and things just work.

Finished code

You can check out the front-end without the connection to the back-end here on this Code Sandbox.

If you want all of the code for the front-end and back-end, check out the redwood-user-dashboard in this Git repo!


Dashboards are a major part of many apps so it's helpful to know how to create one quickly. Redwood is a framework that will help you get started with advanced projects like these and it makes it fast to generate complex structures.


Software Team Lead

Milecia is a senior software engineer, international tech speaker, and mad scientist that works with hardware and software. She will try to make anything with JavaScript first.