This application is used to demonstrate and teach Datadog features through labs and workshops at the Datadog Learning Center.
TechStories is a simple web application that allows users to post stories about technology. Users can also comment on stories and upvote stories and comments. The application is written using Next.js and uses a PostgreSQL database to store data. It also uses a Node.js microservice to serve inspirational quotes.
Frontend Service
- CI Test Visibility
- RUM
- APM
TechStories is designed to be run directly on the host machine, as it was primarily built to demonstrate Datadog CI Test Visibility, but its other services can be run in containers using Docker Compose.
Use the following steps to run TechStories:
-
Clone this repository to your local machine.
-
Set your environment variables by copying the
.env.example
file to.env
and filling in the values. -
Install the dependencies for the Next.js application:
cd techstories-demo-app
npm install
- Spin up the PostgreSQL database and Node.js microservice using Docker Compose:
docker compose up -d
- Prepare and seed the database:
npm run db-prep
- Start the Next.js application:
npm run dev
- Navigate to http://localhost:3000 to view the application.
If you want to build the application for production, use the following command:
npm run build
Then run the production build using the following command:
npm run start
TechStories uses Cypress for end-to-end testing and Jest for unit testing.
To run the end-to-end tests, use the following command:
npm run e2e
# or
npm run e2e:headless # Run in headless mode
To run the tests for Datadog CI Test Visibility, use the following command:
npm run dd-e2e
To run the unit tests, use the following command:
npm run test
To run the tests for Datadog CI Test Visibility, use the following command:
npm run dd-test
Use the following user stories to learn about the features of TechStories:
-
Navigate to http://localhost:3000.
-
On the home page, you should see a list of stories that have been posted by other users. Each story should display the title, author, date, and number of votes and comments.
-
Click on a story to view the story's contents, comments, and upvote button.
-
Navigate to http://localhost:3000.
-
Click the "Sign in" button in the top right corner of the page.
-
Use the following credentials to log in:
- Username:
[email protected]
- Password:
password
-
Click the "+ New Post" button in the top right corner of the page.
-
Enter a title and contents for your story, then click the "Submit" button. You can use Markdown.
-
You should be redirected to the home page, where you should see your story at the top of the list.
Note: You cannot register a new user at this time.
-
Navigate to http://localhost:3000.
-
Use the credentials from the previous user story to log in.
-
Click on a story to view the story's contents, comments, and upvote button.
-
Click the upvote button. The number of votes should increase by one.
-
Navigate to http://localhost:3000.
-
Use the credentials from the previous user story to log in.
-
Click on a story to view the story's contents, comments, and upvote button.
-
Scroll to the bottom of the page and enter a comment in the text box.
-
Click the "Submit" button. Your comment should appear at the bottom of the list of comments.
-
Navigate to http://localhost:3000.
-
Scroll to the top of the page. You should see an inspirational quote.
-
Click the "Get a New Quote" button. A new quote should appear.
Note: This will sometimes lag or fail due to the microservice being slow or down. This is intentional.
The TechStories repository is organized as follows:
-
cypress
- Contains the end-to-end tests for the application and any supporting files. The actual tests are in thecypress/e2e
folder. -
prisma
- Contains the Prisma schema and migrations for the application, along with the seed data and a script to seed the database.Use the
schema.prisma
file to better understand the relationships between the tables in the database. -
public
- Contains the public assets for the application, such as images and fonts. -
services
- Contains the Node.js microservice that serves inspirational quotes. -
src
- Contains the source code for the Next.js application.__tests__
- Contains the unit tests for the application.components
- Contains the React components for the application's UI and functionality.hooks
- Contains the logic for some of the functionality utilized by the components.layouts
- Contains the React components for the application's layouts.pages
- Contains the Next.js pages and API routes for the application.api
- Contains the API routes for the application (accessible through/api
).auth
- Contains the pages for the authentication flow (accessible through/auth
).posts
- Contains the pages for viewing and creating posts (accessible through/posts
)._app.tsx
- Contains the Next.js application component. This is where RUM is initialized.index.tsx
- Contains the home page for the application (accessible through/
).
server
- Contains the server-side code for the application. There's a lot of TRPC boilerplate here, along with the code for the Prisma client.styles
- Contains the Tailwind CSS and custom CSS styles for the application.types
- Contains the TypeScript types for the application.utils
- Contains utility functions for the application.