Loading video player...
Hello and welcome back to another
exciting tutorial of greatest tag.
Nowadays, most businesses promote their
product using UGC video ads. These ads
work well, but they are expensive and
timeconuming to create. So why not
automate it? In this video, we will
build and deploy a full stack AI
application that generates UGC style ad
videos using just a product image and a
model image. To build this full stack AI
project, we will use Postgress, Express,
React, and NodeJS. We will use Google
Gemini API to power our UGC ad video
generator. So, let's take a look at the
project demo. So this is the homepage of
our application where you can see the
navigation bar. Here we have the welcome
message and then we have the features.
Then we have the pricing and after that
we have the FAQs. Then CTA and this
footer. Now if I go to create here we
have this form. Using that we can create
the image and using that image we will
generate the video. Next we have this
plans where you can see the different
plan. We can switch to different plan
and get the credits and we will get
different features. After that we have
this community and in this community
user can see the post added in the
community. It means user can create the
ads and they can also publish it in
their community. Now let me sign up on
this website. So I'll click on this get
started. So it will open this sign up
form and if you already have an account
you can click here to login using your
existing account. So let me login with
my Google account here.
After login you can see here we have the
available credits and if I open this
here you can see we have the generate
button my generations community plans
manage account and sign out. If I go to
my generations. So you can see we have
already generated these ad videos. If I
hover it, you can see it will start
playing this video. This video has audio
also. Right? So this is the UGC ad video
generated using a sneaker image and
model image. Let me move here in the
second one. So you can see this is the
second video generated using a product
which is the handbag or trolley bag. And
here we have a same model, right? So you
can see the used images also in this
circle. We have the suitcase or trolley
bag. And here we have the model image
which is used to create this video. And
here we have other details also like
product name, created date. Then we have
the description. And here we have the
prompt also that is used. After that
here we have the option to publish or
unpublish this ad. So if it is published
it will be added in the community. So
the second one is published that's why
here we are getting the unpublish button
and in the first one we have the publish
button so that we can make it public it
will be added in the community. After
that here we have the view details. If I
click here so here we have this result
page. We can play or mute this audio.
And in this one we have the option to
download the image and download the
generated video. Correct. Now let's
create a new ad. I'll click on this
create button and here we'll add the
product image. So let me add one
product. Let me use this handbag image
as a product. Now we'll upload the model
image. So here I'll choose this model
image.
After that here we have to add the
project name. So let me write the
project name my new project. Then we
will add the product name. So the
product name is handbag. After that here
we have to add the product description
which is optional. So let me write the
product description handbag for women.
After that you can also add the prompt.
So here we will add this prompt.
Showcase the handbag in dynamic and
fashionable way. This prompt is also
optional. So we have added the details
here and added the product image and
model image. Now click on this generate
image. So it will generate the image
first. I'll just click here and after
generating it, it will deduct the
credits also. You can see right now we
have 70 credits. So it will deduct five
credit for generating this image and
after generating the image we will
deduct the credit to generate the video.
So just click here.
It will take few seconds to generate the
video because it is generating the
content using AI. So just wait for that.
Now you can see our image has been
generated. And now you can see in this
model's hand we have this handwag right.
So we have uploaded the separate image
for model and bag. So now we have the
combined image and using this image we
can generate the video. In the right
side you can see we have this download
image button so that we can download
this image. Correct. Now we have this
button generate video. So let's click on
this one. So it is generating the video.
Just wait for that.
Now you can see the video has been
generated.
So I'll pause this audio and uh after
that you can see we have this
UGC video that is generated using the
product image and model image and by
adding small details right and here we
have the download button using that we
can download this video and use it for
our ads. So this UGC ad generator is
working fine. Let me just come back to
the homepage. In this project, we have
added the user authentication and
subscription billing using color. Color
makes it easy to handle user signin,
signup and account management. With
color subscription billing feature we
can provide advanced feature and credits
to our member. Then we have used sentry
for error tracking in this project. It
is powerful tool for error monitoring
and performance tracking. It helps you
to find the bugs in the real time and
understand why your app is slow. Instead
of guessing, Sentry shows you the exact
errors, a stack, traces, and performance
issues.
To store user and projects data, we have
used Neon. Neon is a Postgres SQL
database that helps developers build
reliable and escalable application
quickly. After building this AI powered
UGC video generator project, we will
deploy it online using Hostinger VPS. It
is affordable, fast and perfect if you
are serious about building AI tools. So
if you are also excited to build your
own UGC ads video generator, just write
down I'm going to build UGC ads video
generator AI tool in the comment box. I
will recommend you to build this project
and add the live link in your resume or
you can also use it as your college
project. Now let's get started
to create this UGC ad video generator
project. We have divided this complete
tutorial in different chapter. First we
will create the front end which is user
interface. After that we will add the
user authentication. It means we will
integrate the sign in and sign off
functionality. After that we will create
the backend server where we will create
multiple APIs and after that we will
connect our backend server with our
front end.
At the beginning of every chapter we
will discuss the technologies and
thought process also. So first we will
start with the front end. If you already
have a good experience with the front
end then you can skip this part and you
can come to the user authentication. I
will include all the timestamps in the
video description. But for creating the
front end also we will not take much
time because instead of creating the
front end from scratch we will use
pre-built UI template. So let's open web
browser and search for pre-built UI
template. Open this link. You can see
the website pre-builti.com
and then path. You can also open the
homepage using this URL pre-builti.com.
And here you can find different
components.
So you can easily integrate these
component in your react project. So
let's come here in the templates and
here you will find lots of beautiful
template. So I'll just scroll down and
you can see here we have multiple
templates that we can use for free. So
I'm going to use this template which is
pixel.io digital agency website
template. We can preview this template
from this link. You can see view demo.
Let's click here.
So you can see this template is looking
beautiful. Here we have the hero
section. Then we have services. After
that we have pricing.
Then FAQs. Then CTA and footer.
Right. So we will create the homepage of
our application using this template. And
here you can see the details also. If I
click on this view details.
So you can see it has the dark UI
gradient glass effects and uh after that
you can see
we have some screenshot right and here
we have the list of features. So we are
going to download this template. I'll
just click on this button get for free.
Here we have two options. We can
download this template for nextjs
project and we can download it for
reactjs also. So I'm going to create the
front end in reactjs. So I'll just click
here.
So you can see we have downloaded this
template. Let me navigate it.
I'll place this template here.
Pixel io reactjs. Now let me extract it.
I will extract this zip file in a
separate folder. So I'll extract to this
folder name.
So here we have this
pixel io reactjs
like this. Now in this one you can see
we have the complete structure for react
project. Now we have to start this
project. For that we will use VS code.
So first let's create a project folder.
I'll create a new folder here and I'll
write the folder name UGC
project and after that in this one we
will move this downloaded folder. Let's
move it here. Now in this one we have
this pixel io reactjs which is the front
end. So let's rename this. I'll rename
it as client.
We will create a full stack project
where we'll create the front end which
is the client project and we'll also
create the back end. So here we have the
folder name client and in this one we
have the template that we have
downloaded. Now let's right click on our
project folder and select open with VS
code. So it will open this project in VS
code and uh after that
we will start this front end project. So
right click on this client and then
select open in integrated terminal.
So you can see here we have the VS code
terminal and in this terminal you can
see we are at this path client. So here
we have to install the dependencies. So
let's add npm
install.
So it will install all the dependencies
which is used in this template which is
the ReactJS template.
And after that we have to start this
project. So let's add npm
run dev. Add this command.
So it will start this project and we can
open this localhost 5.73 URL in the web
browser right. So let me just copy this
link and open the web browser.
So in this browser you can see we have
the same template and it is running at
our local host as you can see here. So
we have downloaded the template and it
is running on local browser. After that
we have to customize this template and
after customization we will also create
our custom pages or new pages right that
will be helpful for our project. So I'll
just come here and we'll start with our
index html file. So in this one you can
see here we have the title. So in this
title I have to add our own title. So
let me write
UGC AI create AI generated images and
videos
like this and after that here you can
see we have this link tag and in this
link tag we have the fabicon.ico.
So if I open the web browser you can see
the title has been generated here. It
means the title has been updated but the
icon is same. You can see the fabicon
icon in this tab. So to update this
icon, we have to insert our own images
and icons. So you can download the asset
file from the video description. You can
see here we have the UGC assets. You
will find this
link in the video description. So just
copy everything from this assets folder
that you will find in the video
description. Just copy everything and
open our project folder. Then go to
client and assets. Inside this src you
will find assets. And here let's paste
everything. So in this assets I'll paste
the data that we have copied. It means
the files and this logo. SVG. Then
favicon. SVG. Here we have assets.ts
file also. So in this assets.ts file we
have added the dummy data also that will
be displayed on front end and after
creating the back end we will replace
this dummy data. So here we have all the
assets. Now we have to place some assets
in the public folder also. So
I'll just copy
this fabicon.sbg SVG
and uh after that
let me just come here in the client
project in the client we have public and
in this one you can see here you can see
we have the favicon ico so I'll paste
the file that is favicon ssvg and remove
this ICO file
like this so here we have favicon ssvg
now we can use it in our project so I'll
just close it and Open the VS code and
here let's provide favicon
dot SVG. Save the changes and open the
web page.
So you can see the icon has been
updated.
Correct.
After that I'll just come here
and in this
HTML tag we will add one class. So let's
add the class property and here we'll
add the Telwind class name that is
scroll smooth. So it will scroll the web
page smoothly. Right. After that let's
close it and uh we will come here in the
src. In this src you can see we have the
home.tsx
because this project is created using
typcript. Now in this file you can see
we have hero features pricing faq and
CTA and uh after that if I open this
main.tsx
in this one you can see we have this
app. So first this app component will be
loaded right and then we will open
app.tsx.
So in this one you can see we have this
soft backdrop that will add some
gradient color in the background. Then
we have this scroll and after that we
have this nav bar. Then home and footer.
So this nav bar will be displayed
everywhere. Then we have the home. So we
will change the home in different path.
Instead of home we will display other
pages like generate my generation. And
then we have this footer. So first we'll
start with the navigation bar. You can
see here first we have the navigation
bar and then we have the content that is
available in the homepage. Right? And at
the bottom we have this footer. So first
we'll start with navar customization.
For that I'll just come back here in the
VS code and open the components. And in
this components we have navar.tsx
file. Right now in this one we have to
update the
link name. Right. So you can see here we
have the nav links which is home. It
will be there. After that here we have
this
features. So let's update it. Here we'll
add create. After that we'll add the
third one that is community. And in the
next one we'll add the text called
plants.
Here we'll add the path also. So let's
add the path that is
/g generate in this create. After that
we'll add the path /
community and uh in the next one we'll
add the path called plans.
Save the changes and scroll down. So
here you can see first we have this
div and in this one we have a logo right
and here we have the a tag. So instead
of this a tag I'm going to use link tag.
So let's replace this a I'll write link
and uh after that we have to import the
link from the react router DOM. So we
are not getting the suggestion here. So
let's scroll down. I think react
routerdom is not there. Let me open the
package.json file.
And uh here let's see the dependencies.
So here we have
Telbind framer linucid
react react react to and telin css. So
we don't have the react router dom. So
let's install it. I'll just open this
terminal at Ctrl C to stop the project
and here let's add the package name that
is react router DOM. So simply write npm
install
react router DOM
and after that I start the project again
using npm rundev.
So now the project is running again.
After that let's come here hide this
terminal and open our navar.tsx file and
here if I type link
we are getting the suggestion to import
the link from react router DOM. So here
we have imported the link tag and uh
after that here we have href. So remove
it and we'll add two. In this two
property simply add the path slash. So
it will open the homepage when we will
click on the logo. Here we will add the
onclick property. In this onclick
property let's add one arrow function.
And here we will add a scroll two. And
uh in this scroll to we will provide 0
comma 0. So it will scroll the web page
to top. After that here we have the
image tag src. And in this src we will
add the logo that is available in our
asset file. If I open the src then
assets and assets.tsx. So in this one
you can see here we have all the
import statement that is importing the
images and videos and we have exported
it using this assets object. So we can
simply access this assets object and add
the file name like logo product one
product two like that. So I'll just come
here and here in this src let's add
curly braces assets. Let's click here to
import the assets. Then dot logo. So we
have added the logo in this img tag.
Then we'll add the alt tag logo. And
here we have the height 8. Save the
changes. And now we will open the web
page. Let me refresh it. Here we have
the blank screen. So let me see the
issue here.
So we are getting this error because we
have added the react router down. But we
have not added the support of react
router in our application. So let me
hide it.
And after that just come here and open
our main.tsx file.
And in this one here we will import the
browser router. So let's add import
kalibresses
from package name react router DOM. And
from this react router down we will get
browser router. After that we will use
this browser router to wrap our
application. So instead of this
reactrict mode here we will use the
browser router opening and closing tag.
And inside this we have this app.
Correct. Now we remove this unused
import statement from here. Save the
changes. Right. After that if I open the
web page you can see here we have the
updated logo then we have the updated
text home create community and plans
which is the menu title or text right
after that I'll just come here in the
navartsx file here you can see we have
used the same nav links and map that is
displaying all the links but right now
you can See here we have the a tag. So
instead of this a tag I'm going to use
link tag again. So let's add link. And
here we have the link closing tag. In
this link tag we have to add the
on click. So again copy this same on
click property from here
and paste it here. So it will scroll the
web page to top. After that instead of
this href we are going to use two
correct. So let's add two here
and in this two let's provide link dot
href. So it is coming from here and then
we have this
key then classes and here we have
link.name name save the changes and
after that I'll just come here and now
if I click on this create it is opening
this path /g generate you can see the
path is changing if I click on this
plans you can see the path is
localhost/plans
correct now I'll open this web page in a
smaller screen so you can see if I open
in a smaller screen here we have the
menu icon if I click here it will open
the navigation menus like this. Here you
can see we have same navigation menu
home, create community plans, sign in
and get started button and this close
icon. Let's close it. So it will again
display this menu icon. Let me open it.
Desktop screen or desktop view. So we
have updated our navigation bar. Let me
just come here and you can see here we
have the button that is sign in and here
we have get started button and here we
have the navigation menu for a smaller
screen. Here also we have the same nav
links and after that we have the same
sign in and get started button correct.
Then we have this button using that we
can close the mobile menu. So we have
updated our navigation bar. After that
let's close it. And here we will open
our home.tsx. In this home, first we
have the hero, right? It means we have
this hero section that contains these
data in the left side and this image in
the right side. So to update the content
here we will come back open the sidebar
components and in the components we will
open hero.
TSX. Here we have hero.tsx. tsx file. So
now let's update this file. So we will
update the text first. If I just come
here, you can see we have div and uh in
this div, we have this text called
trusted by, right? So let's update this
text. I'll write
I'll write the text trusted by 10k plus
creators. After that here we have other
text B design and build. So let's update
this text also create vital UGC and here
we'll add small text that is in seconds.
After that here we have some description
like this. So I'll update this
description text also.
So I have added this text.
Save the changes. And after that here we
have some other text. So you can see we
have
primary button and the button text is a
start your project. So let's update the
button text here that is a start
generating it's free
like this. Then we have another button
and here we have text. So let's update
this text also that is watch demo.
Correct. After that you can see we have
other text in this div. So here it will
write
seconds to create.
Then we'll add
another message in this div that is
optimized social formats.
Right. Scroll down. Here we have another
div full service delivery. So let's
update it commercial rights. Then we
will update the second text that is use
anywhere
like this.
After that here we have the right div.
So I'll just save the changes and come
here. You can see these
text and uh description has been
updated. We have updated this button
text also. Correct? And after that let's
update the data in the right side. So
I'll just come here.
Here you can see we have this main image
URL and then we have this text
branding web and growth. So we will
update this text.
Correct. After that we have some text
here in a span tag that is Case studies.
So here we'll add preview
like this and after that scroll down
and uh here you will find this text 20
plus completed projects. So here we'll
add
plus 20 more. That's it. And after that
here you can see we have this logo.
Let's save the changes and come back
here.
You can see here plus 20 more. Then we
have this preview button here.
Here you can see we have the text social
ready. And then we have the ratio,
right? And if you want to update this
image that is in the right side, you can
update it from here. I'll just come back
here. So this is the main image URL. And
this main image URL is available here.
So we have the image coming from this
Unsplash.
Right? So if you want to change it, you
can update any new URL here. Now I want
to update these images also. So I'll
just come back here and here I'll update
these image URL. You can find the images
on unsplash.com. Just get the image URL
from there and replace it here. So let's
replace these images. I'll replace this
main image URL. I'll add this one. And
after that I'll update this gallery
strip images. So here we'll add three
other images
like this. I have updated all the URLs
here. And after that here we have the
trusted logos. So if I come back here
you can see the image has been updated
and these small images also. And here
you can see we have the trusted brand
text. Right? So let's update this one
also. I'll just come back. Here you can
see we have the
add a. So let's add the first brand name
Adobe. Then we'll add Figma.
After that we'll add Canva.
Then we'll add Spotify.
And after that we'll add one more brand
name Web Flow.
Save the changes and come back here. You
can see we have updated these brand text
also which is animated.
So we have updated our hero section.
After that here we have another section
that is services. So let's update this
one also. For that I'll just come back
to the VS code
and let's open this home.tsx. Here you
can see we have the features section. In
the second one we have features. So open
the sidebar then go to components. In
the components you will find features
dot tsx file.
Now in this one you can see we have the
title and in this title we have added
the text
services. So instead of this services
I'm going to use features.
After that here we have to add the
heading right in the heading we will
write built for modern brands. After
that here we have to provide the
description also. So let me provide the
description like this.
After that if I open the web page you
can see here we have features then this
small title and then small description.
Now update the content in these cards.
So I'll just come back here and here you
can see we have the features data dot
map. So we have the features data in
this assets
correct. So let me update the asset
file. If I open the sidebar assets
and in this assets we have dummy
data.tsx.
Correct. In this dummy data we have this
features data array where we can see the
icon title and description. So the icon
will be same upload icon. After that
we'll update the title. So let's update
the title. It will be smart upload.
After that we will update the
description also. So in this description
let's add the text. Now here we have the
second icon. So the icon will be same.
We will just update the title and
description. So here we will add a new
title and a new description.
Now in the third one the icon will be
same. We will update the title and
description. So here we will add a new
title and add a new description
like this.
After that if I open the web page you
can see these data has been updated
correct after that we have another
section that is pricing
right so
I'll just come back here in the VS code
here in this sidebar you will find this
components and
then open pricing tsx file now in this
one you can see we have is title and in
the title we have
pricing then we have the heading and
description. So in the heading let's add
the text called pricing plans
and uh after that we'll add the
description here. So I'll update this
description also
right and after that you can see we have
the plans data do map. So it is
displaying all the plant data from one
array right and uh after that here we
have plant dotpopular
right and in this popular we have
primary button and in the other one we
have the ghost button right and the
button text is same that is get started.
So let me update the button text here.
Here we'll add button text called buy
now. And in the second one also we'll
add the text buy now. Correct? And uh
after that
I'll just come here in the web browser.
Here you can see we have this updated
text pricing pricing plans and
description. And here we have the button
text by now. Now we will update these
data that is here. Right? For that I'll
just come back here in the VS code and
again open our dummy data.tsx file in
this one after this features data. Here
we have the plans data. Right? So let's
update the plan. So first one is a
starter. In this starter we will add the
name starter. Then we'll add the price
that is dollar10.
Then we'll add the description.
So here we have added this description
for this first plan. Then we'll add the
credits. So here we will add
25 credits. Then we'll add the features.
So here let's update all the features.
So first we'll add 25 credits.
Then we'll add
a standard quality.
After that we'll add no watermark.
Then we'll add
slower generation speed. Then we'll add
email support.
Right after that come to the second one
which is pro. Here we will add the plan
name that is pro.
Then we'll add the price that is $1.29.
Then we'll add the description. So here
let's add this description
and after that we'll add the credit. So
let's add 80 credits.
Then we'll add the features here. So in
this features let's update all the
features like this. We have added 80
credits,
HD quality, no watermark, video
generation, priority support. And then
we have added one more property here
that is popular true. So the second plan
will be marked as popular. After that we
have the third one which is ultra and
the name will be ultra. Then we'll add
the pricing that is $99. And after that
we'll add the small description for this
third plan. And then we'll add the
credit. So here we'll give 300 credits.
Then we'll add different features of
this plan. So here we have added these
features. 300 credits, HD quality, no
watermark, fast generation of speed,
chat plus email support. Update this and
after that we will open the web page. So
here you can see we have updated data in
this pricing table. Correct. After that
scroll down here you can see we have the
FAQs right. So we will update the FAQ
data also
right you can see here we have what
services does your agency provide. Do
you work with a startups or only large
companies if I click here it will expand
it and display the answers also like
this.
So we will update this data. I'll just
come back to the VS code.
And uh let's open
home.tsx. So here you can see after
pricing we have FAQ right. So let's open
our FAQ.
TSX file correct. And uh in this one you
can see we have this title. So in the
title we have FAQ. Then we have the
heading that is frequently asked
questions. And then we have description.
So let me update this description only
and after that let's come here in this
FAQ data. So this FAQ data is also
coming from this dummy data file. So
let's open the dummy data file and in
this one you can see we have FAQ data.
So here we will update the
questions and answers. So if you want to
change it you can change it from here.
So this is the first one.
What services does your agency provide?
So let me update the question and answer
from here.
I'll update the question and then we'll
update this answer.
Similarly, we'll update other FAQs.
So here I have updated all the data in
FAQ and after that I'll just come here.
So you can see these data has been
updated correct.
After that here we have the
CTA or call to action. So I'll just come
back here in the VS code open the
sidebar.
In this one you will find the components
and CTA.TSX file. So in this one you can
see we have the text
ready to grow your brand. So I'll change
this text ready to transform your
content. After that here we have the
text in P tag which is this one. So
let's update this small description
also.
And after that here we have one button
start your project. So let's update the
button text start creating now.
So it's simple to update the content.
Let me just come back and you can see
here we have the updated title,
description and button text. Correct.
After that here you can see we have this
footer. So in this footer we have this
logo. We will update this logo. We'll
update the description and you can also
update the footer links. So let me just
come back to the VS code. Open the
sidebar
then components footer. tsx file. So in
this one
first we have this div and in this div
we have the img src and this logo. So
let's replace this logo. I'll write
curly braces assets dot logo.
After that here you can see we have this
small text. So I'll update this text
also
like this. And after that you can see we
have footer links
right we have footer links dot map. So
in this one we have data from this
footer links array that is imported from
another file. And at the bottom we have
this copyright message that is the
current year and then we have this text.
So let me update this text. Here we'll
write great stag
then dot all rights reserved
correct and uh from this text we can
remove the a tag also so let me remove
this anchor link
we can simply use the text like this
save the changes now let's come back and
here you can see we have this copyright
message at the bottom we have the
updated logo in the footer and then we
have this text and if you want to change
the footer links you can come here
open dummy data tsx file and here you
can see we have the link title and links
so in the title I'll write
quick links then we have the links here
we'll add the home then after home we
will add
features
Then we'll add pricing and then we'll
add FAQ.
Right after that we have the next title
that is legal and we have the link's
name, privacy policy, terms of service.
Then we have the
connect. In this connect we have
Twitter, LinkedIn and GitHub. Right? And
if you want to change it you can update
the name here. And you can also place
the URL or link correct. And uh after
that if I open this footer.tsx
you can see here we have the link dot
URL and link dot name.
So it will be displayed on the web page.
So you can update the footer link title
and link text and link. So we have
updated our front- end template. So till
now we have created the homepage only.
Now we have to create the other pages
also. In that page we can create a UGC
add video or image and we can get the
list of generated content and we will
also create the community page and we'll
also create the plans. So let me just
come back to the VS code. We will open
this sidebar and uh here you can see we
have the pages right. So in this pages
folder let's create all other pages.
Right? Now we have only home.tsx
right. So
in this
pages let's create a new file and uh
write the file name generate or we can
write generator.tsx
here let's add our AFC to create the
complainer structure
and let's remove this import statement
from here. After that we'll create the
next page that is community right. So in
this pages create a new file community
dot tsx rightfce
and it will create this component
structure. After that let's create the
next page. So here we will create the
loading page also. Right? So create a
new file loading dot tsx and write r a
fce and remove this import statement.
After that we'll create the next page
that is my generation. So here let's
create a new file my generations dot tsx
and write r afce
and remove this import statement. After
that we'll add the next page that is
plans. So create a new file plans dot
tsx and here we'll add rafce
and remove this import statement. After
that we'll add one more page that is
results where we will display the
generated content result. So create a
new file that is resultsx.
Here also we will write R A F CE and
create this page.
Remove this import statement. Now we
have to set up the routes so that when
we navigate to new route it will open
the new page. So I'll just come here in
the
app dot tsx file. Right in this one you
can see we have this navar and then
footer. And within this navbar and
footer we have home right. So this home
will be displayed on screen but it will
be displayed whenever we will open the
home path that is slash. For that here
let's add opening arrow
routes. Use this routes tag. Just click
here to import it from react router DOM.
Routes tag has been imported. And here
we'll add closing tag like this. We have
routes opening and closing tag and
within this routes open and close we'll
add this home. So we have added the home
here but now we will add the path for
this home. Correct. So here let's add
opening arrow
route and let's click on this
suggestion import route from react
router DOM. So you can see route tag is
also imported and in this route tag
we'll add the self-closing tag like
this. Here we have route and
self-closing. Now we'll add the path
that is slash and after that here we
have to add the element and in this
element we will simply provide the
homepage. So just move it here
like this. So whenever we will open this
slash it will display the home and if I
open anything else it will not display
it. It will only display the navbar and
footer because this navbar and footer is
outside of this routes. So if I open the
web page you can see we are at /path and
here we are getting the homepage
content. Right now if I change the path
like /
plans you can see here we have the
navbar and footer only nothing else. So
just come back to the homepage again and
let's come back here. Now here we'll add
other routes. So just duplicate it. In
this route we'll add the path called
/ generate. And here we'll add the
element or page. So just add
generator. So generator page has been
imported. Now duplicate it. In the next
one, we'll add the path called result.
So here we have added the path result
and we will display the result that will
display different content. Right? So
here we have to add the project ID also.
So just add slash colon and provide the
project ID. So on the same page we can
display different result using this
project id using this dynamic route.
Here we'll add the element also. So in
this element let's add the
result page. You can see result page has
been imported. Correct. After that just
duplicate it. Here we will add the path
that is my generations where we will
display all the users generated content.
So let's add the page
my generations. It has been imported.
Now duplicate it. Here we'll add the
path community.
So if the user makes their project
public, it will be displayed in the
community. So let's add the page also
that is community and click here to
import it. After that just duplicate it.
Here we will add the next path that is
plans. And let's add the page also that
is
plans. It has been imported. Now let's
add one more path. So just add route
path is / loading. And here we have to
add the loading page. So in this element
let's add loading and just click on this
suggestion. So you can see the loading
page has been imported. So we have set
up the routes for each page. Now if I
open the web page
and if I type /
plans it will open the plants page.
Right now we don't have any content in
plants that's why it is blank. So let's
add the data in different pages also. So
let's start with the first one that is
generated. So I'll just come back here
and uh open the
pages. Here we have generator.tsx
file.
In this generator page we will create
the title and after that we will divide
the content in two column. In the left
column we will add the input field using
that user can upload the product image
and model image. And in the right side
we'll add the input fields. Using that
user can enter the details for creating
their content. So in this div first
let's add the
classes. So just add the class name
property and here we will define the
minimum height.
After that we'll add the text white.
Then we'll add the
padding and padding for medium and above
a screen size and margin from top. Now
after that here we have to create a form
and after that let's remove this action.
Now in this form we will insert the
title. So in this components you can see
we already have the title component. So
let's mount it here. So in this form we
will mount title component import it
from components folder and uh after that
in this one we have to provide the
props. So first we'll provide the
heading. So let's add heading and let's
add the text here. After that we'll add
the description also. So just add the
description property. And here we will
add one small description
like this. So we have added the title
for this generator page where user can
create the content. Now in this form tag
also we'll add some classes. So here in
this form we'll add the class name
property and let's add the maximum
width.
Then we have added the MX auto and
margin at bottom.
Correct? Now in this form we'll add the
div so that we can divide the content in
left and right column. But before that,
let me open the web page. So I'll just
come back here and go to this create.
So here you can see we have this title
and then small description. Correct.
After that I'll just come back here and
here we will add a div like this. And in
this one we will add another div.
So in this first one, let me add the
text called
left call. Duplicate it.
Let's duplicate this div only. Here
we'll add right call.
So if I come back here, you can see here
we have left and right call. Now let's
add the classes so that it will be
displayed side by side. So I'll just
come back here and start with this div.
Here we'll add the class name and let's
provide the flex. Then we will add the
gap and after that we have added the
flex column items start justify between.
Now after that here we'll add the
comment also. So let's add the comment
left column and here we'll write the
comment right column. After that I'll
just come back here. So you can see here
we have the left column in the left
side, right column in the right side.
Right? Now let's start with the first
one that is left. So just come back
here. In this div we will add some
classes. So I'll write
class name property here and then
provide the flex
flex column width full. Then we'll add
the max width. then gap then margin top
and margin bottom.
Right? Now in the left side we have to
add the input fields. Using that we can
upload the images. Right? So there will
be two input field for uploading product
image and model image. Right? So for now
I'll write the comment only. Here we
will write product image and duplicate
it. Here we will add the model image.
After that if I come back here you can
see here we have product image and model
image. Now to create both input field we
have to use the same layout. We will
create the input field that accept the
image file and we'll add some properties
here. So let me create a separate
component for that one. So I'll just
come back here and come to the
components folder. In this components
folder, let's create a new component
and write the file name upload zone dot
tsx.
Now I'll write
and remove this import a statement.
Now in this one here we have this div.
So we'll add the class name property and
provide relative and group.
Correct? After that here we'll add
another div and in this one
let's add class name and here we'll add
the dynamic class. So we'll add curly
braces back tick and here let's provide
these telin classes
right and after that we will add some
dynamic classes based on the state. If
the image file is already selected, we
will add other classes. And if the image
file is not selected or not uploaded,
then we'll add the other classes. Right?
So here let's add the props. So just add
curly braces. We will get the label.
After that we will get the file. After
that we will get on clear.
And then we will get on change. So we
will get these data in props. Here we
will add the type also. So just add
colon and here let's add type for these
data. So let me define the type in
separate file. So here you can see we
have this src. In this src I'm going to
create a new folder. So let's create a
new folder here and write the folder
name types. Right now in this folder we
have to create a file. So let's create a
file in this types folder and write the
file name index dot ts
correct and after that here let's add
export interface and write the name
upload zone props like this. Here first
we'll add the label. So the label will
be a string.
After that we will add file.
So in this file just add the file
or we will add null.
After that we will add on clear. So here
just add the add a function that is
returning void.
After that let's duplicate it. Here
we'll add onchange.
And in this onchange we have this
function where we will add event and
colon. And here let's add
react import the react.
You can see it has been imported. Import
type react from react. Then we'll add
dot change event.
And here we'll add this
angle bracket. And within this we'll add
the HTML
input element like this. So we have
added the interface here. Now I'll just
copy this and come here in the upload
zone.tsx file. And here after this colon
we will provide this upload zone props
and just click on this suggestion to
import it. It has been imported.
Correct. After that here let's add the
dynamic classes. So just add dollar sign
curly braces and we will use
this file
question mark. So if the file is
available it means the image file is
uploaded. So here we will add different
classes and if it is not available then
we'll add colon and provide different
classes in this
quote. So in the first one we will add
border color then background and after
that in the second one
let me provide
different border color then we'll add
the hover effect and we will change the
background also when we hover
correct after that I'll just come here
and add curly braces and we'll check the
file if the file is uploaded. So in this
case we will add this parenthesis and
this fragment and after that here we'll
add colon another parenthesis
and in this one we'll add the fragment
like this.
So if the file is uploaded it will be
displayed and if the file is not
available this second fragment will be
displayed. So if the file is already
available so in this case we will
display the uploaded image file and if
it is not available then we'll display
the upload icon. So let's start here
we'll add one image
at this image tag in this image src.
Let's provide the
URL
dot create object URL
and after that we will provide our file
here. So it will create the URL for our
uploaded file and it will be added as
src for this image. Now we'll add the
alt text. It will be preview and after
that we'll add some classes also for
this uploaded image. So in this one let
me provide these tailwind classes. Now
after this image we have to add a button
also and using that button. We can
remove this uploaded image.
Correct? So here let's add a div.
Within this div we will add the button
and in this button we'll add the cross
icon. So just add X icon and import it
from Lucid React.
Right now we have to set the position
for these buttons. So let's start with
this div. In this one we'll add these
classes. After that we have to add the
button type. So let's add the type
button.
After that in this button we will add
the on click property. In this on click
we will provide this on clear.
So it will clear the selected image and
then we'll add the classes also. So we
will provide the class name and here we
have added these TIN classes. Now we
will set the width and height for the
cross icon. So we'll add
class name property and set the width
and height. Right now after that we will
just come here after closing of this
div. Here we will add another div. And
in this one we will add the file name.
So let's add the P tag. And in this P
tag we will provide the file dot name.
Right? And now we will add the classes
also to decorate this text. So here we
have added the class name property
provided these classes and we'll change
the font size and uh font weight. So
here we will add class name text small
font medium and truncate. Save the
changes. So we have added the
image when the image is available.
Suppose the image file is not available.
So in this case we have to add the
upload icon in this one. In this else
statement right here we have added
turnary operator. So this is the else
case. So in this one we will add a div.
Now in this one we have to add the
upload icon. So I'll write upload icon
from Lucid React.
Now for this icon we have to provide
some classes. So we'll add the class
name property and provide these classes.
Now we will add the classes for this div
that contains this icon. So let's add
these classes for this div. Now after
closing of this div here we have to add
the text also. So we will add the text
in S3 tag. So in this text just provide
the label right. So the label will be
upload product image or upload model
image. After that we will add some
description in P tag. So here let me
provide this description text
and after that we have to add the input
field. Using that input field we can
upload our file. So let's add input type
will be file and after that we will add
the
accept property. In this accept property
we will add image/ a star. So it will
allow you to upload any type of image
file. Now we will add the onchange
property also.
And in this onchange just add the
onchange that we are getting from the
props. Then we will add the classes
here. So just add the class name
property and here we will add absolute
insert zero width full height full
right. So it will use the entire space
available in this div correct. So that
we can click anywhere and the opacity is
zero. So it will be hidden. When we
click here it will just open the window
to upload the image file. And we have
added cursor pointer. Now let's add the
classes in this title and description.
So in this title which is in H3 tag, we
will add the class name property.
Provide these classes. And uh let's
provide the classes in the P tag also
like this. Now we will save the changes
and after that we have to mount this
component in our main file that is
generator.tsx
file. So I'll open this generator.tsx.
And here you can see we have added
product image and model image. Right? So
I'll replace this one and simply provide
upload
zone component. Let's
click here. You can see upload zone has
been imported from this components and
uh after that here let's add this
closing tag and we'll provide the props.
So first we have to provide the label
and in this label I'll provide product
image.
So the first one will be product image
and the second one will be the model
image. After that we'll add the file
here. So in this file we have to provide
the uploaded image file. For that we
have to create one a state. I'll create
it later. And after that here we'll add
on clear equal to curly braces. So in
this one also we'll add the setter
function. Using that we will clear the
uploaded file. Right? And after that
here we'll add
on change. In this on change we have to
add a handler function. Using that we
can add the selected file in a state. So
let's create these state and function.
So I'll just scroll up and here before
this
return a statement let's add some space
and here I'll create all the state that
is required in this page. So let's start
with the project name. So I'll simply
use name con name and the setter
function name is set name equal to use a
state and let's initialize it using
empty string. Now duplicate it. In the
second one we will add the product name
and after that we'll add set product
name. After that just duplicate it. Here
we will add product description and then
we will add the setter function set
product description. Duplicate it. Here
we will add aspect ratio and then we'll
add setter function set aspect ratio.
Duplicate it. Here we'll add product
image that we are going to use right
now. And then we'll add the setter
function
set product image. And here we will add
use state and uh initialize it using
null.
And here we have to add the type also.
So let's add this angle bracket and
provide the file.
Let's click here. And after that we'll
add or and provide null. So it could be
file type or null. And here we have the
aspect ratio. So in this aspect ratio
also we have to update the initial
value. So let's add the initial value 9
is to 16. Correct? And after that let's
duplicate this. Here it will add model
image and the setter function name will
be set model image equal to use state
then file null and null. Now let's
duplicate it or I'll just duplicate this
one. First one copy and paste it here.
Here we'll add user prompt and the
setter function name is set user prompt
and after that we'll add use state and
initialize it using empty string. Now
duplicate it. Here we'll add one more
state that is is generating and the
setter function name is set is
generating and by default it will be
false. When we submit the form it will
become true. Right after that here we'll
add the handler function. Using that we
can handle the file change in the input
field. So let's add con
handle file change equal to
add a function like this. Now in this
one we'll get the event provide the
colon and write
react then dot change event
and then we'll add angle bracket and
provide
HTML input element. Let me correct it.
It will be HTML input element and after
that we'll provide the comma here and
here we'll add the type also. So in the
type we will either provide product or
model. So let's add a string that is
product or we will provide model
like this. Now after adding the type
product or model let's come here within
this curly braces and here we'll add the
if statement. If e.target
dot files and
e.target target dot files index zero.
It means when the file is selected. So
in this case we'll add the another if
statement and we'll check the type. So
I'll write type equal to product. So if
the type is equal to product. So in this
case we will use the set function set
product image. And let's add e.target
target dot
files index zero. So it will store this
selected image in this set product image
or product image state. Correct? Then
we'll add the else statement here. So
here let's add else setter function set
model image. And in this one also we'll
add e.target target dot
files index zero like this. So here we
have added the handler function also
handle file change. Correct. Now we'll
add the handler function that will
handle the form submission. So let's add
const handle generate equal to
asynchronous add function
and in this parameter let's use e dot or
we'll add e colon
react dot form event and add the angle
bracket and provide
html
form element
and here simply provide event dot
prevent default. We will complete this
function later after creating the
backend server. So for now we have just
created this handle generate function.
And now let's link this function with
this form tag. So in this form tag we'll
add on
submit and provide this function. Now
just come here
in this upload zone. So in this upload
zone you can see we have added file. So
here let's add product image.
After that here we have onclear. So in
this on clear we'll add the add a
function like this and it will call the
setter function set product image and
provide null. So it will clear the
selected product image. After that here
we have the onchange. So in this on
change just add one arrow function.
Here we'll get the event and after that
let's add handle file change function
and in this one provide the event comma
and provide the type. So the type will
be product like this. Now we will
duplicate it
and in the second one we'll add the
label. It will be model image. So the
first one was product image. This is the
model image. After that here we'll add
file. It will be model image. After that
here we'll use the set function set
model image. It will be null. Then we'll
use handle file change. And here in this
string simply provide model. Save the
changes. After that we will come back to
the web page. So here you can see in the
left side we have two input field where
we can upload the images. You can see we
have the hover effect also. So the first
one is product image and the second one
is model image. Let me upload the image
here so that the uploaded image will be
displayed at this area. Correct? So we
can click here to open the
window where we can upload the image or
we can also drag the image here. So let
me just click here on this product image
and let me upload any product image from
here. So I'll choose this bag. So you
can see the uploaded image is displayed
here and after that if I hover on this
image it is displaying this cross icon
so that we can remove the uploaded
image. So if I click here you can see it
has been removed. Now again click here
and I'll choose another image. I'll
choose this one. So you can see this
product image is added here. And here we
have the name also for this uploaded
image.
Now let's upload the model image also.
I'll just click here and choose the
model image. So I'll choose this model
image. You can see it has been added.
So we have added the input field. Using
that we can upload the product image and
model image to generate our content.
Next we have to create the form in the
right side where we will add the input
fields to get the project name, product
name. Then we will get the product
description and we will get the aspect
ratio and after that we will collect the
user prompt. So let's just come back
here
in the VS code and we will come here in
the right column which is this one. So
in this right column first we'll add the
class name to set the width of this div.
So we'll add class name and width full.
Remove this text from here. Here we'll
add a div.
And in this one we'll add the label tag.
In this label tag we'll add HTML for
name. And uh after that we'll add the
label text that is project name. And
then we'll add the class name here and
provide block then text small and margin
bottom. Correct? After that here we'll
add the input field also. So let's add
input type will be text and after that
we'll add the id here. So in this id we
will use this one that is name. After
that here we have to add the value. So
in the value we will simply add the name
that is the project name. After that
we'll add onchange property also in this
onchange add the add function like this
and get the event here and after that
here we will use the setter function set
name
and in the set name just add e dot
target
dot value. So the available text will be
stored in the name state. After that we
have to add the placeholder also. So
we'll add the placeholder and here let's
add the text called name your project.
Then we have to add one more property
that is required. So this input field is
required to submit the form. After that
we will add the classes to decorate this
input field. So just add the class name
property. And here let's provide these
TIN classes and we'll add the classes in
the div also which is here. So here
we'll add the class name and provide
margin bottom four. That's it. After
that save the changes and let's open the
web page. So in this one you can see
here we have project name and this input
field. After creating this input field
for the project name, let's come back to
the VS code and I'll duplicate this div.
And in this second div, we have this
margin bottom. And with that we'll add
text gray 300. And after that here we'll
add the text called product name.
Instead of this project name we will add
product name.
And after that here you can see we have
this HTML for. So in this HTML for just
provide product name. And in this id
also we'll add the product name. Here
also the type will be text. And here we
have the value. So we'll add the value
here that is
product name and here let's add set
product name correct and uh after that
let's update this placeholder text also.
So in the placeholder text we will
provide enter the name of the product.
That's it. After that you can see here
we have second input field for the
product name.
Now just come back and uh here let's add
another div. So I'll just duplicate it.
And in this one you can see we have
margin bottom text gray 300. And uh
after that here you can see we have
label tag. In this label tag we'll add
the HTML for product description. Right?
And here we'll add the text called
product description.
in this label tag. After that we'll add
the aspan tag and in this aspan tag just
add small bracket optional and after
that here we'll add the classes also to
change the color of this span text. So
we will change the color and size. So we
have added text extra small and text
violet 400.
After this label tag here we have the
input right? So I'm going to remove this
input field from here. And here I'm
going to use text area. Let's use the
self-closing like this. Now in this text
area just add the ID which is this one.
Remove this name. And after that here
we'll add rows. Let's set four. Then
we'll add the value. So in the value
just add product description state
and after that we'll add onchange. In
this onchange function let's add the add
a function and get the event in the
parameter. And here we will use set
product description and provide e.target
dot value. Right now after that here
we'll add the placeholder also. So let's
add the placeholder and enter the text
here that is enter the description of
the product and then we'll add the
classes here. So just add the class name
property again and uh in this one we
will add these TIN classes. Now save the
changes and open our web page. So here
you can see we have this product
description which is optional and here
we have the text area input field.
Correct? Now after that we have to add
the aspect ratio. So I'll just come back
and uh copy this div just this one and
paste it here.
So just paste this div here and add this
closing div. Here we have margin bottom
text gray 300. Now in this one let's add
the label tag. In this label tag, simply
add the class name and provide block
text small and margin bottom four. And
here we'll add the label text called
aspect ratio. And after that we'll add a
div here. And in this div let's add the
class name
and provide flex and gap three because
we have to add two aspect ratio. So it
will be aligned side by side using this
flex. So here let's add one icon
rectangle
vertical icon and click on this
suggestion to import it from Lucid
React. If I scroll up you can see
rectangle vertical icon has been
imported from Lucid React package. After
that here let's add this self-closing
tag and then we'll add the on click
property. In this onclick property we'll
add the add function and provide setter
function set aspect ratio. And here we
have to add the value 9 is to 16. Right?
Then we'll add some classes here. So
I'll write class name property and here
we'll add the dynamic classes also. So
we'll add curly braces and back text.
Here I'm going to use these TIN classes.
So it will be applied in all cases but
here we will add the dynamic class using
this dollar sign curly braces and
provide the aspect ratio state. Then we
will check the aspect ratio that is 9 is
to 16. So if it is true so in this case
we'll add question mark and provide
ring violet 550
and then white 10 that is the
background. After that here we'll add
colon if it is false. So in this case
we'll add empty string. That's it. Now
just duplicate it.
And here also we'll add the icon. So
instead of rectangle vertical icon I'm
going to use rectangle horizontal icon.
It has been imported. Then we have the
on click set aspect ratio. So in this
set aspect ratio just provide
16 is to 9.
And after that again we have the same
classes. And here you can see the aspect
ratio equal to
9 is to 16. So let's reverse it. We will
add 16 is to 9 like this. And uh now
save the changes. After that we have to
add the text area where we can enter the
prompt. But before that let me preview
the web page. So I'll just come here and
you can see here we have the aspect
ratio. And here we have added two type
of aspect ratio that is vertical and
horizontal. If I click on second one,
you can see it is highlighted. If I
click on first one, it is highlighted.
It is working fine. It is because of the
dynamic classes. Now I'll just come back
here
and uh I'm going to copy this div that
contains the text area. I'll just copy
this and paste it here. So in this one
we have label HTML for so here we'll add
user prompt
correct and in this text area we have ID
so it will be user prompt after that
let's come here in this
label tag let's add the level text
called user prompt right then we'll add
the span tag and in this span tag we
have this optional it is correct and we
have the same classes here we will not
change it and then come to the text
area. So here we have value. So in this
value simply provide user prompt. Then
we will provide the setter function set
user prompt. It will be e.target dot
value. Then we have the placeholder. So
in this placeholder I'll enter this text
describe how you want the narration to
be. And after that here we have the
classes. So I'll use the same classes
here also. We will not change anything
just save the changes and we will open
the web page.
So you can see here we have the user
prompt.
Correct. So we can enter the details
here like project name then product name
then description. We can choose the
aspect ratio and we can enter the
prompt. Right now in the first input
field also we'll change the input text
color. So I'll just come back here
and uh just copy this text gray 300 and
paste it here in the first div.
Here we have margin bottom. Then we'll
add text gray 300. So now all the colors
are same. Now let me just clear it. And
after that here we'll add one submit
button so that we can submit the form to
generate our content. So we'll come back
to the VS code and here we have the
write column. Just come here
and it is closing here. Then we have
this div that close both column right
and here we have the closing form tag.
So just before this closing form tag
we'll add our button. So we'll add a div
here
and in this div we'll add the class name
flex justify center and margin top.
After that we'll add the primary button.
So if I open the sidebar and buttons tsx
file here you can see we have the
primary button and ghost button. Right?
So I'm going to import it. Let's come
here. we will write opening arrow
primary button. So you can see the
primary button has been imported here
from component/b buttons. Now let's come
here and uh let's add closing tag also.
Primary button opening and closing tag.
Correct? Now in this one we have to add
the text called
generate image or we will also add
generating
right. So here we'll add turnary
operator. So just add curly braces
is generating property true. So when it
is true we'll add this parenthesis and
provide this fragment. And here we'll
add
colon this parenthesis and this fragment
like this. So in the first case let's
add the loading icon. So just add
opening arrow. I'll move it here. We'll
add
loader to
icon and import it from Lucid React. And
uh in this one we'll add the class name
to animate it. So let's add size and
animate a spin. After that we'll add the
text called generating
like this. And after that here we have
this second case. So in this one also
we'll add the text and with that we'll
add the icon. So let's add this icon and
uh after that we'll set the size. Here
we will not add any animation and after
that we'll add the text called generate
image
like this. Now we will add the classes
in this primary button and this primary
button will be disabled when is
generating is true. So just add disabled
and provide is generating and then just
add the class name property and here
let's add these TIN classes.
Right now save the changes and we will
open the web page.
So here at the bottom you can see we
have this generate image button.
Correct? And if I just come back here
and I'll make it true.
Instead of this is generating here we'll
add true instead of this false. Save the
changes and come back here. So you can
see here we have this loading animation
and the text is generating and right now
this button is disabled.
Right? So when the content is getting
generated it will display the loading
animation and the text will become
generating. And after that if I make it
false you can see we have the text
called generate image
right. So now we have completed our
generate page where user can generate
the content using this product image
model image and adding the product
details and prompt. Next we have to
create our other page. So I'll just
click here on this community. So here in
this community page we have to display
all the content that is saved for
public. For that I'll just come back to
the VS code. To create our community
page we will open sidebar.
Here you will find community.tsx file.
Now in this one we have to display the
generated content. For that we will
create one state and in that state we
will store all the created content data.
So before this return a statement let's
add con
and then we'll add the state name
projects. Then we will add the setter
function set projects
equal to
use a state.
And here we will add the initial value
that will be empty array. And after that
here we will add angle bracket. And here
we'll add the type for this data. So
let's define the type. Here in this
types folder we have index dot ts file.
Right? So here we will define the type
for our
project. So again copy this export
interface and write project like this.
Now in this project first we will add
the id and the type for this ID will be
string. Then we will add the name that
will be the project name. Here also
we'll add the type string.
After that we'll add the user ID. And
here let's add type a string.
In this name we will add question mark.
And uh let's add it here in this user ID
also. After that we'll add user question
mark. And here we'll add the user and we
have to define the user type also.
You can see we have added user here. And
let's define the user type also. So here
we'll add
export
interface
user and in this one we'll add the ID.
So the ID will be a string. Then we'll
add the name and it is a string. After
that we'll add the email
and uh for this email we'll add a
string. Here also we will add this
question mark. ID, name, email and the
type is a string. And here we have added
user property and the type is user.
After that let's add
product name and for this product name
we'll add the type a string. Then we
have to add product description and in
this product description we will add
question mark.
Then we'll add user prompt.
After this user prompt we will add
aspect ratio. So the type will be
string. Then we will add target length.
It will be number. Then we'll add
generated image
and it will be type a string.
Then we'll add generated video.
So the type will be a string. Then we'll
add is generating it will be boolean.
And then we'll add is published. It will
be boolean. It could be true or false.
Then we'll add error. So the type will
be a string. And after that we'll add
created at. The type will be date or a
string. Then we'll add updated at. It is
also date and a string. Then we'll add
uploaded images.
and we'll add a string array. So we have
added the type for the project and after
that we will come here in our community
dot tsx file and in this angle bracket
just add
project and click on this suggestion. So
you can see the type project has been
imported from types correct and here
we'll add this
array.
After that here we will add one state.
For that we'll add con
then loading and the setter function
name is set loading equal to use a state
and initialize it using true. So by
default the loading state will be true
when we open this community page because
it will take some time to load the
project data. So till then we have to
display the loading a screen. That's why
I have added this loading state true.
After that we will add the function that
will get executed and fetch the project.
So I'll write con fetch projects
equal to
a sync add arrow function.
Now in this function we will add some
time out so that we can display loading
animation for few seconds. So just add
set time out add this function and here
we'll add the time delay
3,000 milliseconds that is 3 seconds and
uh in this function just add the setter
function set projects and here it will
add the dummy data. So let's add dummy
generations and you can see the dummy
generations has been imported from our
asset. And after loading the dummy data
we will set the loading
false. So just add set loading and make
it false so that it will hide the
loading animation after 3 seconds. Now
we will add the use effect so that
it will execute this function whenever
the component gets loaded.
So here we have added this add a
function and dependency array which is
the empty array and in this function
let's call the fetch projects that's it.
So when we will open this page, it will
call this fetch projects function and it
will fetch the projects
and it will wait for 3 seconds then it
will display the project's detail and
for 3 seconds it will display the
loading animation using the loading
state. So here you can see we have this
return. So in this return I'll write
loading question mark. So when the
loading is true it will return this div
and if it is false then we'll add colon
and then parenthesis and here we will
add another div
like this. So in this first div we will
add the class name
and here we will add some classes to set
the
minimum height and width. We have added
flex item center justify center and
minimum height is full screen. Then
we'll add the loader icon. So let's add
loader to icon and import it from lucid
react. And then we'll add the classes
for this icon. So here we'll set the
size 7 animate aspin and text indigo
400. You can see loader icon has been
imported. After that, if I save the
changes and open our web page
and refresh this community page,
here we have the loading animation
and after 3 seconds this loading
animation has been removed because it
will fetch the project's data after 3
seconds. Now just come back and we have
to display the project's data. So here
we have this div. So in this one again
we'll add the classes. So we'll add the
class name property here and provide
these TIN classes. Then we will add
another div here and in this one let's
add class name and provide the maximum
width and MX auto. So it will fix the
width and it will be aligned in center.
It will add equal space from left and
right side. After that here we have to
add the title and description and this
title and description will be displayed
in the left side. So here we'll add the
header tag.
Here we have header opening and closing
tag. Now in this one we'll add H1 and
write the text called community.
Then we'll add small text in P tag. So
here we have added this text. After that
if I save the changes and come back here
you can see here we have community and
this small description. So we'll add the
classes here. So let's start with the
header tag. In this header tag we'll add
margin from the bottom. Then we'll add
the classes in the title tag which is
H1. So here we have added these classes.
And then we will change the color in the
small description. So here we have added
the class name to update the color. If I
come back here, you can see the
title and description is looking good
for this page that is community page.
After that, we have to display the
projects list. Right? So, just come back
and after this header, I'll add comment
that is
projects list.
Correct? Now, we'll add a div.
And uh in this one we'll add the class
name and provide the classes
like this. And after that here we have
to get the projects list from this
projects. If I come back here you can
see we have the projects
state. So let's add cyl.
And after that here we'll add the add a
function and then add this parenthesis.
And in this one it will return the
individual project data. Right? So here
let's get the individual project in the
parameter and here it will display the
project data in this div. So for now let
me provide the project ID only. Here
we'll add curly braces
project do ID.
If I come back to the web page here, you
can see we have these project ID.
Correct? If I change it, if I add name,
you can see we have the project name. It
is not available here. Let me just come
back. Here we are getting the individual
generated project, right? So, in this
one, we have the ID and then we will get
product name. Let's add it here and open
the web page. So you can see here we are
getting all the products name correct.
So now we have to display these data in
a card. For that we'll create a separate
component right. So I'll just come back
here in the VS code and uh we will
create a new component called
project card. So here in the components
folder create a new file project card
dot tsx. Here let's add R A FCE to
create the component structure and I'll
remove this import statement.
Now in this one we will get some data
from props. So just add curly braces.
We'll get gen that is the generation.
Then we'll use the setter function
set generations. Then we'll get for
community it could be true or false. So
let's add the default value false.
Right? Now we have to add the type also.
So just add colon and again curly
braces. Now in this one just add zen.
And for this one just add project and
click on this suggestion to import the
project type.
Right? Then we'll add comma. And here
we'll add this one set generations.
And here we'll add colon provide
react dot dispatch. And then we'll add
this angle bracket.
And uh in this one we will again add
react dot set a state action.
And in this one again add this angle
bracket and provide project and array.
After that here we will add the comma
and provide this for community
and here simply provide boolean
and here let's add question mark.
That's it. So we are getting these data
as props. After that here we have to add
the functionality so that when we click
on the card it will open the new page
and we will also add some action buttons
like delete project or we can also add
the
buttons to download the image or video.
For that we will create the menu and
we'll also create the navigate function.
So before this return statement
here let's add const
navigate
equal to
use navigate and import the use navigate
from react router DOM. After that we'll
create the state for menu. So let's add
con open menu and the set function name
is set open menu equal to use a state
and here we'll add false. So by default
it will be hidden right after that let's
come here in this div. So in this div we
are getting this
generated content right. So here we will
add the key property.
In this key property provide this
generated content dot id. So it will be
unique. After that we'll add the classes
here. So just add the class name
property and I'll provide these telin
classes. Then we'll add another div here
and uh in this one again add the class
name property and here we will provide
these telin classes
like this.
After that here we have to display the
preview of our generated content. So
let's add the comment here preview and
uh then we'll add a div here like this.
And after this preview we have to add
the details also. So here we'll add the
comment details and add a div. So first
we'll display the preview that will be
image or video and after that we have to
display the details. So after adding it
let's come here in the first div that is
preview. So here
let's add generated content image. So
let's add curly braces. We will use this
gen dot generated image. Right? when it
is available. So the generated image is
available. So in this case we'll add
this parenthesis and uh here I'm going
to add the img tag
like this. We will add this img tag
image src and in this src simply provide
curly braces
gen dot generated image. After that
we'll add the alt tag. In this alt tag
simply provide gen dot product name. And
then we'll add some classes for this
image. So I'll provide class name
property. And here we'll add the dynamic
classes also. So just add curly braces
back text. And here just add these tele
classes. And after that we'll insert
some dynamic classes. So just add dollar
sign curly braces and use this gen dot
generated video. So if the generated
video is available then we'll add
question mark and here we'll add group
hover opacity zero. So when we hover it
opacity will become zero and else we'll
add colon provide group hover a scale 1
not five. So it will increase the size.
Right?
So after that if I come back to the web
page it will display this card. But we
have to mount this card first. So we
will open our community.tsx file. Here
you can see we have added this div. So
instead of this div let's mount our card
that is project card. It has been
mounted here. And here we'll provide the
props. So first let's provide the key.
In this key just add this project dot
id. After that we'll add the gen. And
here we'll add the project. After that
we'll add setter function set
generations. And in this one just add
set projects. And after that we'll add
for community. And here we will provide
true. Save the changes. And come back
here. You can see here we have these
images but it is using the entire space.
So I'll just come back here and come to
this project card.tsx file. And uh in
this one we will add the classes
for this div right where we have added
the preview. So in this one we'll add
the class name property
and in this class name property we will
add curly braces back text. Then we'll
add dollar sign curly braces. And here
we will add this gen question mark dot
aspect ratio. We will check for the
aspect ratio.
equal to
9 is to 16. If it is true, then we'll
add question mark. And here we'll add
the aspect 9/16.
Right? Then we'll add colon. And here
we'll add the other aspect ratio that is
aspect video. Right? And after that here
we'll add the extra classes like
relative. And we'll add overflow hidden.
That's it. Save the changes and come
back here. So now you can see here we
are getting these images
that is generated
content right and if I hover it you can
see it becomes hidden.
It is because the video is also
generated and when the video is
generated we will hide the image on
hover and we will play the video.
Correct? So let me just come back here
and uh here we have added this curly
braces. So just after this we'll add
another curly braces and in this one I'm
going to check for this video. Let's add
it here. We will add gen dot generated
video. If it is true, it means the video
is also generated. So in this case here
we'll add this parenthesis and provide
the video tag. So let me provide opening
arrow
video and use this closing tag. Now in
this one we will add the src.
In this src just add curly braces
gen dot generated video. Then we'll add
the muted. After that we'll add loop.
After that we'll add plays in line.
Then we'll add the classes. So here
we'll add the class name property
and I'll provide these TBIN classes.
Then we'll add the mouse move event. So
here we'll add on mouse enter.
Here we'll add the arrow function and
provide E and it will be E dot current
target
dot play. Right? So when we enter the
mouse it will start playing this video.
Correct? And after that let's add one
more property here that is
on mouse leave.
Then add the add function and event. And
here we will add e dot
current target dot
pause. So it will pause the video when
we remove the mouse. So after adding it,
we will come back to the web page again.
So you can see when we move cursor over
any image, it is playing the video.
Right? If I go to other one, you can see
it is playing the video. Let's move here
again. It is playing the video. So,
initially it will display the image. And
when we move cursor over that image, it
will remove the image and play the
video. Let's see other content also. You
can see it is playing the video.
Correct? Now, after that, we have to add
the badge here like it is generating or
generated. And we will also add if it is
published or unpublished. So just come
back to the VS code.
And uh here after this curly braces
let's add another curly braces. And here
we will check for the generated image
and generated video. If the image or
video is not generated then we'll
display the loaded icon. Right? So here
we'll add parenthesis not of gen dot
generated image
and let's copy and paste it here. We'll
add generated video. So if the image is
not generated and video is also not
generated. So in this case we'll add and
and here we'll add this parenthesis. And
here let's add one div.
And in this div we'll add the loader
icon. So just add loader to icon import
it from lucid react and for this icon
we'll add the classes and set the size
and animate a spin and we'll add the
classes for this div that contains the
icon. So here we have added this
classes. So it will be displayed when
the image and video is not generated and
after that we'll display the badge. So
here after this curly braces
here let's add the comment
a status badge and we'll add a div. So
in this div let's add the class name
property
like this and within this div we will
add the text. So just add the span tag
and the text is generating
right but this generating text will be
displayed if the status is is
generating. So here let's add curly
braces
gen dot is generating property and
operator and then we'll add this
parenthesis and in this one we will move
this aspan tag
like this and let's add the classes also
for this aspan tag right and after that
we'll add another curly braces so I'll
just duplicate this one and in this
second one we'll add the is published
property gen.published is true then
we'll add the span tag and here we'll
change the color. So here we will add
the green color. So you can see we have
added background green
and here we'll add the text called
published
like this and uh after that here we will
display the action buttons but this
action buttons will be displayed in the
other pages not in the community. So for
now I'll skip this one. Let me fold it.
Here we have the status badge. Right. So
after this a status pad we'll add the
action button later and after that here
we will add the source images that we
have uploaded. So let's add the comment
called source images and here let's add
the div. Now in this one we'll add the
position absolute. So we'll add the
class name and provide absolute right
three bottom three. And here we'll add
two images that will be product image
and model image. So I'll write img tag
here. img src and in this one we'll add
curly braces gen dot uploaded images
and index zero
right and after that we'll add the alt
it will be product
and after that we'll add some classes
here so we'll add the class name
property provide these classes then
duplicate it
in the second one we'll add again
uploaded images index 1. Here we'll add
alt tag it will be model. Now we'll
update the classes here. So we will use
the same classes but at the end we'll
add minus margin left 8.
That's it. Save the changes. And uh
after that here we'll add the animation
delay also. So in the second one we'll
add a style property. And in this style
we'll add curly braces. Let's add
animation
delay and it will be 3 seconds. Save the
changes and come back here. So here you
can see we have the product image and
model image over this card. Right? For
other one also you can see the product
image and model image. Right?
So we are getting the same
model image and product image for each
card.
Here we have headphone. Here we have the
camera. Then we have the headphone. Here
we have S and model image. So it is
working fine. Here you can see the
status published.
Here you can see generating
right here and also generating batch.
Here you can see generating batch.
Now after that we have to add the
details of this generated content like
we'll display the title date and we'll
also add the buttons buttons will be
displayed on other page not on the
community to add the generated content
details. Let's come back to the VS code
and scroll down. Here you can see we
have this details and this div.
Right now in this div we will add the
class name and provide padding four.
After that here first we have to add the
project title. Then we'll add the date
and aspect ratio. So let's add a div
that display all the details.
In this one let's add the classes. So
we'll add class name property and
provide flex item center justify between
and provide the gap. Now in this one
first we'll add the product name and
date in the left side and in the right
side we'll display the aspect ratio. So
we'll add a div here that will be for
the left side. Here we'll add the title
in S3. So just add jen dot product name.
Then we'll add the description in P tag.
So in this P tag we'll not add the
description. We'll add the date when it
was created. So just add created
colon curly braces and here we'll add
new
date and provide
generation dot created at property then
dot to local string and call this
function. Correct. Now after that here
we'll add curly braces and we'll write
gen dot updated at. If it is updated
then only we'll add this new data. So
just add and operator parenthesis and
here we'll add another p tag and in this
p tag let me just copy this and paste it
here. Here we will write updated
and provide new date gen dot updated at
like this. Now let's save the changes
and come back here
on the web page. So here you can see we
have the details like headphones then
created at correct and now let's update
the CSS also. So I'll just come back
here and uh in this div that is for the
left side we will add the classes. So
just add class name and provide flex
one. So it will use the entire space
available in the row. Now we'll add the
classes in the title which is in S3.
Then we will add the classes in the P
tag which is here. Now let's add some
classes in the second P tag that display
the update time like this. You can see
it is looking good here on the web page.
Right now after that we have to add the
aspect ratio in the right side. So after
closing off this div here we'll add
another div. And in this one let's add
text right. So it will align the content
in the right side.
And after that we will add a div. And in
this one just add the span tag. In this
span tag just add aspect
colon curly braces. Then gen dot aspect
ratio.
Correct. Now we will provide the classes
here. So let's add the classes for div
and then we'll add the classes for this
as span tag. So we have added these
classes for a span tag. Now let's come
back here. You can see here we have the
aspect ratio 16 is to 9 and here we have
9 is to 16 right
now after that we have to add the
product description if it is available.
So just come back
and uh we will come here
after this div
here let's add the comment that is
product description
and uh here also let's add the comment
like product
name
date aspect ratio. So here we have added
these details. Let's move it here. So
here we have the details like product
name, date and aspect ratio. Let's fold
this div. And here we have the another
comment.
And uh in this one just add curly braces
provide
generation dot
product description. If it is available
then only this parenthesis will be
displayed and uh in this one we will add
a div
and here we have to add some classes for
the div which is margin
top. So we have added the margin top
here and after that we'll add the text
inp tag that is description and let's
display the actual description here. So
we'll add a div here. Add curly braces.
Then gen dot
product description. Let's come back
here. And you can see here we have the
description also. Right? So we have to
change the size and color for this
content. So I'll come back here and uh
we will add the classes in the text
which is the description text. So let's
add the classes here and after that
we'll add the classes in this div like
this. Save the changes and come back
here. So you can see this description is
looking good. After that we'll display
the user prompt also if it is available.
So I'll come back here
and uh
here we'll add the comment that is user
prompt
and copy this curly braces paste it
here.
Now in this one we will check gen dot
user prompt.
When it is true then we will add a div.
And in this one simply add
this div that display gen dot
user prompt and here we'll add the text
size that is extra small and text color
this one save the changes and uh after
that come back here. So here you can see
we have the prompt also right. So we
have completed our community page.
In this community, anyone can see the
generated content image and see the
video also. And then they can see the
product name, date, aspect ratio, then
description and user prompt.
Next, we have to add the similar card in
the my generation. But in the my
generations we will also add some
features like we can download or delete
these data and we will also add the
feature to go to view page so that we
can view individual project to create
the my generation page we will open that
page first. So if I open the VS code and
go to
app.tsx you can see the path / my
generations. So let's open it here. In
this browser we'll write localhost col
5173/
my generations. So this is the my
generations page. Right now we have the
navigation bar and footer. So here also
we'll display the same card with added
features. So just come back here in the
VS code and uh let's come here in the
pages and my generations tsx file.
Right. And in this one we'll add the
similar content. So I'll just copy the
data from here in this community.tsx
we have this state and functions. So
just copy this and paste it here.
Paste it here before this returned.
So here you can see we have the projects
and set projects. So let's rename it.
I'll write generations and the set
function name is set generations equal
to user state and import the user state.
Then we will add the project. So import
the project type from the interface like
this. And after that here we have the
loading. So we have added loading set
loading use state true. By default it
will be true. And after that we will
fetch the generations. So just change
the function name here. Con fetch
generations equal to async function set
timeout. And here I'm going to use this
setter function
set generations and provide the dummy
generations here. So just get the dummy
generations from asset. After that set
the loading false after 3 seconds and
after that this use effect will be
executed. So let's import the use effect
and it will call this fetch
my generations function
like this.
Correct. And after that here also we'll
add the loading animation if the set
loading is true. So just come back here
in the community and copy this one
and come here.
Here we'll add
loading question mark. If it is true
then we will add this div
right and import the icon
from lucid react here we'll add colon
and add another parenthesis and in this
one we'll add another div so I'll just
copy the div from here in this community
we have this div right so let's copy it
and paste it here in the my generations
right Now in this one first we have this
div with
the minimum height screen text white.
After that we have another div and then
we have the header tag. So in this
header tag we will update the text. So
let's add my generations. Then we will
add the
description here in this p tag. So here
we'll add updated description for this
page. After that here you can see we
have this div that is the projects list
or generation list. So let's add
generations list and then we'll add this
div. So here we have to display the
generated content list. So here we have
generations list right and uh after that
here we have a div and in this one I'll
provide this generations state add it
here. Then we have dot map and uh in
this one we'll get individual generation
just add zen and after that we will
mount the same card that is project
card. So let's import the project card
from here and after that we'll add the
key. It will be genid. Then we'll add
gen. It will be gen that is generations.
And here we'll add the set generations
and remove this for community because we
have added the default value.
Right? So here we have added
key gen and set generations. That's it.
And after that if I open the web page
here you can see we are on my
generations. And here also we are
getting the same content. Here you can
see we have the title my generations and
this description and here we have the
generated content image. When we hover
it we have the video and here we have
the descriptions also like product name,
aspect ratio, date, description and
provided prompts. Right now suppose the
my generation is empty. So in this case
we'll display the message. So just come
back here and uh
here let's add curly braces. After
closing of this div we'll add curly
braces and here we'll add the
generations dotlength equal to zero. So
in this case we'll add
a div
and in this div we will add the text in
s3. So the text is no generations yet.
So when the generations length is zero,
it will display this message. We'll add
the description also. So here let's add
the description
like this. And after that we'll add the
button also. So let's add opening arrow.
Primary button. So primary button
component has been imported. Let's use
the closing tag. And here we'll add
create new generation.
And when we click here, it will open a
new page. So just add
on click then add curly braces and here
we'll add
this add a function and then provide
window dot location
dot href equal to and provide /generate
correct and after that here we have the
p tag so in this p tag we'll add some
classes so let me provide the class name
property here and provide these classes.
Then we will come here in S3 and here
also we'll add the class name and
provide these classes. And now let's add
the classes for the div that contains
both title and description and button
also. So we have added the classes for
this div. Now after that let me clear
the data here. Here we have set
generations and in this one we have the
dummy data right. So let's add empty
array
and save the changes and come back here.
And here you can see we have this
message no generations yet. Here we have
the small text and then we have this
button create new generation. And if I
click here it will open this generate
page. Right now let me just come back
here
and uh refresh it.
So it will check for the data and if it
is not available it will display this
message. Now just come back and here
we'll add the dummy data again. So we
have the dummy generations. So this
dummy generated data will be displayed
here. If I refresh this web page
here you can see we have the generated
content dummy data. Right now we have to
add the additional function like we will
add the menu using that we can delete or
download the image or video or we can
also view this individual project in
generate page or preview page. So I'll
just come back here and open this
project card.tsx.
Right now in this one let's come here
before this source image. Right. So here
before this source image, let's add the
comment.
We will add action menu. Right? And it
is only for the my generations page. So
I'll write the comment here for my
generations only. Now here we'll add
curly braces. Write not of for
community. So if the for community is
false then we'll add and and here we'll
add div like this. Now in this div we
have to add the icon. So
we'll write another div and provide one
icon here.
Use this icon and for this icon I'll add
some classes like this. And now we'll
add the classes for this div. So here
we'll add absolute
top three right three correct and now
we'll add the classes for this div. So
in this one we'll add the class name
property and uh here let's add position
absolute. So here we have added absolute
right three top three here you can see
the opacity zero and when we hover we
will get the opacity 100 right. So after
that I'll just come back here.
You can see when we hover it we have
three dots right? You can see three dots
at top right side. Correct.
Now I'll just come back here and uh
after closing off this div. Here we will
add another div.
In this one we'll add flex
flex column.
Then items end width and text are small.
Now we'll add the ul tag and uh in this
ul tag again add the class name
property. So let's add the class name
property here and we'll add dynamic
classes. So just add curly braces back.
And now we'll add text extra small. Then
we'll add dollar sign curly braces and
provide the
open menu. You can see here we have the
state open menu and setter function
set open menu. Right? So let's come
here. We will add menu open a state and
we'll add question mark. If it is true
then we'll add block and if it is false
then we'll add hidden like this. And
after that we'll add the other classes.
So here we'll add other classes like
this.
Now in this one we have to add different
options in this UL tag. So just add
curly color braces and provide this gen
dot generated image. So if the generated
image is available so in this case we'll
add the a tag
then we'll add href
provide has here we'll add the download
property
then we'll add the classes also. So just
add the class name and uh here let's add
these classes correct and here you can
see we have added self-closing a tag. So
instead of this self-closing we'll add
closing a tag like this. And here we'll
add the text called download image. And
before this text we'll add the icon
also. So here we'll add image icon.
Let me move it in the new line. So you
can see we have the a tag and then we
have the image icon and for this image
icon we will set the size. So let's add
the size 14 and then text download image
right and uh after that let me just come
back to the web page. When we hover it,
you can see we have three dots but it is
not displaying our
menu items that is download image. For
that I'll just come back here and you
can see here we have added this div
for not of community. So in this div we
will add other properties. So let's add
a space here and here we'll add
on mouse down capture
and in this one let's add the arrow
function and provide
curly braces
set menu open
and true
and after that
let's add one more property that
on mouse leave
and uh here let's add curly braces
and provide set menu open and make it
false like this. After that if I come
back to the web page. So when we hover
it you can see here we have three dots.
And now when we click on three dot we
have this button download image. Right?
Let me move the cursor. So it will be
hidden. If I move cursor here we have
three dots. And if I click on three dots
we have download image. Similarly we
will add other links also. So I'll just
come back to the VS code and I'll
duplicate this one. Let's duplicate this
curly braces and uh here we'll add gen
dot generated video. So when generated
video is available we'll add this a tag.
We'll add download and then we'll add
the same classes here and then we'll add
the different icon. So let's add play a
square icon and import this icon from
Lucid React. And here we'll add the text
called download video.
Right after that we'll add another
button here. So let's duplicate it.
Now in this one we'll check
gen.generated
video
and uh let's add it in
small bracket here. We'll add or let's
add gen. dot generated image. So if the
image or video is available, if anyone
is available then we'll add button
right. So let me remove this a tag. From
here we will add the button tag. So we
have added this button and uh after that
here we will add text called share.
So the button text is share and before
this text we'll add the icon also. So
let's add share to icon from Lucid
React. And after that we'll add this
size also. So let's set this size 14
like this. Right now in this button we
have to add the on click property. So
here let's add
on click. In this on click we'll add the
add function. And here let's add
navigator.
And in this navigator we'll add dot
share.
Right? And after that we'll add curly
braces URL. In this URL just add the
generation dot
generated video. And if video is not
available then we will share the
generated image. So just add zen dot
generated image.
Then we'll add comma title. So in this
title we'll add gen
dot product name.
Then we'll add comma text. In this text
property we will add gen dot
product description.
That's it. And after that in this button
we'll add the classes also. So just add
the class name property. And here we
will provide these classes.
So it will add a share button. Correct?
And after that we'll add the delete
button. So here let's add one button
tag. Now in this button tag we will add
the icon and text. So I'll just copy and
paste it here. We will add trash two
icon
and then size 14. And we'll add the text
called delete. Correct? And after that
we'll add some classes also. So here we
will add the class name property for
this delete button and provide these
classes. And then we'll add the onclick
property also. So let's add on click. In
this on click we'll add the add a
function. And after that here we have to
call one function using that we can
delete the
content. So let's add handle delete. And
in this one provide the id. So just add
gen ID. So here we have added this name
but we have not created this function.
So let me create this function here.
I'll just scroll up and uh here
let's add
con
handle delete. So we have added const
handle delete and it will be
asynchronous add function
like this. And after that in this
parameter we'll get the id and the id
will be a string.
After that let's add const
confirm
equal to window dot
confirm and we'll add one message here.
Are you sure you want to delete this
project?
Right. And uh after that let's add if
statement if not of confirm. So in this
case just add return and suppose the
confirm is true. In this case we'll add
console log
and we will provide the id in console.
That's it. Similarly we'll add one more
function here. So I'll just copy this
one. Paste it here. And here we'll
change the function name. So I'll write
toggle publish. So we can publish and
unpublish any project. Here also we'll
get the ID. So let's add a sync
project id it will be a string and after
that remove this one
simply add console log and provide
project id. So we have toggle publish
function right now we will come back
here in the delete button. So here you
can see we have this delete button. We
have added this on click and handle
delete. That's it. If I save the changes
and open our web page and if I click on
this three dot here we have download
image, download video, share and delete.
If I click on this delete button, you
can see we are getting the message are
you sure you want to delete this
project? I'll click cancel.
Now if I click on this download image
and download video, it will not work. We
have simply added this anchor link with
hashtag right and here we have the share
button. If I click on this one, it will
allow us to share the video or image.
Now let's see this web page in a smaller
screen also. So I'll inspect this and
open in a small screen. So here you can
see by default this three dot will be
visible. If I refresh it, you can see
still three dots is visible. And if I
click on this three dot here we have all
the options like download,
share and delete. Right. Let's open it
in full screen
like this. Next we'll add the other
buttons at the bottom of this card. For
that I'll just come back to the VS code
and uh let's come here in this
details section. In this details section
we have this
user prompt right so just after this
user prompt here we'll add buttons
and after that we'll add curly braces
not of for community
and
then parenthesis and here let's add one
div. So we have added this div and in
this div we will add two buttons. So we
will add the grid layout. So just add
the class name and provide
margin top grid grid calls to and gap 3.
Then we'll add the ghost button. So just
import it. We'll add
ghost button from the buttons component.
And after that in this one we will add
some classes. So instead of this
self-closing let's add closing tag
like this
and here we will add the text called
view details.
Now we will add the class name property
and uh we will provide these classes.
Correct. After that here we'll add the
onclick property. So in this on click
property let's add the arrow function
and uh then we'll add color braces and
call the
navigate function. In this navigate
function we have to provide the path. So
just add back tick slash result and
after this result we have to provide the
ID. So just add slash dollars and curly
braces
gen ID. Right? And after that we'll add
the scroll two. So just add a scroll two
and provide 0 comma 0.
That's it. Now we'll add another button
that is the primary button. Right. So
I'll just
add a new button here.
Primary button. Close this tag. And in
this one we'll add the text called
publish or unpublish. So we will check
the status here. Just add curly braces
gen dot is published.
So if it is true in this case we'll add
the text called unpublish. And if it is
false so in this case we'll add the text
called
publish like this. And after that here
we have the prim button tag. So in this
one we'll add the on click also. And in
this on click just add the add a
function.
And uh then we'll add the toggle
function that we have created. So in
this one just add this gen dot id.
That's it. After that we'll add the
classes. So just add the class name
property and provide rounded medium.
That's it. Now save the changes and open
the web page. So you can see here we
have view details and publish.
And in the next one you can see view
details and unpublish because this
project is already published. So here we
are getting unpublish button and here we
have the publish button and here we have
view details. So if I click on this view
details it will open the new path. You
can see the URL / result/ gen1 that is
the generation ID or project ID. So we
have to create this page that is the
result page.
To create this result page, let's come
back to the VS code. We will open the
sidebar and open pages. And here you
will find results
file. I'll open this file. And uh in
this one we have to store the project
data. Here we'll get individual project.
Right? So let's create the state for
that. I'll write con
project and this setter function name is
set project data equal to
use a state and uh after that here we'll
add
empty array as
project and click here to import this
project type. After that here we'll add
the angle bracket and in this one also
we'll add this project.
After that we will create the state
variable called loading. So I'll write
con loading. And the setter function is
set loading equal to use a state. And
now let's initialize it using true. So
by default the loading will be true. And
after that we'll add one more state
variable. So just duplicate it. Here we
will use the state name is generating
and the setter function name is set is
generating and let's make it false. So
by default it will be false. Now when we
will load this web page we have to fetch
the project data, right? So here we'll
create a function. So I'll write cost
fetch project data equal to
async add a function
and uh in this one we will use the set
time out and in this set timeout let's
add the add function like this and here
we'll add time 3,000 milliseconds and
here we will use the set function set
project data and in this one let me add
any dummy project. So let's add dummy
generations
and index zero. So we will add the first
project. You can see dummy generations
has been imported from the asset and
after loading the project data we will
set the loading false. So just add set
loading and make it false.
Next, we have to execute this function
whenever component gets loaded. For
that, let's add the use effect also. So,
I'll write use effect.
And here we'll add the dependency array.
And uh let's call this fetch project
data function.
Correct? After that, let's come here and
after this return will add the loading.
then add question mark we are getting
the turnary operator. So if the loading
is true it will display this div right
and after that we'll add colon
parenthesis and here we will add another
div like this. Now in the first one we
will add the loading animation. So first
let's set the height of this div. We
will add the height
flex item center justify center. Then
we'll add the loader icon. So let's
import the loader to icon from leosid
react. And then we'll add the animate
class and we'll set the size and color.
So we have added this classes.
Correct. Now after that if I save the
changes and open our web page.
Let me refresh it. Here you can see the
loading animation for 3 seconds. After 3
seconds it is disappeared.
Let me refresh it again. Here you can
see the loading animation.
So after 3 seconds it will fetch the
project data and then we have to display
the project data. Correct? So let's come
here in this second div.
In this one also we'll set the screen
height. So I'll set min height a screen
then text white then padding and margin
and uh after that here we'll add another
div.
So in this one we will add the maximum
width and MX auto so that it will fix
the width of this layout and it will add
equal space from left and right side.
After that here we have to add some
title and in the right side we'll add
the button. So here I'm going to use the
header tag.
Now in this header tag we will add the
title in H1. So the title is generation
result.
And after that we have to add a link in
the right side. So just add the link
tag.
Import the link from react router DOM.
And in this link we will add the text.
So I'll write the text in P tag. So the
text is new generation
and with that we'll add the icon also.
So here let's add the icon.
We will use this icon and after that for
this icon we will set the size. So we
have added the width and height. And now
we'll add the
class name in this B tag. So we have
added
max SM hidden. So it will be hidden on a
smaller screen. In a smaller screen, we
will only display this icon. Now we will
add the path in our link tag. So here in
this link tag, we'll add the path /
generate. So when we click here, it will
open this page. Now we'll add the
classes also for this link. So here
we'll add the class name called btn
secondary. And then we have added other
classes for this link. After that if I
open the web page here you can see we
have this generate result and this link
generate
or new generation. Right now just come
back and we have to align it side by
side. So we will use the flex layout. So
come here in this header and provide the
classes called flex justify between item
center and margin bottom. Then we'll add
the classes in the title that is in H1
tag. So in this H1 we have added the
classes like text 2 XL, 3XL and font
medium. After that we will save the
changes and come back here. So you can
see in the left side we have this
generation result and in the right side
we have this new generation button.
It looks good. After that we have to
divide our content in two part. In the
left side we'll display the result. It
could be image or video. And in the
right side we will display the action
buttons like download image, download
video and if we have only image result
then we'll add the button called create
video right because using the generate
page we will just generate the image and
using that image we can generate the
video also. So I'll just come back here
and uh just after this header here I'm
going to add a div.
Now in this div we'll add the grid
layout. So I'll write comment here
that is grid layout and we have added
the classes grid grid columns 3 and gap
8. After that here we have to add the
two columns. In the left side we will
add the result and in the right side
we'll add the action buttons. So I'll
write the comment here
main result display and create a div
like this and after that add the
another comment sidebar actions and here
also I'll add the div.
So let's start with the left side. So in
this left side
we will add the classes. So we'll add
the class name property provide these
classes and then we'll add another div
here. And in this one we have to add the
class name property provide glass panel
then inline block padding and rounded to
excel. After that here we'll add a div
and inside this div we will either
display the video or image. So here
we'll add the turnary operator. Let's
add curly braces
project question mark dot
generated video. It means when the video
is generated. So in this case
we will use this parenthesis and here we
will add the video tag like this. And
after that here we'll add colon add this
parenthesis.
And in this one I'm going to add the img
tag.
It means when the video is generated it
will display the video. Else it will
display the generated image. Right now
let's complete this video tag. So in
this video tag we'll add the src
and in the src simply add curly braces
project. And in this project we will get
the
generated video. After that we'll add
controls.
Then we'll add auto play.
After that we'll add loop.
And then we'll add the classes. So I'll
write class name property here. And here
we'll set the width, height and object
cover like this. Now come to this img
tag. Here also we'll add
project dot generated image and then
we'll add the alt tag. In this alt tag
we have added generated result and then
we'll add the classes here. So we'll add
the class name property and here also
we'll set the width, height and object
cover. So we have added video or image
right now we'll add the classes in this
div that contains this
video or image. So here we have to add
the dynamic classes. So we'll add the
class name property here and add curly
braces back text and here I'll write
dollar sign curly braces and use the
project
question mark dot aspect ratio. We will
check the aspect ratio of this project.
So here let's add 9 is to 16.
Right? So in this case we'll add
question mark and provide the class name
that is aspect 9/116.
Then we'll add colon and here we'll add
another class name that is aspect video.
Correct? Now after that we'll add some
other classes also. So
let me move it here. We will just cut
this curly braces from here and paste it
here.
Now it is correct. You can see the
statement here we have dollar sign curly
braces and in this one we have project
dopect ratio equal to 9 is to 16. If it
is true it will add aspect 9/16
else it will add aspect video. Right?
Now after that let's add the other fixed
classes. So here we have added these
other classes. Right?
Now save the changes and we will open
the web page. So here you can see in the
left side we have the video right
because the video is already generated
for this project
and suppose the video is not available
then it will add the image also. So I'll
just come back here and now we will
create the right sidebar. In the right
side we have to display the action
buttons. Correct? So here we have a div.
So in this one we'll add the class name
and provide a space y6.
So here we have to categorize the action
buttons in two category. In the first
one we'll add the action button like
download image or download video. And in
the second one we will add the button
called generate video. Right? So let's
add one div. And before this div I'll
add the comment download
buttons.
And uh after that let's add another
comment and div like this. Here we'll
add generate
video button. Right now let's come here
in this div and here we will add some
classes. So I'll write class name
property and provide these classes and
then we'll add the text in S3. So the
text is actions.
After that we will add a div. And in
this div we will add two links. Right?
So here we'll add the a tag.
In this a we will add the
download property.
And uh after that here we have to add
the button tag within this a. So let's
add ghost button component. It has been
imported. Let's close this tag. So we
have ghost button open and closing tag.
Now in this one we will add the icon
also. So I'll write
image icon imported from Lucid React.
And for this image icon, we'll set the
size 4.5.
And after that, we'll add the text also.
So the text is download image.
Correct? Now after that, we will add the
classes in this ghost button. So we'll
add the class name property and provide
these classes. And then we'll add one
more property here. So let's add a new
property
called disabled.
and equal to
not of
project dot
generated image.
So if the generated image is not
available then it will be disabled.
Correct? Now let's come here in this
href. So in this href
I'll add curly braces project
dot generated image.
So it will download this image.
Right now after that we will add the
classes in this div that contains the a
tag. So here we will add the class name
property provide flex flex column gap 3.
And now we'll set the font size and font
weight in this text. So here we have
added text excel font semi bold and
margin bottom four.
Correct. Now let's duplicate this a tag.
So I'll just duplicate this one. And in
the second one we'll add
project dot generated video. And after
that here we will use the same classes.
And we have the disabled property. In
this one, we'll add not of
project dot generated video. So if the
generated video is not available, it
will be disabled.
Right? And uh after that here we have
the image icon. So let's change it. I'm
going to use video icon. And then we'll
add the text called download video.
It is correct. Now we will save the
changes and open the web page. So here
you can see in the right side we have
the actions called download image and
download video. And if I click on first
one you can see the image has been
downloaded. Let's open this image in new
tab. You can see we can download the
image that is used to create the video.
Right. After that I'll click on this
button download video. So you can see
the video is also downloaded. Right? You
can click here to play this video. Now
we'll add the other action button like
generate video. Suppose the video is not
generated. So we can use this button to
generate the video. So I'll just come
back to the VS code
and come here in this second div. Now in
this one first we'll add some classes.
So let's add the class name property and
provide these classes. Then we'll add a
div here. And in this div we'll add the
video icon.
And for this one we will set the size 24
like this. And after that here we'll add
the position absolute for this div. So
we'll add the class name absolute top
zero right zero and padding and opacity
10. Then we'll add the
title and a small description. So we'll
add the title in S3 tag and the title
text is video magic.
Then we'll add the description in P tag.
So the description is this one.
Right. Next we will add the classes also
for the title and description. So in
this title we have added these classes
and for this description we will change
the text color, text size and margin
bottom. Now we'll open the web page.
Here you can see we have this video
magic title and this description and
this video icon in the right side which
is having opacity 10% only. Right after
that I'll just come back here and just
after this P tag I'm going to add curly
braces not of project
dot
generated video. So when the generated
video is not available. So in this case
we'll add this parenthesis and provide
one button. So let's add
primary button component
like this. And in this one we'll add the
button text called generate video.
Right? And suppose the generated video
is available. So here we'll add colon
provide second parenthesis and in this
one we will add a div
and in this div we will simply add a
message. So here let's add the message
called video generated successfully. Now
if I save the changes open the web page.
So here you can see the text video
generated successfully because you can
see the video is playing in the left
side
right and suppose the video is not
available it will display the button
called
generate video and with that generate
video button we'll add the icon also. So
here let's add the icon also. So we'll
add a sparkle icon. It has been imported
and here we'll add the size four.
Correct. Now after that let's add the
classes here. So I start with this one.
In this last div we will add the class
name property
and uh provide
these tele classes. Save the changes and
come back here. You can see it is
displayed in green text. Right? So you
can see the message video generated
successfully. After that just come back
here and now we will add the
functionality in this primary button. So
when we click on this button it should
generate the video and for that we have
to create a function also. So let's
create a function here. I'll scroll up
and before this use effect we'll add con
handle generate video equal to
asynchronous arrow function.
Right. And uh after that in this one we
will simply use setter function set is
generating
and let's make it true.
So when we click here it will start
creating the video and it will set the
generating true. And after that I'll
just come back here in this primary
button. In this primary button
we will add the onclick property. So
let's add on click and provide
handle generate video function.
Correct. After that here we have to add
the disabled property. So let's add
disabled equal to and uh then we'll add
is generating. So when the is generating
is true it will be disabled. Then we'll
add the class name here and provide the
width full.
That's it. And uh after that I'll come
back here in this
primary button content that is the icon
and text. So here we have to check the
is generating property. So let's add
curly braces
and provide
is generating when it is true. So in
this case we will add this parenthesis
and provide this
fragment
and within this simply add the text
called generating video
right and after that here we'll add
colon and parenthesis
and in this one we will provide the icon
and text like this.
Let's move it here. Let's wrap it in
fragment. So I'll just add
fragment here and close it here.
Now we will save the changes and open
the web page. So you can see here we
have
text called video generated
successfully. It means the video is
already available. So if I come back to
the VS code and open our assets, we are
using the dummy data, right? So let's go
to assets and assets.tsx file. So in
this one we have this dummy generations
and we are using the first project data.
So in this one you can see we have
generated video and here we have the
video file. So let's remove it and here
we'll add empty string. Save the changes
and open our web page. Let me refresh
it. And now you can see here we have the
image only. You can see the video is not
playing because we have removed the
video. So when the video is not
generated, it will display image only.
And uh in the right side we have the
download image but download video is
disabled. Then we have this video magic.
And here you can see the button called
generate video. And if I click on this
button, you can see the generating video
text here. Right? And right now this
button is disabled.
So let me refresh it.
And after that you will find generate
video button again. So now I'll just
come back here and I'll here provide the
dummy video and once the video is
generated it will display the available
video also
and when the video is generated it will
display this message video generated
successfully. So now we have created
this result page also where we can see
the video or image result and we can
download it also. After that we will
create our plans page. If I click on
this plans you can see here we have the
navbar and footer only. So let's
complete this page. So I'll just come
back to the
VS code and open the sidebar
and go to pages folder and open
plants.tsx tsx file. Now in this one
here we have a div. So in this one we'll
add the class name and provide the
padding y. So we have added max sm
padding y 10 and for sm padding top 20.
Now after that here we have to mount our
plans or pricing component. If I open
the components you can see here we have
the pricing.tsx which is the component.
So let's mount it here.
So let's add pricing component like
this. And you can see the pricing
component has been imported. After that
if I save the changes and open our web
page here you can see we have this
complete
title and price table.
Correct. Now after that
we will add some text at the bottom. So
I'll just come back here and after this
pricing component we'll add the text in
P tag. So in this P tag let's add text
called create a stunning images for just
five credits. Then we'll add and
generate impressive videos for 10
credits.
So we have added this message correct.
Now after that here we have to change
the
color and font weight of selected text
like this one five credits and 10
credits. Right. For that we will wrap
this in span tag. But before that let me
move this one inside this P. Here we
have this P tag. And in this P we will
add the classes and provide
text center.
Then we will provide text gray 400. Then
maximum width. Then text
small. And then margin by and MX auto
and padding X. If I come back here, you
can see here we have this text
at the bottom. Right now we'll add the
different color here in this five
credits and 10 credits. So just come
back and uh let's add the span tag
before this five credits. Let's add a
span opening and closing tag and move it
here. Similarly, we'll add the span here
and move it here.
Right now we'll add the classes here in
the span tag. So we will provide
class name text indigo 400 and font
medium. And in the second span also
we'll add the same thing. Here we have
added text indigo 400 font medium. Save
the changes and come back here. So you
can see the color has been updated for
five credits and 10 credits. Correct.
Now we have completed our plans page
also. After that if I come back here in
the
VS code and you will find we have the
pages folder and in this pages folder we
have loading dot tsx file. So let's
complete this file also and uh here
let's add the
height for this div. We'll add the class
name provide height as screen flex and
flex column. And after that here we'll
add a div.
In this one we'll set the flex layout.
So I'll write class name flex item
center justify center and flex one. Then
we'll add the loaded icon. So let's add
loader to icon. And it has been
imported.
Right now for this icon we'll set the
size and animation. So we have added
these classes to set the size and
animation.
Correct. Now we will display this
loading for few seconds and after that
we will redirect the users on homepage.
For that here before this return a
statement let's add the use effect.
In this use effect we will add the
dependency array which is empty array.
And after that
in this function let's use the set
timeout.
So we have the set timeout and provide
the time
6,000 mconds. And in this function
simply add window dot
location
dot
href
and uh here we will add path that will
be slash. That's it. Save the changes
and I'll come back to the web page. But
before that you can see we have this
app.tsx tsx and you can see the path is
loading. So just copy this loading and
open the web page. And if I type the
localhost 5173/oing
it will display this loading animation
and after 6 seconds we will be
redirected to homepage. So now you can
see we are redirected to homepage. So
now we have completed the front end of
our project. Next we have to add the
user authentication.
Now we will start our next chapter where
we will integrate the user
authentication in our project. It means
we will integrate the user sign in and
sign up functionality.
For user authentication feature we are
going to use color. It is most
comprehensive user management platform.
It also provides subscription billing
feature that allow us to create pricing
plan so that we can offer advanced
feature to our premium members.
Color also provides readytouse
components for user authentication and
billing that we can easily integrate in
our react project. So just click the
link provided in the description to sign
up on the color website. I'll click on
this link sign in and I'll sign in with
my existing account. I'll use my Google
account for sign up
and after that you will come to the
color dashboard. Here you need to click
on this button create application and
enter the application name. So here let
me write the application name
UGC ads
and after that here you can enable the
signin options. So I'll enable this
email sign in and Google sign in. You
can see the preview in the right side.
Here we have continue with Google and
enter email address. Now just click on
this button create application. You can
enable multiple signup option from this
list. I'll click here create
application.
So now we are in this collect dashboard
and after that we have to integrate it
in our front end project. So we have
created the front end using react. So
just click on this react icon. So here
we have the steps to integrate the clerk
authentication in react project. So you
can see the first step create react
application using weight. So we have
already completed this substep. Now you
can see the next step install color
right. So just copy this command from
this icon. Let's click here and copy it.
And after that we will open the VS code.
In this VS code we will open the
terminal. And you can see we are in the
client project and the project is
running. So let's stop it using Ctrl C.
And after that we will paste this
command npm install at color/color
react. Press enter. So it will install
this package. It is installing this
package. So let's see the next step. So
you can see the next step is to add the
environment variable. Right? And uh
after that let's create the env file
that is env file. We will come back here
in the
VS code. We will hide this terminal.
Open the sidebar and here we have the
client project. Right? So in this client
let's create a new file and write the
file name env.
And in this one we will paste this
environment variable. So let's click
here to copy it and paste it here. So
you can see we have provided with color
publishable key and here we have the key
also right and if this key is not
available here you can get it from the
dashboard and after that we'll see the
next step. So you can see the next step
is to open this main.tsx file and in
this one we have to add this
configuration right. So let's just copy
this
and come back here in the VS code. We
will open
src main.tsx.
And in this one
here, let's add this
con pubable key and import the
publishable key from the environment
variable that is env file. And here we
have added if not publishable key then
we will throw error missing pubable key.
Correct. And after that we have to wrap
our application. If I just come back
here you can see here we have this
next code where we have to import the
color provider and from this color
provider we will wrap our application.
Correct? So let's copy this statement.
import color provider. I'll copy this
line and come back here
in the VS code. Let's add this statement
here. Import color provider from at
color/color react and come here. And you
can see we have this browser router. So
before this browser router, let's add
color provider and close this color
provider tag like this. Now let's close
it here at the end.
So you can see the structure here we
have the color provider. In this one we
have the browser router and in this one
we have the app. Now in this color
provider we have to provide one more
thing. As you can see in this document
we have to provide the pubable key.
Correct? So let me just copy this and
paste it here. We have added publishable
key and it will be added from here.
Correct? Now in this one we will add the
one more property that is appearance so
that we can change the theme. So let's
add one property here or I'll add some
space here and then we'll add
appearance. In this appearance we'll add
curly braces and provide theme. In this
theme property, let's add dark.
Then add comma and provide variables and
uh in this variables we'll add curly
braces and provide color primary and
provide our primary color code like
this. Then add comma and here we'll add
color text on primary background. And
here we will add the white color. You
can see we are getting the warning here
for this dark. So we have to import this
dark theme. So let's come here. We'll
add import
curly braces
from at
color/
themes and from this themes we will get
dark. And here we are using this package
color/ themes. So we have to install it.
So let's open the terminal again. And
here we'll add npm install
at color/ themes. So it has been
installed. After that we can start the
project using npm run div. So the
project is running. Let's hide this
terminal.
And you can see we have added this theme
dark and then variables. In this one, we
have provided the color primary and
color text on primary background which
is white. After that,
let's see the next step. So you can see
now we can use the color components like
we can use the sign-in component, sign
out component, user button, user signin
button, right? So we can simply use the
components on any part of our
application. Right? So let me just come
back to the VS code
and uh now we will open our navbar. Here
we have the components. In this
components we have navar dot
tsx file. Right. So in this one we have
to add the functionality so that when we
click on the login button it will open
the login or sign up form. For that
here first we'll get the user data. So
let's come here at the top and let's add
space here
and provide const
and then we'll write curly braces
user equal to use user and import the
use user from this color package.
Now we have the user data here correct
after getting this user data we will get
the components also that is open sign in
and open signup right so here let's add
const
curly braces
equal to and I'm going to use
use
color and you can see the use color is
also imported from the same package Now
from here we can get
open sign in and let's add comma
open
sign up like this. After that let's
scroll down. So first you can see we
have the logo. After that we have the
menu items which is menu links. And then
we have this div. So in this div you can
see we have
sign in button and get a started button
correct. So in the first button that is
sign in here we'll add on click property
and in this on click we'll add the add
function and call
open signin function.
That's it. And after that let's come to
this second button that is get started.
So in this one also we'll add the on
click. So just copy this one paste it.
Here we have on click and here we will
update the function that is open
sign up.
So it will open the sign up form. Right
now these buttons will be displayed if
the user is not logged in. If the user
is already logged in then we'll display
the user icon and when we click on that
user icon it will display all the menu
items. So let's add turnary operator
here we'll add curly braces
not of user.
We are getting the user data from use
user. So here we'll add question mark
and this parenthesis.
So when the user is not logged in it
will display other content and if the
user is logged in then we'll add colon
and this another parenthesis
and uh in this one let's add a div
and let's add div here in the first one
also. So in this first one we'll paste
this one just copy or cut this div and
paste it here. So now you can see the
structure
here. We have this turnary operator. If
user is not logged in, it will display
the sign-in button and get started
button. And if the user is logged in, it
will display another div which is here.
Now in this div we have to add the or we
have to display the credits and we'll
also display the user icon or user
profile image. So
in this one let's add
class name and provide flex and gap that
is gap 2. And after that first we'll add
ghost button. So let's add
ghost button. It has been imported
and uh in this button we'll add the text
that is credits and uh after creating
the back end we'll display the actual
credit value here. Right? But for now we
have just added this text. And after
that here we'll add the classes also. So
just add the class name property and
provide these classes. And when we click
on this credits it should open the plans
page. Right? For that we have to
navigate the users on other page. So
here I'm going to use the use navigate.
So let's come here and provide
const
equal to
use navigate and the use navigate has
been imported from react router DOM.
After that let's come here in this
credits button we'll add
on click.
In this on click let's add the add a
function and call this navigate
function. And in this navigate function
we have to provide the path. So the path
will be / plans. It will open the plans
page.
Right now after this button we will add
the user button and we have to get the
user button from color. Correct? So
let's come here
and you can see here we have this use
color use user. So here only we will get
the user button component
right and after that let's come here
and provide this component
user button like this.
So we have added this user button
component. It will be displayed when the
user is logged in. Now after that if I
open the web page.
Let me refresh it. So here you can see
we have this sign in and get started. If
I click on this get started, it will
open this sign up page. Create your
account. We can create the account using
Google or we can also enter the email
id, password and first name, last name,
right? And if I click on this sign in,
it will open this signin page. We can
enter the email id or we can sign in
using Google account. So let's continue
with Google. We can create an account
here. Here I'll choose the email ID and
after that I'll click on this button
continue.
So after sign up you can see we are
redirected to homepage and here you can
see in the top right side we have the
credits and here we have the user
profile image. If I click here it will
display this drop-down where you can see
the profile image then name email id and
sign out option. And here we have manage
account. If I click on this manage
account here we have the option to
update the profile details like name and
image. We can also update the email id
and after that you can go to security
and here you can update the password or
you can also delete the account.
So you can see when the user is signed
up then we have to display this user
profile image and here we have two menu
items. Now in this one we'll add other
items also. So I'll just come back to
the VS code and within this user button
here we'll add user button
dot
menu items and close this tag. Correct.
Now in this user button menu items we
will add the action buttons. So let's
add user button dot action and it will
be self-closing tag like this. Now in
this one we have to add the button text.
So we'll add the label. And in this
label just add generate.
After that we'll add the label icon. So
here we will add label icon property
equal to curly braces. And here let's
add sparkle icon from lucid react. So we
have added this icon. And for this icon
we have to set the size. So let's add
the size 14.
After that in this one we'll add the on
click property also. So here we'll add
on click
and let's add the add function and now
here we'll add the navigate function
and in this navigate provide the path
that is / generate. So it will open this
generate page. So we have added the
action link or button. Correct. After
that, let's duplicate it. Now, we'll add
the next button called my generations.
So, here we'll add the text my
generations. And in this icon, we will
add folder edit icon. It has been
imported from Lucid React. And here
we'll add the path. So, just add /
my generations. Now, just duplicate it.
And here we'll add
text called
community. And here we'll add the icon.
So let's add gallery horizontal
end icon. It has been imported. And
after that here we'll add the path /
community.
And after that let's add one more icon
here. So just duplicate it.
In this one, we'll add text called
plants.
So the label text is plans. Then we'll
add the icon here that is dollar sign
icon. And after that we'll add the path
called plans. So just add / plans. Save
the changes and open the web page.
If I click on this user profile image,
you can see here we have generate my
generations community plans manage
account. Right after that, let's open
this browser in small screen. So I'll
change the browser size. So now you can
see we are in this small screen and if I
click here, it is displaying these menu
items and if I click here, it will hide
it. So when the user is logged in, we
have to hide this menu icon because we
have already added all the links here.
Correct? For that, I'll just come back
here in the VS code
and just after this user button, you can
see here we have button tag. In this
one, we have menu icon. Correct? So here
we'll add curly braces and then we will
add
not of
user
and so when the user is not available
then only we will display this button.
So let's move it here like this. After
that just come back here. So now you can
see that menu icon has been removed
because we have all the items here in
this drop-down generate my generations
community plans manage account sign out
correct and after that if I log out from
this account
so after log out here we have the menu
items and using this menu items we can
go to different pages and here we have
get started and signin button again so
we'll add the functionality on these
buttons also
So let's close it and come back here in
the VS code and uh let's come here. Here
you can see the button text sign in and
here we have get started. So in this one
let's add comma and provide
open signin function.
We'll add the semicolon here. Now it is
correct. Let's wrap it in curly braces
like this. So we have added curly
braces. In this one we have set open
false and open sign in. And in this
second one also we'll add the another
curly braces like this. And then add
semicolon and provide open
signup function like this. Save the
changes and open the web page. Now if I
open this mobile menu and click on sign
in, it will open this
sign-in form. Let's close it and click
here on get started. So it will open
this sign up form. Right? And we can
also open the sign in and sign up from
same component. If I click on this sign
in and here we are getting this sign up
link. If I click here, so it will
display the signup form and we can
switch from here. Click here to sign in.
So we have added the user authentication
in our project. Next we have to display
the plans also. So right now you can see
here we have the plans like this. So
instead of using this static plan data,
we will get the plans data from the
color. Right? So that we can enable the
color billings also. So we will come
back here in the
color dashboard. Let's go to configure.
In this configure, scroll down. Here we
have billings. Then go to
settings
and here you can see we have this option
enable user billing. So let's click on
this toggle button.
Click on save. So we have enabled the
user billing and after that we have to
create the plans, right? So you can see
in the left side we have subscription
plans. So just click here and here we
can create different plans.
So by default you can see here we have a
free plan. So in this one we have to add
the features also. So let's click on
this one. So you can see we are in this
free plan and you can see the key free
user. After that here we have to add the
features. So just click on this add
feature button and here we'll add the
feature name. So let's add 20 free
credits. After that we'll add new
feature. Let's click on create feature
and we'll add new one. Click on add
feature and write the feature name a
standard quality. Create.
Then we'll add next feature that is no
watermark. Create.
Then we'll add new feature
slow generation speed
and after that we'll add email support.
So we have added
total five features. Click on save.
It is saved. Now just come back here in
the plans. And now we'll create the next
plan. So click on this button create
plan and we'll write the plan name pro.
like this and after that here we will
add the features also and we have to add
the price also. You can see we have
monthly base price. So let's add $9. You
can also add the discounted price when
the user subscribe for annual plan. So
you can see we have the option to enable
the annual discount and here we can
offer the discounted price. So I'll
disable it. I'll keep the monthly price
only. And you can also enable the free
trial. If I enable it and provide the
days like 7 days, so user can explore
this plan for 7 days without making the
payment. So let's disable it. I will not
provide this free trial. If you want you
can enable it. So let's click on save.
And after that here we'll add the new
features. So I'll click here
and here it will add the new feature
that is 80 monthly credits. So let's add
new one.
After that we'll add HD quality
in the next one.
After that we'll add no watermark. So I
think no watermark is already there.
Let's use it.
After that we'll add video generation.
And after that we'll add priority
support.
So here we have no watermark video
generation and priority support.
Let's add it again. Here we'll add
80 monthly credits. Create it already
exist. So let's close it. And let me
save the changes and refresh it.
So let me just click here again. And
here we have this 80 monthly credits.
I'll choose this one. And I'll choose
this one also. HD quality. And click on
apply feature to plan. So now we have
this one also. Let's drag it. I'll drag
this here and this one here at second
position. Click on save. And after that
we'll create the third plan. So let's
come here in the plans and let's create
a new plan
and here we'll add the plan name that is
premium and after that click on save and
here we have to add the price also that
is $29 and click on
save.
It is created. Now go to add feature.
Here we'll add 240 monthly credits. So
go to new feature. add this feature
create
it is added after that we'll add full HD
quality so let's add new feature here
after that we'll add no watermark here
so from this list we'll use no watermark
then we will use another one so just
click on apply to plan
others are removed so let's go to add
feature
Let's add 240.
And uh then we'll use full HD. And after
that we'll add no watermark. Apply. It
is added here. And after that click on
add feature. Go to new feature and
provide
fast generation speed.
Create. Then we'll add one more that is
chat plus email support. So let's add
new feature provide chat plus email
support. It is added here. Then click on
save.
So we have created three different
plans. Let's come back here.
After that you can see here we have the
pricing table tag that we can easily use
in our project and it will display the
price table. So let me just come back to
VS code.
Let's open this sidebar. Here you can
see we have the components and we have
pricing.tsx
file. Now in this one
first we have this section then a div
then title and after this title we have
a div where we are displaying the plans
data right and we are getting the plans
data from this assets dummy data. Right?
So let's remove it. I'll just
clear this div. So here we have this div
with grid layout. Correct. Now in this
one we will add our pricing table.
Before mounting the pricing table
component let me change the classes
also. Instead of grid we will use flex.
So here
let me remove it
and we will provide flex flex wrap item
center justify centered and then we have
maximum width 5 XL and MX auto and now
let's mount the pricing table component
so just add pricing table just click on
this suggestion you can see pricing
table has been imported from color and
here we have the
unused imports so let's remove it like
this
and uh after that let me remove this one
also and remove this one also. So here
we have title and pricing table and
after that let's close this pricing
table tag like this it will be
self-closing and now we will open our
web page. Let's refresh it. And here you
can see we are getting the pricing
details like free plan, pro plan and
premium plan. And here we have price and
it is always free only build monthly and
only build monthly. And here we have the
features also. So next we have to update
the theme color. For that we will come
back here
and in this one let's add the
appearance. And in this appearance let's
add curly braces and provide the
variables. Now in this variables let's
add the colored background and provide
none.
After that here we'll add comma and
provide the next property
elements and in this elements we will
provide pricing table card body.
And for this one, we'll add the
background white/6.
Then we'll add comma and provide
pricing table card header.
And for this one, let's add the
background white/10.
Then add comma. And here we'll add
switch thumb. And for this one, we'll
add background white.
That's it. After adding it, if I save
the changes and open our web page, so
you can see this theme is looking good.
It is matching with our project, right?
And if I go to homepage here also we
have the pricing table. So you can see
this pricing table is also same and it
is coming from the color. And if I click
on this subscribe,
it will open the sign-in page. So first
we have to sign in then only we can
subscribe to any plan. So I'll just
click on this continue with Google
and after that if I scroll down here we
have the pricing plan and you can see
this free plan is active by default. So
we have not subscribed any plan this
free one is active right. If I go to
manage account and here also you can see
this billing and here also you can see
we have the subscription which is the
free plan $0 and from here we can switch
different plan like this or we can also
subscribe to another one using this
button. I'll click on subscribe
and here we have the option to choose
another plan. So we can make the test
payment using this pay with test card.
So I'll just click here.
And now you can see the
badge here. Let's click on continue. And
you can see this pro plan is active.
And this pricing. If I go to manage
account here also you can see billing.
And in this billing you can see we have
pro plan right. And after that if I open
the color dashboard
and go to users
and I'll open this user details. After
opening this user details let's go to
subscriptions. So here you can see this
plan is active that is pro plan. So we
are getting the subscription details in
the color dashboard also and user can
also see the subscription details in the
pricing table and manage account section
like this. So we have added the user
authentication and subscription billing
using color in our project. Now we will
start our next chapter where we will
create the backend server of our
application. Before building the backend
server, let's understand what we are
going to create in the back end. So you
can see first we have to create the
backend server with express and typ
script. So this will be a basic express
server built using typescript. After
that we will connect our project with
database also. For that we are going to
use neon database. Then we are going to
use Prisma OM to manage and update our
neon database. After that here we will
use the color authentication and behooks
controller for color authentication in
our backend server so that we can get
the user data and store the user data in
the database. So let me show you the
flowchart how we are going to use the
color books. So in this web flow you can
see first we'll create the account that
will be the action or we can also update
the account and we will get the details
using the color authentication web
hooks. So using this web hooks we will
get the account creation updating and
deletion data and after that we will
store these data in database. So you can
see here we'll create the controller
function using that we can manage
account creation, deletion, updation and
we will also use plan purchase or
renewal.
Correct? And after that we will update
this data in neon database using this
Prisma OM.
Correct. Now after that you can see our
next step. Next we are going to use
error tracking using Sentry. entry is
performance monitoring and error
tracking online tool. After that we will
create the user controllers. If I come
to this flowchart
you can see here
we will get the user data and after that
we will use the middleware. We will
create the middleware that will check
the user is authenticated or not. If the
user is not authenticated, we will send
the error response. So if the user is
authenticated then we'll create the
controller functions to get the user
credits and we will also get the user
generations and we'll also perform the
publish or unpublish the content using
this controller functions and after that
we will update the data in database and
then we'll send some response to user.
So we'll create this user controllers.
Now let's see the next step. So after
that here we have to create the image
generation controller and video
generation controller. So for that also
I have created this workflow.
So here
we will send the image generation
request and after that we will verify
the user using the middleware. If the
user is authenticated then we will come
to this part and if user is not
authenticated we will send the error
response. So if the user is
authenticated so in this case we will
check for the user's available credit.
If the credit is available we will
deduct the credit and proceed for image
generation. And if the credit is less we
will send the error response. Suppose
the credit is available. So in this case
we'll generate the image using Gemini 3
pro model right and after generating the
image we will store the image file on
cloud nerdy and we will store the image
URL in database and we will send one
response to the user. Similarly, you can
see the
next flowchart. Here we will get the
request from user that is the video
generation request. Then we will verify
the user using middleware and if the
user is authenticated then we will check
for the credits and when the credit is
available we will deduct the credit and
generate the video using the VO3 model.
After generating this video, we will
store our video on cloud nerdy and store
the video URL in database and we will
send one response to the user. So let's
see the next step here.
So you can see we will create the image
and video and store our media on cloud
ner and then we will deploy our project
using hostingervp.
So let's start with the first point that
is creating a backend server with
express and typ script. And to create
the backend server we have already
created one nodes. If I open the web
browser and open
github.com/greatestackdev
which is the greatest stack dev github
repository. Here you will find this
notes. Just open it. And in this one you
will find basic express with typ script.
Let's open it.
Now in this one we have the a
step-by-step guide to create a express
server using TypeScript. So first we
have to create a folder like this. So
we'll create the folder with the name
server. So let me create it here in the
VS code. I'll just come back here in the
VS code and uh let me close all these
files. So right click and select close
saved.
Then let's fold this one which is the
client folder and after that here we
have the UGC project folder. So in this
one create a new folder called server.
So now we have client and server. Two
folders are there. In the client we have
the front end and in this server we will
create the back end. Now after that
let's right click on this server and
select open in integrated terminal.
After that we'll open the nodes here.
Here you can see we have to go to the
server directory in the terminal and
after that we will use this command npm
init-y. So let's copy and paste it here.
After that I'll come back here and you
can see the next command npm install
express. So just copy it paste it here
in this terminal.
We have added npm install express.
After that, let's see the documentation
again.
And in this one, we have these commands
that will install the TypeScript
and TS node then nodemon and type of
this express and type of node. So just
copy this one and come back here
in this terminal. Just paste this and
press enter.
It is installing this
package. After that we'll see the next
step. So next we have to create this
tsconfig do.json file. So I'll copy the
file name
tsconfig.json.
Or instead of creating this file, we can
also use this command. It will create
that. So just copy this command only and
come back here.
Let's paste it.
And after that you can see created a new
tsconfig.json
file. If I open the server folder then
in this one you will find tsconfig.json.
So here we have some default
configurations, right? So I'll just come
back here and I'll place this code in
that file. So just copy this
and clear this one
and paste the code that we have copied
like this. Now let's close it and let's
see the next step. Here you can see next
we have to create a server file. So we
can create server.ts file. Let's copy
the file name and come here in this
server folder. Create a new file and
write the file name server.ts.
After that just come back here and just
copy this code to create the basic
express server. So just copy this one
paste it here.
So here we have added import express
request response from express. Then we
have created one app using this express
and added a port number. And then we
have added the first route that is the
slash and when we will open this route
it will send the response server is live
and here we have added app.list that
will start the server. So in this one
you can see we have added console log
server is running at this URL. So it
will display this message in the
terminal. Now just come back here
and after that you can see we have to
update our package dot JSON file also.
In this one we have to add the start
server and build a script. Right? So
let's just copy this
and come back here. Open this package
dojson file. In this one we have test a
script. So let's remove it. And here we
will add this start server and build. In
this one we have added nodemon. So it
will start the project using nodemon.
Now let's come back here. You can see we
have to add the type module also. So
just copy this type module and let's add
it here.
Add a comma here. That's it. Now just
come back and after that we can start
our project using npm run server. So it
will start the backend server on port
3000. So just come back here open the
terminal.
In this terminal let's provide npm run
server. So you can see the message
server is running at localhost col 3000.
And here you can see we have another
terminal also where the front end is
running. Correct? So here we have the
first terminal where the front end is
running and this is the second terminal
where backend server is running at
30,000. So now I'll open the web browser
and here if I type localhost col 3000 so
you can see the message server is live
correct. So we have created the basic
express server. Now we will come back to
the VS code and here we will change the
port number. So if I open
this server.ts file instead of 3,000 I'm
going to use 5,000.
Right? For this port I'll write it in
uppercase like this. And let's write it
here also. Port and port.
After that here we will add the
middleware like this. If I add a space
here
and we'll add the comment like
middleware
and here we can use the app dot use
method and in this one simply provide
course but we have to add the course
package also right so we can allow all
the front end urls to connect with this
back end using this course. So we will
open the terminal.
You can see the back end is running. So
just add control C and after that we can
use the command course. So let's add npm
install
course and after that we'll add at
using this dash d we'll add dash d. So
we have added npm install course t- d
and provide at types/course
like this and press enter.
After that we'll add the envo. So let's
add
npm install
env.
That's it. Now we can start the project
again using npm run server.
So now the server is running. Let's hide
this terminal and in this app dot use we
can write course
and uh let's call this course and we
have to import it. So here at the top
we'll write import
course from course package and after
that here we'll add import
and let's add
env/config
so that we can use the environment
variables and uh just after this course
let's add app dot use and in this one
we'll add the express dot JSON. So all
the request will be passed using this
JSON method
right and after that
here we will add the environment
variable file also. So in this server
we'll create a new file and write the
file name.
So in this one we will store all the
secret variables or keys. So after
creating this file we can come here in
the server.ts file and here you can see
we have the port. So here let's add
process
dot env
dot port then we'll add or operator. So
if the port number is available in the
environment variable that will be used
else it will start the project on 5,000
port number. Right. Next we have to
connect our project with database.
Before connecting the project with
database. Let me open this package.json
file. And in this one you can see we
have added this course in dev
dependencies by mistake. So let me move
it. Let's cut it from here and we will
add it in this dependencies. So here
we'll add this course.
That's it. Save the changes and remove
this space. We have added both course
and at type of course in same command.
That's why both added in this dev
dependencies. So we have moved it in the
dependencies.
Right now after that we have to connect
this project with database.
To store our data we are going to use
neon database. Neon is a fully managed
serverless Postgress database built for
modern application. Neon helps
developers to build a scalable and
reliable apps faster. It comes with
powerful feature like branching and
autocaling that simplifies the
development and management. With Neon
free plan, you can create up to 100
projects and store.5 GB of data per
project. So just click on the link given
in the description to sign up and start
using Neon for free. So I'll just click
on this sign up button and I'll sign up
with my Google account.
After sign up you need to create a
project on Neon database. So here we'll
add the project name. So we have added
the project name UGC ads. And after that
here you can choose the cloud service
provider and choose the nearest region
and uh after that just click on this
create button. So let's click on this
button create. Now it is asking to
choose any of this. What are you working
on? So I'll choose the first one
building a new app and click on create.
Now after that you can see connect to
your database and here we have this
button connect. So just click here and
here you can see the connection string
that we can use in our project to
connect with this database to manage
this neon database. I'm going to use the
Prisma OM. So I'll search for
Prisma.
Open this website prisma.io.
So after opening this prisma.io just
open the talks from here.
After that let's click on this OM
and in the left side you will find quick
start. Just click here.
Then in the left side you will find this
postgra SQL. Let's click here.
And after that here we have the steps.
So here you can see the first step
create new project. So we have already
created our project. After that come to
the second step install required
dependencies. So we have to install the
Prisma and we have to install the Prisma
client adapter. Right? So let's copy the
first command
and open the VS code. We will open the
terminal
and project is running. So just at Ctrl
C and paste this command. Press enter.
So it will install the Prisma
type node type pg
and it is installing this package so
that we can see the next command. So
I'll copy the next one also
and come here.
So after completing this first command
we'll paste the second one.
So it is executed. Now let's paste the
second command and press enter.
It is also completed. Now we will see
the next step. So I'll come back here
and after that you can see the third
step configure EMS support. So this
configure ESM is not required. It is
already added in the project. Let's see
the next step. So the next step is to
initialize Prisma OM. For that we have
to add this npx Prisma. Just copy this.
Come back to the VS code. Open the
terminal and here we'll add this npx
prisma. Press enter.
It is done. Now see the next one. Here
we have this command. Just copy this.
So you can see this command will create
a Prisma directory and in this one it
will create a Prisma file that is a
schema.prisma file. It will also create
TNV file if it is not available and it
will create Prisma.config.ts
ts file. So just copy this command and
come here in the terminal. Paste this
command. Press enter.
After executing it, you will see the new
files in the left side. You can see here
we have the Prisma config.ts file. It
looks like this, right? And after that
you can see here we have the Prisma
folder. And in this Prisma folder we
have a schema.prisma file like this. Now
just come back. So after executing this
we have this Prisma config.ts file and
we have a schema.prisma file and after
that we have to update our env that is
env file. We have to add the database
URL.
So let's add it from the neon. I'll just
come back here. In this neon you can see
we have the psql. So just click here on
this it will open the drop-own menu and
in this one you will find NodeJS just
click here and then go to env
and you will find this database URL
let's copy it
and come back here in the VS code open
env file and in this one this is already
added right so we can replace it
this is the database URL that we have
copied from neon. Let's remove this
dummy URL. So let me remove this dummy
data from here.
So after adding this database URL again
come back to the documentation
in this quick start. So we have
completed this part
to add the database URL. After that you
can see define your data model. So we
have schema.prisma file. In this one we
have to create the models to store our
data right. So we have already created
the model. You will find the file in
asset folder. So just open the asset
folder that you have downloaded from the
video description. And in this one you
will find a schema.prisma
file.
Correct? So I'll open this file.
So in this file you can see we have the
generator client then database source DB
and after that we have two models that
is user model and project model. So just
copy this one. I'll just copy this
product model and user model from this
file
and after that I'll open this sidebar.
In this sidebar you will find this
Prisma folder. In this Prisma we have a
schema.prisma file. Right? So in this
one we have to provide our model. So
just paste the models here.
You can see we have user and project
model. After that let's open the
documentation again. So you can see the
next step. After defining the data model
we'll come to this step. Create and
deploy your first migration. For that we
have to add this command. Let's copy it
and open the VS code.
Then open the terminal and uh in this
terminal paste this command. Press
enter.
Now it is done. After that just come
back and copy the second command. npx
prisma generate. Copy this and paste it
here. Press enter.
It is also done. Now just come back here
and after that we have to create the
instance of Prisma client but before
that I'll open the neon database and
let's close it and if I open tables
so here you can see we have the project
table
and then we have the user table because
we have already created the model and we
have added this command called Prisma
migrate and Prisma generate.
So to create this instance of Prisma
client, we will come back here.
Let's copy this file name
Prisma.ts and come back to the VS code
and uh after that let's start the
project again using npm run server.
So now the project is running and after
that come to this server folder. In this
server folder, we'll create a new folder
called config.
In this config folder, let's create a
new file and write the file name
prisma.ts.
Now, in this one, just paste the code
from here.
Copy this one and paste it here. So, we
have created this Prisma client.
Right. After that here you can see we
have the Prisma client from this path.
So let me update this path.
We will write Prisma client
from generated/prisma/client
dot js. That's it. Just add the file
name extension. Now it is correct. Save
the changes. So after completing this
Prisma client we have completed the
setup of neon database. It means our
project is connected with neon database.
We can store the data in database. Next
we have to integrate the color o in the
back end also. Here we will use the
color behooks to get the user data and
store the user data in this database.
Now we have to add the color o in the
back end also. For that we'll come back
to the web browser and open color.com.
We will open the homepage and here you
will find docs. In this one you will
find go to color docs or you can also go
to this express. So let me just click
here
and from this dropdown just choose
express because we have created our back
end using express. And after that here
you can see we have the steps to add
color O in the back end. So first we
have to add this package npm install
color/express.
Let's copy this one and open the VS
code. Then open the terminal. Stop the
project using control C and add this
command.
We are installing it in the server
directory. Now just come back and see
the next step. So you can see here we
have the color pubable key and color
secret key that we need to add in the
environment variable. Right here we have
the values also. So simply click on this
to copy it and open the VS codeenv file
and in this env file just paste the keys
that we have copied. After that we will
come back here
and see the next step. So we have to add
env.
So we have already added it. After that
we have to add this color middleware in
our application using this app dot use
and we have to import this color
middleware from express. So just copy
this import statement and open our main
file that is server.ts TS file and in
this one just add this import statement
that is import color middleware from add
color/ express and after that just come
here we will add app
dot
use
and here let's add the
color middleware
and call it.
That's it. Now after that we'll come
back here in this document and uh see
the next step. So we can protect any
route using this required o. So we will
not use it. Let's see the next step.
This is also optional. So we have added
the color o in the backend server. Now
we will create a middleware that will
protect our route. So I'll just come
back
and open this server folder. In this
server folder we will create a new file
or first we'll create a new folder.
So in this one create a new folder
called middlewares.
And in this middleares folder create a
new file and write the file name o.ts.
And here we have to create a function.
So let's add export cost protect equal
to asynchronous add function. We have
created a function called protect. Now
in this one we'll get the request and
response and next function. So let's
import it from express. We will import
request response and next function from
the express package. And here let's add
request comma
response and provide
next like this. And after that here
we'll add try catch statement. And in
this try block we'll add con
curly braces equal to
this request dot o.
So this o will be added using
color because we have added it here. You
can see we have added color middleware.
So it will add this o property.
So from this request do we will get the
user id
right we will extract the user id from
here and here let's add the if statement
if not of user id if the user id is not
available in this request do so in this
case we will add return and provide
response dot a status
and provide the status 4.1 and then dot
json And here we will add the message.
So let's add the message called
unauthorized
right. And suppose the user ID is
available then we will simply call the
next function like this. Now we will add
the code in the catch block. So here
we'll add error colon any and then we'll
add response. So just copy this paste it
here. We will add response status 4.1
JSON. And here we'll add the message
property. In this message property,
let's add
error docode or we will provide error
dot message.
That's it. So we have created this
protect function. Using that we can
protect our route and it will check for
the user ID. If the user ID is
available, it will execute the next
function. It means it will execute the
controller functions and if it is not
available then it will
send the response with message
unauthorized. Here we are getting this
warning in this O because the type is
not defined here. So let's open this
sidebar. In this server we will create a
new folder and write the folder name
types.
Right. And after that in this one we
will create a file. So create a new file
here and write the file name express
d.ts.
So here we are defining the express
data types. So here let's add import
request from express.
After that let's add declared
global.
So in this global we'll add the name
space and then we will add this express
then add this curly braces and here
we'll add the interface.
In this interface, we'll add
request and for this request, we'll add
the O property.
It will be one add function
like this. And in this one, we have to
add the user ID property. It will be a
string. Then we'll add the has property.
It will be add a function. And it will
return boolean.
And in this parameter we'll get the
permission
any and after that here we will add the
plan question mark dot or we'll add
colon and it will be a string type.
After that we will add the file.
So the type will be any like this.
The server is stopped right now. So
let's start it using npm run server at
this terminal. So we have added the
o property here and after that if I open
the o.ts file you can see it is fixed.
So we have created the middleware. Using
that we can protect our route. Next we
have to create the controllers. Using
that we can store the user data in the
database. whenever user creates an
account or update the account details
through front end. So for that we'll
create a new file here. But before that
let me set up the web hooks. So I'll
open the web browser and open color
dashboard and go to configure
and in this one
here we have developers. In this one you
will find hooks. Just click here. Here
you can see this button add endpoint. So
I'll just click here
and after that I'll use this one with
six play. I'll click here and after that
here we have the list of events. So from
here we will subscribe the user events.
I'll scroll down. Here you can see we
have one more event called payment
attempt. So from this payment attempt we
will use this one updated.
Subscribe this payment attempt updated
and scroll down here we have the
user user created deleted updated. So
subscribe all three events here. So we
have total four events and after that
click on this button create.
So now we have created this
and in the right side you can see we
have this signing secret which is the
baybook's signing secret.
Let me reveal it. So here we have the
signing secret and after that we have to
set up the bbooks in our project. So we
will open the
docs page of this color and here in this
search box we'll search for bbooks.
Let's click here behooks overview. So in
the left side you will find web hooks
overview billing behooks and then
syncing data with behooks. Just click
here
scroll down.
So here you can see we have the code
that we can use to create the color web
hooks in our project. So for that we'll
come back to the VS code. Let's open the
sidebar. And here you can see we have
this server folder. In this server
folder, we'll create a new folder called
controllers.
In this controllers folder, create a new
file and write the file name color.ts.
And in this one, we have to create a
function. As you can see here we have
this asynchronous
adder function right so I'll just copy
this one and uh create a function here
and I'll write the function name const
color books equal to async arrow
function and after that here we have to
add the type also that is request and
response type so just import it we will
import request and response from express
and after that here we'll
colon request
colon response.
Right after that here we'll add try
catch block and then let's come here
and here you can see
we have to add this one in the try
block. So just copy this and paste it
here.
Now here we have to add colon any. So
the type will be any. And after that we
have to import this one. So to import it
here we have the import statement. I'll
just copy this and paste it here.
Now it is correct. After that we have to
add the key also. If I scroll up you can
see we have to add the color behook
signing secret like this. So just copy
this involant variable name and open our
env file. In this one just add this
color behook signing secret equal to and
paste the value from here.
Copy this
and paste it here. So we have added
color behook signing secret. Now after
that we will come back here in the
color.ts TS file and here we are getting
the event correct. So from this event
we'll get the data and type that will be
the event data and type. So let's add
the comment here
get data from request.
Right? So here I'll write con curly
braces data
and type equal to event.
Right? And after that we'll add the
switch case for different events. So
let's add switch cases for different
events. And we'll add
switch and key. In this key we will get
the type. Right? So after adding this
switch type here we'll add the case. So
in the first case we'll add the event
called user dot
created. So when this event will occur
in this case we'll add this object and
here we'll add
await and then we'll use the Prisma
client. So just click here to import the
Prisma from this file config prisma.js.
After that from here we'll use the user
model. So just add user
then dot
create. So it will create the user data
in the neon database. So here we'll add
the data property and in this data
property we will add the id. So the id
will be data do ID like this. After that
we'll add email.
We will store the email also.
So let's add the data question mark dot
addresses
index zero. Then we'll add question mark
dot
email address like this. After this
email here we will store the name. So
let's add the name property. In this
name property, we will add data dot
first name. We'll add the question mark
here. Then we'll add plus. We'll add one
space plus. And here we'll add data
do.last name.
After that we'll add the image also. So
let's add the image property. And here
let's add data question mark dot image
URL
like this. After that here we will add
break. So just move it here.
Correct. So here we have added the first
case. Now let me just duplicate it.
So in this one we'll update the event
type. It will be user dot updated. So
when the user gets updated. So in this
case we'll add await prisma dot user dot
update method
like this. And after that here we will
add
next property called where
and just add the comma here. Now in this
object we'll add the id and provide the
data dot id. So it will find the data
and update the data using this one. So
here we can update the email
name and image only. That's it.
And uh after that let's duplicate it.
And here we'll add the next case that is
user dot deleted. Right? So in this case
simply add await prisma dot user dot
delete.
Right? And after that remove this one.
And here just add where
id is data do ID. Let me move it in same
line like this. So you can see we will
use await prisma do user.delete method
and provide where
id is data do ID. So it will delete this
data from database. After that we'll add
our next case. So let's duplicate it and
here we'll add payment
attempt dot updated. We have already
subscribed this event. Now here we have
to add the
if statement.
If and here just add data dot charge
type equal to recting
or
data dot charge type equal to checkout.
Then we'll add and operator
like this. And here we'll add data dot a
status equal to paid.
So in this case we will add this a
statement called cost credits equal to
object. Here we'll add pro 80,
premium
240.
Right now we'll add con
color user ID equal to
data question mark dot pair
question mark dot user id.
After that we'll add the plan ID. So
just at con plan id it will be
key of
type of
credits equal to
data dot
subscription items
dot
index zero
question mark
dot
plan question mark dot slug.
Right? Now after that here we'll add the
if statement again and in this if
statement we'll add the plan ID not
equal to pro and just add plan ID not
equal to premium.
In this case just add return response
dot status 400 dot JSON. And here we
have to add the message. So just add the
message invalid plan
right and after that we'll add
console.log
and here just add the plan id
after that we'll add await and provide
prisma dot user dot
update. We will update the data in
database after
making the payment right. So here we'll
add
where and in this where just add the ID.
So the id will be
color user ID and uh after that here
we'll add comma and provide data that we
need to update. So in this data just add
credits and we will update the credits
property. Here we'll add increment and
provide
credits
and provide the plan ID.
That's it. So it will update the data in
database also. And here we have the
default case.
After that just come here just before
this catch block and we'll write
response dojson and here we'll add the
message. So just add the message
beook received and then we'll add the
type and after that come here in the
catch block. So in this catch block just
get the error in the parameter and here
we'll add the type any and after that
here we'll add response dot a status 500
then we'll add dot JSON and provide the
message. So the message will be error
dot message. So we have created this
beooks controller. So just export this
function from here. So here just add
export default color books right and
after that we have to create the
endpoint for this behooks. For that you
can see the code here
in this document.
You can see we have to use
the
API path. Then we'll add express dot raw
type application JSON and provide our
controller function. Similarly, we will
add the endpoint. So just come back to
the VS code, open our server.ts file and
in this one
here we have the first route. Correct?
So after that we'll add app dot post
and uh after that we'll add path that
will be /
api/
color
and then add comma and here we'll
provide the function that is color
behav
function has been imported from the
controllers folder and color.js JS file.
So we have created the color behooks
handler endpoint and after that we have
to add this endpoint in our color
dashboard.
But instead of adding this endpoint here
we will add it here just before this
express.json because here we will use
express raw. So we have added it here
and here we will add one more thing. So
just come here in this documentation
and you can see after this endpoint we
have to add express raw and provide this
type application JSON. Copy this one and
paste it here just after this comma
and add the comma here. Now it is
correct. Now we will save the changes
and we will add the endpoint in our
dashboard. So to get the endpoint
locally we will use this terminal. We
will open the terminal here and go to
ports. Let's click here
and after that here we'll click on this
forward a port. So I'll click here.
Now we have to enter the port number. So
our back end is running at port 5,000.
So I'll enter 5,000 and uh press enter.
And it is forwarding this port. So now
it is forwarded. Here you can see the
visibility private. So this port is
forwarded by default because my VS code
is configured with GitHub. So if it is
not configured when you will enter the
port number, it will ask you to connect
it with your GitHub account. So just
configure it and after that it will be
forwarded and here you will get the URL
and you need to change the visibility.
So right click here on this private and
go to port visibility and make it
public. Click continue.
So now you can see it is public and here
we have the forwarded URL forward
address right. So just copy it.
So I'll click here. Let me open it in
the web browser
or I can simply copy it and I will come
back here in the
color dashboard. So here you can see we
have this end point. So just click on
this edit button
and uh here we will paste our URL
like this and at the end we'll add /
API/color.
Make sure to add the same path that you
have added here / API/color.
So just add it here and click on save.
Now it is saved and after that we have
successfully configured the web hooks.
Now whenever the user create a new
account the user data will get saved in
the database. So I'll just come back
here. Let me refresh it.
And right now you can see we have one
user account also. So let me delete this
account from here. I'll go to
manage account
security delete
and type this text here and delete.
So it is asking for OTP because it is
the sensitive task. So I'll provide the
OTP to delete this account.
So after adding the OTP our account has
been deleted and now I'll click on this
get started and I'll sign up with my
Google account.
Click on continue
and our account has been created. Now we
will open the neon
dashboard and in this one we have the
user table. Just open it.
So it should display the user data here.
it is not available.
Let me check this issue. I'll come back
to the collect dashboard. Go to
configure and I'll open this developers
web hooks
and after that I'll click on this link.
So here you can see these events are
failed. So just click here user.created.
Scroll down and if I open it
here we have one error message cannot
read properties of undefined reading
zero. So let me just come back to the VS
code and here you can see we have this
controller function. In this one we have
added email. It will be data do email
addresses. So by mistake we have added
emails two time. So let's update it.
I'll correct this one. email addresses.
Now it is correct. And I think I have
added it in the second case also.
Let's scroll down. Here you can see we
have the second case. So here also we'll
add email addresses.
Save the changes. And uh after that I'll
delete the account and create another
one.
So let me open the manage account
security delete.
and get started.
Continue with Google.
And now we have created the account on
our front end. And after creating the
account, I'll check the database again.
Let's come back here. Go to user. And
now you can see here we have the user
data like user ID, email, name and image
URL. And here we have 20 credits
right and here we have the timestamps.
And here we have the projects. And we
don't have any projects right now. So
when we create the user or when we
update the user, user data will get
saved in the database using color web
hooks. But right now you can see we are
using a local URL using this VS code. So
whenever we will restart the VS code
this URL will get updated. If I open the
terminal port. So you can see here we
have this URL. So this URL will get
updated whenever we will restart the VS
code. So in this case we have to update
the URL here in this
dev section.
then only it will work. So for
development purpose we are using this
URL. So when we will deploy it online
we'll get a permanent backend URL. So we
will add the permanent backend URL here
after deployment and it will work at any
time. So finally we have completed the
color behook setup and we can save the
user data in database.
So after completing the color
authentication and beook controller now
we will add the error tracking in our
backend project. For that we will use
Sentry. Sentry is a tool that helps
developers find and fix bugs and
performance problems in their app. It
watches your code in real time, shows
you exactly where error happens and
tells you why they happened so you can
fix them faster. Developers use Sentry
to catch crashes, track slow code and
improve app quality before user notice
it. So just click on the link given in
the description and sign up on Sentry
for error monitoring. So I'll click on
this get started button and I'll
continue with Google. I'll create a new
account here and after sign up it will
ask you some onboarding questions and
after that you will see this screen
and here you will find this option
create project.
So just click on this button create
project
and here you need to choose the
platform. So we are creating our back
end using expressjs. So just click on
this icon expressjs
and uh after that here you can see we
have this set your alert frequency. I'll
keep it default
alert me on high priority. So then we
have to add the name of the project. So
here let's add the name UGC
ads
and after that click on this button
create project.
After that here we have the steps to
integrate this sentry in our project for
error tracking. So first we have to use
this command. Just click here to copy it
and open our VS code. Let's open the
terminal and you can see we are in the
server terminal. Let's add control C to
stop it. And here we'll add this command
npm install at sentry/ node
save.
After that again start the project using
npm run server.
Now the project is running. Let's hide
this terminal and see the next step. So
after that you can see we have to create
this file instrument.j
js file. So let's copy the file name and
open our VS code.
And here we have this config folder. So
in this config folder we will create a
new file and write the file name
instrument. And here we'll add the file
name extension
mjs.
Here you can see the file name. We can
use either JS or MJS. So we have added
instrument.m MJS file and after that
let's add this configuration in this
file. So let's click on this icon to
copy it and paste it here. Now in our
project we are using the import
statement. Right? So instead of this
required we will use import. So let's
remove it
and
I'll add this import star as sentry from
this package like this.
So here we have this details that is DSN
and we have this URL and after that we
have this send default
pi equal to true.
And uh after that we will see the next
step.
So the next step is to import this
instrument.js file in our main file. So
let's import it. I'll just come back to
the VS code. Open main file that is
server.ts file. And in this one let's
add import
and provide the path here. So just add
dot /
config / and the file name that is
instrument mjs
and we have added it here in this sixth
line but it should be in the first line
only. So just move it and here we will
add it in the very first line. So first
we have this import and we are importing
the instrument MJS file and after that
let's see the next step.
So after that we can import the
sentry and after that we can add this
sentry dot setup express error handler
and in this one we will provide our app.
So let's add the import statement first
from here.
And uh let's add it in the
file that is server.ts file. Here we'll
add import
and uh let's add this quote. So we have
import star as sentry from this package
and after that we will add this
statement. Let me add the comment also.
Copy this one and paste it here. We will
paste it just before this app dot
listen.
So here we have added this sentry setup
express app handler and provided our
app. That's it. So now it will track all
the errors in our project. Now let's
create one error also so that we can see
the error details in our sentry
dashboard. So just come back here and
here only you will find the next step.
So if I scroll down here you can see we
have this option verify. So just copy
this one
and come here
and let's add it here
just after this first route. So we'll
add app.tget and we have the
route path debug sentry and here we have
a function. In this one we are throwing
one error right. So after adding this
statement it will catch all the errors
that occurs in the application. So here
we are throwing one error. So this error
will be handled using this sentry. So
after adding it now we will hit this
route. So we will come back to the web
browser and I'll open the local host col
5,000/
and this path that is debug centry.
Let's press enter.
So here we are getting the error right.
So when we will hit this path it will
throw an error. Now let's verify this
error in the sentry dashboard. So I'll
just open the dashboard here.
Let's click on this button take me to
ISU or you can also click here on this
left sidebar issues. So I'll just click
here.
So again it is displaying the steps that
is installing the package. I'll click on
next. Then configured SDK it is also
done. So I'll click on next.
And after that we have also added this
code. and then click on this button.
Still this button is not enabled. So let
me refresh this page. I'll just come
here refresh it. So when we refreshed
this URL, you can see we are getting the
error like this. My first sentry error,
right? So it throw an error. After that
we will come back here in the sentry
dashboard. And you can see this button
is enabled. Take me to my error. So here
you can see we have the complete details
where this error occurs and what was the
ASO. So if I scroll down here you can
see we have this exact URL
trace id and after that you can see
handled no label is error. After that
you can see here we have the details
like this error occurred in this line.
So we have the kod structure also and
I'll scroll down here we have
breadcrumbs where you can see the error
message and here we have the console
info after that here we have trace
preview
then we have the http request so we made
the request on this
route using get method and here we have
the headers address details and uh then
we have the user details also like we
have the user's IP address then browser
details runtime details operating system
and other details and uh in the right
side we have the time zone device
information and trace ID
and let's come here in the sidebar so in
this one you can see
we have this button
fix with seir. So this is an AI feature
of Sentry. If I click on this button
and here you can see
SE is Sentry's AI agent that helps you
troubleshoot and fix problems with your
applications including bugs and
performance issues.
It includes issue triage, root cause
analysis and solutions and code changes.
So to use this AI feature you need to
purchase the plan and you can also go
for the 14 days free trial and after
that it will help you to fix the issue.
You can connect with your GitHub and it
will automatically fix the issue on your
GitHub repository also. So I'll just
skip this one. So you can see using this
sentry dashboard you can manage all the
errors whenever error occurs in your
project it will display the entire
details. I'll just come back here in the
VS code and now let's add the same error
tracking in other routes also. So we
have created one function called
protect right in this o.ts file. So in
this one also we'll add the error
tracking. So let's add the import
statement that we have added here. So
I'll just copy this import
and paste it here.
And after that let's catch the error in
this catch block using sentry. So here
just add
sentry dot
capture exception and in this one just
add the error.
So whenever error occurs in this page,
it will display the error details in the
sentry dashboard. Similarly, we have
created the controller file. So we have
this color.ts file, right? So in this
one also, we'll add the same import
statement. We will import this entry
from this package. And after that, let's
come here in the
catch block.
Here we have the catch block. So in this
catch block again use sentry
dot
capture exception
and provide the error.
So all the error will be captured and
managed by sentry. So now we have added
the error management and performance
optimization in our project using
sentry.
Now we will add the controllers for user
features. For that let me just come back
to the VS code.
Here you can see we have this
controllers folder. So in this one let's
create a new file and write the file
name user controllers.ts.
I'll write user controller.ts file. And
after that here we have to create the
controller function so that we can get
the credits of any user. So I'll add the
comment here
get user credits and we will create the
function and export from this file. So
just add export const and the function
name is get user credits equal to
async add function. And after that here
we will get the request and response. So
first we have to import the request
response from express. Let's add import
from express and let's import
request response. I'll write capital R
like this. Now just come here in this
parameter and provide
request and provide the request type.
Then we'll add response and response.
Now after that in this one we'll add the
try catch statement. And in this try
block we'll add the logic to get the
user's credit. And in this catch block
just add colon any. We have provided the
type any. And here we will use the
error tracking using sentry. So again
use the same import statement. Import
sentry. And after that here we'll add
sentry dot
capture exception and provide the error
and we'll also display the error in the
response. So just add the response dot
send and provide the 500
error code. Then we'll add dot JSON
and here we'll add the message also. So
in this message property provide error
dot code or
we will add
error dot message. So by mistake we have
added response dot send. It will be
response dot a status. Let's correct it.
We have added response do status 500.
Now we have added the first controller
function. Using that we will get the
credits. And here in this try block
we'll add the logic to get the credits.
But before adding that logic let's add
other functions also. So I'll write the
comment here that is con get all user
projects. So we can get the projects of
individual user. So let's copy this one
paste it here. In this one we will
update the function name that is get all
projects
and everything will be same. We will add
the logic later and after that we'll add
the next controller. So here we'll add
the comment get project by ID so that we
can get individual project using the ID.
So let's add the same function. Copy and
paste it here and we'll change the name
that is
get project by ID. Right now after that
we have to add one more function using
that we can publish or unpublish the
project. So let's add the comment here
and copy and paste this function and
change the function name. So I'll write
the function name toggle
project public. So you can see here we
have added four functions.
If I fold it, you can see the functions
name. Get user credits, get all
projects, get project by ID and toggle
project public. Now using these
functions we have to create the routes.
For that we will create the
routes folder. So in this server folder
create a new folder called routes
and in this one create a new file and
write the file name user routes.ts.
Correct. Now to create the route we will
use express. So just add import express
from express and then we'll add
con
user router
equal to
express dot
router. Now in this router we have to
add different endpoint. So let's add
user router dot get method and provide
the path here. So the path will be
credits so that we can get the credits.
And here we'll add the controller
function. So the controller function
name is get user credits. Let's add it
here. Let's click on this suggestion to
import this from this file. User
controller dot js file. Now this route
will be protected. It means only logged
in user can access this route. So here
we'll add the protect middleware. So
just add
protect comma. So this protect
middleware has been imported from o.js.
Right? Now just duplicate it. Here we'll
add the next route. So here also we'll
use get method and then we'll add the
path that is projects so that we can get
all the projects of the user. Here we'll
add the function. So the function name
is get all projects. Let's add it here.
and import it. You can see get all
projects has been imported. After that,
let's duplicate it. Here again we will
use get method and we'll provide
projects
and then we'll add
/
colon and provide the project ID so that
we can get the individual project.
Right? So we have updated the path and
uh after that here we'll add the product
middleware pair and provide the function
name. So just copy the function name
from here. Get project by ID. Let's add
it here. And after that
let's import it. So get project by ID
has been imported. Now just duplicate
it. Again use get method. And here we'll
change the path. So the path will be /
publish and then provide colon project
id. We have added colon because this
project ID will be dynamic. So here we
have added the path
and publish path name so that we can
publish and unpublish any individual
project. So here we have added the
product middleware. Then we'll add the
function. So copy the function name from
here.
Paste it here. So the function name is
toggle project public and import this
function.
So this function has been imported.
After that we have to export this router
from here. So just add export default
user router. Now we can add this user
router in our main file to create the
final route. So let's open server.ts TS
file and uh here we will write app dot
use
and uh let's add the path that is / API/
user and then add the comma and provide
the user router. You can see the user
router has been imported from the routes
user routes dojs file.
So we have created the routes but we
have to add the logic in our functions
that is the controller function. So
let's create it one by one. Let's come
to the first one that is get user
credits and we'll get the credits data
from the database that is the new
database. Right? So first we have to get
the user ID. So in this try block let's
add con curly braces
user id equal to
request dot o. So from this o property
we will find the user id and here we'll
add the if statement if not of user id.
Suppose the user ID is not available. So
in this case simply add return and
provide the response dot status
and write the status for not one and
then we'll add dot JSON and here we'll
add the message. So let's add the
message called unauthorite. So we will
send this response
right.
Let's add space here.
So you can see we have added the user ID
in the try block. If the user ID is not
available we will send the response that
is unauthorized.
And after that let's come here in the
next line and write const
user. So when the user ID is available
we will find this user from the
database. So just add await
Prisma.
Let's click on this suggestion. So you
can see Prisma has been imported from
the configs folder Prisma.js file. And
in this one we will use dot user. So we
are using user model. And here we will
add
find unique
so that it will find the unique data
using the ID. So let's add object and
provide where. And in this where just
add the id and the id will be user id.
So now we have the user data and in this
user data we'll get the credits also
correct. So let's send this credit in
the response. So just add response dot
JSON and uh provide the credits property
and in this credits property let's
provide this user question mark dot
credits.
So we have created this controller to
get the users credit.
Now let's complete this one that is get
all projects.
Right? So here also we need the user ID.
So just copy this
paste it here.
And after this user ID we have to find
all the project of this user. So I'll
write con projects
equal to await. You can see we have
added the same thing here. User equal to
await and prisma model. And then you can
see we have added the same thing here.
User equal to await. Prisma dot user
model. So here we are adding projects
equal to await
prisma dot project model
because we have to find the project and
we will find all the project using this
user id. So just add dot
find many method and here we'll add the
object and provide where and let's add
the user ID. So it will find all the
project for this particular user id and
we will write new property order by. So
it will sort all the project list. So
just add
created at and provide descending and uh
after that here we will send the
response and in the response we'll send
this projects. So just copy this
response dot JSON and in this one simply
provide this
projects.
That's it. You can see we have added
this code in the try block to get all
projects of individual user. After that
we have to find the project using
project ID. It means we have to get the
individual project data. So I'll just
copy the same code from this try block
and paste it in this one that is get
project by ID. Let's paste this code
here. So here you can see first we are
finding the user id. After that we have
to find the project ID from the padams.
So just add const
because in the
route we are providing the project ID
using colon project ID. As you can see
in this routes you can see we have added
project ID in the routes. So we will get
it using the project ID equal to this
request dot
padams.
So now we have the user ID also and
project ID also. Let's add con project.
We will find the project equal to prisma
dot project model dot find unique.
And here just add where
id
is
project ID then comma user ID. Let's
remove it.
So it will find the project where the ID
is project ID and this user ID is
available in that project data. Now
suppose this project is not available
using this project ID. So in this case
just add the if statement
not of project. So here let's add return
response dot
a status
and provide the status 44. Then add dot
JSON and in this one just add the
message called project not found.
Right now after that suppose the project
is available. So in this case we'll
return this project in the response. So
simply add response dojson and project.
That's it. Save the changes.
Now after that come here in the next
function. Here we will change the
public property.
So it will be either public or private
project. So that user can make it public
or private. For that also we have to use
the same code. I'll just copy this one
and paste it here in this try block. So
first we will get the user ID. After
that we'll get the project ID and then
we will find the project.
Right? And if the project is not
available we will send this message
project not found. Now the project is
available. So in this case here we'll
add another if statement and write not
of
project question mark dot
generated image if the generated image
is not available and
not of project
question mark dot generated video.
So if the generated video and generated
image is not available. So here let's
add return
response dot a status and provide 4.4
then add dot
JSON and in this one we'll add the
message called image or video not
generated.
So we have added this statement. It will
check if the image is not available and
video is not available. So in this case
it will display this message in the
response. Now suppose the image is
generated or video is generated. So in
this case we can make it public or
private. It means we can publish and
unpublish the project. For that we'll
use this project. So just add await
prisma dot project dot
update.
And uh in this update let's add where id
is project ID. And after that we'll add
the data that we need to update. So in
this data just add
is published property. And here we'll
add not of project dot is published. So
if it is true it will make it false and
if it is false it will make it true.
So we can toggle from published to
unpublished or unpublished to published
and after updating this we will send one
message right. So here we'll add
response dot JSON and in this one let's
add is published property and here let's
provide the same thing that is not of
project dot is published.
So we will send this response. So we
have created the controllers for getting
the user data and for getting the user
credits, user project and updating the
project status. After creating the user
controllers, next we have to create the
controllers for image generation and
video generation and then we will store
the
media file on cloud nut and we will
create all these controller function in
a single file. So let me just come back
here in the VS code and in this
controllers folder create a new file and
write the file name project
controller.ts.
Now in this one we have to create
different controller functions. So first
we'll create the create project
function. So let's add export
con
create project equal to and create the
asynchronous arrow function and in this
function parameter we'll get the request
and response. So let's add import
statement first. We'll add import curly
braces
from
express
and here let's import the request and
response. Now here we'll add the
parameter that is request and it will be
this request type. After that we'll add
response also. So just add response
colon response.
Now in this one we'll add the try catch
statement. So
let's add try catch block and after that
in this catch block we will handle the
error using sentry. So again we have to
import this entry here. So let's add the
same code from here.
Copy this one and paste it here. Now
just come back here and copy this line
sentry dot capture exception
and paste it in this catch block. And
after that we'll also send the response
here. So just add response dot a status
500. Then JSON it will be message error
dot message and here we'll add the type.
So let's add the type any
like this. So now let's save the
changes. So here we have created the
first function that is create project.
So in this create project only we will
create the project image. Right? We'll
create the image using AI. Now let's
create the second function that is
create video. So just duplicate it
and we'll change the function name. So
the function name is create video. It
will be a sync function. And uh in this
one we'll use the same try catch. Now
let's duplicate it. Here we'll add the
next function name that is get all
published project so that we can display
on the web page. It will display all the
published or public projects. Now just
duplicate it. Here we'll add the next
function name that is delete project. So
that user can delete any single project.
So we have added different controller
function. Now using these controller
function we'll create the route. So we
have the routes file right. We have the
route folder and in that one we'll
create the file. So
let me create a new file here in the
routes folder and write the file name
project controller.ts
and in this one let's add import express
from the express package and using this
express will create the router. So I'll
write const project router equal to
express dot router. Now after that we'll
add this project router dot post method
and in this one just add the path called
create.
Using that we can create a project and
after that here we will add the
controller. So let's add the controller
create project. As you can see here we
have the function name create project.
So let's import this function here it
has been imported
right now in this path we have to add
the product middleware also so that only
logged in user can access this route. So
let's add
protect and it has been imported from
the middleares folder ojs file. Here
we'll add the comma.
That's it. Now let's duplicate it. We
will change the path here. It will be /
video. And here also we'll use the type
post. Then we'll change the function. So
it will be create video and import this
function. Now just duplicate it. And
here we'll add the type get. You can see
we are using the type get. And we'll
change the path. So it will be
published. So it will give all the
published project. So let's add the
function here. And from here we can
remove this protect because it will be
displayed to all users. So just add get
all. Let's correct it. We'll add get all
published projects.
You can see it has been imported. Now
let's copy this line. Paste it here. And
here we'll add
type delete
project router dot delete method. And
then we'll add the path. It will be /
colon and project ID. So we'll provide
the project ID in the params. And then
we'll add the product middle pair. And
here we'll add the function
delete project. Delete project has been
imported. Right now after that we have
to export this router from the file. So
let's add export default and project
router. It has been exported. Now after
that we can add this router in our main
file that is server.ts file. So just
come here and duplicate this line. Here
we'll add the path that is / API/
project like this. And here we'll add
project router. So you can see the
project router has been imported from
route/ projectcontroller.js
file. So we have created this route
also. And uh here you can see we have
this path create video published and
project ID and here we have the
controllers. So now let's complete these
controllers one by one. So we will start
with this create project right. So in
this create project first we need a
temporary project id right. So before
this try block only here we'll add let
temp project id
equal to or we'll add
colon a string.
We will add the type string for this
project ID. And after that let's add the
user ID. We will get the user ID from
request do. So just add con curly braces
user ID equal to request do.
And after that let's add let is credit
deducted and uh let's make it false. So
we have added this variable let temp
project id and is credit deducted
correct because after generating the
project we have to deduct the credit
also.
Now here we will get some data from the
request body. So let's add con curly
braces equal to request dot body. So to
create the project we need some data
from the request right. So in this one
we'll get the project name, we will get
the aspect ratio, user prompt, product
name, product description and we'll get
the target length. So here let's get the
name first. So I'll write name and here
we'll add the default value. So just add
name equal to new project. Then we'll
add aspect ratio. After that we will get
user prompt.
After that let's add comma and provide
product name.
After that we will add product
description.
Then we'll add comma
target length
and let's add the default value five.
Next we need the images also so that we
can generate the
add image using our given image. We will
provide the model image and product
image and AI will generate the ad image.
Right? So to receive the image we will
use the multter package and the malter
package will add the files property in
the request and in that file we will get
the images. So just add const images and
here we'll add the type any equal to
this request dot files
right and by default this request dot
files will not give anything. we will
add the malter that molter package will
add the files in the request
right and after that let's install the
molter package also and uh with that
we'll add one more package so just add
this command in the terminal we'll open
the backend terminal we'll add control c
to stop the project and here we will add
npm
install and add the package name
Molter and then we'll add one more
package that is cloud nerdy because
after handling the image we will upload
the image on cloud ner it means after
generating the AI image or video we will
upload it on cloud ner so just add this
package npm install malter and cloud ner
press enter it is done now we'll add the
type of this molter package because we
are using the typescript in our
projects. So we will add that in the dev
dependencies. So just add npm
install
dash d. And here we will add at
types/malter
like this and press enter.
It is also done. Now start the project
again using npm run server.
So now the backend server is running.
Now we can hide this terminal and open
our package.json file. So in this one
you can see here we have this molter.
Then we have the cloud nerdy and in the
dev dependency we have this
types/malter.
Now after that we'll create the
molter configuration file. So let's open
the sidebar.
Here we have the configs. In this
config, create a new file and write the
file name multi.ts
like this. And after that, let's import
this package. And after that, we will
create the storage. So just add con
storage equal to
this molter dot disk storage. And here
we'll add the empty
object. Now we'll add con upload
equal to multter. And in this multter
provide this curly braces and provide
this a storage.
Right? And now let's export this upload
from here. So we'll add export
default
upload.
Now save the changes. Next, we have to
add this upload as middleware in our
route. So, you can see we have created
this
routes file that is the project routes.
Let's find it here. By mistake, we have
added the name project controller.ts.
Let me change the name here. I'll right
click. You can see we have the routes
folder, right? So, in this routes
folder, we have project controller.ts.
So right click here and we'll change the
name. I'll write rename and I'll write
the name here that is project routes.ts.
After that click on yes. So it will
update the import statement also. If I
open server.ts file let's come here. You
can see this file name has been updated
routes/ project routes.ts. Now it is
correct. And after that I'll come here
in the
project routes.ts file and here we will
add our upload middleware.
So let's add
comma here and provide upload. You can
see upload has been imported from
multi.js file. And in this upload we'll
add dot array
because we'll upload multiple images
right and then we'll add the property
name it will be images and here we'll
add the number of files. So just add
comma two and then we'll add the comma
here. So it will handle the images added
in the request and it will add all the
images in the files property and using
that files property we will receive the
image here you can see we have images
equal to request dotfiles
correct now let's continue this function
so here let's add the if statement if
this images dot
length
is less than two or
not of
product name.
So if the product name is not available
or we don't have two images. So in this
case we will add return here and we'll
send the response also. So just add
response dot a status and provide the
status 400. Then we'll add dot JSON
method and in this one we'll add the
message
please upload at least two images.
Right now after that here we will add
con
user equal to await and we'll add
Prisma.
Import the Prisma from config. Then
we'll add dot user model dot find unique
and let's add
this curly braces where
ID is user ID.
So using this user id we will find the
user. Correct? Now let's add the if
statement again. If not of user
or
user dot
credits is less than five. So if the
user is not available using this user ID
and if the credit is less than five. So
in this case we cannot create the add
image or video. So just add the return
response dot a status 4.1 and provide
the JSON method. In this one we'll add
the message that is insufficient
credits. Right now for this if we'll add
the else statement and in this case we
will deduct the credit for image
generation. So let's add the comment
here. So here we have added the comment
deduct credits for image generation. And
let's add await
Prisma dot user model. Then we'll add
dot update method. In this update method
just add where and uh let's add ID. So
the ID will be user ID. And after that
we'll add the data that needs to be
updated. So in this data just add the
credits and let's add
decrement five. So it will deduct five
credits correct and after that here
we'll add
dot then
after this update
right so just add dot
then method and uh in this then we'll
add the arrow function like this and
here just add
is credit deducted equal to true.
So it will deduct the credit and after
that set this variable true. So here
after deducting the credit next we have
to upload the images on our storage. So
we will store the images on cloud nary
storage. So let's set up the cloudnary
first. So we will open the web browser
and open cloudnary.com. And here you
need to create an account. After sign up
you will come to the cloudary dashboard
and in this one just go to home and here
you will find go to API keys. So just
click here and here you will find this
API environment variable. So just copy
this one. You can see this URL like this
cloud URL. So I'll copy this and come
back to the VS code and openV file. In
this one, let's add this URL. You can
see we have added cloud URL. So here we
have cloudy colon//
your API key. Then we have to add your
API secret. And then we have some keys.
So we have to add the API key and secret
key. So just come back here
and here we'll create a new key. So I'll
just click on this button generate new
API key
and provide the confirmation code sent
on email. So I'll enter the confirmation
code here
and after that a new key has been
generated. You can see the key name
untitled. So let's add the name here
UGC
ads.
Then we have the API key. So click here
to copy this and paste it here.
Just paste it after this forward slash
and within this colon. So here we have
this API key and after that we have this
colon and after that just copy this API
secret. So click on this I icon to
reveal it and click on this icon to copy
it. And after that paste it here. After
this colon
paste the API secret. So we have
completed this Cloud Nerdy URL. Now we
can upload the media on Cloud9 storage.
So just come here in this project
controller. TS file and in this one we
have to import the package. We have
already installed the package cloud ner.
So let's add the import statement. Here
we'll add import
curly braces
v2 as cloudy
from cloudary package. So we have added
this import statement
import v2 as cloudary. And now let's
come here in the try block. So in this
try block we'll add
let
uploaded images
equal to await
promise dotall
and uh in this one just add the images
dot map and in this one let's add the
addo function. So let's add the
asynchronous add function. Here we'll
get the individual
item
provide colon any right and here we'll
add the
let
result equal to await then just add the
cloudy
dot uploader
dot
upload.
And here we have to add the
item
dot path.
Then we will add comma. And here we'll
add the object. And in this one just add
the resource type. So we'll add resource
type colon image because we are
uploading the image here.
Correct? And after that here we'll add
the
return and it will return this result
dot
secure URL. So here we'll get the
uploaded image URL in this one uploaded
images.
Right now after that we will store the
project data in the database. So we'll
add cost project equal to
await and provide the Prisma
dot
project dot create method and here just
add the data
and in this data we will store the name.
Then we will store the user ID. After
that we will store the
product name.
Then we will store
product description.
Then we'll add
user prompt.
Then we will add the aspect ratio.
Then we'll add
target length.
And in this target length just add
parse int.
In this parse int we will add the target
length
and then we'll add comma provide the
uploaded images and then we'll add is
generating
and we will make it true.
Right? So a new project data will be
created in the database with these
details
right after that we have the temp
project ID right. So in that one we will
store this project ID. So just add
project ID equal to this project
dot id.
Next we have to generate the add image
using this uploaded image and prompt
right for that we are going to use
Google Gemini API. So let's use the
Google gen AI package here.
But before adding the Google Gemini AI
package, let's see the documentation and
let's see how to generate the API key.
So we will open the web browser. You
need to search for Google Cloud free
credits. Scroll down. Here you will find
this free trial and free tier service
and products where you will get $300
free credits to use Google Cloud. So
just click on this link.
You can see the URL also. It is
cloud.google.com/free.
Right? And here you can see this message
$300
free credit for new customers. So when
you will create a new Google cloud
account or if you have existing cloud
account and uh if you want to claim the
credit it's better to create a new
Gmail. So you will get 300 free credit
after creating a new Google cloud
account. And uh once you will sign up
you need to enter some details. You need
to verify the payment method. It will
not charge you anything for 90 days up
to 300 credits. It will be free. So once
you receive the credit then only you
proceed for creating the API key. If you
get the credit you will see the details
like this. You can see in this project I
have already claimed the free credits.
As you can see here this is the
remaining days and this is the available
credit limit. So once you see this
credit in your Google cloud dashboard
you will find your project name here.
You can see the project name my first
project. So most probably your project
name will be same. So you need to
remember the same project name where you
have received the credits. So after
receiving the credit just come to Google
and again search for
Gemini API and open this website that is
a studio.google.
So once you will open this
aistudio.google.com/app/
this path then you will find this button
create API key. So once you will click
on this button, it will ask you to
choose the project. So make sure to
choose the same project. If I click
here, you can see. So if you don't have
the project here, just click on this
drop-down and it will ask you to import
the project. So import the same project
where you have claimed the free credit.
And after importing that project, let's
add the name for your key. And then you
will generate a key like this. And you
can click on this icon to copy your API
key and then copy the key in your
environment variable. So let me just
come back to the VS code. To add this
key in the environment variable, I'll
just come back here in the VS code and
open the env file. And here at the end,
let's add the environment variable name.
So I'll write Google Cloud API key like
this. You can see we have added Google
cloud API key equal to and provide the
key that you have copied. So in this
quote we will paste the key like this.
Save the changes and uh after that I'll
come back here
and go to this docs.
You can see this link API quick start.
I'll click on this link. So it will
display the documentation to use Google
geni API key. So in the left side you
will find this one nano banana image
generation. Let's click here.
And uh after that
I'll click on this image generation
JavaScript.
And here you can see we have to use this
Google/ Gen AI package and uh after that
import this Google geni from this
package and then we have to use this
model.
So using this Google gen AI package
we'll create the AI instance and uh we
will create one prompt for generating
the image and after that we can use this
instance and models and provide this
method. In this one provide the model
name and provide our prompt. So here
we'll get the response. So in this
response we'll get the
candidates then content and parts. So
that will be our final result. So let's
use it. I'll just come back here in the
VS code and install this package. So
just come back here in the VS code, open
the terminal
and project is running. So just add
control C and provide npm
install
at Google/ genai.
So now this package has been installed.
Start the project again using npm run
server.
After adding the package,
let's
hide this terminal.
Now we'll create a configuration file
here. So let's create a new file in this
config and write the file name AI do. TS
that is Typescript. And in this one we
will import this
Google gen AI from this package. After
that we have to create the instance. So
just come back here and see the steps.
So I'll just scroll down. You can see
here we have the image generation text
to image. And if I come to the next
section we have text and image to image.
So we will use this one because we'll
provide some prompt also. we will
provide the image also and then we will
generate our image. So for this one we
will use this setup.
So we have to create the instance using
this new Google gen AI right and in this
one we have to provide our API key. So
we will come back here
and let's add const
AI
equal to new Google gen AI
and in this one just add the API key
property and here provide the API key
from the environment variable. So I'll
write process env dot and uh let's add
the environment variable name. So the
environment variable name is Google
cloud API key. It is added here.
Now after that we have to export this
AI. So I'll write export default AI
so that we can use this AI in any other
page also. Right now let's see the next
step. So you can see we have to create
the image path image data and base 64
image that we can send on
AI request and it will generate the new
image using this
image data and text prompt.
So to upload the images and text in the
AI request, let me just come back here
in the VS code and uh we will open
project controller.ts file. Here you can
see we have this
project ID. So after that here I'm going
to use the Gemini 3 pro model. So let's
add the con model equal to here you can
see the model name.
So just paste it here. And in the same
way we will add Gemini
3
pro image preview
like this. So we have added the model
name. This is the pro model. So make
sure you receive the credit then only
use this model. After defining this
model here we'll add con
generation config
and for this one let's add the type that
is generate content config equal to
object. Now let's import this type from
Google geni. So let's add import a
statement import curly braces
from and provide the package at
google/ genai and from this package we
will get this
generate content config. It has been
imported. Now let's come here and in
this object let's add different
properties. So first we'll add the max
output tokens. Let's add this maximum
number of tokens. Then we'll add the
temperature provide one.
After that we'll add the top P.
It will be
95.
Next we'll add response modalities.
In this one just add the array
and provide image.
After that we'll add comma provide the
image config.
In this image config provide the object
and provide the aspect ratio. So for
this aspect ratio we'll add the aspect
ratio or this 9 is to 16. Correct? After
that we'll add the
image size. So let's add
1k.
After that we'll add comma and here
we'll add the safety settings. In this
safety settings we will add the array.
And to get the safety settings data
we'll come back here in this
documentation. In the left side you will
find the safety and here you will find
safety settings. Now just scroll down
and uh let's click on this JavaScript.
So you can see we have to add the
details like this. So just copy this two
object and paste it here. So here we
have the category and threshold and in
this one we have this harm category
rashment like this. So we have to import
it right. So
let me just come here at the top and
let's add comma provide this harm block
threshold comma harm category import
from the same package. Now just come
here. Here we will add category and
threshold. So in this category
let me remove it and provide this harm
category
dot harm category hit speech.
Now in the threshold we'll add this harm
block threshold dot
off
like this. Now let me just copy this one
only and paste it here. In the second
one, we'll add
harm category. Then we'll add dangerous
content
and it will be threshold of. Now just
duplicate it.
In the next one,
let's update this value.
Now just duplicate it and update the
value.
So we have added these safety settings
and after that we have to prepare the
images in the format that we need to
send on AI. So
here we have to create one load image
function because we have two images. So
instead of creating the functions to
time let's create a function here that
will be reusable. So here just after
this import statement we'll add con
load image equal to
add a function
in this function parameter we'll get the
path and the path will be a string then
we will get the mime type and for this
mime type let's add
a string. Now in this one just add
return.
In this return we'll add inline data and
uh for this inline data we'll add the
data property
and in the data property we will add fs
that is file system. So we have to
import the fs. So here let's add import
fs from fs package and we will also
import the path here. So just add import
path from path. Right now after that
here we'll add data
fs dot read file sync and in this one
provide the path
dot
two string
and in this one we'll add
base 64
right then we'll add comma
mime type
so we have added this function load
image
where we will provide the path and mime
type. So after that just come here and
uh after creating this generation config
here we will generate the images right
so let's add the comment here
images to base 64 structure for AI model
and here let's add con
image or img1 base 64 equal to load
image function. And in this one, just
add the images index 0 dot path. Then
add comma images index 0
dot mime type. Now just duplicate it.
Here we'll add img2 to base 64. So we
have two images. Here we'll add index
one and index one.
That's it. So we have two images to
provide in AI model. After that we'll
provide the prompt also. So let's add
con prompt equal to
this object. And here we'll add the text
property.
Right? And in this text property we'll
add the back text. And here let me type
this prompt.
Right? And here at the end we have added
this
dollar sign curly braces user prompt. So
make sure to add this exact prompt.
Just write down after pausing this
video. And after that here we will add
the comment.
Let's add the comment generate the image
using the AI model. For that let's add
con response
colon any
equal to await. And here we'll add the
AI dot
models.
Let's import this AI. Here we'll add AI
and click here to import it from the
configs. It has been imported. Then
we'll add dot
models dot generate content. Now in this
one we will provide the model.
After that provide the contents. In this
contents just add the array and provide
the
image 1 base 64 comma image 2 base 64
comma prompt
and after that we have to provide the
configuration also. So let's add the
comma here and provide
config and in this config just add
generation config.
That's it. So here we will get the
response. So let's add the comment also.
Let's add the comment. Check if the
response is valid. So we'll add if not
of response question mark dot candidates
question mark dot index zero
question mark dot content
dot parts. So when this if statement is
true. So in this case we will add throw
new error
and here we'll add the message
unexpected response because we have
added this not operator. So if any
error occurs we don't get the exact
response in this parts then we'll throw
an error. Right? So after that suppose
the response is valid. So in this case
we'll add con parts
equal to this response dot candidates
index zero content dot parts. Right
after that we'll add let
final buffer
colon we will add the
buffer
or we will add null equal to null. Now
after that we'll add for
and we'll add for of loop. So just add
const part of parts
and provide if statement if part dot
inline data
if it is true. So in this case we'll add
the final buffer equal to buffer
dot from
and uh in this one just add the part dot
inline data dot data
comma
base 64
right now after that we'll add another
if statement here we'll add if
not of final buffer
So in this case we'll throw an error
with the message failed to generate
image
and after that we'll add const
just after this if statement let's add
con
64 image equal to back text provide the
data colon image/png
semicolon
base 64
comma
and provide dollar sign curly braces.
In this one we have added final buffer
dot two string and base 64. So here we
have the base 64 image.
So now here we have the base 64 image
and after that
let's upload this image on cloud ner. So
I'll write const
upload result
equal to await
cloudy dot uploader dot upload
and in this one provide this base 64
image
then comma provide the object resource
type in this resource type we'll add
colon and provide
image because we are uploading the
generated image and after that we will
store this generated image data in the
database. So just add await prisma dot
project model dot update method. In this
update method let's add where and
provide the id. So the id will be this
project
dot id and then we'll add comma
data that needs to be updated. So in
this data we will add
generated image property. In this
generated image just add the uploaded
result dot secure URL. So we will store
the uploaded image URL in the database.
And after that we'll make the is
generating property false.
That's it. So now we have generated the
project image and uploaded it on the
cloud storage and then we have updated
the database also. Now we can send the
response. So just add response dot JSON
and uh in this one just add the project
id property and in this project id
provide the project
dot id. That's it. Now after that let's
complete this catch block. So in this
catch block we will refund the credit if
any error occurs while creating this
project or image. So here we'll add if
temp project id
here we'll add exclamation sign
and after that we'll add the comment
update project a status and error
message. So here we'll add await
prisma dot project model dot update. Now
in this update let's add the where
property. In this where we'll add id and
here we'll add the temp project id and
after that we'll add the data here and
in this data we'll add is generating and
make it false and after that we'll add
error property and provide the error dot
message
like this and after that here we'll add
another if statement. So let's add if
and here we'll add is credit deducted.
Right? So in this case we will add the
comment add credit back. For that we'll
add await
Prisma dot user model dot update method.
And uh in this update method we'll add
where and provide the
id. So the id will be user id. And for
this user we will update the credit. So
just add the data property. And in this
data property let's add the
credits
and in this credits just add
increment five. So it will refund the
credit. That's it. So now we have
completed this controller function.
Using that user can create a project
where user will enter the project
details like product name, product
image, model image, enter the prompt and
user will generate the image.
Now after creating this controller
function, we'll create the next
controller function. Using that we can
generate the video also. Now let's
complete our next controller function.
Using that we can generate the video. So
here we have this create video
controller function where we have added
the try catch statement. Now in this one
also we need the project ID and user ID.
So before this try block let's add const
curly braces user id
equal to
request dot
o after that we will get the project ID
from the body. So just add con curly
braces project id equal to request dot
body.
After that here we'll add one variable
using let. So just add let is credit
deducted and let's store false here.
That's it. And after that here we will
add con user
equal to await. Then we will add the
Prisma dot user model and then we'll add
dot find unique.
Now here we have to add
where property. In this where property
just add the id and the id will be our
user id. After that here we will add if
statement. In this if we'll add not of
user.
Then we'll add or operator
and provide
user dot
credits
less than 10. So if the user is not
available or the user credit is less
than 10. So in this case we'll add the
return and send the response. So just
add return response dot a status for not
one dot message. So just add the dot
JSON method and provide the message
property insufficient credits. Right now
let's deduct the credit for generating
the video. So here let's add the comment
deduct credits for video generation and
write await
prisma dot
user model dot
update and after that in this update
just add the where property in this
where just add the id and it will be
user id and after that let's add data
that needs to be updated so in this data
property provide the credits
and here just add decrement
10. So it will deduct 10 credit and
after that here we'll add dot then
method and in this one just add one
add a function and here we will add
is credit deducted and make it true.
That's it. So here we have deducted the
credit from the user data in database
and after that just come here in the try
block and in this one we will
find the project. So just add con
project equal to
await.
Then we'll add
Prisma dot
project dot
find unique.
Now in this one just add where property
and let's add the ID and in this ID we
will add the project ID. Then we'll add
the user ID.
After that we will add
include and in this include just add the
user. So it will include the user data
also in this project data.
So after getting this project data,
let's add the if statement. We'll add if
not of
project. It means we could not find the
project using this project ID or we will
add the project
dot is generating.
It means the is generating property is
true. So in this case we'll add return
response dot a status 44 JSON messages
generating or generation in progress.
Right now let's add another if
statement. We'll add if project
dot
generated video. It means when the
generated video is already available.
Right? So in this case we will add the
return statement. So just add return a
status for not four and the message is
video already generated
like this. Now after that let's add
await and uh here we will add Prisma
dot
project dot update method. In this
update method, we will add where id is
project ID
and after that let's add the data.
And now we'll add is generating
and make it true. Right? It means video
is not available and is generating is
false. So in this case we can generate
the video.
So we have made is generating true and
uh after that here just add the prompt.
So we'll add con prompt equal to back
tick and let's add this prompt.
You can pause this video and write this
prompt. In this one you can see we have
inserted the variables using this dollar
sign and curly braces. It means we have
used the template literal. So here we
have added the project
dot product name then product
description then we have added the
product description here if it is
available. Now after that let's add the
model name. So just add const model
equal to and here I'm going to use VO
3.1 model. So just add the complete name
VO 3.1 generate preview.
So this is the AI model and after that
we'll add the if statement. If not of
project dot generated image
it means the generated image is not
available. So in this case we cannot
generate the video. First we need the
image. Right? So here we will throw an
error. So just at throw new error and
the error message is generated image not
found. So if the generated image is not
available, it is throwing an error. And
if the generated image is available, so
we have the generated image URL in the
database. So using that URL, we have to
fetch the image. And to fetch the image,
I'm going to use the AIOS package. So
let's open the terminal.
In this terminal, we'll add Ctrl C and
install one package. We'll write npm
install
AIOS.
Press enter.
Install this Exio package.
After installation, start the project
again using npm run server.
Now the project is running.
hide this terminal and here we will
import the AIOS package. So let's add
import
AIOS from Exio package.
After importing this Exio package, let's
come here
and here let's add const
image equal to await
axios
dot get method and here we'll add the
project
dot
generated image which is an URL. After
that we'll add comma curly braces and
here we'll provide the response type and
the response type will be add a buffer
like this. Now we'll add con image bytes
colon any. We have added the type any.
And here we will provide buffer dot
from
and after that here we will add the
image dot data.
Correct. After that let's add one
variable let operation and provide the
type any. So just add colon
any equal to await and provide the
AI. So just use the AI instance dot
models dot generate videos. And in this
generate videos we will provide our
model name. Then we'll provide our
prompt. And after that we'll provide the
image property. And in this image
property just add the object and provide
this
image bytes. And in this image bytes,
let's store this image bytes
dot
to string and provide base 64.
After that we'll add the mime type. So
let's add comma and provide m type
image/png.
Then we'll add the comma here and
provide the config. So let's add the
config.
In this config we will add the aspect
ratio
and in the aspect ratio we will add
project question mark dot aspect ratio.
Then we'll add odd
9 is to 16.
After that we'll add the number of
videos. So let's add one. Then we'll add
resolution. Let's add 720p.
After that we have to generate our video
right. So here we'll add the while. Just
add
while and in this one we'll add not of
operation dot done
and until the operation done is not true
we'll add
console log. So it will continuously
execute this code. We'll add the message
here waiting for video generation to
complete and after that we'll add await
new
promise
and uh in this one let's add the arrow
function like this. In this function
parameter we will get resolve and here
we'll add set time out. In this set
timeout provide the resolve comma
10,000 milliseconds.
And after that here let's add operation
equal to await
provide the AI instance dot operations
dot
get videos operation
and uh here we have to provide the
operation and let's provide operation
that's it now after that we have to
generate the file name and file path. So
after this while we'll add const file
name equal to
back text and here we'll add dollar sign
curly braces insert the user id then
we'll add dash dollar sign curly braces
insert the time stamp using date dot now
and then we'll add dot mp4.
So this will be the file name right
after that let's add con file path. So
here we will provide path. We have
already imported the path. Then we'll
add dot join.
And in this join we'll add videos,
provide the file name. That's it. After
that we have to create the image
directory. if it does not exist in our
project. So let's add
one comment and after that we'll add fs
that is file system dot make dear sync
and uh in this one we'll add the
directory name videos and after that
we'll add curly braces we'll add
recursive true.
So we have created this directory and uh
after that let's add if and provide not
of operation dot
response
dot generated videos. So in this case we
will throw an error. So just add throw
new error
and in this one provide operation dot
response dot R AI media filtered
response index zero. After that here
we'll add the comment download the
video. So we'll add this comment and
provide await
AI
dot files dot download. Now in this
download we'll add the file
and here just add the operation
dot response
dot generated videos
index zero. Then we'll add dot video.
After that we'll add comma and provide
download path.
And uh here just add
file path from here. We have this file
path right? So just add it here. After
that we have to upload this video on
cloud ner right so that we can get the
video URL. So let's add const
upload result
equal to
await and provide cloud ner dot uploader
dotupload method.
And in this one just add the file path.
Then we'll add the object and provide
the resource type. So in the resource
type we will provide video because we
will upload the video here. And after
that we will store this video URL in
database. So let's add await Prisma dot
project dot
update. And here just add the where
property and provide the
id and let's set the id that is project
do id.
Then we will add
data property
and in this data property we will
provide the generated video and in this
generated video property we'll provide
the upload result
dot seccure url. Then we'll add is
generating property and let's make it
false. After generating the video, we
will store the video on cloud n and
store the video URL in database and
we'll set is generating false.
Right now after that we will remove the
video file from the disk after upload.
Correct? So here
let's add the comment and now provide
fs dot
unlink sync and provide file path
and after that we will simply send the
response. So just add response dot JSON
and uh here we will add the message
property. So we have added the message
here video generation completed and with
that we will also provide the video URL.
So let's add the video URL property and
in this one just add the upload result
dot secure URL.
That's it. Now after that here we have
this
catch block also. So in this catch block
let's add the code so that we can
return the credit if any error occurs
and we'll also update the error in
database. So let me just copy the code
from previous function. We have the
previous function here. Here you can see
we have added this. So I'll just copy
this one
and paste it here in this catch block.
We'll add a space here and provide this
code. Now in this one you can see we
have the temporary project ID. Right? So
I'll remove it.
Remove this if statement. We will simply
provide this comment. Update project a
status and error message. So we'll add
await prisma.pro.update
update where id is project ID
right and after that we'll add the user
id also now we'll update the data and in
this data we'll set is generating false
and provide error it will be error dot
message after that here we have one if
statement if is credit deducted is true
so in this case we will add credit back
right so just add await prisma dot
user do.date update provide the ID it
will be user ID and provide credits and
here we will refund
10 credit correct and then we have the
other statement in this catch block it
will be there save the changes
so we have created the controller using
that we can generate the video also next
we have the function called
get all published projects so let's
complete this one also in this
Let's add const within this try block.
We'll add const projects will find the
projects from database.
Projects equal to await and provide the
Prisma dot project model dot find many.
And here just add the where property and
let's add
is published property and true. So
wherever the is published is true, it
will provide all the projects. Correct?
Now we have to send it in the response.
So just add
response dot JSON and in this one
provide this projects. That's it. Then
we have this catch block. After that we
have this delete project, right? So we
have to delete the project from
database. So just come here. Here we
have this try block and in this try
block we'll find the user ID. So just
add const curly braces. User ID is
request.
After that we have to find the project
ID. So just add con curly braces.
Project ID equal to this request dot
pads because we are providing the ID in
route path. After that we'll add con
project. We will find the project from
database. So it's at con project equal
to await. then Prisma dot
project model then we'll add dot find
unique
and uh here let's add where property in
this one just add the id and provide the
id that is project id and with that
we'll also provide the user id so it
will find this project correct now
suppose the project is not available so
just add if statement if not of project
So in this case we will add the return
and send the status 44. So just add
return response status 44 and the
message is project not found. And
suppose the project is available in this
case we will delete it from database. So
just add await prisma dot project dot
delete and uh in this one just add where
and provide
id and the id will be project id.
So it will get deleted. After deleting
the project we'll send the response
also. So just add response dojson and
provide the message project deleted. So
we have created this controller function
also. Using that we can delete the
project and using these controller
function we have already created the
routes. If I open the sidebar go to
project routes you can see we have
created create video publish and project
ID which is the delete. So we have
created all controller function. If I
just come back here on this web page,
you can see we have completed this step.
User controller, image generation, video
generation, media storage on cloud n,
right? And after that we have to connect
our front end with back end. Then only
the project will be completed. Right?
Right? Now we have created the back end
and we have created our front end
in this client directory. Right? So we
have created back end and front end. If
I open the terminal
here, you can see this back end is
running fine. We don't have any issue
here. If I go to front end terminal
here, the front end is running.
It is stopped. Let me start it using npm
rundev.
Now you can see the project is running
at localhost 5173.
Correct. Now we have completed the back
end and front end. Next, we have to
connect the back end with our front end
to make a fully functional application.
So, right click here and select close
saved.
To connect our backend server with front
end, let's open this client folder. And
in this one, we will create one env
file. So, I think we have this env file
here. So, in this one, you can see we
have wheat color publishable key. So,
here we'll add our backend URL also. So
let's add the environment variable name
v base URL and in this base URL we will
provide our backend URL. So you can see
the back end is running at
this one
localhost 5,000. So just copy this URL
paste it here. So we have added the
backend URL. At the end we have this
forward slash. So just remove this
forward slash from here. It should end
with 5,000. That's it. So, we have the
wheat base URL. Now, in this project, we
will make the API call to get the data
from database. For making the API call,
we are going to use Exio package and
we'll also add the notifications. For
that, we'll use the React or toast to
generate the notifications. So, we'll
install these packages. So, just open
the terminal.
This is the backend terminal. Let's come
to the client terminal.
In this one, project is running. So just
add Ctrl C to stop it. And here just add
npm
install
axios. And then we'll add react hot
toast.
So it is installing these packages. And
after installation, start the project
again using npm runde.
So now the project is running. Let's
hide this terminal and come here
in the src. Now in this src we have this
app dot tsx file. So in this app dot tsx
we will add the
toaster so that we can display the toast
notification. Right? So here we'll add
the import statement
import
calibr toaster
from
React hot toast. And after that just
mount it here.
After this fragment we will mount this
toaster tag like this. Now in this
toaster tag we'll add the toast options
to change the theme. So just add toast
options equal to curly braces and here
just add the a style property. In this a
style property we will add the
background
and provide the background color
like this. And after that we'll add the
color also. So just add comma
color and provide the white color
like this. So we have added a style
background and color. Now after that
let's close this file and we will open
the
src. In this src we will create one
config folder. So just create a new
folder here and write the folder name
config.
In this configs folder, create a new
file and write the file name axio.ts.
And here we will add importios from
axios package. And now we'll add con api
equal to
axio dot
create method. And uh in this one we
will provide the base URL property. In
this base URL, we will provide our
backend URL that is available in the
environment variable. So just import it.
We'll add import
dot
meta dot env
dot
whe
then we'll add or operator and provide
this one. So if the URL is not available
in the ENV then it will use this URL
localhost col 5000. Now let's export
this API from here. So using this API we
can simply make the API call. We don't
have to provide the base URL. We will
simply provide the remaining path for
making the API call. After that we will
open our
components. In this components we have
the navbar.tsx
file. So here you can see we have the
user data
from this use user which is imported
from color and after that here we have
to display the credit in the navigation
bar. If I open the web page
this is the homepage and in this
navigation bar
you can see we have this credits we have
the credits empty right. So let's
display the available credit here. So
I'll just come back
and uh in this one we will create a
function where we will make the API call
to get the credits data from database
and we will store the credit data in a
state. So we'll create one state also.
So here
let's add one state con
credits and the setter function name is
set credits equal to use state and
initialize it using zero
right and uh after that here we'll add
con curly braces path name
equal to
use
location and the use location has been
imported from react router DOM.
Now after that
here let's create a function. So we'll
add const
get credits
equal to
asynchronous add function.
In this try block, we have to make the
API call and we have to authenticate the
API request using token. So first we'll
generate the token and to generate the
token we will use the
get token function. So let's add
con get token equal to
use o and you can see the use o has been
imported here. Let's come here. use o
has been imported from color. Now using
this use o we'll get the get token and
using this we can generate a token. So
let's add con
token equal to await
get token function. Now after that we'll
add con
curly braces data
equal to await and provide the API
and you can see the API has been
imported from this file and then we'll
add dot
get method and here we'll add the path
that is / API
/ user
slash credits. We are using the get meth
header and this is the remaining path
and here we have to authenticate the
request using the headers property and
in the headers property we will add
authorization
and in this authorization we'll add back
beer dollar sign curly braces token. So
it will authenticate our request and
allow us to make the API call and get
the data from database. Now after that
we'll use the setter function set
credits and here just add the data dot
credits. So it will update the data here
in this estate.
Now after that let's come here in the
catch block we'll add colon any and here
just add the toast notification. So just
add toast import the toast then we'll
add dot error and here we'll add the
error dotresponse dot data dot message
or we will provide error dossage.
After that here we'll add console log
also. So just add console log and error.
That's it. So we have created this get
user credits function. Now it will be
executed whenever we load the component.
So just add use effect.
Now in this use effect we will add the
dependency add. And in this one just add
the user. Let's see the user is
available here or not. So here we have
the user. So whenever the user changes
it will execute the function again. So
just add user and after that we'll add
comma and provide the path name. So
whenever path name changes it will
execute this function. So here we'll add
if statement if user. So when the user
is logged in then only we will fetch the
credits right. So just add if user and
then we'll add
this parenthesis and we have to call it
like this. And in this one just add the
asynchronous
add a function
let's add await and provide get user
credits like this. Now save the changes.
So what will happen here? Whenever we
will load the web page it will fetch the
credits and here we have the credits
state that we can use to display the
credits in the navbar. So let's come
here. Here you can see we have added the
credits right. So just after that we'll
add curly braces and provide credits.
Save the changes and open our web page.
And here you can see we have 20 credits.
Let me refresh it.
You can see we have the 20 credits in
the navigation bar. If I click here, it
will open this page that is the pricing
plan. And if I buy any other plan, it
will increase the credit also. Right? So
if I click on this pro plan, I'll click
on this subscribe button
and here I'll choose pay with test card.
Continue.
So after that you can see the credits
has been increased. We have received 80
credits and total credit is 100. So
whenever we will purchase the plan it
will increase the credits also.
Right?
You can see in this plan we have 80
monthly credits. In the premium one we
will get 240 monthly credits.
So this is how we can purchase the plan
and after purchase we are getting the
credits also. And when we have the
credit we can generate the
UGC ad. Right. So next we have to
complete this page. If I come to
homepage it is working fine.
We have the pricing plan here also. And
if I go to create, this is the generate
page where we will enter the details and
upload our images and generate the
content. So let's make this page
working. For that, I'll just come back
here
and close this file
and let's open the pages.
In this pages, we have generator.tsx
file.
Right now in this one I'm going to add a
function using that we can generate the
content. So here you can see we have
this handle generate function. So let's
complete this handle generate function.
This is asynchronous add function. Here
we have added e.t prevent default. So
here let's add if statement and here we
will check for the user. If the user is
logged in then only we will continue
this function right. So first we'll get
the user data here. So scroll up here.
Let's add con
curly braces
user equal to
use user and the use user has been
imported from color. Then we will get
the get token function also. So just add
con curly braces
equal to
use o import the use o and from this use
o let's get
get token function correct and uh after
that here we'll add the navigate
function also so I'll write con equal to
use navigate And the use navigate is
imported from react router DOM. Now
after that let me just come here in this
handle generate we'll add if not of user
it means when the user is not logged in.
So in this case simply add return and
provide the toast notification. So just
add toast
dot error or we can simply write the
toast and provide the message here.
Please login to generate
like this. After that we'll add the
another if statement if
and write not of
product image or
not of
model image or
not of
name
or not of
product name
or not of
aspect ratio. So if any of this data is
missing, we will simply add return
and then provide the toast notification.
So just add toast and uh let's add the
message here that is please fill all the
required fields
like this. And after that suppose we
have all the details then we'll add the
try catch block here. So just add
try catch a statement. Now in this one
we will use the setter function set is
generating and make it true. After that
we have to create a form data and in
that one we will add all the data which
is required to create our project. So
just add con form data
equal to new form data.
Now in this one we will add the
form data dot append method and here
we'll add the property name which is
name and then we'll add the value which
will be name state. Now let's duplicate
it.
Here we'll add the field name which is
the product name and here also we'll add
the value product name. Now duplicate
it. We'll add the field name that is
product description and then we'll add
product description value.
Duplicate it. Here we will add user
prompt
and then we'll add user prompt.
Duplicate it. Then we'll add aspect
ratio and provide the aspect ratio.
Duplicate it. Then we'll add images.
And here just add product image.
Duplicate it. Again we'll add the
images. And here we'll provide the model
image.
Right. After that we have to generate
the token also to make the API call. So
just add con token equal to await
provide the
get token function. Now after that make
the API call. So just add con curly
braces data equal to await then we will
add the API import the API from config
folder dot post method and in this post
method we'll add the path which is /
API/ project/create
then we'll add the data here that is the
form data it will be sent in the request
then we'll add curly braces and here we
have to add headers property in the
headers we'll add
authorization bearer token. So it will
authenticate the request. After that
we'll add toast notification. So just
add toast dot success. And uh here we
will add the message which we will
receive from the request. So just add
data dot message. After that we will
navigate the users on result page. So
just add the navigate function. In this
navigate function just add the path that
is slash
result slash and provide
this data dot project id.
So it will redirect user to new page
which is / result/ project id and in
that one we will get the new project and
we have the image that is UGC add image
and uh after that just come here in the
catch block. In this catch block we will
set the is generating
false.
So let's add it here.
Is generating make it false and then
we'll add the toast notifications. So
just add toast dot error and in this one
let's add the same error message which
we have added in the previous catch
block
like this and here we'll add colon any
save the changes so we have created this
function using that we can generate the
project and there will be a UGC add
image for the project.
So when we upload the product and model
image and enter these detail, click on
this button. It will generate the UGC ad
image and it will redirect us to the
result page so that we can see the
result. So let me add the functionality
in the result page also. After that we
will enter the details.
So I'll come back to the VS code and
open sidebar. Here we have the pages. In
this pages we have result.tsx tsx file
and uh in this one you can see we have
fetch project data handle generate video
right so let's complete these functions
so in this one we have to make the API
call so we'll generate the token and uh
after that we have to get the
project ID from the
URL so we will add
const
curly braces
project id
equal to
use padams. use params is imported from
react router DOM. After that we'll add
con curly braces equal to
use o. use is imported here and after
that from this use we'll get get token
function. After that we'll add cones
equal to use user and the use user is
imported here. From this use user we'll
get the user and we'll also get is
loaded property.
Right now after that let me just come
here in this function and here we'll get
the
navigate function also. So let's add
con equal to
use navigate import the use navigate.
Now come to this function that is fetch
project data. So let's clear this dummy
code. We are using the dummy generations
right? So let's remove it and here we
will remove this import a statement that
is importing the data from asset and
after that here let's add try catch
block and in this try block we'll add
con token equal to await
get token
after that we'll add con
curly braces data equal to await and
provide the API import the API from
config dot get method and after that
we'll add the back tick here and provide
/ API/ user/
projects and then we'll add dollar sign
curly braces and here we will insert the
project ID also after that we'll add
comma curly braces and here we'll add
the headers property to authenticate our
request so we added this headers. Now
after that let's add
set project data and in this set project
data we will add data dot project
that we are getting from the API request
and after that we will add
set is generating
and in this one just add data. project
dot is generating
and after that we'll add set loading and
let's make it false.
Now come to the catch block. Here we'll
add error colon any and then we'll add
the toast notification here. So we'll
add toast import the toast here. Then
write toast dot error and provide the
same error message. Then we'll add
console log error.
That's it. So using this it will fetch
the project data when we open the result
page and in the result page we will add
the project ID also right now using this
result page we can generate the video
here you can see we have this handle
generate video right so let's complete
this function also in this one we have
set is generating true then we'll add
the
try catch and in this catch block we'll
paste the same code like this and come
here in the try block and in the try
block we'll add con token equal to await
get token then we'll make the API call
so just add cones data equal to await
then API dot post
and here we'll add
path which is / API/ project/
video
and after that we will provide the
project ID also. So just add curly
braces and provide the project ID here.
After that we'll add curlys and in this
one just add the headers property to
authenticate the API request. Now after
that here we'll add
set project data. In this setter
function just add the arrow function and
here we'll get the previous data in
parameter
like this and provide this parenthesis
curly braces a spread operator
previous
generated video
and in this generated video we'll add
the data
dot
video URL
and after that we'll add
is generating and here we'll add false.
Let's add a space here.
So we have added this setter function.
After that we'll display the toast
notification. So just add toast dots
success and provide data dot message.
And after that we'll add set is
generating and make it false.
And here in this catch block we have the
error. So just add colon any save the
changes. So we have added the function
using that it will generate a video. Now
after that come here in the use effect.
In this use effect we have added fetch
project data. So this function will be
called when the user is available. So
let's add the if statement here. We'll
add if user
and we'll add and operator
not of
project dot id
when we have the user data and don't
have the
project ID. So in this case let's add
this fetch project data
and after that let's add the else
statement also and here we'll add else
if in this else if we'll add
is loaded and
not of user.
So if is loaded is true and we don't get
the user. So in this case we'll add
navigate and we will navigate the users
on
homepage. So without login user cannot
open the
result page. Right now we have the
dependency array. So in this dependency
array provide the user so that whenever
the user changes it will execute this
function.
Now after that we will add one comment
here and provide one use effect fetch
project every 10 seconds right it means
when the video is not generated we will
fetch the project data after every 10
seconds to get the video so here we'll
add use effect
in this use effect we have added this
add function and provide the dependency
array here in this dependency array just
add the user
Comma provide is generating
and after that here let's add if
statement if
user
then we'll add and
is generating.
So when it is true in this case just add
const interval equal to
set interval and in this set interval
just add
this add a function and provide the time
10,000 milliseconds and here just add
the
fetch
project data function. It will call this
function and after that here it will add
return. So let's add
return the arrow function and let's add
the clear interval.
In this clear interval provide this
interval.
That's it. Now after that let's come
back to the web page. So we have added
the functionality in the result page
also. And after that if I add the
details here. Let me refresh this web
page.
And uh after that we will upload the
images like we will upload the
product image. So just click here and I
will upload one product. Let's upload
this trolley bag. After that here we
will upload the model image. So I'll
click here and choose this model
picture.
So we have added the product and model
image. After that let's add the project
name. So let's add my project
and then we'll add product name. So the
product name is trolley bag.
We are getting the ad for this trolley
bag. Right. After that we'll add the
product description also. It is optional
but let me write it. I'll add very small
description.
Sky colored trolley bag. After that
we'll choose the aspect ratio. So let's
use this vertical video or image. So we
have selected this first one. And here
you can add the prompt also which is
also optional. So let me add the prompt.
Create the video where center of
attraction is a trolley bag. And after
adding all these details, click on this
generate image button. Right now you can
see the credit is 100. I'll click here.
It is generating the image.
Here we are getting some error response
unsupported mime type. Let me fix it.
Let me open the sentry dashboard. And in
this one we'll go to issues.
So in this one you can see here also we
have received this API error. Let me
open it. And here also you can see the
same message
invalid argument. And you can see the
message unsupported mime type. And here
we have the isue in this line. And you
can see the file name also that is
project controller.ts file. Right? So we
are getting the isue in this project
controller.ts file. And uh here we have
to connect the mime type. So let me just
come back here in the VS code. We will
open the
server folder. In this server you will
find controller and in this controller
we have this project controller.ts file.
In this project controller.ts you can
see we have added this image one base 64
load image and here we have the dot path
and here we have dot mime type. So here
let's add a small t and here also we'll
add a small t. Connect these two mime
type. Save the changes. So it will
automatically restart the back end and
after that we'll come back here and let
me update these details. So first we'll
refresh this web page
and let's update the
product image. We'll upload the product
image like trolley bag. We will upload
the model image this one. Then add the
project name my project.
Then we'll add the product name. And uh
in this product name I'll provide
trolley bag.
Then we'll add the description a sky
colored trolley bag. Then we'll add the
aspect ratio. And here we'll add the
prompt which is optional. Then click on
this generate image button.
It will generate the image from Google
Gemini API. Right? So it may take few
seconds. And after that you can see we
are redirected to this result page. You
can see the URL / result and then we
have the project ID right. And here we
have a image. You can see we have the
image with this model and product in the
hand. We have the trolley which is the
product and we have the model also.
Right? We have uploaded the separate
image for product and
model. So now we have the generated
image. Next we can generate the video
also. You can see here we have download
image button because only image is
generated yet. Next we can generate the
video using this button. So I'll click
on this button generate video.
You can see the button text generating
video right. So button text has been
updated. Now it will take some time to
generate the video using AI. So just
wait for that.
Here you can see after generating the
image the credit has been reduced. Here
we have 95 credits. Correct? And after
generating the video it will further
reduce the credit by 10. So just wait
for this video to be generated.
>> Incredibly light and maneuvers perfectly
even in tight space has been generated
here. Check out this new sky trolley
bag. Let me pause it and let me mute
this audio. And now I'll play this video
again. So you can see here we have the
UGC add video that we have generated
using a model image and product image
and after adding some simple prompt.
So it is easy to generate a UGC ad video
and image using this application. Now we
have the option to download the image
also and we can also download the video
using these buttons and you can see the
message here video generated
successfully.
Correct? So this feature is working
fine. After that we have to add the
functionality in the community page
where we will display all the public
content right which is shared or public.
Now before creating this community we
will create the my generation page. If I
open this drop-down here, you can see my
generations. If I open this my
generations, here we have the dummy data
which is coming from the assets, right?
So, let's remove everything here. We
will get the data from database. If I
open our new database, let me refresh it
and uh come here in this project. You
can see here we have two projects,
right? And uh in this one you can see we
have the generated image and this is the
generated video. We have the image URL
and video URL
correct and after that I'll just come
back here and you can see the credit is
also reduced. Right now we have 85
credit. So everything is working fine.
Let's complete this my generation page.
So I'll just come back to the VS code
and close this file. Close this one
also. And now let's open the pages.
In this pages we have my generations dot
tsx file. So in this one we have to
display all the
projects created by a single user. So in
this one first we will get the user data
from color. So just add con
curly braces equal to use
user.
It has been imported and from here we
will get the user and we will also get
is loaded. Now after that we will get
the token. So just add con curly braces
get token equal to
use o and use o is imported. After that
we will get the navigate function. So
just add con
equal to
use navigate and import the use navigate
from react router dom. Now after that
here we have this fetch my generations
function. So let's update this function.
We will clear this and here we'll add
try catch a statement. Now in this try
block we will add con token equal to
await get token function. Now we'll make
the API call. So just add cones data
equal to await API and import the API
from config then dot get method. In this
one we have to add the path that is /
API/ user/ projects and uh let's add it
in quote
like this and after that we'll add the
headers property in this object so that
we can authenticate our API request and
after that we'll get the response in
this data. So just use this setup
function set generations and provide the
data dot projects
right and after that we'll add set
loading and let's make it false. Now
come to the catch block here we'll add
error colon any and then we'll add the
toast notification here. So just add the
toast import the toast here and then
toast dot error and provide the same
error message and then provide console
log and in the console log just add the
error. Now here you can see we have this
dummy import. So just import remove this
import statement and after that come
here in this use effect. So in this
dependency array just provide the user.
So whenever the user changes it will
execute this function and in this one
just add the if statement and provide
user. So when the user is available then
only we will call this fetch my
generation function and after that here
we'll add else if. So just add
else if and here just add is loaded and
not of user. So when the is loaded is
true and we don't have the user. So in
this case we will navigate the users on
homepage. So just add navigate and
provide the path which is home. Save the
changes. And now let's open our web
page.
So here we have two project. You can see
in this one the image was not generated
because there was some error. Right? So
we'll create the functionality to delete
any project also. Right? If I click
here, we have the delete option. So, we
have to create the functionality to
delete the project. And in this one, you
can see we have this image. And with
this image, we have the other details
also like trolley bag. Then we have the
description. Then we have the prompt.
Here we have the publish button. And
here we have view details.
And then we have this aspect ratio. And
here we have the original images that is
used. And if I hover on this image, it
will play the video like this. Now I'll
click on this view details.
>> Check out this new sky color where we
can preview this content. Right. Let me
just come back.
And here we'll add the functionality
like toggle the publish a status. It
will be publish or unpublish.
And we'll add the functionality to
delete the project. So let me just come
back to the VS code. We will close this
file and open this sidebar components.
And in this components we have project
card.tsx file. Now in this one you can
see we have this
handle delete and toggle publish
function. So let's complete these
functions. So start with this one handle
delete. In this one we have to make the
API call. So we need the
user data and token. So here
let's add con
curly braces and provide get token
equal to use o. So get token is
available here. We have imported the use
o from color. And uh after that let's
come here in this handle delete. Here we
have if not of confirm then return and
after that we have this console log. So
remove this console log from here and
provide
try catch block. Now in this one let's
add con
token equal to await and get token
function. Then we'll add con curly
braces data equal to await
and provide API. Import this API. Then
we'll add dot
delete. And here we'll add the back tick
and provide the path. It will be / API/
project. And then we'll add dollar sign
curly braces and insert the id here.
Right? And you can see here we are
getting this id from parameter. Now
after that we'll add the headers. So
just add comma curly braces and provide
the headers property to authenticate our
request
like this. Now after that we will use
the setter function set
generations and in this one create the
add function like this. And here we'll
get the generations.
And after that let's add generations dot
filter. And in this filter again add the
arrow function. And here we'll add gen
for generation. And here we'll add the
gen dot id
not equal to
ID.
That's it. And after that we'll add the
toast notification. And so just add
toast dot success and provide data dot
message. Correct? Now let's come here in
the catch block and provide colon any
here we'll add toast dot error and
provide the same error message and then
provide the console log like this. So we
have completed this handle delete
function.
Correct? Now after that let's complete
this function which is
toggle publish. So in this toggle
publish let's remove it and provide
try catch or let me provide the same try
catch from here just copy this one paste
it here in this toggle publish now in
this one first we'll get the token then
make the API call and here we will use
await API get method we will change the
method type it will be get and after
that here we will add the path / API/
user user
slash and provide publish
and after that we will provide the
project id here. So in this parameter we
have the project ID. So just add it here
in this dollar sign curly braces. Next
we have to authenticate the request
using this headers property. Then we
will use the setter function set
generations and provide the same thing
here which is the arrow function here.
And after that here we have added
generation dot filter. So let's remove
this generation dot filter from here.
Here we will add generations dot
map and in this map let's add the arrow
function provide
gen and then provide the
gen dot id equal to
project id. If it is true. So in this
case we will add this curly braces
spread operator
gen
is published and in this is published
let's add
data dot
is published.
Else we'll add colon and provide gen.
That's it. Now after that we'll add
toast dots success and in this one just
add data dot
is published. If it is true so in this
case we'll add the message project
published.
If it is false in this case we'll add
the message project unpublished.
That's it. And then we will keep the
catch block same. Save the changes. And
after that let's open the web page. Here
we are getting the error toast dot
error. So let's import the toast. Here
we have added the toast. Let's import
the toast. Save the changes and come
back. Now let me refresh it again. Here
we have toast dot error unexpected
token. Let me just come back. Here we
have
set generations and uh let me move it
like this.
We have this function
and after that here we have this
function which is closing here. So here
we have to add one more
closing tag. That's it. Save the
changes. Now open the web page.
So here we have two projects. Let's
click on this one and click on delete.
Click okay. You can see project deleted.
Let me refresh it. You can see in this
my generations
we will get only one project. Let me
refresh it again.
Yeah, it is working. So here we have
only one project and uh after that let
me change the status here. Right now you
can see we have this publish button. If
I click here,
you can see project published and here
we have unpublished button. So right now
we have the status public so that we can
display this project in the community.
Right? So now let's create our community
page also.
We will come back to the VS code.
Close this file. Open this sidebar pages
community.tsx file. Now in this one you
can see here we have fetch projects
function right so we have to complete
this function here we are getting the
dummy data from asset right so let's
remove it I'll just clear this and
remove this import a statement now in
this one
let's add try catch
and in this one we'll add con curly
braces data
equal to await and here we'll add the
API import the API from config then dot
get method and here we'll add the path
it will be / API/ project/published
that's it here we have not added the
authorization because in this one we
have not added the product middleware it
is public API and here we have added get
method now after that we will simply use
the set function
set projects and provide data dot
projects
Right. And after that we will use set
loading and let's make it false.
That's it. And in this catch block just
add colon any. And here let's add the
toast notification. So we'll add toast
dot error and provide the same error
message and then provide console log.
And this fetch projects will get
executed whenever we load the component.
So here we have already added the use
effect. That's it. So after that let me
open our web page. And now we'll go to
community.
So in this community you can see here we
have only one ad.
So this is the user generated content
ad.
And here we have the details also.
So now we have completed all feature of
our project.
Let's come to homepage. So first we have
the navigation bar and in this one we
have added the user profile. If I log
out here we will get the login and get
started button and here we have the
credits. After login user can see the
credits here. If I click here it will
open the pricing plan where user can
switch to different plan. User can
subscribe to different plan. And when
user will purchase any plan they will
receive the credit and it will be
displayed here in the navbar. And after
that if I come back to homepage. So in
this homepage we have this details. And
if I go to create here we can enter the
details provide the product image, model
image and generate the image. And after
generation we'll come to the result
page. Let's open the result page. So in
this result page if the video is not
generated here we will get the button to
generate the video right and here we can
download the generated video or image
using these buttons and we can also
change the visibility whether it is
public or private. So for that we'll
come here in the my generations and here
we have the option to publish or
unpublish this project. If it is
published then it will be displayed in
community so that any user without login
can see this project in their community.
So now we have completed our project
which is UGC ad generator project. Next
we have to deploy it online.
Now our full stack AI powered UGC ads
maker project is ready. The next real
question is where do we deploy this? So
it actually works in production. If you
have been building project but delaying
deployment, this is exactly where most
people get stuck. And honestly, this is
the easiest time to fix that. For this
project, I'm using Hostinger VPS. It's
affordable, fast, and perfect if you are
serious about building AI tools, agent,
or side projects in 2026.
If you have been telling yourself, I'll
deploy this later. This is the right
time to stop waiting and start
deployment. Right now, Hostinger has a
new year sale running on. So, you can
start at a very affordable price. I will
share the link in the description and
pin comment or you can also type this
URL in the browser. So, just type
greatstack.dev/go/hostinger-vps
div/go/hostinger-vps
and press enter or you can also follow
the link given in the description that
will directly take you to this VPS page.
If you follow our link and sign up for
this hostinger VPS you will get the
maximum discount and if you get any
issue if you are stuck in deployment
I'll definitely help you to resolve your
issue. So here you can see we are
getting the message we are getting up to
60% off on AI managed VPS hosting and
here you can see the new year sale is
going on. Now if I scroll down here we
have different plans for VPS hosting. We
have KVM 1 2 4 and 8. In the first one
we are getting one CPU and 4 GB of RAM
and 50 GB of disk space and 4 TB
bandwidth. In the second one, we are
getting two CPU, 8 GB of RAM, 100 GB of
disk space and 8 GB of bandwidth. Then
we have KVM 4 and KVM8 plan also. So the
first or second one is enough to run
your project. So let me choose this one
KVM2. I'll click on this button, choose
plan.
So it will take you to this page. And
here you can see we are logged in using
this email id. And if you don't have the
account, it will ask you to provide your
email ID and create the account. And
here also you can see the message new
year sale is running on. And we are
getting the biggest saving on 24 months
plan.
And here we are getting 2 months free.
Right? And here we are getting the free
domain name also. Correct? So here you
can choose the duration for your
hosting. If I click on this drop-down
here we have 1 month, 12 months and 24
month. If you sign up for 1 month, it
will be very costly because you need to
renew it every month and the renewal
cost will be very high. So at least go
for 12 months or 24 months. So if I
choose 12 months plan, you can see this
is the final price. And from here if I
choose the 24 months plan right now you
can see the monthly price is this one.
So from this drop-down if I choose 12
months we are getting this price in the
right side you can see the final price
and uh after that if I click on this
drop-down and choose the 24 months this
is the final price but here it will get
the additional discount after applying
my coupon code. I'll click on this link
have a coupon code and provide the
coupon code great stack 15. This great
stack 15 coupon code will only work on
24 months plan. I'll click on apply
button
and here you can see we are getting
additional 15% off right and here we are
getting 2 months extra web hosting which
is the VPS hosting and we are getting
free domain name also. After that scroll
down and here you can choose the server
location. So let's click on this
drop-down and here you can choose the
nearest region. So I'll choose.
So I'll choose anyone from this Asia.
I'll choose this one Singapore. And
after that here we have the option to
choose the operating system. So here we
have a beautiful feature while hosting a
VPS. We can choose different operating
system. So it will be pre-installed.
After that you have the option to use
the OS with some panel like you can
install the OS also and with this panel
also and here we have the option to
install the applications also. If I
click on this application so we can
directly create the VPS server by using
these application. These applications
will be pre-installed. So I'm going to
use this plain OS and in this one we
will choose this Ubuntu operating
system. If I click here, here we have to
choose the version. So I'll choose this
one 24.04 LTS which is the stable
version and click on confirm.
After that I'll click on this continue
button and provide our billing details.
So let's click here.
On this page you need to provide the
billing details and after that it will
add some taxes also. And this is the
final price. And here you can make the
payment using your preferred method like
you can use the card payment, UPI,
PayPal or EMI. So use your preferred
payment gateway and complete the
payment.
After completing the payment, you will
come to the Hostinger dashboard which is
the Hostinger panel and in that one you
need to choose the reason and then you
need to provide the root password for
your VPS server and after that you will
come here in this dashboard. Here you
can see we are in this home and here we
have this VPS server also. Right here we
have two VPS server or you can also find
it in the left sidebar and in this VPS
menu. Let's click here. So here you can
see we have two VPS server. Now we need
the domain name also that we will
connect with our project. For that let's
click here on this domains. So just open
this domains and click on get new
domain. And here we have this search box
where we can search for the domain name
that we want to purchase. So let me
search for make
ugcad.com.
I'll search for this one. And you can
see it is available. If it is not
available, you can again search the new
domain in this search box. And if it is
available, just click on this add to
cart. So after that, it will ask you to
choose the duration. So I'll select 1
year. And here it is displaying the
price. I have to purchase it because
this is my old VPS account. I have
already claimed the free domain. And if
you have purchased a new VPS for 12
months or 24 months, you will get the
domain name for free. You don't need to
make any payment. You just need to
provide the contact details to get this
domain. So I'll click on this button.
Continue to check out.
In the next step, you need to provide
the contact details to book your domain
and then click on finish registration.
Now you can see this message. Start
using your new domain. I'll click on
continue.
Then click on skip. So after registering
your domain name, you will come to this
page. Right? And after that it will also
ask you to verify your email ID. You
will receive one email. Just click on
that link and verify your email ID. And
after that, let's come here in this VPS
again. I'll open VPS.
And here you'll find your IP address. So
this is the VPS server that I'm going to
use to deploy our project. And here we
have this IP address. So let me just
copy this IP address. And after that we
have to point our domain name on this
IP. So let me just come back again in
the domains.
Here you can see we have this domain
make ugcad.com
and here we have manage button. So I'll
click on this button manage.
In the left side you will find DNS name
server. Just click here
and in this one
you can see we have the DNS records
correct. So here you will find this A
record at the bottom we have this A
record and it is pointing to this IP
address. So we have to update it. I'll
click on edit
and add the VPS IP address. So I'll
provide this IP address that is our VPS
IP address. And here let's update it.
All right.
This one. Click on update.
So you can see the DNS record updated
successfully. Correct. Now we'll add one
more record for our backend server. We
will run our backend server on subdomain
with the name API. Right? So let's come
here and here you can see manage DNS
records we have the type A and here
we'll add the name. So let's add the
name API then we'll add the IP address
of our BPS server and click on add
record.
So there will be two A records for at
the rate and for API which is the
subdomain. Click on confirm.
You can see DNS record created
successfully. And uh here you can see
this one a API and this IP address and
it is exactly same IP address that is
provided in our VPS hosting. So if I
open VPS server in the left side you
will find this VPS.
Here you can see we have the same IP
address for our VPS server. Now let's
click on this manage button to manage
our VPS server. I'll click here.
So here you can see the details. This is
the operating system running on our
Hostinger VPS. Here we have the root
access. So we can use this SSH in our
terminal and provide our root password
to connect with the VPS. Here we have
the option to change the root password
also. And here we have reoot VPS. After
that here you can see the
status like usage
and after that here we have the other
details like server location operating
system host name uptime SSH username,
username is root and this is the IP
address and in the right side we have
the plan details like KVM2 expiry date
and auto renewal and other details. So
next we have to login in our VPS root.
For that we can use this SSH access in
our terminal and provide the root
password or here the hostinger VPS has
provided a beautiful option to connect
with the root using one click. Here you
can see in the right side we have this
terminal. So I'll just click here.
So you can see now we are in the VPS
terminal. From here we can manage our
VPS.
Now here we have to run our project. We
have to deploy our project. For that we
have created a dedicated nodes. So let's
open that. I'll open
github.com/grastackdev.
Open this repository which is great
stack. And here you will find this
nodes. I'll click here
and after that here you will find this
one
deploy on VPS. So I'll just click on
this file. So it will open this one.
So here we have the step-by-step guide
to deploy MER or P project on Hostinger
VPS. So the first step is to preparing
the VPS environment. You need to get the
VPS hosting. You can also use this link.
Just click here and sign up for hosting
VPS. Then you need to login in VPS
terminal using this SSH. So we are
already in the VPS terminal. After that
you can see the next step update and
upgrade your system. For that we will
use these commands. So just copy the
first one and come back here in the
terminal. Just paste it. Press enter.
Now it is done. After that I'll just
come back here
and copy the second one. Copy and paste
it here.
Then press enter.
Let me zoom in.
Now it is also executed. After that
let's see the next step. So the next
step is to install NodeJS and npm using
this line. So let's copy this
and paste it here.
Press enter.
So it is installing the NodeJS and it is
done. Now see the next step. So let's
copy this command
and paste it here.
It is done. Now just come back and copy
this one. nvm install 22. Copy this.
Paste it here.
Now it is also done. After that let's
come back here and see the next step. So
next we have to install the git. So copy
this command and paste it here.
So it is also installed. Now let's see
the next step. So you can see the next
step setting up MongoDB database and if
you are using the postgress database you
can also set up that but here I'm going
to use the neon database only in our
project we are using neon database so uh
skip this second step directly come to
the third one so in the third one we
have deploy the express and NodeJS back
end. So first we will deploy our back
end. For that we have to create a
repository here and then navigate to
this repository and here we will clone
our GitHub project. For that we have to
deploy our project on GitHub first. For
that I'll just come back to the VS code.
In this VS code we have this file. Let's
close it.
Let's right click and close saved. Now
open the sidebar. Here we have the
client and then we have this server.
Right? If I open the terminal, you can
see this is the backend terminal and
this is the client terminal.
Right? So the client project is also
running. Now let me check our build
here. If I add control C, it will stop
the front end which is the client,
right? And after that here we'll add
npm
run
build. Press enter.
So it will create the build of our
project. If it is successfully created
then only we can deploy it. So just wait
for it.
So now the build has been created. If I
open the client project here you can see
we have this dist folder. In this dish
folder we have this project. So it is
successfully creating the build. It
means we can deploy this project without
any issue. So now let's close this
terminal
and uh we will delete this d folder
also. Just click on
delete
and after that here we have the server.
In this server we will open this
package.json file. So in this package
dojson file we have to add a new script
that will be post install that will
generate the Prisma right. So just add
this
double quote and provide post install
colon and then write npx
then prisma
generate.
You need to add this one and then add
comma. Make sure to add it.
After adding it, save the changes and
close this file. Correct? And after
that,
let's open the sidebar. And here in the
root folder, which is the UGC project,
let's right click and create a new file
that is dot get ignore.
And in this one just add env. So it will
skip this environment variable file and
we'll also add node modules.
So it will escape the node modules
folder. That's it. After that I'll just
click on this source control icon. You
will find this icon when the VS code is
configured with your GitHub. So I'll
just click here and click on initialize
repository.
So here you can see the total number of
file it is 80 correct. Now we'll add the
commit message.
First commit and click on this button.
Now click on publish branch.
Now it is asking to choose the private
or public repository. So I'll choose the
first one private repository and the
repository name is UGC project. I'll
choose this one.
So it will publish the codes on GitHub.
In the right side you can see this
progress. And now you can see the
message successfully published the
repository. Right now let's open our
GitHub repository. So let me open it.
Here you can see we have this UGC
project repository where you can see we
have the client and server and it is
uploaded just now. Correct. Next we have
to clone this project on our VPS. So
let's see the document again. First we
have to create this directory. So copy
this and open the terminal and paste
this one.
So it will create this directory. Now we
have to navigate here. So copy the
second one cd/ware/www.
Copy and paste it here.
Press enter. So now we are in this www
directory. And here we have to clone our
project which is this one. So just copy
this
or we can simply copy this one. Get
clone.
Paste it here. And after that we have to
provide our repository link. Correct. So
just come back here in the GitHub
repository
and uh here you will find this link.
Just click on this button and click on
this icon to copy this GitHub repository
link. And after that if I add it in the
terminal, it will not work because right
now this repository is private. So I'll
go to settings and I'll make this
repository public for few seconds. So
I'll change visibility change to public.
And now this repository is public. Let
me provide the password also to confirm
the action.
Now after that our repository is public.
Right. Now let's come here in this
terminal and paste this
URL. Here we have to add the space also.
After this get clone provide the
space and provide this URL and press
enter.
Now it is done. After that we can again
make the repository private. So just
come here change visibility
and make it private.
Let's come back here.
You can see the UGC project repository
is private.
Right now let's see our next step.
So I'll open the documentation.
In this one you can see we have to
navigate to our project repository and
then we have to go to the server or back
end because we will deploy the backend
server first. So let's come back here
and we'll write
cd and repository name that is
UGC project.
Now in this UGC project we have the
client and server. So let's navigate to
the server. Just add cd
or you can also see the repository using
this ls. Just add ls. You can see the
repository name client and server. So we
will deploy the backend server. So just
come here using
cd
server. Now we are in the server
repository or server directory. So now
let's see the next step. We have to
install the dependencies using this npm
install. But before installing the
dependencies, let me create the
environment variable also. For that we
have to use this nano.env. So copy this
paste it here.
So it will create env file and open this
file. Now in this one we have to provide
our environment variables. So let me
just come back to the VS code then open
the server then env file and here you
can see we have this database URL then
color keys then we have the cloud and
Google key. So just copy this one. Copy
everything from here and uh let's paste
it here. Right click and paste. After
that we have to save this file. So just
at Ctrl X
Y enter. Now it is saved. After that we
will install the dependencies using this
npm install. So copy and paste it here.
So it is installing the dependencies
in our server project.
Now it is done. After that let's see the
next step. So you can see the next step
is to add the
PM2. Using that we will start the
backend server. Correct. So just add npm
install-g
space PM2. Copy this one and paste it
here.
Press enter.
So it is installing the PM2 package.
After that let's see the next step. So
the next step is to add the
PM2 start server.js
then name and one name that is project
backend or anything. But here we will
make some changes because we have
created this project using TypeScript.
This command is written for the
JavaScript project, right? So, let's
make some changes here. Instead of
adding this, I'll just add this one. Let
me open the notepad
and I'll add this one.
And in this one, we will make the
changes. So we'll write
PM2 a start and after that we'll write
npm
dash name and then we'll add the
project name. So let's add the project
name here which is UGC server
right and after that we'll add test dash
and provide a start.
Now just copy it
and paste it here
in this terminal.
Press enter.
So now you can see this UGC server is
added in this PM2. It will start it
whenever server restarts.
Correct? You can see the status is
online. And after that I'll just come
back here and see the next step. So
after that we have to allow the firewall
right. So first we'll check the firewall
status but before that we have these
part also that is PM2 startup and PM2
save. So just add this one also copy
this paste it here.
So we have added PM2 startup here and
after that we have to add this PM2 save.
So let's come back and provide this one
PM2 save.
It is done. Now let's see the next step
that is allowing the firewall. So just
check the status using this. Copy and
paste it here.
So you can see the status is inactive.
So let's make it active using this one.
Copy this.
Paste it here.
Press Y.
Now you can see the message firewall is
active and enabled on system startup.
After that here we have to add this one
that is allow open SSH. So copy it and
paste it here.
Done. So you can see the message rule
added. So it is allowed in firewall
which is open ssh. Now we have to allow
the port number also. So you can see the
port number is 4,000. So let's copy this
and uh here we'll write sudo ufw allow
5,000 because we have created our
backend server on 5,000 port number.
Copy this and add it in this terminal.
Now it is also added in the rule. If I
come back here, you can see the next
step deploying the front end. Right? For
that we have to navigate into our front
end directory. Right? So let's come back
and here we'll write
cd
dot dot. So now you can see the command
not found. Let me add cd space dot dot.
So now you can see we are in the ugc
project. Here we'll add ls. So here you
can see we have the server and client.
So next we have to navigate to the
client directory. So just add cd client.
So now we are in the client directory
and here we have to add the dependencies
using this npm install. So let's copy
it. Paste it here.
So it is installing the dependencies
and after that we have to add the
environment variable also using this
nano.env.
Correct? So let me just come back here
and you can see the dependencies has
been installed.
Now let's add this command nano.env.
So it will create environment variable
file and open this file. Here we have to
provide the environment variables for
client. So just come back here
in the VS code. Close this one. Go to
client. Then open env. And uh here we
have these environment variables. So
just copy it and paste it here.
And in this one we will make the
changes. Here you can see we have this
wheat base URL where we have to provide
our backend URL. So we will run our back
end on subdomain. So just add https
col/ slash and here we'll add api which
is the subdomain
then dot
make ugc
add.com.
So we have added the domain name.
You can see this one wheat base url
equal to https/
api dot make ugcad.com.
We have added the subdomain where we
will run our backend server. Just copy
it and then
come back here in the terminal.
Just paste it and save this file using
Ctrl X Y enter. It is done. Next, we
have to create the build of our project
using npm run build. Copy this one and
paste it here.
So it is generating the build and once
the build is generated we can run the
front end also.
So it is done
and after that it will generate the
build in dist folder. So let me just
come back here and see the next step. So
next we have to install the engineext
right. So for that let's copy this
command
and paste it here.
It is completed. Let's see the next one.
So we have to allow the engineext in
firewall. So just copy this one
to check the status. Paste it here.
So here you can see we have the allowed
port and open SSH right now after that
let's allow the NX full also. So just
copy this one
paste it here.
So it is added in the rule. Now after
that we have to create the
NX for the front end. We have to
configure the enginex right. So I'll
just copy this one
and paste it here in the notepad. And
here we'll add the domain name for the
front end. So let's add
make ugc add.com
dot cf
that is configuration right. So just
copy this one and come back here in the
terminal.
So it will create this file and open it
that is make ugc add.com
conf. Now in this one we have to add
this configuration. So I'll just copy
this configuration
paste it here in the notepad and let's
update the domain name here. So I'll
write
make UGC
add.com
and then we'll add www
make UGC add.com. So we have added make
ugcad.com and then space wwwugcad.com
and after that here you can see we have
this
root. So here we have to add the
repository name and then at the end
we'll add dish. So let's add the
repository name here UGC- project
and in this one we have the client
just update this path www/ugc
project/client/dist
and after that just copy this one and
paste it here in this file and we have
to save this file.
Crl X Y enter it is done. Now after that
you can see the next step we have to
create the similar file if we have
multiple front end. So just skip this
one and after that we have to create the
symbolic link to enable this site. So
let's copy the command here. Copy this
one and paste it here.
Now in this one you can see we have
sites available and provide the domain
name. So the domain name is make
ugcad.com
then this path that is /c/x/
sites enabled just copy
and paste it here
in this terminal.
It's done. Now let's see the next step.
So we have to test the engineext
configuration for syntax error. So let's
copy this one. Paste it here.
You can see the message test successful.
Now just see the next one that is
restart. So just copy this one and paste
it here.
It is executed. After that let's come
back. And here you can see we have to
configure the reverse proxy. Configure
enginex as reverse proxy. So here we
have to create a new file for the back
end. So just copy this command paste it
here in the notepad and here we'll
provide the
domain name. So we'll add api dot
make
ugc
add.com.
Now let's copy this command and paste it
here in the terminal.
So it will create this file and open it.
And after that in this one we have to
add this configuration. So copy it and
paste it here in the
notepad. And here we'll provide the
domain name
make ugcad.com.
Here we have ai dot makeugucc.com
and then we have to add the port number
here which is 5,000.
Now everything will be same. Just copy
this one and uh after that paste it
here.
Then add control x y enter. Save this
file. Now after that again we have to
create the symbolic link using this
command. So just copy this one and paste
it here. And in this one we'll add the
domain name like make ugcad.com.
So we have the complete subdomain which
is api.make
ugcad.com
which is the file name. So just copy it
and come here.
Just paste this one.
It is done. Now see the next command
which is restart engineext. So let's
copy it.
Paste it here.
It will restart the enginex. And after
that you can see the
next step that is connect domain name
with website. For connecting the domain
name we have to point all the domains
and subdomain on the VPS IP address. If
we have not pointed the IP address, just
add it. We have already added the IP
address in the domain name DNS record.
Right? So if you have not added, just
add the IP address. Then only proceed
for the next step. And after adding the
IP address in the DNS records, it will
take some time to reflect the changes.
So just wait for 10 to 15 minutes, then
only proceed for sixth step. So we have
already added the IP address. So we can
directly come here in the next step that
is installing the search w. So let's
copy this
and paste it here in the terminal.
It is done. Now just come here and copy
this one that is obtaining SSL
certificate. So let's copy this
and paste it in the notepad. And here we
have to update the domain name. So you
can see we have searchbot d-engineext-
d and provide the domain name that is
make
ugc
add.com and then we'll add www
make ugcad.com then we'll add
API. So let me remove this one. Just add
dash d api
dot make uducad.com. So we have total
one domain and two subdomain which is
make ugcad.com then www. make uducad.com
and api.makeugucad.com.
Let's copy it and it will add the SSL
certificate for this domain and
subdomain. So just paste it here in this
terminal.
Press enter.
Now it is asking to provide the email
id. So let me provide one email id here.
Then press enter.
After that press y to agree to the terms
and condition.
Here we will press N for no.
Now you can see the message account
registered and it is requesting the SSL
certificate for this domain and
subdomain. So just wait for that.
Now you can see the message here
successfully deployed certificate and
here we have the files
and after that we have to verify the SSL
renewal. If I come back here in the
documentation
you can see the next step verify auto
renewal. For that just copy this one.
Let's paste this command and press
enter.
So after that you can see the message
simulating renewal of an existing
certificate.
You can see the message congratulations
or simulated renewals succeeded. It
means it will successfully renew the SSL
certificate before expiry. So here you
can see we have completed these steps
and if you have purchased the VPS using
our given link then you can also contact
us on this email id if you need any help
in the deployment. if you're stuck in
deployment. So after that now let's open
our domain. So open the new tab and here
we'll search for
make ugcad.com.
So you can see our website is running
live. Here we have makeugucc.com
and here you can see the same website
that we have created on localhost.
And right now the web hooks will not
work because in the color web hooks we
have added the temporary URL. So we have
to update that URL. Then only the books
will work. We can store the user data in
database. So let's just open the color
dashboard again.
In this color dashboard just go to
configure.
Then in the left side you will find
developers behooks. Just open this
behook settings and uh in this one you
can see we have the end points. So this
is the temporary URL of our backend
server. So let's update it. I'll click
here and go to edit and here we will add
our backend URL. So it will be
https col//appi
dot
make
ugcad.com/
api/clark.
We have to add the complete endpoint for
the clerk webbooks. So again you can see
the URL it is api dot make
ugcad.com/api/clerk
and click on save. So we have updated
the bebooks URL and after that whenever
we will create a new account our user
data will get saved in the database also
and when we sign up for any plan we will
get the credits also. So now let's test
our application after successful
deployment.
So I'll click on this sign in button and
I will sign in with my existing account.
Now this signin is working and here we
are getting the credits also and after
that we'll come here in the community.
So here we have a UGC ad which is added
in the community. If I go to my
generations. So here also we are getting
the details. We have generated this UGC
ad. Now let's create a new one. I'll
click on this create button and here it
will provide the product image.
So I'll click on this button
product image and upload this sneaker
image. After that I'll upload the model
image also. I'll click here and I'll
choose this model.
So here we have the product image and
model image. After that we'll add the
project name. So let's add second
project. Then we'll add the product
name. So the product name is sneakers.
Then we'll add the product description
which is optional but let me write it.
So we have added the product
description. We will choose the aspect
ratio. And after that we can also add
the prompt. So here we will add this
prompt. So case the sneakers in a
dynamic and fashionable way and click on
generate image. So first it will
generate the image.
Here we are getting network error. Let
me fix it.
I'll right click and inspect then go to
network and I'll click on this button
again.
So here we are getting network error.
And if I click on this post request, you
can see we have this a status that is
request entity too large. So we cannot
upload more than 1 MB of image in this
project because of the engineext limit.
So we have to reset the limit. So let me
just come back here and uh I'll come
back here in the terminal.
We have this VPS terminal. So in this
one just add this command sudo nano/etc/
engineext/engineext
config. So it will open this file.
Let's add it here.
Press enter. Now in this one we have to
find this one which is client max body
size 100 MB. If it is available we will
modify it or we will add it. So let me
just come back here. So now this file is
open and in this one we have to find the
client max execution inside this HTTP.
So in this one let's move down here we
have basic settings and then some other
settings like SSL setting.
So in this one we don't have that
client max size right. So here it is
closed. So before closing off this curly
braces, we'll add the space. And here
just add this command or configuration.
Let's copy this client max body size.
Just copy this one and right click and
paste it. So we have added client max
body size 100 MB. And after that save
this file using Ctrl X Y enter. Next we
have to restart our engine X. For that
we have this command that is system
control restart engineext. Just copy
this one and paste it here.
Press enter. After that I'll just come
back to the web page again. Now let me
refresh this web page
and I'll upload the product image again.
Let me upload this sneaker. After that
we will upload this model image. Then
we'll add the name. So let's add
second project. We'll add the name that
is sneakers. Here we'll add the
description. So let's add the
description here.
And then we'll add the user prompt. So
the prompt is optional. So let me write
it. And after that click on this
generate image button.
Now you can see it is generating our
image using this product and model
image. So just wait for that. It will
take few seconds because it is
generating the image using AI.
You can see the loading animation in
this button.
Now it is generated and we are
redirected to this result page. In this
result page you can see we have this
model image and in the hand of this
model we have this sneaker right and uh
this model is wearing the same sneaker.
So we have created the image using the
product and model. After that here we
have the button to download this image.
Let me just click here. You can see we
can download this image like this. Let's
close it
and uh let's open the page again.
We will open our website.
Let's open the homepage. Go to
my generation. So here we have this
generated image. Let me just click here.
It will open the result page. So in this
result page we have this image. Correct?
And after that if I click on this
generate video it will generate the UGC
add video also using this image. So I'll
click on this button. You can see the
text here generating video. In this
button we have this text generating
video. So it will take few seconds to
generate the video. So just wait for
that
>> defined. Introducing the new must-h have
sneakers. Watch as they shift to this
ultra clean white finish. Style and
comfort redefined.
>> Introducing the new must-have sneakers.
Watch as they shift to this ultra clean
white finish.
>> So I have muted this video and you can
see it is generated using AI. So this
project is successfully working after
deployment also. And here we have this
button to download this video.
So we can download the image and video.
And uh you can see our credits has been
reduced.
Let me refresh it.
Here we have 70 credits after generating
the video. Now let me just come back to
the homepage. So now we have
successfully created our UGC ad maker
project that is AI powered project and
we have successfully deployed it online
using hostingervp.
I hope this video will be helpful for
you. If you have any question, you can
ask me in the comment section. Please
like and share this video and also
subscribe my channel greatest tag to
watch more videos like this one. Thank
you so much for watching this video.
Full Stack AI SaaS Project π UGC Short Video Ads Generator with PERN, Gemini API & VPS Deployment | Step-by-Step Beginner Friendly Tutorial π Neon: https://get.neon.com/ZA5t2RA π Clerk: https://go.clerk.com/DBJRKt7 π Hostinger VPS: http://hostinger.com/in/greatstack π Sentry: https://dub.sh/sentryai (Get $100 for FREE Credits) π Source Code & Assets: https://greatstack.dev/p/ugc π Live Preview: https://makeugcad.com SUBSCRIBE: @GreatStackDev ------------------- In this step by step Full Stack AI Project tutorial, we will build and deploy a Full Stack AI Powered UGC Ads Video / Image Generator using the PERN Stack (PostgreSQL, Express, React, Node.js). This real world AI SaaS project uses Google Gemini API to generate high converting UGC video ad content, making it perfect for developers, startups, and creators who want to build production ready AI applications. π§ Tech Stack Used Frontend: React Backend: Node.js & Express Database: PostgreSQL (Neon) Authentication & Billing: Clerk AI Integration: Google Gemini API Monitoring & Error Tracking: Sentry Deployment: Hostinger VPS π What Youβll Learn Build a Full Stack AI Application from scratch Integrate Google Gemini API in a real project Implement authentication & subscription billing with Clerk Use PostgreSQL with Neon in a production environment Monitor performance & errors using Sentry Deploy a PERN stack application on VPS (Hostinger) Create a magnetizable AI SaaS product This tutorial is ideal for: Full Stack Developers JavaScript Developers SaaS Builders AI App Developers PERN Stack Learners If youβre looking to build AI SaaS projects, startup ready applications, or portfolio level full stack projects, this video is for you. #fullstack #webdevelopment #aiprojects #coding #greatstack #programming #collegeprojects #fullstack #mernstack #aitutorial #reactjs Timestamps: 00:00 Project Overview 07:39 Create Frontend using React and PrebuiltUI.com 01:34:47: Create Community Page 02:34:20 Create Result Page 03:04:37 Add User Authentication with Clerk 03:38:00 Create Backend Server 04:03:34 Connect Neon Database 04:33:40 Error Tracking using Sentry 04:45:36 Create API for User Features 05:03:43 Create API for UGC image and video creation 06:16:56 Connect Backend Server with Frontend 07:08:01 Deploy project using Hostinger VPS ------------------- Build more full stack projects Watch Full Stack Food Order Website tutorial: π https://youtu.be/DBMPXJJfQEA Watch Full Stack Chat App tutorial: π https://youtu.be/gbocZlm71nE Watch Full Stack Music Streaming Website π https://youtu.be/KdGfhSpT6pc Watch Full Stack Blog Website Tutorial π https://youtu.be/HdWCh_4XE1Q ------------------------------------- Build more React JS projects: Complete Portfolio Website In React: π https://youtu.be/4ag1LsgIUc0 Build ChatGPT Clone In React: π https://youtu.be/EzkWAviyYgg Build AI Image Generator with OpenAI In React π https://youtu.be/PZG2MvOjud0 Create Weather App In React π https://youtu.be/7JqdjWB88Kk ------------------------------------- Connect with me: π https://linktr.ee/iamavinashkr Connect with GreatStack: Instagram: https://instagram.com/GreatStackDev Twitter: https://twitter.com/GreatStackDev Facebook: https://facebook.com/GreatStack