Back to Blog

Refactoring with Gemini cli

Refactoring my project with the help of Gemini cli

July 8, 2025
7 min read

Every developer will agree that refactoring is such as painful and tedious task. On top of that, if you work alone on a project, it can be even more challenging to find problems that needs fixing. That's why I decided to use Gemini cli to help me with the refactoring process.

What is Gemini cli?

Gemini cli is a command line interface that allows you to interact with Gemini, Google's AI model. It can be used to generate code, refactor code, and even run tests. I have been using it to help me develop this blog for the past few days, and it has been a game changer. My productivity has increased significantly, and I have been able to focus on the more important parts of the project.

How to use Gemini cli

To use Gemini cli, you need to have Node.js version 20 or higher installed. Once you have that, you can install Gemini cli globally using npm:

Bash
npx https://github.com/google-gemini/gemini-cli

For more information on how to use Gemini cli, you can check out the official documentation.

Refactoring with Gemini cli

I started by asking the Gemini cli to analyze my project and find areas that needed refactoring.

Markdown
Project Overview:

- Framework: Next.js (a popular React framework)
- Styling: You're using a combination of Material-UI (MUI) and Tailwind CSS. This is a bit unconventional, and it might be worth
  exploring whether you can consolidate to a single styling solution to simplify your codebase.
- Deployment: It seems you're set up for deployment on Cloudflare Pages, which is great for performance and scalability.
- Features: The project includes user authentication, a contact form, documentation, and user-specific pages.

Potential Improvements:

1.  Dependency Management:

    - You have a large number of dependencies. It would be beneficial to review them and see if any can be removed or replaced with
      more lightweight alternatives.
    - Some of your dependencies might be outdated. Running npm outdated can help you identify which packages have newer versions
      available. Keeping your dependencies up-to-date is crucial for security and performance.

2.  Code Quality and Consistency:

    - You have eslint configured, which is excellent. Running npm run lint will help you identify and fix any code quality issues.
    - With both MUI and Tailwind CSS in use, there's a risk of inconsistent styling. I would recommend establishing clear guidelines
      on when to use each, or consider migrating to a single system.

3.  Performance:
    - Next.js offers many performance optimization features out of the box. I can analyze your code to see if you're taking full
      advantage of them, such as:
      - Image Optimization: Using the next/image component.
      - Component Loading: Using next/dynamic for lazy loading components.
      - Data Fetching: Ensuring you're using the most efficient data fetching strategies (e.g., Server-Side Rendering vs. Static
        Site Generation).

Next Steps:

I can start by running a few commands to get a more detailed picture of the project's health. Would you like me to proceed with any
of the following?

- Run npm outdated to check for outdated dependencies.
- Run npm run lint to check for code quality issues.
- Analyze the code for performance and best-practice improvements.

Gemini cli provided me with a detailed analysis of my project, including potential improvements and next steps. It suggested running npm outdated to check for outdated dependencies, running npm run lint to check for code quality issues, and analyzing the code for performance and best-practice improvements.

Not so bad right?

I then proceeded to run the suggested commands and Gemini cli provided me with a list of outdated dependencies and code quality issues. Also it suggested some performance improvements that I could implement. Here are some of the key suggestions:

Gemini cli suggested that I should implement next/dynamic for lazy loading components to improve performance. I had a few components that were not critical for the initial page load, so I implemented dynamic imports for those components.

Gemini also suggested on using Redux or Zustand to manage my authentication state instead of using React context. I had been using React context for authentication because I thought it was going to be an overkill to use a state management library for such a small project. But I've got to admit that using Context made my code a bit messy and hard to follow. So maybe in the future I will consider using a state management library for my project.

Conclusion

Gemini cli has been a great help in refactoring my project. It provided me with a detailed analysis of my project and suggested improvements that I could implement. I was able to improve the performance of my project and make it more maintainable. If you're looking for a way to improve your productivity and refactor your code, I highly recommend giving Gemini cli a try.

Back to Blog
Loading