Category: Hobby project

  • Coding with AI – Part 2: Accessible, robust, and secure?

    Coding with AI – Part 2: Accessible, robust, and secure?

    In part one of my story about my vibe coding experiment we got a first design and set up a deployment pipeline for my music search application. We ended with a vague feeling of unease that something was missing. In this part, we will learn what it was and also a bit more about security, robustness and accessibility testing with AI. So let’s just dive in where we left off: with my concerns.

    Major security issues

    Since I could see the code and had to do some manual steps to enable the communication, I noticed that I had been asked to paste all the login details needed into an environment file. And I knew the project was synced with github. So what would happen if someone else actually downloaded the project from there as it was set up as a public project? I asked Cursor about it.

    Yup. Major security issue detected! By me. Not Cursor. If not specifically asked to do so, Cursor does not consider the security of what it is developing one bit. Cue major code changes and changes of passwords not only at Supabase but also my hosting provider as those had also been exposed. 

    Lesson learned: don’t trust a vibe coding tool to consider security when generating code. It is all up to you.

    The need for robustness

    In the conversation with the other course attendant I mentioned earlier about vibe coding using AI, we agreed that the good practices from ”regular” coding also must be applied there. Based on my experiences so far, having good coding practices is even more important when vibe coding than otherwise. What I mean by that is stuff like documenting the code and working test driven. When you personally write the code by hand, you do understand what it does. If someone else does it for you, finding an issue with it could be very time consuming and difficult. Hence, documenting it is important. 

    Both Lovable and Cursor happily update large portions of code based on, at best, vague prompts from the user. This can have big effects you don’t find out until much later if you are not careful. Hence, working test driven and ensuring tests are run regularly is important. 

    I asked Cursor about this and it installed something that apparently runs tests upon both commit and push. It also checks test coverage. So that’s good. But here’s the kicker, it didn’t suggest working like this itself and it tries to avoid it when it can. If I ask it to commit it sometimes tries to skip the tests entirely or, if there are issues found, asks to commit and push the code anyway and ”deal with the issues later”. I know I’m dealing with a non sentient piece of software, but I still feel like a strict parent forcing it to do its homework before it gets to go out and play. I guess there is some configuration file somewhere where I can specify the importance of both security and robustness, but given that these tools will be used by beginners, it would be nice if a bias towards robustness and security was built into the tool itself.

    Getting back to Lovable

    As I said earlier, the plan was to work on the backend in Cursor and front end in Lovable. When I started out, I generated the base code in Lovable and then went into Cursor. During the process, multiple issues in working with Cursor had us strip down the front end to the very basics, i.e. remove everything basically except for the title, search box, and results. In addition, most of the styling was also removed. This allowed me to focus on the backend issues with the project setup rather than the functionality before adding complexity to it. However, removing all this made Lovable a bit… confused… It did NOT like what we had done with the place so to speak. To get a better understanding of exactly what parts it had issues with, I asked it to look at the code and give me feedback. Interestingly, the feedback was not only on the format of the font end code – it also identified yet another security issue where login credentials were stored in plain sight. Since this was not a front end issue, I copied the feedback and had Cursor fix it before pushing the code again. 

    A short interlude with accessibility

    All this talk about testing made me think of another aspect that should be tested regularly: how accessible the application is. I asked Cursor to help me with this and fed it with the url to the WCAG 2.0 specification. It seems like I wasn’t the only one who had this thought before because not only did it write its own tests (very basic and not very good to be honest), it also installed some kind of testing tool to include in the other set of automatic tests run upon commit and push. It did require some iterations though as getting them to set up a server with the application and run various browsers in the background did not work the first time the tests were run. Did it find any accessibility problems? Yes. Did it improve the accessibility of the very simple app. No idea to be honest. It checks for obvious things like if there are language attributes, titles, if it’s navigational by the keyboard etc. However, if the alt text and such like actually makes sense is something I doubt it can test (yet).

    Using Lovable to get design suggestions

    Once I was satisfied with the deployment pipeline and test coverage, it was time to work on the actual application. I found the design generated by Lovable to be a bit dull so I went to redo it. It got even worse. I figured, why not try out some other AI tools to get some inspiration. First up Figma Make. It gave me a design that was not as bad but the thing with design is that you shouldn’t just go for the first thing that shows up – you should come up with alternatives. This to be able to go beyond the first idea and hopefully end up with something even better. The thing with both Lovable and Figma Make is that they take a prompt and then spit out one result in full with code and all. You cannot ask them to provide a couple of ideas to just look at and choose from even if they are not functional. 

    While trying to get new design suggestions in Lovable, I noticed that what it showed me and how it described the designs it generated differed quite a bit. At first I thought it was just crappy at describing, but then I got a bit suspicious. Could it be that the switching between Cursor and Lovable didn’t work as well as I thought it should? A quick check using Cursor to get the code from git confirmed my suspicion: Lovable did update the code as it said it would, but it couldn’t display it for some reason. At that point I decided to stick to just one tool to edit the code for now: Cursor. 

    Getting to a decent design

    Even though I liked the styling Lovable apparently had provided, I wasn’t too happy that it had introduced buttons and other elements into the interface that actually didn’t work. In addition, there were no tests written for the new code. Hence, I asked Cursor to keep the styling, remove the new functionality, and write tests for what now wasn’t covered. It actually turned out pretty well. The lesson learned by this is that it seems fine to start out with one tool and switch to another early in a project, but the more complex it gets, the smaller the chances are it will actually continue to work to do the switch back and forth. No surprise there really. I just wish there was a tool that allowed for the amount of control Cursor provides (even though I don’t understand half of it) while allowing visual edits and feedback the way Lovable and Figma Make does. 

    Final words(?)

    So this is where my story ends. With a search page, a results page with functions and a database full of links. Or who am I kidding – of course I will continue playing around with this! There are still improvements to be done and things to learn. But this is where I leave off for now. Maybe there will be a part 3 of the story at some point. 

    I leave you with a summary of what I learned from this experience in the hope it will help you with your own experiments in AI land:

    • Avoid using AI for something you know nothing about. See next point.
    • Solutions suggested by the AI are not always the best. Check for alternatives if you suspect there are better ones. At least when there is money involved, e.g. for hosting, services etc.
    • Git integration in the tools is a neat feature! It provides the flexibility to switch tools if you want to or access the code in whichever way you like.
    • Cursor’s lack of memory, especially after application restart, is a major source of frustration!
    • So far, it seems the AI coding tools available are not biased towards good coding practices such as test driven design or good documentation. It’s up to you to get that going.
    • AI coding tools will not take security into account when setting up projects or writing code. Your login details etc. might get exposed and you end up in trouble. If you do, you can’t really blame the AI as it is your responsibility to make sure what you deploy online is secure.
    • The AI tools for design I’ve so far tested are currently lacking in supporting the design workflow of coming up with multiple ideas before getting to one to continue with.
    • Switching between AI tools once the project gets more complicated is not recommended.

    And if you actually want to see what the application currently look like, go to https://ssaasearch.se . If you are curious about the actual code, you can find it at https://github.com/nannis/choir-music-search.

  • Coding with AI – Part 1: The journey begins

    Coding with AI – Part 1: The journey begins

    I’ve been out of a job since the beginning of summer and as the AI revolution is running at full speed while I’ve been away, I figured it was time to catch up a bit. Not having a real, in use codebase to start from was a bit of a challenge for me, but nothing I couldn’t overcome quite easily. (The reason I wanted one was that if I was in a real work life setting, there would be a code base that had been developed and mismanaged for years that I would have to learn to work with.) So what did I do and learn?

    Getting something to start with

    I started out, as many do, with a basic and vague idea of what I wanted to build. For the purpose of learning, I wanted something straight forward, but that still involved common application infrastructure. Being a member of an all female choir, the idea I eventually chose was a search engine for sheet music for all female choirs. 

    Having just attended a course in the design of AI agents where we were given a no limit access to such, my initial idea was to use Perplexity (an AI search engine) to handle the search behind a custom made interface. However, even for a hobby project like mine, that would not be feasible cost wise. And it turned out to be a bit over complicated to start with in terms of getting it working. This became evident in my first actual interaction with vibe coding:

    Lovable

    We’ve all heard of Lovable at this point, I figure. You just write what you want and then it generates an interface to look at and the code to support it. I told it I wanted a search engine for choir music and it gave me a search page for that. I told it I wanted to be able to search for music in multiple languages and it added support for that. Then I searched for Swedish music. Nothing. Tried Latin. Got results. Got curious. ”So how does it actually handle the search?” 

    Since I do have a bit of a technical background and have been working in software development for quite some time, I went into the code to have a look. The languages that were allowed in the search were hard coded. So were the responses. Lovable had generated a lovely front end, but I knew next to nothing about what was actually behind it. And the free tier of Lovable doesn’t allow the user to manually modify the code even if you can read it. Enter Cursor.

    Cursor

    At the course I had attended, another attendant I spoke to about this gave me the tip to use git as the way to use more than one tool for the development. I could connect git to Lovable and it would automatically commit and push changes there. I could then set up Cursor on my local PC, pull the project, do changes, commit and push. And then open it in Lovable again if I wanted (or so I thought – back to that later).

    Working with the AI agent in Cursor is a bit like working with a very enthusiastic and positive newly graduated developer with dementia. You work on something for a long time one day, shut down the program, return the next day and it has no memory of what has been done before. There is probably a way to fix this, but my efforts so far have been unsuccessful. It can also end up in a loop where it tries something, fails, tries the same thing, gets reminded that it already tried that, apologizes and promises to try something completely different only to do the same thing again… 

    That said, it is very transparent in what it is doing and asks for permissions for most of it in a way I didn’t experience that Lovable did. I started out asking what the architecture of the Lovable app actually was like and it turned out to be very, shall we say, flat. For demonstrating the idea, it was fine. For actually running a scalable application, it was not. So I started exploring the alternatives in discussion with Cursor. 

    We landed on a solution where there should be a thin backend layer and a database in which information about songs along with links to the actual sources would be stored instead of running searches at the actual sources every time a user wanted to find something. The hypothesis was that the sources wouldn’t change much over time. To handle any such changes a regular check and update to my projects database would suffice. This solution would also leave me with a very common architecture where I would have to learn to handle a database as a part of a project as well. (I do have basic knowledge about databases, but could learn more about how they actually interact with backend code.) 

    Hosting the application

    Since I do have my own website already I figured I might as well set up a sub site. I even set up a new database for that site before I started to worry a bit: Do I really dare to let an AI loose near the code of my actually working website? The answer was NO. But I did have enough space to set up a new domain and host it so that’s what I did. A clean slate with a clean database. 

    Cursor and I started working on the application locally, but since I wanted to get something up and running, I actually needed to get the backend and database in place. This is when I ran into some trouble: turns out my hosting provider does not allow for remote calls to their databases. Fair enough – that is a security concern, but at that point I actually wanted to be able to set it up and update it directly using code. Remember – I am no developer really – I’m just trying to learn. 

    I asked Cursor for alternatives and it came up with a few. A quick google later and I had rejected most of them. Another quick google and I found some other alternatives I presented to Cursor and asked for feedback on. Based on my needs and the cost (free tier!) I decided to go with Supabase. Since then, I noticed that it is the choice in many similar projects and even built in as an option to use in Lovable and Figma Make. Maybe it is the Baader-Meinhof phenomenon, but now I see it everywhere.

    Supabase backend and database

    The thing about Cursor is that it happily sets up services and installs software in the background. It does ask for permission, but it is easy just to accept everything it does. I honestly have no idea about what half of the things it has installed actually does – I just have to trust what it’s doing. And this leads me to another very important insight into the use of AI: you need to have at least a basic understanding about what you are asking it to help you with, because otherwise it can go wrong. Very wrong. But we’ll get back to that.

    To communicate with supabase, it apparently needed to install some software from supabase. It initially didn’t work so I had to do some manual help. Here again it is like an enthusiastic junior: it won’t admit defeat until you really force it to. Instead it goes ”That didn’t work. Let me try this” ”That didn’t work either. Let me try something completely different” and will continue with that until you say enough is enough. Quite often it will end up in a loop as mentioned above where it just tries the same thing over and over and over…

    Once we had overcome the initial communication issues, the communication with Supabase went relatively smooth. We developed something and deployed it. No probs. But there was something else that started to gnaw in the back of my mind.

    So what happens next?

    In the next post you will learn a bit about my findings regarding security, robustness, accessibility and actually designing with AI. And see that my unease was not entirely uncalled for.