DEV Community

Cover image for Creating a Social Network for Bakers with the use of Generative Artificial Intelligence as an Assistant. part 1
Rodrigo Alexandre
Rodrigo Alexandre

Posted on

Creating a Social Network for Bakers with the use of Generative Artificial Intelligence as an Assistant. part 1

In the past few weeks, I have been dedicating myself to studying how to use Generative Artificial Intelligence to improve my software development work. As a frontend engineer, I have the qualifications to use JavaScript with React to do my job, but I don't have much proficiency in the obscure arts of backend development.

I started the project by creating a system specification with ChatGPT. I requested that it create the code for the project, prompt by prompt. Despite the fact that some parts of the project are functional, I believed that the overall process was frustrating and every part of the code did not communicate with each other without intervention.

Until I watched the DataCamp webinar called 'Beginner's Guide to Prompt Engineering with ChatGPT' and understood that my issue with the code was more related to my mental model of how to use ChatGPT than the code itself, I was using the AI as an agent when I should have been using it as an assistant.

In the words of @adeel Nehme, the difference between an AI assistant and an AI agent is 'a mental model of how you think about it. An AI assistant is something that you need to edit its outputs - you need to use it as a co-pilot, whereas an AI agent is more of an independent actor. It is very important to think about Chat GPT as an independent AI assistant, a tool that you use as a co-pilot, rather than an agent that you let into the wild.'

With these thoughts in mind, I elaborated a prompt based on the "Formula Prompt of ChatGPT" taught in the webinar, and I will restart the project with ChatGPT. As my proficiency in the "dark arts of backend" is lower than my knowledge in frontend, I decided that I should start with the API.

That's is the prompt:

"Act as a backend developer, with knowledge in NodeJS, Express, authentication with Google and Facebook platforms, and MongoDB. You must create an API for a social network of amateur bakers. In this social network, bakers will be able to exchange messages like in a forum, send direct messages, post recipes and offer or request donations of natural yeast starters among themselves. Follow the instructions very carefully and do not deviate from them.

1. Provide a step-by-step explaining the reasons why you are making the decisions you are making;
2. Model the database to contain the following entities: recipes (ingredients, preparation time, fermentation time, and materials used), bakers (name, user, address for conversion to coordinates, and subsequent creation of a proximity resource between bakers), posts and messages, and any other entities that you deem necessary for the proper functioning of the API.
3. Authentication should be done by token and with refresh token on Google and Facebook platforms.
4. Write clean, accessible, and scalable code. All variable and function names must be in English, and comments, where necessary, must be in Portuguese.
5. Avoid security breaches.
6. Avoid bad code.
7. Avoid inaccuracies."
Enter fullscreen mode Exit fullscreen mode

And that is the result:

Start of Output

Step by step and decisions:
1.1. Initialize a new Node.js project and install the necessary dependencies: Express, Mongoose, Passport, Passport-Google-OAuth, Passport-Facebook-Token, CORS, and others.

1.2. Set up the Express server and define routes for the described functionalities.

1.3. Define Mongoose models for the database entities.

1.4. Implement authentication with Google and Facebook using Passport.js and JWT to manage tokens and refresh tokens.

1.5. Implement the API functionalities as described in the instructions.

1.6. Add middleware to handle errors and validation.

1.7. Test the API using tools like Postman or Insomnia.

1.8. Add comments in Portuguese and ensure code quality.

Database modeling:

Recipes:

_id
title
ingredients: Array of objects (name, quantity, unit)
preparationTime
fermentationTime
materials: Array of Strings
bakerId: Reference to the author baker
Bakers:

_id
name
username
address
coordinates: { lat, long }
authProvider: 'google' or 'facebook'
authId
Posts:

_id
content
bakerId: Reference to the author baker
createdAt
updatedAt
Messages:

_id
content
senderId: Reference to the sender baker
recipientId: Reference to the recipient baker
createdAt
Sourdough starter donations:

_id
donorId: Reference to the donor baker
recipientId: Reference to the recipient baker
status: 'offered', 'requested', 'accepted', 'declined', 'completed'
createdAt
updatedAt
Enter fullscreen mode Exit fullscreen mode

Authentication will be done using Passport.js, integrated with the Google OAuth and Facebook Token strategies. JWT will be used to generate tokens and refresh tokens.

To ensure clean, accessible, and scalable code, we will follow SOLID principles, organize the project in layers (routes, controllers, services, and repositories), and use ESLint to maintain code style consistency. In addition, we will use variable and function names in English and add comments in Portuguese when necessary.

To prevent security breaches, we will apply best practices such as input data validation, using JWT tokens, dependency updates, error handling, using HTTPS, and CORS.

Avoiding "bady code" (bad code) will be achieved by following the guidelines mentioned in item 4.

To avoid inaccuracies, we will test the API with unit and integration tests, using libraries like Jest and supertest. Additionally, we will validate project requirements with stakeholders.

End of Output

On the next days I will implement the sugestions of my AI Assistant and you can follow these journey .

Top comments (0)