> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmocha.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Backend & APIs

> Mocha writes backend code for you, calls external APIs, and manages secrets

Mocha is "full‑stack", which means you can build useful software, not just pretty mockups. Beyond the visual pages, Mocha can run logic for you in the background—things like saving form submissions, talking to other services (APIs), and powering features your business needs.

<Info>
  Backend code runs in a scalable serverless runtime. It can handle a lot of traffic and scale up and down as needed.
</Info>

## Quick start

<i>This section won't be long, because mostly Mocha just does the work for you.</i>

<Steps>
  <Step title="Describe what you want">
    Say what you need in plain English. For example: “I want users to be able to subscribe to my app by giving their email address.” The AI will create the necessary backend logic.

    <Tip>
      Don't give Mocha technical details like "use postgresql". This won't work well, Mocha is highly opinionated on how to build things technically, and you should describe your desired outcomes for the product, instead of the technical details.
    </Tip>
  </Step>

  <Step title="Try it out">
    Use the in‑app preview to test the feature. You can see results and logs right away, then deploy when you’re ready.
  </Step>

  <Step title="That's it!">
    That's it! Congratulations on building a full-stack feature that uses your own backend code.
  </Step>
</Steps>

## Managing secrets

Some features require private keys to talk to other services (often called "APIs"). These private keys are called secrets.

<Frame caption="Manage your secrets in the project settings">
  <img src="https://mintcdn.com/mocha-47857bf6/Q5Os2Tbn61W-oFpO/images/secrets-settings.png?fit=max&auto=format&n=Q5Os2Tbn61W-oFpO&q=85&s=61597adf09acd06138ea45a0f3a49a82" alt="Managing your secrets in the project settings" width="1712" height="912" data-path="images/secrets-settings.png" />
</Frame>

<AccordionGroup>
  <Accordion title="What is a secret?">
    A secret is a private value your app uses to connect to another service. It might be an API key, access token, or signing key.
  </Accordion>

  <Accordion title="Examples of secrets">
    * Weather API key (for example, an OpenWeather key) to show today's forecast in your app
    * OpenAI API key to generate images or summaries for your content
  </Accordion>

  <Accordion title="How the AI helps with secrets">
    If your feature needs a secret, the AI will prompt you to add one and will wire it up correctly. You just provide the key once.
  </Accordion>
</AccordionGroup>

Usually, Mocha will ask you to add a secret to your project as part of the conversation, and will even show you how to get the secret from the provider, just follow the prompts.

<Warning>
  Avoid pasting the secrets directly into the chat input. Instead, paste them into the secure forms that appear in the chat inyour pages or commit history. Store them as secrets instead.
</Warning>

<Frame caption="Adding a secret through the chat interface">
  <img src="https://mintcdn.com/mocha-47857bf6/Q5Os2Tbn61W-oFpO/images/add-secret.png?fit=max&auto=format&n=Q5Os2Tbn61W-oFpO&q=85&s=47bddd29d2cfa243b99061b4d6594854" alt="Adding a secret through the chat interface" width="1707" height="924" data-path="images/add-secret.png" />
</Frame>

## Common patterns

<AccordionGroup>
  <Accordion title="Connect to other services (APIs)">
    Want weather data, maps, email, or payments? Save your API key as a secret and ask the AI to connect the service. Example: “Show today’s weather in San Francisco using my OpenWeather key.”
  </Accordion>

  <Accordion title="Collect form responses">
    Add forms to your pages to collect emails, feedback, or orders. The AI saves submissions and can store them in your database.
  </Accordion>

  <Accordion title="Notifications from other tools (advanced)">
    Some services can notify your app when something happens (often called webhooks). Ask the AI to set this up and it will handle the details.
  </Accordion>
</AccordionGroup>

***

## Payments & Monetization

Want to accept payments or sell products through your Mocha app? Here's what you need to know.

<Note>
  Mocha doesn't have a built-in payment system. To accept payments, you'll need to integrate with an external payment provider like Stripe.
</Note>

<AccordionGroup>
  <Accordion title="Can I add Stripe to my Mocha app?">
    Yes, it's possible to integrate Stripe with your Mocha app. However, we don't have an official step-by-step guide yet—this is an area we're still developing better support for.

    **Our recommendation:** Start simple. For most use cases, you don't need complex payment integration:

    * **Stripe Payment Links** - Create payment links in Stripe and add them as buttons on your site. No coding required.
    * **Stripe Checkout** - Redirect customers to Stripe's hosted checkout page for a more seamless experience.

    These simple approaches work for selling products, services, subscriptions, and donations without needing to build custom payment flows.
  </Accordion>

  <Accordion title="Does Mocha have its own payment system?">
    No, Mocha doesn't have a built-in payment processor. You'll need to use an external service like Stripe or PayPal to accept payments.

    The good news is that these services are designed to be easy to integrate, especially if you use their hosted solutions like Payment Links.
  </Accordion>

  <Accordion title="How do I sell products on my website?">
    The simplest approach:

    1. **Create a Stripe account** at stripe.com
    2. **Create Payment Links** in Stripe for each product you want to sell
    3. **Add buy buttons** to your Mocha app that link to your Stripe Payment Links

    This approach lets you start selling quickly without complex integration. Stripe handles the payment form, security, and receipts.
  </Accordion>

  <Accordion title="Can I accept PayPal?">
    Similar to Stripe, you can integrate PayPal by using their hosted checkout options and linking to them from your Mocha app. PayPal also offers simple button generators that work well for basic payment needs.
  </Accordion>

  <Accordion title="What about subscriptions and recurring payments?">
    Stripe supports recurring payments and subscriptions through their Payment Links feature. You can create subscription products in Stripe and link to them from your Mocha app.

    For more complex subscription management (like customer portals, usage tracking, etc.), you may need to build more custom integration.
  </Accordion>
</AccordionGroup>

<Tip>
  Starting simple with Payment Links is a great way to validate your business idea before investing time in more complex payment integrations. You can always upgrade to a more sophisticated setup later.
</Tip>
