<?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 Aldrin Çifliku on Medium]]></title>
        <description><![CDATA[Stories by Aldrin Çifliku on Medium]]></description>
        <link>https://medium.com/@acifliku?source=rss-18177c0e30fb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LxR4sHlRGYfA0z-qYHESXA.jpeg</url>
            <title>Stories by Aldrin Çifliku on Medium</title>
            <link>https://medium.com/@acifliku?source=rss-18177c0e30fb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 05:10:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@acifliku/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[How I solved the riddles of RAG]]></title>
            <link>https://medium.com/@acifliku/how-i-solved-the-riddles-of-rag-a684114d158d?source=rss-18177c0e30fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a684114d158d</guid>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <dc:creator><![CDATA[Aldrin Çifliku]]></dc:creator>
            <pubDate>Thu, 07 May 2026 17:15:51 GMT</pubDate>
            <atom:updated>2026-05-07T17:15:51.805Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DxXqJUrvEZYAaJl3DIVv3A.png" /></figure><p>These past months I have been exploring the domain of RAG and agentic AI. There are a lot of topics being discussed right now and a lot of progress being made in multiple fronts. There is also an abundance of open source software that is being produced by the community in that direction. However, for quite some time there has been an issue with RAG that has been bugging me. RAG IS STRUCTURELY DUMB! Simple RAG fails to acknowledge that chunks carry meaning based on their positioning, size, or formulation just as much as they carry it semantically. There are two types of open source solution to the RAG problem:<br>1 — Those that are incomplete. So, they do solve the RAG problem but fail to acknowledge the structure of the document<br>2 — Those who offer a more complete solution but are not entirely open. So, you can use them for free but you have little ability to modify them and they offer no transparency at all.<br>So, I set myself on a mission to create a platform that solves the RAG problem including structure identification and anaphoric references extraction, and at the same time is completely open and transparent for the community. That platform is <a href="https://github.com/guy1998/glaucias">GLAUCIAS</a></p><h4><strong>Understanding the problem</strong></h4><p>Before I explain what Glaucias does and why it is better than other open source platforms I will first explain what the problem with simple traditional RAG is. Let’s look at some quick examples:</p><blockquote># Example 1</blockquote><blockquote>Imagine we have a company policy document.</blockquote><blockquote>Original document:</blockquote><blockquote>Section 1 — Remote Work Policy</blockquote><blockquote>Employees can work remotely up to 2 days per week.<br>Exceptions are explained in Section 7.</blockquote><blockquote>Section 7 — Executive Exceptions</blockquote><blockquote>Senior managers may work remotely full-time with approval from HR.</blockquote><blockquote>Now imagine the RAG system splits the document every 150 characters without understanding sections.</blockquote><blockquote>The chunks become:</blockquote><blockquote>Chunk A:<br>“Employees can work remotely up to 2 days per week. Exceptions are explained in”</blockquote><blockquote>Chunk B:<br>“Section 7. Senior managers may work remotely full-time with approval from HR.”</blockquote><blockquote>User question:<br>“Can senior managers work remotely full-time?”</blockquote><blockquote>The semantic retriever may return Chunk A because it contains:<br>- work remotely<br>- employees<br>- exceptions</blockquote><blockquote>But Chunk A does not contain the actual exception. The important information is in Chunk B<br>So the AI may answer:<br>“Employees can work remotely up to 2 days per week.”<br>Which is incorrect for senior managers.</blockquote><p>==================================================</p><blockquote># Example 2</blockquote><blockquote>Now imagine the chunks are properly split.</blockquote><blockquote>Chunk 1:<br>“Employees can work remotely up to 2 days per week.<br>Exceptions are explained in Section 7.”</blockquote><blockquote>Chunk 2:<br>“Section 7:<br>Senior managers may work remotely full-time with approval from HR.”</blockquote><blockquote>User question:<br>“What are the remote work rules for senior managers?”</blockquote><blockquote>The retriever may successfully find Chunk 1 because it contains:<br>- remote work<br>- rules<br>- employees</blockquote><blockquote>But Chunk 1 only references another section:<br>“Exceptions are explained in Section 7.”</blockquote><blockquote>Humans immediately understand:<br>“I should also read Section 7.”</blockquote><blockquote>Traditional semantic search does not think this way. It only retrieves chunks based on embedding similarity. So Chunk 2 may <strong><em>never </em></strong>be retrieved.<br>The AI then generates an incomplete answer because it never saw the actual exception.</blockquote><h4><strong>Turning problems into opportunities</strong></h4><p>So, now we know that there are 2 major issues with traditional RAG:</p><p>- No structural awareness: chunks may be meaningless<br>- Semantic approach cares more about wording than it does about meaning</p><p>Are there really no solutions to this problems out there? I wouldn’t say that exactly. First of all, people have probably already solved such issues in big enterprises. It is hard to imagine that top engineers with a multi million dollar budget have failed at this. However, every possible solution that exist has not been disclosed. I mean, it makes them money so it is fair enough. <br>Secondly, there is a promising direction to RAG called GraphRAG. I would suggest to have a look at <a href="https://github.com/microsoft/graphrag">Microsoft’s graphrag platform</a>. GraphRAG is quite innovative on its own. What really rubs me the wrong way about it is that it is quite dependable on the concept of named entities (Read more about it <a href="https://www.geeksforgeeks.org/nlp/named-entity-recognition/">here</a>). For certain documents this is completely fine. However, many documents, especially manuals and or guidelines are more oriented to action words (verbs) rather than named entities. So, a lot of information can get lost. Therefore I went for a different approach.</p><p>Firstly, I had to solve the problem of irregular chunking. As you read earlier in the examples section dividing the document in equal chunks is just not good enough since you can never be sure of having caught the full meaning. Luckily, people of other domains have already come up with solutions to that. It is called document parsing and it basically extracts the document as a list of meaningful nodes. You can imagine a pdf being divided as follows:</p><pre>[Node 1] Title<br>&quot;Introduction to Computer Vision&quot;<br><br>[Node 2] Paragraph<br>&quot;Computer vision enables machines to understand and analyze visual data from images and videos.&quot;<br><br>[Node 3] Heading<br>&quot;Applications&quot;<br><br>[Node 4] Bullet List<br>- Face recognition<br>- Autonomous driving<br>- Medical imaging<br><br>[Node 5] Paragraph<br>&quot;Deep learning models such as CNNs are widely used for image classification tasks.&quot;<br><br>[Node 6] Table<br>| Model        | Accuracy |<br>|--------------|----------|<br>| ResNet50     | 76%      |<br>| EfficientNet | 84%      |</pre><p>Now there are a few alternative platforms that carry out such extraction. For my purposes I used <a href="https://github.com/docling-project/docling">Docling</a>. After having all the nodes extracted I embed each node as a chunk. So, now all my chunks have their full structural meaning.</p><p>The second part of the problem is trickier. How to connect nodes with one another? This requires a little bit of knowledge of how a part of the text can relate to another. There are 3 main categories that are identified in Glaucias.</p><p>- Anaphoric references (see above, as mentioned before, etc)<br>- Cataphoric references (see below, as we will see next, etc)<br>- Explicit references (see section 7.2, etc)</p><p>Now, I think you might begin to understand why this problem is so tricky. There are thousands of ways to make anaphoric/cataphoric references and even more ways to reference sections since section titles differ from document to document. This is how I approached. I firstly generated a generalist dataset of possible anaphors/cataphors. This is so that the first guess about possible present references is created using simple regex checks over each node. That works like a charm for most anaphors/cataphors. But what do we do with explicit references? We surely cannot use regex to match all possible section titles, right? Well turns out we can and it is quite reliable. It seems far fetched but when you think about it even for large pdfs that would mean checking 1000 titles over like 1000–10000 nodes. That might be a lot for a human but for the average computer that is a kids game.<br>Finally, for an extra layer of security every node that doesn’t have a connection after the process explained above might be passed to an LLM for a non deterministic analysis to find out about any edge cases which the method that was presented earlier might have a blind spot for.</p><h4>What happens during retrieval?</h4><p>This is the easiest part of the problem. You can approach to it similarly to GraphRAG. In Glaucias I am semantically searching for relevant nodes, expanding possible edges that were build during reference matching, and then reranking the results and presenting them to the user or to the LLM so that it can formulate a response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*DryxSLgKPzD7fWk6cbkQeQ.png" /><figcaption>Retrieval flowchart</figcaption></figure><h4>Final remarks</h4><p>This article aims to clarify how the platform operates. By doing so I hope to offer transparence to the community that may use it in the future. So, if any further clarification is needed please feel free to leave your comments. Glaucias will always be available for free in this <a href="https://github.com/guy1998/glaucias">github repository</a> alongside instructions on how to use it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a684114d158d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DeepSeek fever — my personal take]]></title>
            <link>https://medium.com/@acifliku/deepseek-fever-my-personal-take-d7a6ab7877a5?source=rss-18177c0e30fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7a6ab7877a5</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[economy]]></category>
            <dc:creator><![CDATA[Aldrin Çifliku]]></dc:creator>
            <pubDate>Tue, 28 Jan 2025 14:56:36 GMT</pubDate>
            <atom:updated>2025-01-28T14:56:36.038Z</atom:updated>
            <content:encoded><![CDATA[<h3>DeepSeek fever — my personal take</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUJgTTHTnyDQnlT_LeZp-w.jpeg" /></figure><p>Recently, the world was shocked as NVIDIA suffered a $600 billion market cap loss. This marks the biggest loss for a U.S. company in a single day. Most of this uncanny economic hit was related to the recent rise of a Chinese AI model known as DeepSeek. This model is said to be comparable to the well-known GPT models while having a much lower cost of development. To put it in numbers, OpenAi spent billions of dollars developing the GPT models while DeepSeek was created with just about $6 million. Moreover, most DeepSeek features are free, including the developer’s API. That said, a debate has sparked regarding the capabilities of this new model and how it compares to previously established models such as GPT or Gemini. In this article, I have tried to make a fair assessment of the model from a user’s point of view while considering ChatGpt as the benchmark.</p><p><strong>1 — Text generation</strong></p><p>Obviously, the most important task for a LLM is to generate text. One or two conversations with DeepSeek are enough to notice that the responses of this model are much shorter than those of ChatGPT. This does not necessarily mean that the responses are incomplete or incorrect. It rather means that the responses are usually more concise. So, if the question does not need an elaborate response the model knows how to be concise. That is not an indicator of the quality of the model though. I had to prompt a more elaborate task. I chose the prompt “Write an essay on global warming”. This is where the DeepSeek model showed its true power. The essays both models generated had largely the same content. The quality of the language used was largely the same. However, DeepSeek was much faster in generating the response than ChatGpt. Here, I have to remind the reader that OpenAi has declared that the delay in generation is related to higher quality in response. Therefore I have to give credit to DeepSeek for overcoming such a problem. DeepSeek is the clear winner in this area.</p><p><strong>2 — Code generation</strong></p><p>It is difficult to test this feature without working for some time with both models. However, I tried to implement some scenarios to test them and give my evaluation. The first scenario is generating code from scratch. I prompted both models to create a login page in React. Both models give a similar answer, with DeepSeek focusing on developing a raw react solution while ChatGpt is more oriented towards employing different libraries. Again, DeepSeek was much faster in the response while also providing instructions on how to integrate this code snippet into a larger project.</p><p>The second scenario is code fixing based on the bug that occurred. For this, I used a bug from stack overflow. I gave both models the bug and the code snippet and told them to fix it. Both models performed well and provided even some possible external causes for the bug.</p><p>The third scenario is improving an existing code. Given an unoptimized piece of code, both models came out with the same optimizations while requiring almost the same time.</p><p>So, for the code generation capabilities, I must say both models are at the same level.</p><p><strong>3 — Deep thinking</strong></p><p>DeepSeek offers this feature separately from the regular response. But to be honest I do not notice any improvement in the quality of responses even when deep thinking is employed. I reckon is still a feature in development. It is very interesting to see what the future of such a feature will be.</p><p><strong>4 — Searching the net</strong></p><p>When searching the net ChatGpt gives more concise responses. The DeepSeek model is biased towards including Chinese results. For example, when asked for a list of ROS tutorials, DeepSeek provides the list that ChatGpt provides while also adding some Chinese resources.</p><p>To conclude, it is clear that DeepSeek has launched a very advanced LLM. The model is able to mimic the behavior of ChatGpt and other models in the market with high accuracy and does that without the extreme costs that were declared by OpenAi, Google, or Meta. It is fascinating to see an entire field such as AI have this major improvement in such a short time. I am only hoping that DeepSeek is allowed to further develop this model without any censure by the Western governments. That being said I would urge the developers to take advantage of this new opportunity as soon as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7a6ab7877a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rollercoaster from software engineering to robotics — my experience]]></title>
            <link>https://medium.com/@acifliku/rollercoaster-from-software-engineering-to-robotics-my-experience-df283881361b?source=rss-18177c0e30fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/df283881361b</guid>
            <category><![CDATA[gui̇de]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[fresh-start]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[robotics]]></category>
            <dc:creator><![CDATA[Aldrin Çifliku]]></dc:creator>
            <pubDate>Tue, 26 Nov 2024 13:05:08 GMT</pubDate>
            <atom:updated>2024-11-26T13:05:08.967Z</atom:updated>
            <content:encoded><![CDATA[<h3>Rollercoaster from software engineering to robotics — my experience</h3><figure><img alt="My rollercoaster" src="https://cdn-images-1.medium.com/max/1024/1*eie_D8yrJVVFhocO9NK59A.jpeg" /></figure><p>Recently, I started my master’s degree in Automation and Robotics at TU Dortmund. As a graduate in Software Engineering, I must say the change has been massive. It is not just the new subjects but also how they’re applied and how you can practice them. This new beginning, even though thrilling, has been quite challenging for me. So, I decided that the best thing to do is drop an article on the entire experience, which will hopefully be a manual for anyone who wishes to pursue robotics after getting some initial background in computer science. Buckle up cause here we go!</p><p>My first ever class in this course was Robotic manipulators. Pretty cool, right? Well, I was surprised that my dear old friend mathematics had not forgotten to register for this course either. Yes, playing with robotic arms and watching them perform tasks is cool. But I guess I didn’t expect the calculations to be so detailed. The good thing about this course is that most of the mathematics and physics included are familiar to computer science graduates. It only requires some understanding of linear algebra and kinematics/dynamics. Especially for software engineers with a focus on game development or VR simulations, it should be pretty easy.</p><p>But of course, this is only one of the five mandatory courses. The second one would be Advanced Engineering Math. While the name sounds scary, the content of this course is mostly related to simple linear algebra concepts and principles. Then there is MATLAB Programming and Computer Systems. Both these subjects are entirely based on computer science, so there is really no remark to make on them. I would rather like to talk broadly about my toughest subject so far, Control Theory and Applications (CTA).</p><p>CTA has been quite a challenge for me as a student with a background in computer science. What we learn in this subject is how to model real-life systems and how to regulate controllers for those systems based on our model. To put it in a simple example: how can we define a gas pedal such that the car gains a certain amount of acceleration after pushing it to a certain point? In fact, the logic behind the subject is as simple as this example. You just have to express it in the form of matrices and vectors that can be calculated. Here starts the tough part. These matrices are all calculated using advanced physics and chemistry. So, for anyone wanting to do well in this subject, some strong knowledge in both these science classes is needed.</p><p>That being said, CTA is the only course that might feel strange to a computer science graduate. Every other course is related to mathematics, programming, operating systems, or machine learning.</p><p>I want to end this article by saying that most of the physical aspects of robots have already been discovered and are in use. The entire industry has now shifted towards the software that manipulates robotic bodies. This includes pre-programmed software but also AI software. With this new shift, the industry is more and more interested in people with a computer science background. So, it is not a surprise to find yourself pursuing a degree or a training program in this area. With that in mind never forget these five suggestions:<br>1 — Get a good grasp of physics<br>2 — Learn as much as you can about the dynamics of chemical reactions<br>3 — Keep an eye on linear algebra because it rules everything<br>4 — Learn as much as you can about machine learning, deep learning, computer vision, and operating systems. <br>5 — Have good knowledge of Python, C++, and MATLAB</p><p>I hope this short article can summarize my first impression of the Automation and Robotics course. And I also hope that it can serve as a guiding book for you to avoid the challenges that I faced during these last couple of months. Until we meet again, keep learning folks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df283881361b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top 10 Software Development Trends in 2024]]></title>
            <link>https://medium.com/@acifliku/top-10-software-development-trends-in-2024-8e7dce0a4a83?source=rss-18177c0e30fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e7dce0a4a83</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[trends]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Aldrin Çifliku]]></dc:creator>
            <pubDate>Fri, 30 Aug 2024 20:18:21 GMT</pubDate>
            <atom:updated>2024-08-30T20:18:21.234Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9Xgbc0u6vhaZYD1-" /></figure><p>The world of software development is ever-evolving, and staying ahead of the curve is crucial for developers and businesses alike. As we move through 2024, here are the top 10 trends shaping the industry, explained in simple terms.</p><h4>1. Artificial Intelligence and Machine Learning Integration</h4><p>AI and ML continue to transform software development, making applications smarter and more adaptive. AI tools are now embedded in development environments, helping automate tasks like code generation, bug detection, and even project management. This trend reduces development time and enhances the functionality of software applications​.</p><h4>2. Serverless Computing</h4><p>Serverless computing is all about building and running applications without worrying about managing infrastructure. Developers can focus solely on writing code while the cloud provider handles the servers. This approach is cost-effective and scalable, making it ideal for businesses looking to streamline operations.</p><h4>3. Microservices Architecture</h4><p>Microservices architecture involves breaking down an application into small, independent services that communicate with each other. This design allows for faster development, easier scaling, and more flexible maintenance. Each microservice can be updated or deployed without affecting the entire application, making it a popular choice for modern software projects​.</p><h4>4. Low-Code and No-Code Development</h4><p>Low-code and no-code platforms enable users to build applications with minimal coding knowledge. These platforms use visual interfaces to design and develop software, allowing even non-developers to create functional applications. This trend is empowering businesses to innovate quickly and reduce dependency on skilled developers​.</p><h4>5. DevSecOps: Security in the Development Process</h4><p>DevSecOps integrates security practices into the software development lifecycle. Instead of treating security as an afterthought, it becomes a core part of the development process. This approach ensures that security vulnerabilities are identified and addressed early, reducing the risk of breaches.</p><h4>6. Distributed Cloud</h4><p>Distributed cloud technology spreads cloud services across multiple locations, rather than relying on a single data center. This setup enhances reliability, reduces latency, and improves the overall user experience. It’s particularly useful for applications that need to remain operational even if one part of the system goes down​.</p><h4>7. AR/VR Integration</h4><p>Augmented Reality (AR) and Virtual Reality (VR) are no longer just for gaming. These technologies are being integrated into various industries, from retail to healthcare, to create immersive experiences. AR overlays digital information on the real world, while VR creates entirely virtual environments, both offering unique ways to engage users​.</p><h4>8. Total Experience (TX)</h4><p>Total Experience (TX) combines customer experience, employee experience, and user experience into a unified strategy. By focusing on all aspects of interaction with a product, businesses can improve satisfaction and loyalty across the board. This holistic approach is becoming essential for companies looking to stand out in competitive markets​.</p><h4>9. Progressive Web Apps (PWA)</h4><p>PWAs offer a blend of web and mobile app experiences without needing to download an app. They work on any device with a web browser and provide features like offline access, push notifications, and faster load times. PWAs are cost-effective and easier to maintain, making them an attractive option for many businesses.</p><h4>10. GreenOps and FinOps</h4><p>GreenOps and FinOps are emerging practices that focus on sustainability and financial efficiency in software operations. GreenOps aims to reduce the environmental impact of IT operations, while FinOps focuses on managing cloud costs effectively. Together, they help businesses run more sustainable and cost-effective operations​.</p><p>Staying updated with the latest trends in software development is crucial for anyone involved in the field. As technology rapidly evolves, keeping pace with these changes ensures that you remain competitive, innovative, and prepared for future challenges. By embracing new methodologies, tools, and practices, you not only improve your skills but also contribute to the advancement of the industry as a whole.</p><p>I invite you to follow me for more insights, trends, and tips on software development and technology. Let’s continue exploring the future of software together, one trend at a time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e7dce0a4a83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Frontend development made easy — Every frontend resource you need: A Comprehensive Guide]]></title>
            <link>https://medium.com/@acifliku/frontend-development-made-easy-every-frontend-resource-you-need-a-comprehensive-guide-89bba0741e67?source=rss-18177c0e30fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/89bba0741e67</guid>
            <category><![CDATA[assets]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[javascript-frameworks]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <dc:creator><![CDATA[Aldrin Çifliku]]></dc:creator>
            <pubDate>Wed, 10 Jul 2024 17:00:56 GMT</pubDate>
            <atom:updated>2024-07-10T17:00:56.914Z</atom:updated>
            <content:encoded><![CDATA[<h3>Frontend development made easy — Every frontend resource you need: A Comprehensive Guide</h3><figure><img alt="Frontend cover" src="https://cdn-images-1.medium.com/max/1024/1*DSzdAbhLdBIrx_8HbqzDGg.jpeg" /></figure><p>Are you new to frontend development? Or finding it challenging to grasp its logic? It’s okay — I’ve been in your shoes. Whether you’re encountering this during your school courses or throughout your career as a software engineer, tackling frontend development is an inevitable step for many. While some may find it frustrating, others might consider it uninteresting. Personally, I struggled to see the logic in it. However, these are common feelings that should be overcome. To do so, it’s crucial to start your journey with the right resources. That’s why I’m writing this article to share valuable resources that I wish I had when I started developing frontend. These resources include learning materials, reusable code, and much more.</p><h4>Where can you learn frontend</h4><p>As wise men have said before me: The best way to learn is by doing. While that holds true I would still suggest having some guidance in that process. So, here is a list of all the websites and forums where you can learn frontend skills. If you already have some knowledge I suggest skipping to the next section.</p><p>1 — <a href="https://www.w3schools.com/css/default.asp">W3Schools</a></p><p>If you are unsure where to start, this is your place. There are hundreds of tutorials for beginners on HTML, CSS, and Javascript. This is not just a website to learn. I also use it as my personal code library. Instead of remembering all types of CSS syntax you can just have a quick search over the W3Schools list of tutorials.</p><figure><img alt="w3schools image" src="https://cdn-images-1.medium.com/max/900/1*vB10uqRvj3LIVjOfeVgOeA.jpeg" /></figure><p>2 — <a href="https://v2.scrimba.com/the-frontend-developer-career-path-c0j">Scrimba</a></p><p>Moving on to something more advanced now. Scrimba offers what they call “The Frontend Developer Career Path”. And as the name suggests this is one of the most comprehensive tutorial programs out there. It offers everything you need to know to start developing web applications independently. The only issue is that this is a paid program. In my opinion is a good investment.</p><p>3 — <a href="https://www.theodinproject.com/paths/full-stack-javascript">The Odin Project</a></p><p>The name sure is impressive and I can confirm so is the program. If you follow this course you will have advanced knowledge of HTML, CSS and Javascript. And you will also be able to develop in fullstack Javascript with Node.js and React. The best thing: Everything is free. Heads up, though, everything is learned through mini projects and examples.</p><figure><img alt="odin project image" src="https://cdn-images-1.medium.com/max/1024/1*BseILc9XkhHW1qPSmMKNeQ.png" /></figure><p>4 — <a href="https://www.youtube.com/watch?v=zJSY8tbf_ys">FreeCodeCamp</a></p><p>As always one safe option to learn programming is freeCodeCamp. It couldn’t be any different for frontend. They provide a full free course on HTML, CSS, and Javascript. If you follow this course you will have all the competence needed to take up any frontend framework in literally just days. So, I suggest having a look at it.</p><figure><img alt="free code camp image" src="https://cdn-images-1.medium.com/max/1024/1*fVV34MwKN6P0mUcnLVim0w.png" /></figure><h4>Code resources</h4><p>After gaining some experience in frontend development you might notice that not everything can be done in an authentic fashion. After all, think about it, you didn’t invent the navbars or forms, did you? This begs the question: Where can we find reliable resources that we can reuse in our own projects? And this section is the answer.</p><p>1 — <a href="https://codepen.io/">codepen.io</a></p><p>If you are looking for unique effects, decorations, and outstanding designs look no further. Codepen has everything you need. The best part is that everything is in code snippets that can be copied and pasted easily. I personally use the code provided by users in Codepen as it is. I find it very uncomfortable and error prone to modify it. If you are looking for code that can be adapted easily the next option in line is your answer.</p><figure><img alt="codepen image" src="https://cdn-images-1.medium.com/max/1024/1*dijiWZaenhXgTiElaPH_7w.png" /></figure><p>2 — <a href="https://uiverse.io/">uiverse.io</a></p><p>Here you can find basically everything you need: buttons, forms, inputs, cards, and much more. The code comes in separate snippets which makes it perfectly editable. I love using resources provided by uiverse.io when using React.js because it is always easy to think of each of the items provided as a separate component.</p><figure><img alt="uiverse.io image" src="https://cdn-images-1.medium.com/max/1024/1*h1oY-PJwAka-bwTchNR3Sg.png" /></figure><p>3 — <a href="https://mui.com/">MUI</a></p><p>This is specifically for React.js users. While at first using this library may seem overwhelming you will soon notice that everything is not only easy to understand but requires little to no changes at all to adapt to your project. I definitely suggest to React beginners to accustom themselves with MUI library.</p><figure><img alt="mui image" src="https://cdn-images-1.medium.com/max/1024/1*75OHDRCq83tVDINcEaS6MA.png" /></figure><p>4 — <a href="https://github.com/codingknite/frontend-development">codingknite repo</a></p><p>This is a hidden gem of the internet. I found it out only a few weeks ago. It has material for everything you need to know about frontend development. There are of course many items in there but you can always filter what you need to use. 10/10 recommended.</p><h4>Assets</h4><p>Finally, what is a good frontend developer if he ain’t got no assets. This is the list of the websites which I believe provide enough assets for you to develop any type of web application.</p><p>1 — <a href="https://www.flaticon.com/">Flaticon</a>, <a href="https://fonts.google.com/icons">Google Font Icons</a>, and <a href="https://akveo.github.io/eva-icons/#/">Eva Icons</a></p><p>These are the go to websites to find the most modern interface icons. You can download your icons from Flaticon if you prefer to have them downloaded but you will have to acknowledge the creator of each icon. I would suggest using the svg tag to access any of these providers simply by using the name of the icon you want to display. A tutorial for that can be found in the odin project presented above.</p><p>2 — <a href="https://www.freepik.com/">Freepik</a> and <a href="https://www.canva.com/">Canva</a></p><p>If you are trying to create a website from scratch and haven’t got any bright ideas so far then, I suggest to look through the content provided by Freepik and Canva. Not only can you find here inspiration for your website, but also assets such as vectors, videos, images, logos, and so on.</p><p>3 — <a href="https://www.pexels.com/">Pexels</a></p><p>Finding images of good quality which have the proper size for your web app is always difficult. My go to place in such cases is always Pexels. With thousands of free high quality images I can guarantee you will find what you need.</p><h4>Final remarks</h4><p>I know that frontend development can sometimes be overwhelming. Especially to people that do not have an orientation towards creativity and design. However, I do believe that the resources provided in this article can help you to improve your skills and feel more confident during development. I hope you enjoyed it and I invite you to leave your comments so that we can improve the community together.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89bba0741e67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secrets to power up your software developing career with AI.]]></title>
            <link>https://medium.com/@acifliku/secrets-to-power-up-your-software-developing-career-with-ai-c6a3032517fb?source=rss-18177c0e30fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6a3032517fb</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[business-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[gpt-4]]></category>
            <dc:creator><![CDATA[Aldrin Çifliku]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 22:49:42 GMT</pubDate>
            <atom:updated>2024-07-08T22:49:42.246Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xiX672OqnFtHtTWY3anT8A.jpeg" /></figure><p>The future is now. AI is finally unleashing its true potential. Tasks that once were difficult and time-consuming such as essays or speeches are now one prompt away from completion. In fact, AI is now capable of generating images. A mighty warrior fighting a dragon or a unicorn enjoying that midnight breeze? No problem, your epic image can be manufactured out of thin air.<br>But as the world enjoys this fascinating new playground there has been a lot of noise and speculation amongst the software developing community about the impact AI will have on the industry. It is no secret that models such as GPT or Gemini can generate code that complies with many scenarios. But are these models capable of replacing us software developers? Is it the doomsday for this billion-dollar industry?<br>I don’t think so. I do, however, believe that software developers who are not engaging AI in their activity will soon find themselves at a serious disadvantage. Don’t let yourself be amongst them! Here are the tips you need to ‘tame’ the AI and use its power to enhance yours.</p><h4>Live with it</h4><p>As a software developer, you should understand that AI is not going anywhere. It will be part of our reality from now. Get accustomed to AI by understanding how it works internally. You don’t need to be an expert in it. That requires time and includes a lot of math, to be honest. But having a basic understanding of the essential theory will give you an idea of what it can and cannot do. Resources, to get you started such as books and courses can be found in the resources section.</p><p>After having an understanding of the internal logic of the model, move to the most important part: mastering interaction with these models. You should practice prompting in a way that increases the chances of an accurate answer. AI models like Chat GPT can misinterpret prompts, so it’s important to develop the skills to prompt effectively. You can learn more about prompting by asking the AI model itself to provide information about good and bad prompts and feedback about the prompts you make. Here are examples of good and bad prompts provided by Chat GPT:</p><p><strong><em>Bad Prompt:</em></strong></p><p>“Tell me about baking a cake.”</p><p><strong><em>Good Prompt:</em></strong></p><p>“I’m planning to bake a chocolate cake for my friend’s birthday next weekend. Can you provide a step-by-step guide on how to bake a moist and fluffy chocolate cake from scratch, including the ingredients, measurements, and baking instructions?”</p><h4>Find proper usage for the AI</h4><p>By using AI effectively, you can enhance your work and improve your productivity. You should avoid relying on AI for everything, but also be aware of tasks that can be automated using these models. Don’t worry! I will provide you with some of them.</p><ul><li><strong>Debugging</strong></li></ul><p>Stop trying to debug everything by yourself. First of all, that is annoying and secondly, AI can do it much better without getting tired of it.</p><ul><li><strong>Documentation</strong></li></ul><p>Whether you want to use comments to document your modules or write full paragraphs to explain the workflow of your code, it doesn’t matter. Don’t be boring! Just ask an AI model.</p><ul><li><strong>Reusing code</strong></li></ul><p>You know how annoying it is sometimes when you have the code for something maybe from another project and you need to modify it for the new project. Don’t sweat it! Just ask your favorite AI. It works every time. (Don’t tell anyone but I would suggest Blackbox for code generation and modification)</p><ul><li><strong>Generating datasets</strong></li></ul><p>Most people will not tell you this but the best way to get datasets, or placeholder data is by prompting an AI model. I was able to expand the dataset of a chatbot by using Chat GPT only. The results are great so I would recommend it to any of you machine learning enthusiasts.</p><h4>Remember you’re not dumb</h4><p>A common mistake among developers is that they consider AI to be ‘smart’. AI, however, is not smart. The proper term to describe would be knowledgeable. It has a large array of knowledge about the specific field or purpose it was trained for. But during your daily interaction with AI, you will notice that it is not particularly good at making use of that knowledge. You will still be the supplier of intellect in that men-computer relationship. AI is only a tool to apply that intellect faster.</p><h4>Resources</h4><p>As promised here are a few resources to get you started with AI. Hope they help. Feel free to comment other resources you may know so you can help the community.</p><p><a href="https://microsoft.github.io/AI-For-Beginners/">AI for Beginners</a></p><p><em>Artificial Intelligence A Modern Approach (3rd Edition)</em> by Stuart Russell and Peter Norvig</p><p><em>Artificial Intelligence for dummies </em>by John Paul Mueller and Luca Massaron</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6a3032517fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSON Web Token (JWT) authentication explained — Node.js + React Example]]></title>
            <link>https://medium.com/@acifliku/json-web-token-jwt-authentication-explained-node-js-react-example-0d51cfc62050?source=rss-18177c0e30fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d51cfc62050</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Aldrin Çifliku]]></dc:creator>
            <pubDate>Sat, 30 Mar 2024 13:10:40 GMT</pubDate>
            <atom:updated>2024-03-30T13:14:22.612Z</atom:updated>
            <content:encoded><![CDATA[<h3>JSON Web Token (JWT) authentication explained — Node.js + React Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IliroQ9pDQ3bRytwwhcMJw.jpeg" /></figure><p>In modern web development, ensuring secure authentication is paramount. And one widely adopted method for managing user authentication is JSON Web Tokens (JWT). One may define JWT as a compact, URL-safe means of representing claims between two parties, typically used for authentication and information exchange. In this article, however, we will try to create a lower level view of what JWTs are and how you can make use of them in your upcoming project. So, stick till the end to learn the secrets of JWT authentication and enjoy a full example with React + Node.js.</p><h3><strong>Understanding Json Web Token</strong></h3><p>At its core, a JWT is simply a JSON object that has been encoded into a string. This string is composed of three parts: a header, a payload, and a signature, separated by periods. These parts are:</p><ol><li>Header: This part typically consists of two sub-parts: the type of token (JWT) and the signing algorithm being used, such as HMAC SHA256 or RSA. As a developer you will never need to know much about these algorithms and might always go with the default option presented by the framework you are using.</li><li>Payload: The payload contains the claims. Claims are statements about an entity (typically, the user information) and additional data. These claims can be divided into three types: registered, public, and private claims. Registered claims include predefined fields such as issuer (iss), subject (sub), audience (aud), expiration time (exp), and more. Public claims are defined by the application, while private claims are custom claims that are agreed upon between parties. Usually the expiration time is the most needed out of these and the only one you will generally set yourself.</li><li>Signature: The signature is created by combining the encoded header, encoded payload, and a secret key. This signature is used to verify that the sender of the JWT is who it says it is and to ensure that the message wasn’t changed along the way. I know this sounds confusing right now but it will become way more clear during our example.</li></ol><h3>How JWT Authentication Works</h3><p>JWT authentication follows a straightforward process:</p><ol><li>User Authentication: When a user logs in, the server verifies the provided credentials. If the credentials are valid, the server generates a JWT containing relevant user information (claims) and signs it with a secret key.</li><li>Token Issuance: The server then sends this JWT back to the client, typically as part of the response body or in an HTTP header. The client stores this token securely, often in local storage or a cookie. The server might also opt to send a server side cookie to the client for extra security.</li><li>Subsequent Requests: For subsequent requests that require authentication, the client includes the JWT in the request, typically in the Authorization header using the Bearer schema or in the credentials section in case you are using https cookies to transfer the tokens. We will use the latter in our example</li><li>Token Validation: Upon receiving a request with a JWT, the server validates the token’s signature using the secret key. It also checks whether the token is expired and whether the token’s issuer is trusted. If the token passes these checks, the server extracts the claims from the payload and proceeds with the request.</li><li>Response: After processing the request, the server sends back the response as usual.</li></ol><h3>Benefits of JWT Authentication</h3><p>JWT authentication offers several advantages:</p><ul><li>Statelessness: Since JWTs contain all necessary information within themselves, the server does not need to store session data, making it inherently stateless. This makes JWTs particularly suitable for microservices architectures and scalable applications.</li><li>Scalability: With traditional session-based authentication, the server needs to keep track of active sessions, which can become a bottleneck as the number of users increases. JWT authentication eliminates this overhead.</li><li>Flexibility: JWTs can carry any type of data in their payload, allowing for flexible use cases beyond authentication, such as authorization and information exchange between parties.</li></ul><h3>Implementation</h3><p>Now let us dive into some real work with JWT. To explain this concept I have chosen a basic web application which might be familiar to some of you guys. The infamous <em>Lamp Simulator</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3xf0pyc07HYViJp2tH-ykw.png" /><figcaption>The lamp simulator</figcaption></figure><p>During early days of learning front-end frameworks such as React or even pure HTML&amp;CSS one common exercise teachers and mentors request is the lamp exercise. The idea is to turn the lamp on and off using a “switch”. Of course, our example must include JWT, so the user will have to be authenticated to have permission to change the lamp’s state. When you toggle the switch without signing in the program will prompt you as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*87557Y4wrlpq7iiHiufPoA.png" /></figure><p>Once you are logged you will be able to change the state of the lamp. Now let us see how this is done. Before we go on, for all those that prefer to work with the full code base rather than step by step you can find the project in this repo: <a href="https://github.com/guy1998/JWT-Article.git">https://github.com/guy1998/JWT-Article.git</a></p><p>So, to begin working you will first need to set up the project. In your chosen project folder create 2 folders: client and server. It should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*kMrz94zMw9kb3iFXPeAvfQ.png" /></figure><p>Then open a terminal and navigate to the server folder. The terminal may be from the editor as in my case (I am using VS Code) or the computer’s Terminal/CLI. Once you are in the server folder run the following command:</p><pre>npm init -y</pre><p>I am assuming you already have node in your PC. If not please refer to this tutorial: <a href="https://nodejs.org/en/learn/getting-started/how-to-install-nodejs">https://nodejs.org/en/learn/getting-started/how-to-install-nodejs</a>. After running the command you need to create an index.js file within the server folder. The folder content should be something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*_PxdtzivPz_X1gdSRygxCg.png" /></figure><p>Having created the file we now need to install some packages in order to continue with our work. We initially need ‘express’ and ‘cors’ for the rest api and for cross origin resource sharing respectfully. I know the latter is confusing but in simple terms it is to allow the communication from multiple clients that are not located in the same place as the server.</p><pre>npm install express<br>npm install cors</pre><p>Then we write the following code in our index.js file:</p><pre>const express = require(&#39;express&#39;);<br>const app = express();<br>const cors = require(&#39;cors&#39;)<br><br>const allowedOrigins = [&#39;http://localhost:3000&#39;]; //This will be our app<br><br>app.use(cors({<br>    origin: (origin, callback) =&gt; {<br>        if (allowedOrigins.includes(origin) || !origin) {<br>            callback(null, true);<br>        } else {<br>            callback(new Error(&#39;Not allowed by CORS&#39;));<br>        }<br>    },<br>    methods: &#39;GET,HEAD,PUT,PATCH,POST,DELETE&#39;,<br>    credentials: true,<br>    optionsSuccessStatus: 204,<br>}));<br><br>app.listen(5443, ()=&gt;{<br>        console.log(`Listening on port 5443`);<br>})</pre><p>This is the initial setup for our project. It is a simple API basically which is ready to receive requests at port 5443. Now, we can move on to the database set up. For this project I am using MongoDB but feel free to use any database you feel comfortable with because it is not that important for our purpose. Firstly, create a .env file with the following line:</p><pre>CONN_STRING = your_connection_string</pre><p>Then run the following commands to install mongo and mongoose.</p><pre>npm install mongo<br>npm install mongoose</pre><p>After installing both packages go ahead and create a db.js file with the following content:</p><pre>const mongoose = require(&quot;mongoose&quot;);<br>require(&quot;dotenv&quot;).config();<br><br>// Connection URI<br>const uri = process.env.CONN_STRING;<br><br>// Connect to the MongoDB server<br>const connect_db = (proceeding) =&gt; {<br>  mongoose<br>    .connect(uri, { useNewUrlParser: true, useUnifiedTopology: true })<br>    .then(() =&gt; {<br>      console.log(&quot;Connected to the database&quot;);<br>      proceeding();<br>    })<br>    .catch((error) =&gt; {<br>      console.error(&quot;Error connecting to the database: &quot;, error);<br>    });<br>};<br><br>module.exports = connect_db;</pre><p>A slight adjustment is needed in the index.js file as well:</p><pre>connect_db(()=&gt;{<br>    app.listen(5443, ()=&gt;{<br>        console.log(`Listening on port 5443`);<br>    })<br>})</pre><p>Now we have an application that is connected to the database. The next thing we need is to create a folder called models and create our user model inside of it. This model will be our way of carrying out CRUD operations. So, in the models folder inside a user.js file write:</p><pre>const mongoose = require(&#39;mongoose&#39;)<br><br>const user_schema = new mongoose.Schema({<br>    name: String,<br>    surname: String,<br>    username: String,<br>    password: String<br>})<br><br>const User = mongoose.model(&#39;User&#39;, user_schema);<br><br>module.exports = User;</pre><p>By now the server folder should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*kjC24e0X6zSWJ5DQLumo5Q.png" /></figure><p>Now, we will move to the most important part: the JWT handling. For this we have install the jwt package running the following command.</p><pre>npm install jsonwebtoken</pre><p>Having installed the package we need something called an encryption key. To generate mine I used this website <a href="https://acte.ltd/utils/randomkeygen">https://acte.ltd/utils/randomkeygen</a> but for this application you might use the same JWT_KEY as I did. Just make sure to add the following line in the .env file.</p><pre>JWT_KEY = fnpoEoLoYxaPONucTvCODWljVLBUqxRd</pre><p>Then we need to create a folder called controllers. In this folder we create a file named login-controller.js and add the following content:</p><pre>const User = require(&quot;../models/user.js&quot;);<br>const jwt = require(&#39;jsonwebtoken&#39;);<br><br>const token_issue = (user) =&gt; {<br>  const accessToken = jwt.sign(<br>    { name: user.name, surname: user.surname },<br>    process.env.JWT_KEY,<br>    { expiresIn: 900 }<br>  ); //15 minutes<br>  const refreshToken = jwt.sign(<br>    { name: user.name, surname: user.surname },<br>    process.env.JWT_KEY,<br>    { expiresIn: &quot;1h&quot; }<br>  );<br>  return { accessToken: accessToken, refreshToken: refreshToken };<br>};</pre><p>This is just the code to issue the tokens. We issue two types of tokens an access token and a refresh token. The access token is the one that keeps the permissions (basically the one that is checked at each request). The refresh token on the other hand is used to retain the information for a longer timeframe and use that info to create a new access token for as long as the simulated “session” is not finished yet. In my case I have set the expiry time of the refresh token to be 1h which is the time limit a user can have permission before having to sign in again. But we also need a method to verify a token don’t we? That is why we add the following code to the same file.</p><pre>const tokenChecker = (token) =&gt; {<br>  try {<br>    const decoded = jwt.verify(token, process.env.JWT_KEY);<br>    return { result: true, payload: decoded };<br>  } catch (error) {<br>    if (error.name === &quot;TokenExpiredError&quot;) {<br>      return { result: false, code: 2 };<br>    } else {<br>      return { result: false, code: 3 };<br>    }<br>  }<br>};</pre><p>And last but not least we need the method which refreshes the access token. So, we add the following code:</p><pre>const tokenRefresher = (refreshToken) =&gt; {<br>  console.log(&quot;Refreshing token&quot;);<br>  const checkToken = tokenChecker(refreshToken);<br>  if (checkToken.result) {<br>    return {<br>      result: true,<br>      content: jwt.sign(<br>        checkToken.payload,<br>        process.env.JWT_KEY,<br>        { expiresIn: 900 }<br>      ),<br>    };<br>  } else if (checkToken.code === 2) {<br>    return { result: false, content: &quot;Token expired&quot; };<br>  } else {<br>    return { result: false, content: &quot;Token is invalid&quot; };<br>  }<br>};</pre><p>As you can see the access token is only refreshed for as long as the refresh token is also valid. Otherwise, the user needs to sign in once again. Finally, we add to the login-controller the rest of the code which is a method for signing in:</p><pre>const verify_credentials = async (username, password) =&gt; {<br>  const user = await User.findOne({ username: username });<br>  if (user) {<br>    if (user.password === password) return { code: 1, user: user };<br>    else return { code: 3, user: {} };<br>  } else {<br>    return { code: 2, user: {} };<br>  }<br>};<br><br>const login_process = async (username, password) =&gt; {<br>  const result = await verify_credentials(username, password);<br>  if (result.code === 1) {<br>    const token_obj = token_issue(result.user);<br>    return { message: &quot;Successs&quot;, token_obj: token_obj };<br>  } else if (result.code === 2) {<br>    return { message: &quot;User does not exist!&quot;, token_obj: {} };<br>  } else if (result.code === 3) {<br>    return { message: &quot;Invalid password!&quot;, token_obj: {} };<br>  }<br>};<br><br>module.exports = {<br>  login_process<br>};</pre><p>Now, let us create a folder called routers and inside of it a file named login.js. This will be the login endpoint. It should contain the following code:</p><pre>const express = require(&#39;express&#39;);<br>const app = express();<br>const login_controller = require(&#39;../controller/login_controller.js&#39;);<br>const cookieParser = require(&quot;cookie-parser&quot;);<br>const bodyParser = require(&quot;body-parser&quot;);<br><br>app.use(cookieParser());<br>app.use(bodyParser.json());<br><br>app.post(&#39;/login&#39;, async (req, res)=&gt;{ <br>    const login_result = await login_controller.login_process(req.body.username, req.body.password);<br>    if(login_result.token_obj){<br>        res.cookie(&quot;tokenCookie&quot;, login_result.token_obj, {<br>            maxAge: 3600000,<br>            httpOnly: true,<br>            secure: false, //when true it implies https<br>            sameSite: &quot;none&quot;<br>        });<br>        res.status(200).json(&quot;User authenticated successfully!&quot;);<br>    }else{<br>        res.status(401).json(login_result.message);<br>    }<br>})<br><br><br>module.exports = app;</pre><p>Before I explain the logic I have to note that the cookie-parser and body-parser are packages which are used for accessing cookies and accessing the json version of the request body on the endpoint. It is most likely not the only way but for sure the most popular way to do it so I suggest reading about them at the npm documentation.</p><p>Now back to explaining the code. The server firstly carries out the standard authentication procedures using username and password. We saw the code for this in the <em>login_process</em> method. If the process is successful an object containing both tokens is returned. This object is then encapsulated on an http-only cookie. These are cookies that cannot be accessed through scripts but only through HTTP requests. This means that the client will send this cookie every time it requests something so that the server verifies the JWT. But how will the server verify the tokens? For this we add the following method to the login-controller file and export it.</p><pre>const authorize = (req, res) =&gt; {<br>  const tokens = req.cookies ? req.cookies.tokenCookie : undefined;<br>  if (tokens) {<br>    const checkAccess = tokenChecker(tokens.accessToken);<br>    if (checkAccess.result) {<br>      res.status(200).json(&quot;Authorized!&quot;);<br>    } else {<br>      const refreshAccess = tokenRefresher(tokens.refreshToken);<br>      if (refreshAccess.result) {<br>        res.cookie(<br>          &quot;tokenCookie&quot;,<br>          {<br>            accessToken: refreshAccess.content,<br>            refreshToken: tokens.refreshToken,<br>          },<br>          {<br>            maxAge: 3600000,<br>            httpOnly: true,<br>            secure: false,<br>            sameSite: &quot;none&quot;,<br>          }<br>        );<br>        res.status(200).json(&quot;Authorized!&quot;);<br>      } else {<br>        res.status(401).json(refreshAccess.content);<br>      }<br>    }<br>  } else {<br>    res.status(401).json(&quot;No token presented&quot;);<br>  }<br>};<br><br>module.exports = {<br>  login_process,<br>  authorize,<br>};</pre><p>The method initially checks whether the access token is valid. If not it tries to refresh the token using the <em>tokenRefresher</em> method. The cookie is updated with the new token. Obviously, if neither of the tokens is valid or if no token is presented an unauthorized status is returned.</p><p>To finalize our work, let us create a new file at the routers folder called authorization.js. This will be the endpoint where the “switch” verifies the user’s permission.</p><pre>const express = require(&#39;express&#39;);<br>const app = express();<br>const login_controller = require(&#39;../controller/login_controller.js&#39;);<br>const cookieParser = require(&quot;cookie-parser&quot;);<br>const bodyParser = require(&quot;body-parser&quot;);<br><br>app.use(cookieParser());<br>app.use(bodyParser.json());<br><br>app.get(&#39;/authorize&#39;, (req, res)=&gt;{<br>    login_controller.authorize(req, res);<br>})<br><br>module.exports = app;</pre><p>Now that we have the two routers let us update the index.js so that it uses these 2 endpoints.</p><pre>//Final version of index.js<br>const express = require(&#39;express&#39;);<br>const app = express();<br>const connect_db = require(&#39;./db.js&#39;);<br>const login_router = require(&#39;./routers/login.js&#39;);<br>const authorization_router = require(&#39;./routers/authorization.js&#39;);<br>const cors = require(&#39;cors&#39;)<br><br>const allowedOrigins = [&#39;http://localhost:3000&#39;];<br><br>app.use(cors({<br>    origin: (origin, callback) =&gt; {<br>        if (allowedOrigins.includes(origin) || !origin) {<br>            callback(null, true);<br>        } else {<br>            callback(new Error(&#39;Not allowed by CORS&#39;));<br>        }<br>    },<br>    methods: &#39;GET,HEAD,PUT,PATCH,POST,DELETE&#39;,<br>    credentials: true,<br>    optionsSuccessStatus: 204,<br>}));<br><br>app.use(&#39;/auth&#39;, login_router);<br>app.use(&#39;/permission&#39;, authorization_router);<br><br>connect_db(()=&gt;{<br>    app.listen(5443, ()=&gt;{<br>        console.log(`Listening on port 5443`);<br>    })<br>})</pre><p>So, we have finished the server side. If you followed through your folder should look similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*KHHuTv8zI7Q24KK3ebYFxg.png" /></figure><p>Now, we have to deal with the client side. I know that you guys by now should be familiar with how to complete the lamp exercise. If you are not then you can simply check the code in the link provided at the beginning of this explanation. You can also experiment with it and use it for your purposes.</p><p>In this article however, I will not spend time explaining how to build the client app. I will simply show you how your requests should look in order to use this specific JWT authentication that was presented above. So, below is the code for the request which is sent every time the user tries to change the lamp’s state:</p><pre>export const get_authorization = (success_action, failure_action)=&gt;{<br>    fetch(&quot;http://localhost:5443/permission/authorize&quot;, {<br>    method: &quot;GET&quot;,<br>    credentials: &quot;include&quot;<br>  })<br>  .then(response=&gt;{<br>        if(response.status === 200)<br>            success_action()<br>        else if (response.status === 401)<br>            failure_action()<br>  })<br>  .catch(err=&gt;{<br>    console.log(err);<br>  })<br>}</pre><p>It is a pretty normal http request performed using <em>fetch </em>but you should note that there is a line<em> “ credentials: “include” ”. </em>This line specifies to the request that it should transmit to the server any http cookie that was stored at client side. The server then will filter out the cookie that contains the token. As simple as that and you have a full authentication system set up. For those of you who prefer <em>axios</em> below is the equivalent code.</p><pre>const get_authorization = (success_action, failure_action) =&gt; {<br>  axios.get(&#39;http://localhost:5443/permission/authorize&#39;, {<br>    withCredentials: true // Include credentials (cookies) in the request<br>  })<br>  .then(response =&gt; {<br>    if (response.status === 200)<br>      success_action();<br>    else if (response.status === 401)<br>      failure_action();<br>  })<br>  .catch(error =&gt; {<br>    console.error(&#39;Error occurred:&#39;, error);<br>  });<br>};</pre><h3>Final remarks</h3><p>As we come to the end of this article I should make some final remark on what you guys have just learned. Firstly, I really hope that the concept of JWT as an authentication tool is clear to you. If not, don’t worry! It does take some time to adjust yourself to a new concept. Secondly, this is a very solid authentication system. In fact, I use it in all my projects with small modifications to what is stored in the payload. So, I do recommend that you save this article and refer to it if you are ever working with node.js as your server side framework.</p><p>As you embark on your next coding journey, whether it’s diving deeper into programming paradigms, mastering new languages, or architecting complex systems, may you find joy in the exploration of programming concepts and the endless possibilities they unlock. Wishing you a wonderful time coding your next app, filled with creativity, problem-solving, and the satisfaction of turning ideas into reality!</p><h3>Resources</h3><p>ACTE Technology Co., Ltd. <a href="https://acte.ltd/utils/randomkeygen">https://acte.ltd/utils/randomkeygen</a><br>Node documentation: <a href="https://nodejs.org/en/learn/getting-started/how-to-install-nodejs">https://nodejs.org/en/learn/getting-started/how-to-install-nodejs</a><br>npm documentation: <a href="https://www.npmjs.com/">https://www.npmjs.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d51cfc62050" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>