Inspiration

Journaling is a powerful tool for self-reflection, but recognizing cognitive distortions in the moment can be tough. Personally, as we journal, we often notice how easy it is to fall into a downward spiral and get stuck in negative thoughts without realizing it.

That’s where cognitive distortions come in. Cognitive distortions are biased ways of thinking that distort reality and fuel anxiety, self-doubt, and negativity. When left unchecked, they can cloud judgment and drag down your mindset. That’s why we created ThoughtMirror: an AI-powered companion that helps users recognize and reframe these distortions as they journal, fostering clarity, resilience, and personal growth.

In today’s world, AI often takes the reins—making decisions, passing judgments, and shaping our experiences in ways we don’t always see. This overreach can subtly influence our thinking, sometimes reinforcing biases rather than helping us break free from them.

That’s why we made sure that ThoughtMirror would be an AI that doesn’t judge or decide for you, but instead empowers you to recognize your own thought patterns. Rather than interfering with your reflection, it acts as a guide—helping you gain clarity without imposing bias, so you remain in control of your own growth and self-discovery.

What it does

ThoughtMirror analyzes journal entries in real-time, detecting cognitive distortions and providing gentle, therapist-inspired feedback. Users can visualize and track their thought patterns over time using our interactive calendar feature. By revealing these patterns, it helps users reflect more clearly, break out of negative loops, and shift toward healthier, more balanced thinking.

How we built it

We drew inspiration from cognitive behavioral therapy techniques, specifically how therapists identify and address problematic thinking patterns to catalyze self-reflection in their patients. Our goal was to replicate this therapeutic approach in a digital format, enabling AI-powered feedback for users in two distinct stages.

First, we fine-tuned Gemini-2.0-Flash-001 on a dataset of about 2,000 clinician-annotated text samples, where each sample contained labelled cognitive distortions. This allowed our fine-tuned model to identify distorted segments within journal entries and classify the type of cognitive distortion present.

Then, we implemented a RAG pipeline using a non-fine-tuned Gemini-2.0 model. This pipeline retrieves real therapist responses from a curated knowledge base of therapist feedback. The model then generates gentle, reflective prompts to help users critically examine their thought patterns, closely simulating how a therapist would encourage a patient to reflect on a cognitive distortion.

For our tech-stack, we used Next.js to build our frontend, FastAPI for our backend, Firebase for data storage, and Gemini API and LangChain for NLP-powered analysis.

Challenges we ran into

Our project has a lot of moving pieces, so making sure that the database could be updated in an efficient way was difficult, especially as users can continuously create, edit, and delete journal entries. We also initially had trouble fine-tuning Gemini, as we had to preprocess our data extensively to ensure it was in the correct format. Furthermore, implementing the RAG pipeline added another layer of complexity because we needed to balance model creativity with factual, therapeutic responses, so it took multiple iterations to make sure the tone of the model’s explanation was correct.

Another huge challenge was managing permissions and credentials across Next.js, Firebase, and Google Cloud Vertex AI. Since we had never worked with Gemini before, we struggled with the precise service account configuration and spent a lot of time debugging 403 Forbidden errors and tracking down misconfigured environment variables.

Accomplishments that we're proud of

We built an intuitive journaling tool that doesn’t just store thoughts, but actively helps users reframe negative thought patterns and track their emotional growth over time. It was really fulfilling to build a tool that we would all definitely use, and we’re excited to continue to develop the tool in the future!

On the technical side, none of us have used Gemini API before, and the majority of us had never used TypeScript before, so learning while building this project was a big accomplishment for all of us.

What we learned

None of us had ever worked with the Gemini API before, so we learned how to perform supervised fine-tuning and successfully deploy our fine-tuned Gemini model. We also really exercised our creativity on the UI/UX design side, which was very enriching as most of our team has primarily backend experience.

What's next for ThoughtMirror

In the future, we would like to refine AI suggestions, adding more source data to our RAG Gemini implementation, to allow us better responses that are fitting to what a cognitive-behavioural therapist might say. Alongside that, we hope to build a more interactive dashboard where users can set personalized journaling goals, track their emotional patterns over time, and receive targeted cognitive distortion feedback—empowering them with deeper insights and progress monitoring throughout their mental health journey.

Built With

+ 6 more
Share this project:

Updates