Setting Up Next.js Blog Starter and Understanding Its Structure

We'll get to know a sample blog application that we'll be adding a comments section to. We'll also go over the setup and explain the directory structure.

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the The newline Guide to Full Stack Comments with Hasura and React course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to The newline Guide to Full Stack Comments with Hasura and React, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course The newline Guide to Full Stack Comments with Hasura and React

In the previous module, we covered the backend part of our course. We have a database that can store the comments and we learned a few bits about GraphQL and Hasura. We also mentioned that we are going to connect to Hasura via GraphQL to add and retrieve comments. And that's what we are going to focus on in this module. We will integrate with Hasura from moving in the front end application. In the following lessons, we will create a custom React hook that will have the logic responsible for sending post requests with GraphQL queries and mutations. However, we need a sample application that we can use to demonstrate the commenting system. We will go with a simple block as it perfectly fits the comments use case. We are going to use the next JS block starter as it is pretty simple and will let us get started very quickly. Next JS is a front end framework created on top of React, enabling server site rendering and creating static websites. For example, blocks. We introduced two new terms, so let's quickly see what they mean. Server site rendering. A typical React application renders its content on the client's site. In the browser, server site rendering means rendering web applications on the server and passing the HTML to the browser. A static website displays the same content for every user. It means that the content is fixed static. This course doesn't require knowledge about next JS, but if you want to learn more about the framework itself, you can check out the next JS documentation. To get started with the next JS sample block application, you have to visit the link that you see on the screen. You can also find it below in the description. In the next JS block starter repository, we can see setup instructions. Let's use the first command. Instead of block starter type script app, you can provide your own name. By using NPX, we don't have to install create next app package locally. The NPX stands for node package execute and it's installed along with npm out of the box if you're using npm versions 5.2.0 and above. It can execute any package from the npm registry without installing the package . So, after successful is setting up the block, we can run it with Yarnedef or npm runedef, depending on what you prefer to use. Let's quickly see the project structure. I won't go into very details of this project as we'll only use it as an example for the commenting system. In underscore post directory, we have example block posts written in markdown. Components directory has all different components used in the UI, for example alert avatar, footer and so on. The lib directory stores library level code, utility functions, command constants and so on. That might be a good place for our has to write integration code. In the pages directory, we have react components and each one is associated with a root corresponding to its file name. Pages / posts, we can see slack.txt file and the square brackets is a dynamic root notation in next.js. You can think about it as a template for posts. The underscore app and underscore document are next.js special pages. In underscore app, app component is used to initialize pages, we can control the page in initialization and for example add global CSS past state to pages handle errors. The document component is mostly used to control apps HTML and body. For example, we can insert custom tags to head, later title and description. The public directory stores public assets like images or favicons. Stairs has index.css file with styles used in the sample application. Then we have post CSS config and tailuit config, which stands for configuration for post CSS and for tailwind. Tailwind is a CSS framework exposing utility classes. We're going to explore it a bit when building the command section UI. Then we have TS config JSON, which has style script, compiler's configuration, and then we have package JSON and TR unlock containing information about the project and dependencies. Now that we have our sample application, we'll go straight to implementing the Hastera integration. See you in the next lesson.