Posts

Showing posts with the label project(calorie tracker)

A Fresh Start: The Decision to Reboot My Project

Sometimes in development, you need to take a step back and look at the bigger picture. Recently, I reached a significant turning point in my project. There had been considerable progress - adding extra features, integrating the FatSecret API, and more. But as my project grew, I realized I had a problem: lack of organization. The codebase had become unwieldy. Making changes to a single feature became increasingly difficult, and without proper test code, it was impossible to verify functionality piece by piece. Though it was a tough decision emotionally, I've decided to start over, viewing the experience as a valuable lesson. For the reboot, I'm taking a more structured approach: Using React for the frontend Implementing Spring Boot for the backend Adopting proper Git workflows with multiple branches to simulate a real company environment Even though this is a solo project, I'm committed to following professional development practices. This will not only make the project ...

Solve - Redirecting to TrainingList After Saving Training Data

Image
  When building a Single Page Application (SPA) with React on the frontend and an Express server with Sequelize on the backend, one common challenge is handling navigation and redirects properly after switching from server-side rendering (Firstly, I developed the app with ejs ) to an API-based architecture . In this post, I’ll walk through how I tackled an issue where saving training data was incorrectly redirecting to the FoodList page instead of the desired TrainingList page. Let’s dive into the problem, the solution, and the final implementation! The Problem In the original setup, my Express server used res.render to serve EJS templates and res.redirect to navigate users to different pages after certain actions—like saving a new training entry. For example: // Before: Server-side redirect res.redirect( '/foodlist' ); However, I refactored the application to use an API-based approach, replacing res.render and res.redirect with res.json to return JSON responses. Th...

Solving a Data Update Issue: Lessons in Consistency and Stability

Image
Recently, I encountered an issue in my application where updating an item in both the "food" and "training" sections didn’t behave as expected. Even though the update itself was successful, the app didn’t redirect properly or throw an invalid error when it should have. After some investigation, I identified the root causes and implemented two solutions to address the problem. Here’s what I did, why it mattered, and the key takeaways from the experience. The Problem When updating an item, I noticed that the system wasn’t handling missing or invalid data gracefully. For example, if a date field was missing or invalid, the update would still complete, but it wouldn’t trigger the expected redirect or validation error. This led to inconsistencies in the UI and potential data integrity issues. I needed a way to ensure the system remained stable and user-friendly, even when the data wasn’t perfect. Solution 1: Defaulting to Today’s Date The first fix was simple but effe...

March 18, 2025: Issue with Redirect, Update Items, and Save Order

 18.03.2025 Currently, I’m facing an issue with my training list. When I save a new training entry or edit an existing one, it doesn’t redirect properly or shows invalid values. Also, when I add new food to the list, it gets saved at the bottom, whereas new training entries are saved at the top. I’ve been struggling with this problem for two days. Still, I’ll keep working on it until I figure it out, and I’ll come back to share what I’ve learned from the experience!

Why I Decided to Migrate My JavaScript Project to TypeScript

Image
I’ve been working on this project to support my health tracking and climbing training routine. It’s a project close to my heart. Not just a tool, but a companion for my family's long-term fitness journey. As I started planning its future, I realized that keeping it maintainable and scalable over the years would be a challenge with plain JavaScript. That’s when I decided to take the plunge and migrate my project to TypeScript. Here’s why I made that choice, focusing on one key reason: long-term maintenance. The Project: A Long-Term Commitment This isn’t a throwaway app or a quick side project. My goal is to build something I can rely on for years, tracking my nutrition, workout progress, and climbing goals. Over time, I’ll likely add features like data visualizations, goal-setting tools, or even integrations with wearables. With that kind of evolution in mind, I needed a foundation that wouldn’t crumble under the weight of future updates. JavaScript, while flexible and fast to work...

Simplifying Development: Moving from a Multi-Database to a Single-Database Setup

Image
The Original Setup: Two Databases Initially, I used two PostgreSQL databases: one for calories data and another for users data. Here’s how I configured them with Sequelize: I avoided foreign keys across databases and planned to handle relationships in the application code. However, this setup quickly became cumbersome for my small project in the sense that without foreign keys, I had to manually handle relationships, slowing down development. The Switch: A Single Database I consolidated into a single database for simplicity. Here’s the updated configuration: I migrated both users and calories tables into the calorie-app database, added foreign keys, and updated my Sequelize models to use associations. Benefits of the Transition Faster Development : Foreign keys and Sequelize associations simplified my code. Simpler Queries : I could use JOINs for efficient data retrieval. Trade-Offs A single database might limit scalability in the future, but for my small user base, this ...

Efficient Data Management Through Food Model Separation

Image
I've enhanced the data structure by separating the food model and changing the lookup method from date-based to ID-based. This transformation offers several significant advantages: Improved Data Retrieval Speed Local Data Store Limitation : In the local data store, the getFoodItemByDate method reads and parses an entire JSON file into memory using this.getAllFood() and then searches for a matching date with find. This approach works fine for small datasets but becomes painfully slow as the data grows, requiring a full scan every time. PostgreSQL Benefit : With PostgreSQL, operations like Food.findByPk(id) leverage primary key indexing, making lookups lightning-fast even with thousands of records. Adding an index on the date column could further optimize date-based queries, something a file-based system can't easily replicate. Enhanced Data Integrity Local Data Store Limitation : The JSON-based system relies on the application to enforce data rules. For example, there's no g...

Transitioning My Project’s Data: local data files to PostgreSQL

Image
  I've decided to take a PostgreSQL course to facilitate my project's data transformation stage.  The structured approach of PostgreSQL offers significant advantages over my current file-based system, particularly for handling complex relationships and ensuring data integrity. I believe learning these database concepts will serve as a valuable investment for both my current project and future endeavors. I will keep you updated about my project when I start transitioning to PostgreSQL!

"Project Start"

Image
  A few  days ago, I started building a personalized wellness website for my wife and me. The goal is to track our nutrition and fitness goals without the constant interruptions of ads you often find in free apps. What's made a huge difference is using Agent Mode with Claude 3.7 Sonnet in Copilot. It's been a game-changer for productivity, especially when correcting features or variable names. If I miss something that should have been changed based on new features or variable names, it quickly finds it through global searching, saving me a lot of time. I highly recommend this approach to anyone working on side projects or doing full-stack development solo.