DEV Community

Cover image for GPT is my new BFF (Backend for Frontends)
Sylvain Hamann
Sylvain Hamann

Posted on

GPT is my new BFF (Backend for Frontends)

As a front-end developer I encountered several types of backend during my career (e.g. GraphQL). They were written with different languages (e.g. Rails or PHP). I don't consider myself as a fullstack developer, I always prefer focusing on crafting the UI.

I saw people asking Chat GPT to answer with a JSON formatted response:

Screenshot from a discussion with Chat GPT showing a prompt asking o generate a JSON containing a question about French history with four possible answers. The answer contains the expected JSON.

This is clearly an example of BFF (Backend for Frontends) pattern.
It means we could now create a lot of projects without having to worry about having a dedicated backend or database!

This is exactly what I did with Daily Kanji. It will prompt GPT to return a random Japanese Kanji and its translation as a JSON. A scheduled GitHub action (similar to a CRON job) will create a new video everyday thanks to Remotion, a React framework to programmatically render videos. The video will then be published on Instagram.

With this kind of setup you don't really need to worry about your OpenAI API usage since it will only run once a day. During development you should rely on a JSON mock so you don't need to query OpenAI each time. With all my local tests an production runs I did not even reach $1.

Instead of generating daily videos you could have some sort of daily quiz similar to Wordle. Your only limit is your imagination!
With frameworks such as Astro you can generate a new static build each day based on data generated by GPT. The data would again be only fetched once at build time via a scheduled deploy. If for any reason the request failed or the data does not have the expected shape then you could cancel / retry the job.

Something that would require further explorations: how to make sure each JSON is unique? For now I am using a little trick where I ask GPT to the the current timestamp as a seed, it seems to work!

Top comments (0)