Skip to content

Making A Full Stack Change To The Project

tylowe-labs edited this page Apr 18, 2023 · 7 revisions

Our objective for this guide is to add a small feature to the project which will require changes to both the Frontend and Backend to successfully work. We will use a toy example of a "song"; however, feel free to try adding your own concept.

The code for this example can be found on the onboarding/song-example branch

Prerequisites

  • Ensure that you are able to pull the codebase down and run it. Follow the instructions here.

Making A Backend Change

To start, we first have to perform a modification to the Backend to add the concept of a "song" to the project and have it persist in the system. This requires edits to the libs/shared folder and libs/server folders and you will need to how to use typeorm, @orcha, and nestjs.

Setup Song Data Models

  1. In the libs/shared/domain/src/lib/domain directory, mkdir song && cd song to create the directory which houses our song model files

  2. In the song directory create a Song interface (defines what a Song will look like)

218326030-352f9250-25ca-4ff5-aef5-f8dc4b134056

  1. In the song directory create Song DTO models. These define what the parameters are for Song Backend operations, you should have one for each of the operations you expect would be performed on the Song model.

218326132-9845d010-4220-4720-a0ab-b008a702d703

  1. In the song directory create a Song query to define what data will be fetched during Song Backend operations

218326175-18e13ab1-c86c-4b0e-94d0-10e16546f25f

  1. In the song directory create a SongOrchestration interface (defines the operations that Backend/Frontend can use and their associated input & outputs)

218326234-d2117e55-6cd5-4963-9835-a26c684a4155

  1. In the song directory create an index.js to export created files and register the song with the parent directory libs/shared/domain/src/lib/domain

image

image

Register Song With Backend

  1. In the libs/server/core/domain-services/src/lib/ directory, mkdir song && cd song to create the directory which houses our Song backend files

  2. In the song directory create a SongEntity. This is used to map the Song data model to the Backend database for storing purposes.

218326348-a3360a6d-4340-47fc-ac6e-7b2d4cd6c740

  1. In the song directory use the SongEntity to create a SongRepository. This is the database table where the Song objects will be stored.

218326373-9bca1c4e-c210-4e95-a5dc-d8e4dd4938eb

  1. In the parent directory (libs/server/core/domain-services/src/lib/) register SongEntity and Repository with "server-core-domain-services-module.ts"

image

Implement Server Orchestration

  1. In the libs/server/core/application-services/src/lib, mkdir song && cd song to create the directory which houses the Backend Song business logic.

  2. In the Song directory create a SongService to handle the logic for Song backend operations

image

  1. In the parent directory (libs/server/core/application-services/src/lib) register the SongService with "server-core-application-services.module.ts"

image

  1. In the libs/server/orcha/src/lib, mkdir song && cd song to create the directory which houses the Backend implementation of Song Orchestration

  2. In the Song directory, implement SongOrchestration using the required Backend application services

image

  1. In the parent directory (libs/server/orcha/src/lib) register with "server-orcha.module.ts"

image

Testing Changes

  1. Run npx ng s api after starting PostgreSQL service

  2. Validate that project registers the SongOrchestration

218326538-749e8140-0839-4b5f-ae64-bee5dfb4feb6

  1. Use PGAdmin or PSQL to validate that a PostgreSQL table has been generated with appropriate fields

218326603-3bb2d30f-d938-4140-b80e-836c90359cb1

If the changes have been validated, then you are ready to move onto the Frontend to allow users to interact with these Backend changes.

Making A Frontend Change

Now we want to perform a modification to the Frontend to allow the Frontend to call the Backend service using the @orcha RPC mechanism. This requires edits to the libs/client/ directory and we will need to use Angular, @orcha, and nx to succeed.

Register Song with Frontend

  1. In the libs/client/shared/data-access/src/lib/orchestrations directory, we need to implement the SongOrchestration interface (defined in the Backend steps) for the client

image

  1. In the parent directory (libs/client/shared/data-access/src/lib/), we need to register the Client SongOrchestration implementation with "client-shared-data-access.module.ts"

image

Create Frontend Song Library

  1. Create a new nx library project with nx g lib songs --directory=client in the main directory of the project

image

  1. cd libs/client/song/src/lib and create an Angular component with ng g c create-song

image

  1. Edit the file "create-song.component.ts" and make it look similar to "forget-password.component.ts" by having a form for song values with a submit button.

218339780-114b811d-438e-4429-b341-411a0e6c1c81

218339787-6c2d817e-2f1a-42e5-90f3-87d43942f0ea

  1. Edit the file "create-song.component.html" to allow the client to use the form

218339840-bdc74c08-3d9f-45c5-b48a-535144d86d2e

  1. Edit the overall "client-song.module.ts" file generated by nx to add appropriate imports and routes used by the create-song component

218339856-87b6ef18-a704-44ae-9d8d-c59f885585a9

  1. Edit the "im-routes.ts" file in libs/shared/domain/src/lib/routes to add new Song library to Frontend

image

  1. Edit the "client-shell.module.ts" file in libs/client/shell/src/lib to register Song routes to the Client Frontend

image

Testing

  1. Run npx ng s and npx ng s api in separate terminals

  2. Navigate the songs route (localhost:4202/songs) and check create-song form appears

218340017-af9751f9-d4ea-4fea-9e70-4176cdbb5e4d

  1. Test the ability to insert songs into the form

218340034-1a2f4d05-845c-438c-af48-db7c13f9d995

218340041-3716a66d-3cf1-4c9f-a790-b20d38abc054

  1. Double check with PGAdmin or PSQL that updates are persisted in the PosgreSQL

218340055-340e2409-f46c-4dd8-88bb-fca90ee92bf3

Now we are done and have created a project-wide code change using the Frontend and Backend!