Build an AI MicroSaaS App using a Low-Code Template Integrated with Stripe
Tags: tutorial, opensource, codenewbie, cloud
Published: 2023-06-16 11:52:33

<p>SaaS (Software as a Service) refers to a software delivery model where <strong>applications are hosted and provided over the Internet</strong> as a <strong>service to customers</strong>. Instead of purchasing and installing software locally, users access and use the software through a web browser or a dedicated application.</p>
<p><img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FogImage%2FPnMb5baU4tLMQoCFhDgW-microsaas-1.png?alt=media&amp;token=d3e51f22-7101-4519-b727-fbc5c1da6b0c" alt="microsaas-1" /></p>
<p>With the flexibility of low-code development, we can effortlessly create our own <strong>MicroSaaS</strong> application called <strong>AI MicroSaaS Background Remover</strong>. This powerful application allows users to <strong>easily remove the background from their images</strong> without compromising the image quality! 🪄</p>
<p>Additionally, it offers valuable features like <strong>user authentication</strong>, <strong>a credit system</strong> where each photo removal consumes one credit, and the option for users to <strong>purchase credit packages</strong> for additional image removals.</p>
<p>The AI Background Remover application is built using <a href="https://www.rowy.io">Rowy</a>, a <strong>powerful low-code platform</strong>, and utilizes local backend management tools hosted on Google Cloud. By leveraging the <strong>Replicate API</strong>, the application efficiently <strong>removes backgrounds from uploaded photos</strong>, ensuring high-quality results. Furthermore, the integration of the <strong>Stripe API</strong> enables seamless credit purchases, enabling users to acquire additional credits for image removals. The application's** frontend is powered by a separate NextJS project**, ensuring a smooth and intuitive user experience.</p>
<h2 id="aboutthetools">About the Tools ⚙️</h2>
<h3 id="backgroundremovalwithreplicateapi">Background Removal with Replicate API 🖼️</h3>
<p><img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2F0eXv8ppwZkxRcItGVboM-microsaas-2.png?alt=media&amp;token=4bf0399f-4c51-45ab-95b5-7885e60c8f85" alt="microsaas-2" /></p>
<p>The AI Background Remover application leverages the <strong>Replicate API</strong> to perform <strong>accurate and efficient background removal</strong> from uploaded photos. Replicate is a powerful AI-driven image processing API that specializes in background removal tasks.</p>
<p>By utilizing advanced algorithms and deep learning techniques, Replicate enables the application to automatically extract foreground subjects and remove backgrounds while preserving the quality of the image. This integration ensures that users can <strong>effortlessly achieve professional-looking results</strong> without any manual editing.</p>
<h3 id="paymentprocessingwithstripe">Payment Processing with Stripe 💰</h3>
<p><img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FHcwMmDfXw09VyzatmVd7-microsaas-3.png?alt=media&amp;token=b361dfb6-1028-45ff-87ca-4b287b5562f5" alt="microsaas-3" /></p>
<p>Stripe is a <strong>popular payment processing platform</strong> that the AI Background Remover application integrates with. It enables seamless handling of credit purchases within the application.</p>
<p>With Stripe's secure and reliable payment infrastructure, users can easily and safely purchase additional credits to remove backgrounds from more images. The Stripe API provides the necessary functionality to <strong>handle transactions, manage subscriptions, and ensure a smooth payment experience</strong> for users.</p>
<h3 id="seamlessfrontendexperiencewithnextjs">Seamless Frontend Experience with NextJS ✨</h3>
<p><img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FYlR1dMHW9Zz6GJbprbOf-microsaas-4.png?alt=media&amp;token=ccf40e2a-f72f-4bb4-ab6e-d792b8685c7a" alt="microsaas-4" /></p>
<p>NextJS is a popular frontend development framework that <strong>powers the user interface of the AI Background Remover</strong> application. It provides a <strong>robust and scalable environment</strong> for building interactive and performant web interfaces.</p>
<p>NextJS offers features such as server-side rendering, client-side rendering, and static site generation, which enhance the overall user experience. With NextJS, the application delivers fast loading times, smooth transitions, and responsive designs, ensuring a seamless and enjoyable user experience while interacting with the AI Background Remover features.</p>
<h2 id="retrievingthereplicateapitoken">Retrieving the Replicate API token ✅</h2>
<p>Follow these steps to retrieve your Replicate API token for the application:</p>
<ul>
<li>Visit the <a href="https://replicate.com/">Replicate Website</a> and sign in to your account. If you don't have an account, you will need to create one.</li>
<li>Click on the dropdown adjacent to your profile in the top-left corner of the page and navigate to the <a href="https://replicate.com/account/api-tokens">API tokens</a> page. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2F1cNrjFyDIRHGqWLuCCyj-microsaas-5.png?alt=media&amp;token=a7710a83-9a49-4ead-8630-e898180efb8c" alt="microsaas-5" /></li>
<li>Copy your Replicate API token and store it temporarily for further use in the application.</li>
</ul>
<h2 id="retrievingthestripeapikey">Retrieving the Stripe API key ✅</h2>
<p>Follow these steps to retrieve your Replicate API token for the application:</p>
<ul>
<li>Visit the <a href="https://dashboard.stripe.com/test/dashboard">Stripe Website</a> and sign in to your account. If you don't have an account already, create a new one.</li>
<li>Click on the <strong>Developers</strong> button in the top-right corner to navigate to the <a href="https://dashboard.stripe.com/test/developers">Developers&rsquo; Page</a>.</li>
<li>Navigate to the <strong>API keys section</strong>, copy your Stripe API key, and store it temporarily for further use in the application. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FzCuliguPrP5AtPqLWSTs-microsaas-6.png?alt=media&amp;token=33bcfeed-1276-4f44-9ca1-48d2c60dd030" alt="microsaas-6" /></li>
</ul>
<h2 id="settingupthebackendonrowy">Setting up the backend on Rowy 💪</h2>
<p>Follow these simple steps to set up the backend of the application in Rowy and create the necessary tables:</p>
<ul>
<li>To create a table in Rowy using the <strong>AI MicroSaaS</strong> template, click on the "Use this template" button. This will open the Template Setup Wizard, where you can proceed by clicking the "<strong>Let's begin!</strong>" button to start the setup process. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FiXyuKlP8casuLMIJqGjZ-microsaas-7.png?alt=media&amp;token=cca3d9d6-f14c-43c4-bec6-cf69f00e5506" alt="microsaas-7" /></li>
<li>You will be asked to enter a name for the table where all your data will be stored. You can choose to keep the default values and proceed without making any changes.</li>
<li>In the upcoming step, you will need to input your <strong>Replicate API key</strong>. If you haven't already added it to the <strong>GCP Secret Manager</strong>, click the '<strong>Add a key in Secret Manager</strong>' button. You will be redirected to the <a href="https://console.cloud.google.com/security/secret-manager">GCP Secret Manager</a>, where you can create a new secret with name <code>replicate</code> and enter the Replicate API token as its value. Once done, navigate back to the <strong>Template Setup Wizard</strong> and select your key. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FpXacLYwMuDmBR7mpZdoe-microsaas-8.png?alt=media&amp;token=1ec08e57-2210-4044-b4e4-529682344a32" alt="microsaas-8" /></li>
<li>In the next step, you will be required to input your Stripe API key. Similar to the previous step, create your secret key in the <a href="https://console.cloud.google.com/security/secret-manager">GCP Secret Manager</a> and select it in the Template Setup Wizard. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FpzVHhC01WcVISXfL3jb6-microsaas-9.png?alt=media&amp;token=4dff79fc-f54b-49a0-ba37-175599685b02" alt="microsaas-9" /></li>
<li>Next, you should provide your Vercel URL. For local testing purposes, you can temporarily use "https://localhost:3000" as the default host for your frontend project. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2F6O6vuJ6tcXnFcBwOgnSA-microsaas-10.png?alt=media&amp;token=4aa8ea23-c2e2-4a77-9882-b36ec31065d4" alt="microsaas-10" /></li>
<li>In the next step, you will simply need to <strong>deploy pre-built Webhooks</strong>, provided by Rowy, to your own Google Cloud project. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FviZkuEbRdsaJqPPk2yIz-microsaas-11.png?alt=media&amp;token=8dce0df5-88b6-494b-9155-a83758c51a3a" alt="microsaas-11" /></li>
<li>Finally, we can deploy the cloud functions required by our project and click on the &lsquo;<strong>Proceed</strong>&rsquo; button, which will redirect you to the project table. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2F6MzEm61LYtnSqqRMk3W4-microsaas-12.png?alt=media&amp;token=ec8fc4e0-324a-4d28-965b-388bfa4c640b" alt="microsaas-12" /></li>
<li>Navigate to the <strong>Webhooks menu on the top right corner</strong> to see all the Webhooks used in the project. Copy the <strong>Webhook Endpoint</strong> from the "<strong>Prediction Done Webhook</strong>" and paste it inside the code for the "<strong>Start Prediction webhook</strong>", where prompted. Update the webhook and click on the &lsquo;<strong>Save and Deploy</strong>&rsquo; button. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FqmbUzL8QYcZTuVvoxBoZ-microsaas-13.png?alt=media&amp;token=b9de6cbc-002b-448a-ad28-9c811cf66e18" alt="microsaas-13" /></li>
</ul>
<h2 id="settingupthenextjsfrontend">Setting up the NextJS Frontend ✨</h2>
<p>Before running a Next.js application, you need to ensure you have certain prerequisites such as Node.js, a code editor, and a terminal available on your device.</p>
<p><img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FZcZZRMAEto93qCRpPGGY-microsaas-14.png?alt=media&amp;token=5b20212c-95c6-4055-8dd4-e4da899b16ce" alt="microsaas-14" /></p>
<p>To begin with the Next.js Frontend, you will need to navigate to the project <a href="https://github.com/rowyio/demo-microsaas">repository</a> and clone it onto your local machine. This can be achieved by running the command:</p>
<pre><code class="bash language-bash">git clone https://github.com/rowyio/demo-microsaas.git
</code></pre>
<p>Once our project has been cloned, we can move inside the project folder and install the dependencies using the command:</p>
<pre><code class="bash language-bash">npm install
</code></pre>
<h3 id="settingtheenvironmentvariables">Setting the Environment Variables 🪴</h3>
<ul>
<li>Navigate to the project folder in your preferred code editor and in the root directory, create a file named <code>.env.local</code> for local environment variables.</li>
<li>Referencing the <code>.env.local.example</code> file, copy the code, and paste it into the newly created <code>.env.local</code> file. This will populate the environment variable file with the necessary content, as indicated below:</li>
</ul>
<pre><code class="bash language-bash">REPLICATE_API_TOKEN=
STRIPE_SECRET_KEY=

