# Refactoring of sample application

**URL:** <https://forums.pega.com/t/refactoring-of-sample-application/8051>\
**Category:** Knowledge Share\
**Tags:** other-industry, 24-2, constellation, lead-system-architect\
**Created:** [August 14, 2024, 5:39am UTC](https://forums.pega.com/t/refactoring-of-sample-application/8051 "2024-08-14T05:39:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KamilJaneczek](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/kamiljaneczek/32/23339_2.png) [@KamilJaneczek](https://forums.pega.com/u/KamilJaneczek)\
**Post date:** [August 14, 2024, 5:39am UTC](https://forums.pega.com/t/refactoring-of-sample-application/8051/1 "2024-08-14T05:39:48Z")

</div>

![banner.jpg](https://pega1.discourse-cdn.com/pega/original/2X/7/758092b73b016a349d9213de9a75e9086a7722b7.jpeg)

This article is part of series of articles named **Constellation Flexible UI**. Please check table of contents: [https://support.pega.com/discussion/constellation-flexible-ui](https://support.pega.com/discussion/constellation-flexible-ui)

 ![disclaimer.png](https://pega1.discourse-cdn.com/pega/original/2X/2/28397d0895947b0ce03c195ad13af16e75b50a44.png)

We have done all the preparation steps as well we have a good understanding of Pega application that we integrate with as well as we understand core principles of Delight Design System that we will use. Let’s refactor a little bit starting application that comes with SDKs. As this is just a sample application it needs to be tailored to specific needs.

# Cleaning up project structure

After all the hard work with preparation it is time to get our hands dirty with some coding. We are almost there. Just a few things that we would like to do to refactor our sample app.

At this point you shall already have repo downloaded to your PC. Please open in the IDE of your choice. There are quite a few files and folder there:

 ![folder structure.jpg](https://pega1.discourse-cdn.com/pega/original/2X/4/4f5464730cab8be8673977dd21c5fc67221973e8.jpeg)

Take you time to investigate all of them to make sure you understands their purpose. Main project files are located in src folder:

 ![src folder.jpg](https://pega1.discourse-cdn.com/pega/original/1X/650dea49c00b4acc0feec47fa8475987fddb2dee.jpeg)

Couple of observations on how the code is structured:

- barrels pattern in used (more about it here [https://basarat.gitbook.io/typescript/main1/barrel](https://basarat.gitbook.io/typescript/main1/barrel)). This is great for larger project but for smaller ones (like the one that we will create) it is not need so we will opt out from it
- SDKs are in path to migrate to TypeScript, although there is no full type safety so far SDK comes with eslint and prettier config that you can adjust to your needs components folder - you can delete it as we will recreate it
- samples - includes code for sample app. You can delete it, we don’t need it anymore

For our sample app for Sweet Life company we will follow folder structure similar to one used in Next.js projects (here is more about [https://next](https://nextjs.org/)[j](https://nextjs.org/)[s.or](https://nextjs.org/)[g](https://nextjs.org/)[/](https://nextjs.org/)[)](https://nextjs.org/)

 ![app folder.jpg](https://pega1.discourse-cdn.com/pega/original/2X/4/48e5c54927621f3d8a78cb15dcccbc1b4ce8f69c.jpeg)

We will use following folder structure:

- app - this folder induces main app files, with separate file for each route. Folder components comprise of reusable UI parts like header of footer

 ![app folder | Kamil Janeczek | Pega LSA.jpg](https://pega1.discourse-cdn.com/pega/original/2X/f/f014b33d584147c75fc1e93c28f586a6a42316d0.jpeg)

- components (outside app folder) - here we will have our overwritten components from SDK
- design-system - here we will keep files specific to Delight Design System
- hooks - our custom hooks
- lib - libraries and utilities

Note: When modifying folder structure it is needed to reconfigure Webpack to properly build assed for browser.

 ![webpack config.jpg](https://pega1.discourse-cdn.com/pega/original/2X/2/2465c0f97c7811757fa89a0794d38825d6afff1b.jpeg)

# Modularize code

In React SDK application file react-sdk/src/samples/Embedded/EmbeddedTopLevel /index.tsx consist of more than 500 lines. In one file there is logic responsible starting authentication, connection to Constellation as well as for screen rendering. We can apply rule of separation of concerns and split that code making it more reusable.

We create custom hook named **useConstellation** that will be responsible for connection to Infinity server.

 ![useConstellation custom hook | Kamil Janeczek.jpg](https://pega1.discourse-cdn.com/pega/original/2X/8/8bb79962b223f4a47d1ce40062bee759a968ee4d.jpeg)

This single line is responsible to connecting to Constellation. See details of custom hook here: [https://github.com/kamiljaneczek/Sweet-Life-Pega/blob/main/src/hooks/useConstellation.ts](https://github.com/kamiljaneczek/Sweet-Life-Pega/blob/main/src/hooks/useConstellation.ts) It returns the Boolean that we can use later to conditionally render a screen. We will render Pega UI only author setting up connection to Pega

 ![Loading component.jpg](https://pega1.discourse-cdn.com/pega/original/2X/5/5491801fcd52f855ecbdc41a0a23b744ba514da1.jpeg)

Before that we will show elegant (and animated) Loading component.

 ![loading component.jpg](https://pega1.discourse-cdn.com/pega/original/2X/2/283f1f9107e8fca89322e07e36b20cfe54f30ce1.jpeg)

---

<div class="post-metadata">

**Author:** ![KamilJaneczek](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/kamiljaneczek/32/23339_2.png) [@KamilJaneczek](https://forums.pega.com/u/KamilJaneczek)\
**Post date:** [April 16, 2026, 6:41am UTC](https://forums.pega.com/t/refactoring-of-sample-application/8051/2 "2026-04-16T06:41:08Z")

</div>

This post is not being further actively updated and refers to pega23-branch on [GitHub - kamiljaneczek/Sweet-Life-Pega at pega23-branch · GitHub](https://github.com/kamiljaneczek/Sweet-Life-Pega/tree/pega23-branch)

Updated version of repo for Infinity 25 is in pega25/react-rotuer branch: [GitHub - kamiljaneczek/Sweet-Life-Pega at pega25/react-rotuer · GitHub](https://github.com/kamiljaneczek/Sweet-Life-Pega/tree/pega25/react-rotuer)

Checkout more here: [Migrating Sweet Life from Pega Constellation SDK 23 to 25](https://forums.pega.com/t/migrating-sweet-life-from-pega-constellation-sdk-23-to-25/10879)
