<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chanuka Geekiyanage on Medium]]></title>
        <description><![CDATA[Stories by Chanuka Geekiyanage on Medium]]></description>
        <link>https://medium.com/@gchanukalakmal123?source=rss-e3c81b5cdbec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1C73udrZQ-rcIp0t0MWDKw.jpeg</url>
            <title>Stories by Chanuka Geekiyanage on Medium</title>
            <link>https://medium.com/@gchanukalakmal123?source=rss-e3c81b5cdbec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 10:31:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gchanukalakmal123/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Incorporating Design Patterns for Better Code Structure in Our Diet Recommender System]]></title>
            <link>https://medium.com/@gchanukalakmal123/incorporating-design-patterns-for-better-code-structure-in-our-diet-recommender-system-0fd3fa2b8fff?source=rss-e3c81b5cdbec------2</link>
            <guid isPermaLink="false">https://medium.com/p/0fd3fa2b8fff</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[nutricare]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Chanuka Geekiyanage]]></dc:creator>
            <pubDate>Tue, 22 Apr 2025 07:46:55 GMT</pubDate>
            <atom:updated>2025-04-22T07:46:55.947Z</atom:updated>
            <content:encoded><![CDATA[<p>As our Personalized Diet Recommender System started growing in features and complexity, we quickly realized something important: writing working code isn’t enough. We needed to write <strong>maintainable</strong>, <strong>scalable</strong>, and <strong>modular</strong> code.</p><p>That’s where <strong>design patterns</strong> came in. Design patterns are proven solutions to common software design problems. In this article, we’ll walk through how we applied patterns like <strong>Repository</strong>, <strong>Service Layer</strong>, and <strong>Factory</strong> to organize our code better and keep it flexible for future improvements.</p><h3>Why Use Design Patterns?</h3><p>When building even a mid-sized system, the code can get messy if everything is handled in one place. You might end up with:</p><ul><li>Logic mixed with database access</li><li>Duplicated code for similar tasks</li><li>Tight coupling between components</li></ul><p>Design patterns help you avoid all that. They bring structure, make testing easier, and improve the ability to add new features without breaking existing ones.</p><h3>1. Repository Pattern — Managing Data Access</h3><p>In our system, we needed a clean way to <strong>fetch, filter, and update food data</strong> from CSV files using Pandas. Instead of placing that logic directly inside the business layer, we created a <strong>Repository</strong>.</p><h4>Benefits:</h4><ul><li>Keeps data access logic separate from business logic</li><li>Makes unit testing easier (you can mock the repository)</li><li>Centralizes all data operations in one place</li></ul><h4>Example: food_repository.py</h4><pre>import pandas as pd</pre><pre>class FoodRepository:<br>    def __init__(self):<br>        self.food_df = pd.read_csv(&quot;data/foods.csv&quot;)</pre><pre>    def get_food_by_tag(self, tag):<br>        return self.food_df[self.food_df[&#39;Tags&#39;].str.contains(tag)]</pre><pre>    def get_low_calorie_foods(self):<br>        return self.food_df[self.food_df[&#39;Calories&#39;] &lt; 100]</pre><p>Now, the business layer can just call:</p><pre>repo = FoodRepository()<br>diabetic_foods = repo.get_food_by_tag(&quot;diabetic&quot;)</pre><h3>2. Service Layer Pattern — Isolating Business Logic</h3><p>To keep our backend logic clean, we separated the <strong>business rules</strong> from the FastAPI endpoints. This meant putting the actual recommendation logic into a <strong>service layer</strong>.</p><h4>Benefits:</h4><ul><li>Keeps API routes lightweight and focused</li><li>Makes logic reusable across multiple endpoints</li><li>Easier to scale and maintain</li></ul><h4>Example: recommendation_service.py</h4><pre>from food_repository import FoodRepository</pre><pre>class RecommendationService:<br>    def __init__(self):<br>        self.repo = FoodRepository()</pre><pre>    def generate_plan(self, user_input):<br>        foods = self.repo.get_food_by_tag(user_input.health_condition)<br>        # Logic to build 7-day meal plan<br>        return foods.sample(7)</pre><p>And in our FastAPI route:</p><pre>@router.post(&quot;/generate-diet-plan&quot;)<br>async def generate_diet_plan(data: UserInput):<br>    service = RecommendationService()<br>    plan = service.generate_plan(data)<br>    return {&quot;plan&quot;: plan.to_dict(orient=&quot;records&quot;)}</pre><h3>3. Factory Pattern — Dynamic Object Creation</h3><p>Our system needed to support multiple dietary conditions (e.g., diabetic, high cholesterol, high blood pressure). Instead of writing separate functions for each, we used a basic <strong>Factory pattern</strong> to generate condition-specific filters.</p><h4>Benefits:</h4><ul><li>Simplifies conditional logic</li><li>Makes adding new conditions easier</li><li>Keeps the main logic clean and readable</li></ul><h4>Example: filter_factory.py</h4><pre>class FoodFilterFactory:<br>    @staticmethod<br>    def get_filter(condition):<br>        if condition == &quot;diabetic&quot;:<br>            return lambda df: df[df[&#39;Tags&#39;].str.contains(&quot;diabetic&quot;)]<br>        elif condition == &quot;cholesterol&quot;:<br>            return lambda df: df[df[&#39;Tags&#39;].str.contains(&quot;low-fat&quot;)]<br>        else:<br>            return lambda df: df</pre><p>Usage:</p><pre>food_filter = FoodFilterFactory.get_filter(user_input.health_condition)<br>filtered_foods = food_filter(food_df)</pre><h3>How Design Patterns Improved Our Architecture</h3><p>Here’s how these patterns mapped to our Layered Architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*CtbHHItGP_UmyPLITIs6sg.png" /></figure><p>By applying these patterns, our code became more <strong>organized</strong>, <strong>testable</strong>, and <strong>modular</strong>. If we want to upgrade to a database later, we can just swap out the repository logic without touching the business layer.</p><h3>Final Thoughts</h3><p>Using design patterns gave our project a much-needed structure. They helped us keep our logic separate, reduce duplication, and prepare the system for future growth.</p><p>If you’re building a multi-layered application, these patterns aren’t just optional — they’re essential.</p><p>In the next post, we’ll dive into <strong>testing strategies</strong> and show you how we ensured our system was not only functional, but also reliable and robust.</p><p>Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0fd3fa2b8fff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ensuring Data Integrity and Security in Our Personalized Diet Recommender System]]></title>
            <link>https://medium.com/@gchanukalakmal123/ensuring-data-integrity-and-security-in-our-personalized-diet-recommender-system-beacf7114e61?source=rss-e3c81b5cdbec------2</link>
            <guid isPermaLink="false">https://medium.com/p/beacf7114e61</guid>
            <category><![CDATA[nutricare]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[data-security]]></category>
            <dc:creator><![CDATA[Chanuka Geekiyanage]]></dc:creator>
            <pubDate>Mon, 21 Apr 2025 16:48:50 GMT</pubDate>
            <atom:updated>2025-04-21T16:48:50.701Z</atom:updated>
            <content:encoded><![CDATA[<p>In any system that handles personal or health-related data, <strong>security and data integrity</strong> are non-negotiable. Even though our Personalized Diet Recommender System does not store user data permanently, we still had to ensure that the data we process is accurate, secure, and handled with care during its brief time in the system.</p><p>In this article, we’ll break down the techniques we used to protect user data, validate inputs, maintain consistency across the system, and design secure APIs as part of our overall software architecture.</p><h3>Why Security and Integrity Matter</h3><p>Even without a login system or database storage, users still input sensitive health details like blood pressure, cholesterol, and BMI. If this data is mishandled, it could lead to:</p><ul><li>Incorrect or harmful diet recommendations</li><li>Security vulnerabilities like data leaks or injection attacks</li><li>A poor user experience that damages trust in the system</li></ul><p>That’s why <strong>data protection starts from the very first interaction</strong> — the moment a user types into the form.</p><h3>Step 1: Input Validation at Multiple Levels</h3><h4>Frontend Validation (React.js)</h4><p>We started by adding form-level checks to catch errors before data is sent to the backend. This included:</p><ul><li>Ensuring all required fields are filled</li><li>Enforcing numeric input formats for age, BMI, and health metrics</li><li>Preventing out-of-range values (e.g., a BMI of 200 is obviously invalid)</li></ul><pre>if (bmi &lt; 10 || bmi &gt; 60) {<br>  alert(&quot;Please enter a valid BMI&quot;);<br>}</pre><h4>Backend Validation (FastAPI + Pydantic)</h4><p>Client-side checks are helpful, but they can be bypassed. That’s why we used <strong>Pydantic models</strong> in FastAPI to validate all incoming requests on the server side too.</p><pre>class UserInput(BaseModel):<br>    age: int = Field(..., gt=0, lt=120)<br>    bmi: float = Field(..., gt=10, lt=60)<br>    activity_level: str</pre><p>This makes sure only clean, expected data reaches the core logic.</p><h3>Step 2: Avoiding Data Storage Altogether</h3><p>One of our key security strategies was to <strong>process everything in real-time</strong> without saving user data to a database.</p><p>This means:</p><ul><li>No risk of data breaches from stored records</li><li>No need for authentication or session tracking</li><li>Every user session is stateless and independent</li></ul><p>By avoiding storage, we significantly reduced the system’s attack surface.</p><h3>Step 3: Secure API Design</h3><p>To protect the communication between frontend and backend, we designed our API with the following practices:</p><h4>HTTPS-Only Communication</h4><p>All API calls are made over HTTPS, preventing man-in-the-middle attacks and ensuring data is encrypted during transmission.</p><h4>Strict CORS Policy</h4><p>We enabled <strong>Cross-Origin Resource Sharing (CORS)</strong> to allow only requests from our own frontend.</p><pre>from fastapi.middleware.cors import CORSMiddleware</pre><pre>app.add_middleware(<br>    CORSMiddleware,<br>    allow_origins=[&quot;https://our-frontend.com&quot;],<br>    allow_credentials=True,<br>    allow_methods=[&quot;*&quot;],<br>    allow_headers=[&quot;*&quot;],<br>)</pre><h4>Error Handling and Response Control</h4><p>We avoided exposing system internals by customizing error responses.</p><p>Instead of this:</p><pre>{<br>  &quot;detail&quot;: &quot;Traceback (most recent call last)...&quot;<br>}</pre><p>We return this:</p><pre>{<br>  &quot;error&quot;: &quot;Invalid input. Please check your values.&quot;<br>}</pre><p>This helps protect backend logic and prevents information leakage.</p><h3>Step 4: Data Consistency Across Layers</h3><p>We ensured that data remained accurate and consistent from the moment it was entered to the moment it was used to generate a meal plan.</p><p><strong>How we achieved this:</strong></p><ul><li>Used consistent variable names and data types across frontend, backend, and logic layers</li><li>Ensured the same health thresholds (e.g., BMI ranges) were applied throughout the system</li><li>Wrote test cases to validate edge conditions like empty inputs, conflicting data, or duplicate tags</li></ul><h3>Final Thoughts</h3><p>Even a simple system like ours can benefit from careful planning around <strong>data integrity and security</strong>. By validating user input, keeping everything stateless, designing secure APIs, and enforcing consistency across the system, we made sure the recommendations we provide are not only smart but safe.</p><p>In the next article, we’ll talk about <strong>version control, dependency management</strong>, and how we kept our project organized across multiple updates and commits.</p><p>Security might be invisible to users, but it’s one of the most important layers in any software system — and we’re proud of how we approached it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=beacf7114e61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Frontend Architecture with React.js: Designing Smart Components and Managing State Effectively]]></title>
            <link>https://medium.com/@gchanukalakmal123/frontend-architecture-with-react-js-designing-smart-components-and-managing-state-effectively-a5b65228c7d4?source=rss-e3c81b5cdbec------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5b65228c7d4</guid>
            <category><![CDATA[nutricare]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Chanuka Geekiyanage]]></dc:creator>
            <pubDate>Mon, 21 Apr 2025 15:57:00 GMT</pubDate>
            <atom:updated>2025-04-21T15:57:00.539Z</atom:updated>
            <content:encoded><![CDATA[<p>With the backend architecture solid and responsive, the next piece of the puzzle was building a <strong>clean, user-friendly frontend</strong> for our Personalized Diet Recommender System. That’s where <strong>React.js</strong> came in.</p><p>React is known for its flexibility and component-driven approach, making it an ideal choice for a modular, interactive interface like ours. In this post, we’ll explore how we structured our frontend using React components, how we manage state across the app, and the tools we considered to make everything efficient and scalable.</p><h3>Why React.js for the Frontend?</h3><p>Choosing React was a no-brainer for a few key reasons:</p><ul><li><strong>Component-Based Structure</strong> — Perfect for building reusable and modular UI elements</li><li><strong>Virtual DOM</strong> — Enables fast rendering and smooth user experience</li><li><strong>Large Ecosystem</strong> — Plenty of libraries and community support</li><li><strong>Easy API Integration</strong> — Great for communicating with our FastAPI backend</li></ul><p>React gave us the flexibility to build and scale features independently without breaking the UI.</p><h3>Breaking Down the Component Structure</h3><p>React applications are built around <strong>components</strong> — small, self-contained pieces of UI that manage their own rendering and behavior. Here’s how we organized ours:</p><h4>InputForm Component</h4><ul><li>Collects user data such as age, gender, BMI, health conditions, and dietary preferences</li><li>Handles input validation before submission</li><li>Uses controlled components for real-time form updates</li></ul><h4>MealPlanDisplay Component</h4><ul><li>Displays the personalized meal plan returned from the backend</li><li>Formats the data into a user-friendly weekly layout</li><li>Supports filtering and adjustments based on user feedback</li></ul><h4>Header and Footer Components</h4><ul><li>Reusable layout elements used across all pages</li><li>Helps maintain a consistent design</li></ul><h4>Loading and Error Components</h4><ul><li>Handle different system states like fetching data or API errors</li><li>Improve user experience by providing feedback</li></ul><p>This <strong>modular structure</strong> made the app easy to scale and maintain. Each component has a clear job and can be tested or reused independently.</p><h3>State Management: Local and Global</h3><p>In any frontend app, managing <strong>state</strong> is crucial. State refers to the data your app tracks over time — things like user input, API responses, and UI status.</p><p>We used a combination of <strong>React’s built-in hooks</strong> and <strong>Context API</strong> for state management.</p><h3>Local State with useState</h3><p>For form inputs, toggles, and local UI changes, we used the useState hook:</p><pre>const [bmi, setBmi] = useState(&quot;&quot;);</pre><h3>Global State with Context API</h3><p>Some state, like the user’s submitted health data or the diet plan received from the backend, needed to be accessible across multiple components. We used <strong>React Context</strong> to handle this.</p><p>We created a UserContext and wrapped our app in a UserProvider so that components like MealPlanDisplay or InputForm could access shared state.</p><pre>const { userData, setUserData } = useContext(UserContext);</pre><h3>Why Not Redux?</h3><p>Redux is a powerful state management library, but it can be <strong>overkill for small to medium projects</strong> like ours. We needed something simpler and quicker to implement. Context API met our needs with less boilerplate.</p><p>However, we kept Redux in mind as a <strong>potential upgrade</strong> if the project expands to include:</p><ul><li>Authentication and login state</li><li>Complex UI interactions</li><li>Offline mode or caching</li></ul><h3>Strategies for Reusability and Scalability</h3><p>Here’s what we focused on to keep our codebase clean and scalable:</p><h3>1. Component Reusability</h3><p>We broke larger components into smaller pieces where possible. For example, the InputForm contains reusable InputField and Dropdown components.</p><h3>2. Styling Consistency</h3><p>We used CSS modules to scope styles to components and avoid global conflicts. In the future, we could switch to styled-components or Tailwind CSS for more flexibility.</p><h3>3. Separation of Concerns</h3><p>We separated logic from UI wherever possible. For example, API requests are handled in separate utility files (api.js) instead of being embedded in components.</p><h3>Final Thoughts</h3><p>Building the frontend with React.js allowed us to create a responsive, modular, and maintainable interface for our system. With well-structured components and efficient state management using Context API, we ensured that users could easily input their data and receive personalized diet recommendations with a smooth experience.</p><p>In the next post, we’ll talk about <strong>how we ensured data integrity and security</strong> across the architecture — especially important when handling sensitive health-related information.</p><p>Stay tuned as we keep building the system, one layer at a time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5b65228c7d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing the Data Flow in Our Personalized Diet Recommender System]]></title>
            <link>https://medium.com/@gchanukalakmal123/designing-the-data-flow-in-our-personalized-diet-recommender-system-29109d0c97d6?source=rss-e3c81b5cdbec------2</link>
            <guid isPermaLink="false">https://medium.com/p/29109d0c97d6</guid>
            <dc:creator><![CDATA[Chanuka Geekiyanage]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 06:14:01 GMT</pubDate>
            <atom:updated>2025-03-28T06:25:25.816Z</atom:updated>
            <content:encoded><![CDATA[<p>Every software system is like a living, breathing organism where data moves constantly between different layers. If the flow of information isn’t carefully designed, the entire system can break down or behave unpredictably. That’s why <strong>designing the data flow</strong> is a critical part of software architecture.</p><p>In this article, we’re going to show you exactly <strong>how data travels through our Personalized Diet Recommender System</strong>. We’ll introduce concepts like <strong>data pipelines</strong>, <strong>input validation</strong>, and <strong>data mapping</strong>, and end with a clear visual flowchart of our system’s inner workings.</p><h3>What Is Data Flow in Software Architecture?</h3><p><strong>Data flow</strong> refers to how input data travels through different parts of a system, how it gets transformed, processed, and eventually turned into meaningful output.</p><p>In our case, the flow starts from the <strong>user</strong> and ends with a <strong>personalized diet recommendation</strong>. In between, data passes through several transformation stages within the layered architecture we previously discussed.</p><h3>Step-by-Step Breakdown of the Data Flow</h3><h4>1. User Input — Presentation Layer</h4><p>The process begins when the user enters their information through the web interface. This includes:</p><ul><li>Age and gender</li><li>BMI and activity level</li><li>Blood pressure, blood sugar, cholesterol</li><li>Dietary preferences and restrictions</li></ul><p>Before anything else, this data undergoes <strong>input validation</strong> to check for missing fields, incorrect formats, or invalid values.</p><h4>2. Data Sent to Backend — API Communication</h4><p>Once validated, the data is sent from the frontend (React.js) to the backend (FastAPI) using HTTP requests. We designed RESTful API endpoints to handle these requests securely and efficiently.</p><h4>3. Processing — Business Logic Layer</h4><p>This is where the core of the system does its job. The FastAPI backend takes the user data and:</p><ul><li>Maps each input to nutritional requirements using rules we’ve predefined</li><li>Analyzes any health constraints like high blood pressure or diabetes</li><li>Applies logic to select suitable foods from the dataset</li><li>Builds a 7-day meal plan personalized to the user’s profile</li></ul><p>This entire step is the <strong>data mapping</strong> phase, where raw user inputs are converted into meaningful health-related parameters.</p><h4>4. Fetching Nutritional Data — Data Layer</h4><p>To generate the diet plan, the system pulls relevant information from a structured <strong>Sri Lankan food database</strong>, stored using Pandas in Python.<br> This includes:</p><ul><li>Nutritional breakdowns</li><li>Food categories</li><li>Tags like vegetarian, low-carb, diabetic-friendly</li></ul><p>The backend performs filtering and aggregation here, using pandas operations to finalize meal choices.</p><h4>5. Response Sent Back to Frontend</h4><p>Once the diet plan is ready, it is packaged into a JSON response and sent back to the frontend.<br> The UI then displays the results in a clean, readable format, usually as a weekly meal chart with timing and portion sizes.</p><h3>Introducing Key Concepts</h3><h4>Input Validation</h4><p>We validate all data on the client side and again on the server side to prevent errors and ensure safe processing. This includes checks like:</p><ul><li>Is BMI within a logical range?</li><li>Did the user select a dietary preference?</li><li>Are numeric values provided for age, blood pressure, etc.?</li></ul><h4>Data Mapping</h4><p>We map inputs like activity level or cholesterol status to actual nutritional needs. For example:</p><ul><li>High activity = higher calories</li><li>High cholesterol = low-fat food options</li><li>Diabetic = low glycemic index items</li></ul><h4>Data Pipeline</h4><p>Our system uses a basic data pipeline where data flows in one direction:<br> User input → Validated input → Mapped to logic → Meal plan generated → Output displayed</p><p>Although it looks simple, the key is keeping each step modular so the pipeline is easy to debug and extend.</p><h3>Visualizing the Data Flow</h3><p>Here’s a simplified flowchart to illustrate how data flows through our system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*8BZCqFPnFOaU4vz_fvsmcA.png" /></figure><h3>Final Thoughts</h3><p>Designing a solid data flow is like planning a road trip — you need to know where you’re starting, where you’re going, and every stop along the way.</p><p>Our carefully structured flow ensures that the user’s information is processed safely, intelligently, and efficiently. This also reinforces the <strong>Layered Architecture</strong> we’re following, where each layer has a clear role in the journey from input to output.</p><p>In the next post, we’ll take you behind the scenes of our <strong>FastAPI backend</strong> and explain the key design decisions that make it powerful and scalable. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29109d0c97d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why We Chose a Layered Architecture for Our Personalized Diet Recommender System]]></title>
            <link>https://medium.com/@gchanukalakmal123/why-we-chose-a-layered-architecture-for-our-personalized-diet-recommender-system-1aa85315e281?source=rss-e3c81b5cdbec------2</link>
            <guid isPermaLink="false">https://medium.com/p/1aa85315e281</guid>
            <dc:creator><![CDATA[Chanuka Geekiyanage]]></dc:creator>
            <pubDate>Sun, 23 Mar 2025 15:26:30 GMT</pubDate>
            <atom:updated>2025-03-28T06:27:12.541Z</atom:updated>
            <content:encoded><![CDATA[<p>After defining the core concepts of software architecture, the next big step in our project was deciding on the right architectural pattern. For our <strong>Personalized Diet Recommender System</strong>, we settled on a <strong>Layered Architecture- </strong>and for good reason. This decision wasn’t random; it was carefully considered based on the nature of our system and the long-term goals we had in mind.</p><p>In this post, we’ll take a deep dive into the <strong>Layered Architecture pattern</strong>, explore why it’s the best fit for our project, and highlight the benefits it brings in terms of scalability, maintainability, and modularity. We’ll also walk you through a high-level diagram of our system to show how everything fits together.</p><h3>What Is a Layered Architecture?</h3><p>A <strong>Layered Architecture</strong> organizes code into distinct layers, where each layer has a specific responsibility and communicates only with the layer directly above or below it. This makes the system <strong>modular</strong> and <strong>easy to manage</strong> because each layer functions independently while contributing to the overall system’s operation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pXv4yYAVhnluLpwc.png" /></figure><p>In a typical Layered Architecture, you’ll find the following core layers:</p><ul><li><strong>Presentation Layer</strong> — Handles user interface and user experience</li><li><strong>Business Logic Layer</strong> — Processes inputs, applies business rules, and makes decisions</li><li><strong>Data Layer</strong> — Manages data storage and retrieval</li></ul><h3>How Our Personalized Diet Recommender System Is Structured</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*qYdEs7FLQS7mW3675YcnSA.png" /></figure><p>For our project, we structured the system into three primary layers:</p><ol><li><strong>Presentation Layer</strong> (Frontend) — Built with <strong>React.js</strong> to handle user interactions and display results.</li><li><strong>Business Logic Layer</strong> (Backend) — Developed using <strong>FastAPI</strong> to process user data, apply dietary rules, and recommend meal plans.</li><li><strong>Data Layer</strong> — Uses <strong>Pandas</strong> and other data-handling tools to store and retrieve user data efficiently.</li></ol><p>This setup allows us to isolate functionality, making it easier to test, scale, and modify each part of the system without affecting the others.</p><h3>Why We Chose a Layered Architecture</h3><h4>1. Scalability</h4><p>Scalability was one of the biggest reasons we leaned toward a layered design.</p><ul><li>As user data increases and new features are introduced, the modular structure allows us to scale individual layers independently.</li><li>For example, if we experience a surge in user traffic, we can scale the backend services without touching the frontend or data layer.</li></ul><h4>2. Maintainability</h4><p>A clean separation of concerns means that changes in one layer don’t ripple across the whole system.</p><ul><li>If we need to update the dietary rules or improve the recommendation algorithm, we can adjust the business logic layer without rewriting the UI or changing the data handling.</li><li>This makes debugging and future updates much simpler.</li></ul><h4>3. Modularity</h4><p>Each layer is self-contained, which makes it easier to modify and extend the system.</p><ul><li>If we decide to switch from Pandas to a different data handling library, we only need to update the data layer without touching the business logic or frontend.</li><li>This modularity allows faster development and encourages code reuse.</li></ul><h3>Why Not a Microservices or Monolithic Architecture?</h3><p>We considered other architectures, but they didn’t align with our project’s scope and requirements:</p><ul><li><strong>Microservices Architecture</strong> — While powerful, it introduces complexity and communication overhead that isn’t necessary for a single-purpose system like ours.</li><li><strong>Monolithic Architecture</strong> — Easier to set up initially, but difficult to scale and modify over time. The lack of separation between logic, presentation, and data makes future updates challenging.</li></ul><h3>Lessons Learned So Far</h3><p>Choosing a layered architecture was a strategic move, but it also required careful planning. We had to clearly define how data flows between layers and ensure that each layer remains independent yet cohesive.</p><p>So far, the benefits are paying off:</p><ul><li>The frontend and backend teams can work independently without stepping on each other’s toes.</li><li>The code is structured and organized, making it easy to debug and extend.</li><li>We’re already planning future updates without fearing system-wide disruption.</li></ul><h3>What’s Next?</h3><p>Next, we’ll focus on defining system requirements and functional specifications. Understanding the system’s requirements is crucial for designing a solid architecture. We’ll explore how we gathered inputs like user preferences and dietary data, and how those inputs translate into functional and non-functional requirements.</p><p>Stay tuned as we continue building and optimizing our personalized diet recommender system!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1aa85315e281" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>