FlowPro

FlowPI Backend Documentation

Welcome to the documentation for your auto-generated backend API using Express.js and Prisma. This API is designed to provide CRUD functionality for your defined entities and relations, along with optional authentication features.

Table of Contents:

1. Setup

To get started with your backend, follow these steps:

  1. Make sure you have Node.js installed.
  2. Clone or download the generated project files.
  3. Navigate to the project directory and install the dependencies:
1
npm install

Environment Variables

Create a `.env` file at the root of your project and add the following variables:

1
DATABASE_URL="your-database-url"
2
JWT_SECRET="your-secret-key"
3
PORT=3000

2. Authentication

If you enabled authentication during the generation, JWT-based authentication is built into the backend. This includes:

  • Signup and Login routes for user creation and authentication.
  • A middleware that protects routes by verifying the user's JWT token.

Using Authentication Middleware

Add the `authMiddleware` to any route to secure it:

1
router.get('/protected', authMiddleware, (req, res) => {
2
res.json({ message: 'You are authenticated!' });
3
});

3. Routes

The backend provides CRUD operations for all your entities. Here's an example of the auto-generated routes:

  • GET /entity-name
  • POST /entity-name
  • PUT /entity-name/:id
  • DELETE /entity-name/:id

Replace `entity-name` with your entity's actual name in lowercase.

4. Database (Prisma)

The project uses Prisma to interact with your database. Here's an example of the Prisma schema that was generated:

1
model User {
2
id String @id @default(auto()) @map("_id") @db.ObjectId
3
email String @unique
4
password String
5
}

To apply changes to your database schema, run the following commands:

1
npx prisma generate

5. Run

To run your backend, after setting up the environment and the database, use the following command:

1
npm run dev

6. Deployment

To deploy your backend, you can use services like Heroku, Vercel, or Railway. Make sure to set up your environment variables on the hosting platform.