What should I include in a prompt to build a CRUD app?
Essential components of a CRUD prompt
Start by specifying the technology stack: language, framework, database, and any libraries. For example: 'Build a Node.js Express API with a PostgreSQL database using Prisma ORM.' Then describe the data model: fields, types, and relationships. For instance: 'A User has an id, name, email, and createdAt.'
Next, list the CRUD operations you need. Be explicit: 'Create a new user', 'Read all users', 'Update a user's email', 'Delete a user'. If you need a frontend, specify the framework and key UI elements. Also mention any additional requirements like input validation, error handling, or authentication.
- Tech stack: language, framework, database, ORM.
- Data model: fields, types, relationships.
- CRUD endpoints: HTTP methods, paths, request/response shapes.
- Validation rules: required fields, format constraints.
- Authentication/authorization: if needed, specify method (JWT, sessions).
- Frontend: if applicable, framework and basic UI components.
Example structure
A well-structured prompt might look like: 'Create a REST API for a blog. Use Express and MongoDB with Mongoose. The Post model has title (string, required), content (string, required), and author (string). Implement GET /posts, GET /posts/:id, POST /posts, PUT /posts/:id, DELETE /posts/:id. Include input validation and return appropriate status codes.'
This gives the AI everything it needs to generate a working CRUD app. You can then iterate to add features like pagination or search.
Common mistakes
- Forgetting to specify the database or ORM, leading to generic or incompatible code.
- Not defining the data model, so the AI guesses fields and types.
- Omitting error handling and validation, resulting in fragile code.
