In this tutorial, we will be creating a full stack SaaS application called ScrapeFlow using Next.js, React, Typescript, React-Flow, Prisma, and ReactQuery. ScrapeFlow will be a web scraping tool that allows users to extract data from websites and store it in a database.
- Setting up the backend with Prisma
First, let’s set up the backend of our application using Prisma. Prisma is an ORM that allows us to interact with our database using a type-safe API. To get started, create a new folder for your backend and run the following commands:
npx create-nx-workspace@latest
Next, add the Prisma package to your project:
yarn add prisma
Now, let’s set up Prisma. Create a new file called schema.prisma
in your prisma
folder and define your database schema. Here is an example schema:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
model Website {
id Int @id @default(autoincrement())
url String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Next, run the following command to generate your Prisma client:
npx prisma generate
You can now start building your API routes using Prisma client to interact with your database.
- Setting up the frontend with Next.js
Next, let’s set up the frontend of our application using Next.js. Next.js is a React framework that allows us to build server-side rendered applications with ease. To get started, create a new folder for your frontend and run the following commands:
npx create-next-app@latest
Now, add the ReactFlow package to your project:
yarn add react-flow
Next, create a new page in your pages
folder called index.tsx
. In this file, you can start building your frontend components using React and ReactFlow. Here is an example component using ReactFlow:
import { useEffect, useState } from 'react';
import ReactFlow from 'react-flow-renderer';
const ScrapingTool = () => {
const [elements, setElements] = useState([]);
useEffect(() => {
// Fetch data from your API and set it to elements
}, []);
return (
<div style={{ height: '800px' }}>
<ReactFlow elements={elements} />
</div>
);
};
export default ScrapingTool;
- Setting up ReactQuery
ReactQuery is a powerful tool that allows us to manage data fetching and caching in our application. To get started, add the ReactQuery package to your project:
yarn add react-query
Next, create a custom hook to fetch data from your API using ReactQuery. Here is an example custom hook:
import { useQuery } from 'react-query';
const useWebsites = () => {
return useQuery('websites', async () => {
const response = await fetch('/api/websites');
return response.json();
});
};
export default useWebsites;
Now, you can use this custom hook in your React components to fetch data from your API and display it in your frontend.
- Putting it all together
Now that you have set up your backend with Prisma, your frontend with Next.js and ReactFlow, and ReactQuery for data fetching, you can start building out your full stack SaaS application, ScrapeFlow.
You can add features such as CRUD operations for websites, web scraping functionality, data visualization using ReactFlow, and more. Remember to test your application thoroughly and optimize it for performance.
I hope this tutorial was helpful in getting you started with building a full stack SaaS application using Next.js, React, Typescript, ReactFlow, Prisma, and ReactQuery. Happy coding!
⭐If you enjoy this type of content and would like access to all my video code with an MIT license, consider supporting me on Patreon—your support means the world and helps me create even more for you! https://dub.sh/scrapeflow ⭐
Vscode setup used in the video:
Theme: Vesper
Font used: Github Monospace
A literal gem ❤
But openAI api is not free
You should create a web course from the basics of React, I will definitely pay for it! Best material ever found online
Amazing work!
First of all I would like to say THANK YOU SO MUCH. KEEP GOING!!
And below you can find a bit improvements for project:
We can use PropsWithChildren instead of React.ReactNode;
Hook useActiveRoute:
const useActiveRoute = () => {
const pathName = usePathname();
const activeRoute =
ROUTES.find(
(route) => route.href.length > 1 && pathName.includes(route.href)
) || ROUTES[0];
return activeRoute;
};
Routes
export const ROUTES = [
{
href: "/",
label: "Home",
icon: HomeIcon,
},
{
href: "workflows",
label: "Workflows",
icon: Layers2Icon,
},
{
href: "credentials",
label: "Credentials",
icon: ShieldCheckIcon,
},
{
href: "billing",
label: "Billing",
icon: CoinsIcon,
},
];
Component RoutesList
interface RoutesListProps {
setClose?: () => void;
}
const RoutesList = ({ setClose }: RoutesListProps) => {
const activeRoute = useActiveRoute();
return (
<>
{ROUTES.map((route) => (
<Link
className={buttonVariants({
variant:
activeRoute.href === route.href
? "sidebarActiveItem"
: "sidebarItem",
})}
key={route.href}
href={route.href}
onClick={setClose}
>
<route.icon size={20} />
{route.label}
</Link>
))}
</>
);
};
Create workflow action with more granular Error handling.
Prisma documentation for error handling.
https://www.prisma.io/docs/orm/reference/error-reference#prismaclientvalidationerror
export async function createWorkflow(form: workflowShemaType) {
const { userId } = auth();
if (!userId) {
throw new Error("Unauthenticated");
}
const { success, data } = workflowSchema.safeParse(form);
if (!success) {
throw new Error("Invalid form data");
}
let result;
try {
result = await prisma.workflow.create({
data: {
userId,
status: WorkflowStatus.DRAFT,
definition: "TODO",
…data,
},
});
if (!result) {
throw new Error("Failed to create workflow");
}
} catch (error) {
if (error instanceof PrismaClientKnownRequestError) {
if (error.code === "P2002") {
throw new Error("Workflow name already exist");
}
}
throw new Error("Something went wrong");
}
redirect(`/workflow/editor/${result.id}`);
}
top
my man is cooking
Amazing course. What theme and font family are you using in vscode?
When will you start working on a MERN microservice or microfrontend architecture? All your previous projects have been monolithic. Please consider creating an e-commerce application using a microfrontend and microservice architecture.
The bar keeps rising ⬆
Can I use your code in my product by changing design? Btw love your explanation❤❤
Thank you bro for this tutorial. That's insane the amount of work needed to do this. 🙏
Hey man thanks for sharing this! Not everyone is willing to put the effort and share their knowledge, you're trully contributing to this world! Just out of curiosity, are you using Linux? What tiling manager are you using?
Bro, please show how to deploy the project to production (maybe vercel). Facing a lot of issue to deploy it because of puppeteer. Please help!!!
Hello Kliton,
If I follow this tutorial and able to build scrapeflow will I be able to convert this project to a workflow automation project or no-code drag and drop rest api builder?
Amazing, grazie
also make advance ecommerce application
my god you are damn insane man every video in your channel so unique and totally different unique. Teaching style is also 🔥🔥🔥
1:04:43