# Firebase specific envs
NEXT_PUBLIC_FIREBASE_API_KEY=
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
NEXT_PUBLIC_FIREBASE_SENDER_ID=
NEXT_PUBLIC_FIREBASE_APP_ID=
NEXT_PUBLIC_FIREBASE_PROJECT_ID=


# Rowy specific envs
NEXT_PUBLIC_PROFILES_TABLE_ID=

NEXT_PUBLIC_START_PREDICTION_WEBHOOK=
NEXT_PUBLIC_CREATE_STRIPE_CHECKOUT_WEBHOOK=
</code></pre>
<ul>
<li>First, you need to fill in the values for the Replicate API Token and the Stripe Key that you obtained earlier.</li>
<li>Next, we need to set a bunch of firebase-related environment variables.</li>
<li>In your web browser, go to your Firebase project and open the project settings. Scroll down to the 'SDK setup and configuration' section and click on 'Config'. Here, you will find the necessary environment variable values that you need to configure in the <code>.env.local</code> file. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FmOflIUNpdLwrVvGljCoG-microsaas-15.png?alt=media&amp;token=2f68c52b-43d3-47f1-b4e0-a29074d30b34" alt="microsaas-15" /></li>
<li>For the 'Table ID' environment variable, if you haven't changed the default table name, enter 'microSaasProfiles' as its value. Otherwise, set it to the table name you added earlier.</li>
<li>To obtain the final two environment variables, namely the webhook for starting the prediction and creating the Stripe checkout webhook, you can find these values in the Webhooks section of Rowy. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2F12MruQk6KXioUWfEbtuV-microsaas-16.png?alt=media&amp;token=8431233a-1ee8-4ee0-8d61-a2ff43f2cc77" alt="microsaas-16" /></li>
</ul>
<h3 id="settingthestripewebhookurl">Setting the Stripe Webhook URL 🕸️</h3>
<p>After successfully adding the environment variables, we are nearly ready to start our project. However, there is one more task remaining. We need to set a <strong>Webhook URL</strong> in the Stripe dashboard, which will be triggered whenever a checkout is completed.</p>
<ul>
<li>In the Stripe <a href="https://dashboard.stripe.com/test/dashboard">dashboard</a>, go to the <strong>Developers section</strong> and access webhooks. Locate and click the "<strong>Add an endpoint</strong>" button.</li>
<li>To obtain the Endpoint URL, return to Rowy and navigate to the Webhooks section. Look for the "S<strong>tripe Checkout Session Completed</strong>" webhook and copy the corresponding endpoint URL. Paste this URL as the Endpoint URL in Stripe.</li>
<li>Next, click on "<strong>Select events</strong>" and search for <code>checkout</code>. Choose the event labeled <code>checkout.session.completed</code> and click "<strong>Add Events</strong>".</li>
<li>Finally, click the "<strong>Add endpoint</strong>" button to create your endpoint in the Stripe dashboard. <img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FMya3opphXgOoqJmNjEdv-microsaas-17.png?alt=media&amp;token=7cec11ee-e73c-4c38-9a4f-fa522adca6db" alt="microsaas-17" /></li>
</ul>
<h3 id="runningthenextjsproject">Running the NextJS Project ▶️</h3>
<p>In the project directory, launch the local development server by running the following command in your terminal:</p>
<pre><code class="bash language-bash">npm run dev
</code></pre>
<p>This command will start the server and enable you to test and develop the application locally.</p>
<p>We can now run up our <a href="https://localhost:3000">localhost:3000</a> to see the Next.js frontend running. Thus, we can verify the features of the application as both our Frontend and Rowy Backend are up and running.</p>
<p><img src="https://firebasestorage.googleapis.com/v0/b/website-a1s39m.appspot.com/o/blog%2F6HEbFhFrwOjGlZ60A9hh%2FcontentImages%2FSe7S1mgoznHCB7BFxo54-microsaas-18.png?alt=media&amp;token=caec381d-f2aa-403e-8029-e13ab6b02815" alt="microsaas-18" /></p>
<h2 id="conclusion">Conclusion 🚀</h2>
<p>MicroSaaS services offer <strong>tremendous potential for building powerful applications with ease</strong>. With the assistance of Rowy's low-code backend, developers can efficiently explore a multitude of opportunities in creating innovative solutions. The AI MicroSaaS Background Remover application exemplifies the capabilities of such services by providing users with an intuitive platform to remove image backgrounds effortlessly.</p>
<p>Expanding the AI MicroSaaS Background Remover application, additional features could include advanced image editing options, collaboration capabilities, etc. Furthermore, Rowy's <strong>versatility extends beyond background removal</strong>, enabling developers to <strong>explore diverse MicroSaaS applications</strong> such as <strong>sentiment analysis tools</strong>, <strong>document recognition systems</strong>, or <strong>data visualization platforms</strong>. 🎯</p>
<p>By harnessing the power of Rowy and MicroSaaS services, developers can unlock <strong>endless possibilities</strong> for creating impactful and user-friendly applications, revolutionizing various industries, and driving innovation to new heights. 🧠</p>
<p>If you enjoyed our content, please give us a&nbsp;<a href="https://twitter.com/rowyio">follow on Twitter</a>&nbsp;or&nbsp;<a href="https://rowy.io/discord">join our Discord</a>&nbsp;in case of any questions. We look forward to hearing from you! 💜</p>