<?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 Arindol Das on Medium]]></title>
        <description><![CDATA[Stories by Arindol Das on Medium]]></description>
        <link>https://medium.com/@arindoldas?source=rss-753d9a7f5437------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ATnKzp2pOwMz-xGT</url>
            <title>Stories by Arindol Das on Medium</title>
            <link>https://medium.com/@arindoldas?source=rss-753d9a7f5437------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:36:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arindoldas/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 Built an Automated AI Code Reviewer with FastAPI, Groq (Llama 3.3), and GitHub Webhooks]]></title>
            <link>https://medium.com/@arindoldas/how-i-built-an-automated-ai-code-reviewer-with-fastapi-groq-llama-3-3-and-github-webhooks-f6c3650f5e07?source=rss-753d9a7f5437------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6c3650f5e07</guid>
            <category><![CDATA[groq-ai]]></category>
            <category><![CDATA[ai-code-review]]></category>
            <category><![CDATA[llama-3]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Arindol Das]]></dc:creator>
            <pubDate>Sun, 26 Jul 2026 08:44:01 GMT</pubDate>
            <atom:updated>2026-07-26T08:45:54.022Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CdsKfXMlIuoXocVhCxn4Lw.png" /></figure><p>All developers are familiar with this process: you open a Pull Request (PR) and then carry on waiting. You keep waiting. Whether you’re waiting for a busy colleague or are working alone on a side project, receiving immediate and high-quality feedback on your code makes a big difference.</p><p>I chose to tackle this problem by creating an event-driven automation engine which connects directly to GitHub; as soon as you open or update a pull request, the local FastAPI server detects the event, retrieves the code changes, passes them to an open-source <strong>Llama 3.3 70B</strong> model through <strong>Groq</strong>, and then automatically adds a line-by-line code review back into the GitHub timeline.</p><p>The highlight is that it makes use of tools that are available for free, operates asynchronously so that it won’t time out, and requires less than 100 lines of Python code to set up. The following is a step-by-step guide for building your own automated AI code reviewer.</p><h4><strong>The Architecture: How It Works Under the Hood</strong></h4><p>Before we jump into the code, let’s look at the lifecycle of a single PR event:</p><ol><li><strong>The Trigger:</strong> You push code and open a PR on GitHub.</li><li><strong>The Webhook:</strong> GitHub fires an asynchronous POST request to a public URL.</li><li><strong>The Tunnel:</strong> ngrok routes that public web traffic directly onto your local machine&#39;s localhost:8000.</li><li><strong>The App:</strong> A FastAPI backend receives the payload, verifies the action, and hands the heavy lifting over to a background task so GitHub’s connection doesn’t time out.</li><li><strong>The Brain:</strong> The background worker fetches the raw git diff from GitHub, feeds it to <strong>Llama 3.3</strong> using <strong>Groq&#39;s</strong> high-speed inference engine, and gets an optimization report.</li><li><strong>The Response:</strong> The app uses GitHub’s API to post the structured markdown review back onto the PR conversation timeline.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_6TPL0F0oxp6EzYD8iplgA.png" /><figcaption><strong>The Architecture</strong></figcaption></figure><h4>Prerequisites &amp; Setup</h4><p>To follow along, make sure you have Python installed and grab these free API keys:</p><ul><li><strong>Groq API Key:</strong> Sign up at the <a href="https://console.groq.com/">Groq Console</a> to get blazing-fast inference speeds.</li><li><strong>GitHub Personal Access Token (PAT):</strong> Go to your GitHub Settings -&gt; Developer Settings -&gt; Tokens (classic). Generate a token with the <strong>repo</strong> scope checked so your app can post comments.</li></ul><pre>mkdir ai-pr-reviewer &amp;&amp; cd ai-pr-reviewer<br>python -m venv env<br>source env/bin/activate  # On Windows use: .\env\Scripts\Activate.ps1<br>pip install fastapi uvicorn requests groq</pre><p><strong>Step 1: The Core Backend Engine (</strong><strong>app.py)</strong></p><p>Create a file named app.py. This script contains our FastAPI endpoint, background worker tracking, and our payload interaction logic.</p><pre>import os<br>import requests<br>import traceback<br>from fastapi import FastAPI, Request, BackgroundTasks<br>from groq import Groq<br><br>app = FastAPI()<br><br># Extract keys from system environment<br>GITHUB_TOKEN = os.environ.get(&quot;GITHUB_TOKEN&quot;)<br>GROQ_API_KEY = os.environ.get(&quot;GROQ_API_KEY&quot;)<br><br># Initialize the Groq inference engine client<br>client = Groq(api_key=GROQ_API_KEY)<br><br>def process_and_review_pr(pr_payload):<br>    &quot;&quot;&quot;<br>    Background worker that handles fetching code, running inference,<br>    and posting comments without blocking the live webhook connection.<br>    &quot;&quot;&quot;<br>    try:<br>        repo_name = pr_payload[&quot;repository&quot;][&quot;full_name&quot;]<br>        pr_number = pr_payload[&quot;pull_request&quot;][&quot;number&quot;]<br>        diff_url = pr_payload[&quot;pull_request&quot;][&quot;diff_url&quot;]<br>        <br>        # 1. Fetch raw code changes (diff format) securely from GitHub<br>        headers = {<br>            &quot;Authorization&quot;: f&quot;Bearer {GITHUB_TOKEN}&quot;,<br>            &quot;Accept&quot;: &quot;application/vnd.github.v3+json&quot;<br>        }<br>        diff_response = requests.get(diff_url, headers=headers)<br>        raw_diff = diff_response.text<br>        print(&quot;[Log] Successfully fetched PR diff from GitHub.&quot;)<br><br>        # 2. Instruct the open-source Llama model<br>        system_instruction = (<br>            &quot;You are an elite, concise senior software engineer reviewing a pull request.\n&quot;<br>            &quot;Examine the incoming code diff line by line. Highlight potential bugs, &quot;<br>            &quot;edge cases, logical loopholes, or performance problems.\n&quot;<br>            &quot;Provide your review in professional markdown with explicit optimization examples.&quot;<br>        )<br>        <br>        print(&quot;[Log] Sending diff data to Groq API...&quot;)<br>        completion = client.chat.completions.create(<br>            model=&quot;llama-3.3-70b-versatile&quot;,<br>            messages=[<br>                {&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: system_instruction},<br>                {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: f&quot;Review this git diff code change:\n\n{raw_diff}&quot;}<br>            ]<br>        )<br>        ai_feedback = completion.choices[0].message.content<br>        print(&quot;[Log] Successfully received AI feedback from Groq.&quot;)<br><br>        # 3. Post the compiled review comment back onto the GitHub issue timeline<br>        comments_api_url = f&quot;https://api.github.com/repos/{repo_name}/issues/{pr_number}/comments&quot;<br>        comment_payload = {&quot;body&quot;: f&quot;### 🤖 Free Llama-Agent PR Review\n\n{ai_feedback}&quot;}<br>        <br>        result = requests.post(comments_api_url, json=comment_payload, headers=headers)<br>        print(f&quot;[Log] GitHub API response status: {result.status_code}&quot;)<br><br>    except Exception as e:<br>        print(&quot;\n [ERROR IN BACKGROUND WORKER] &quot;)<br>        traceback.print_exc()<br><br>@app.post(&quot;/webhook&quot;)<br>async def receive_github_event(request: Request, background_tasks: BackgroundTasks):<br>    &quot;&quot;&quot;<br>    Listener endpoint for incoming GitHub webhook events<br>    &quot;&quot;&quot;<br>    payload = await request.json()<br>    action = payload.get(&quot;action&quot;)<br>    <br>    # Run processing only when a pull request is brand new, updated, or reopened<br>    if action in [&quot;opened&quot;, &quot;synchronize&quot;, &quot;reopened&quot;]:<br>        background_tasks.add_task(process_and_review_pr, payload)<br>        return {&quot;status&quot;: &quot;Processing pull request changes asynchronously.&quot;}<br>        <br>    return {&quot;status&quot;: &quot;Event ignored.&quot;}</pre><p><strong>Step 2: Inverting the Network Tunnel with </strong><strong>ngrok</strong></p><p>Because GitHub cannot send a webhook payload directly to your machine’s localhost, we need a secure public tunnel. Download ngrok and fire it up in a separate terminal window to point to your backend port:</p><pre>ngrok http 8000</pre><p>ngrok will spin up a dashboard layout in your terminal. Look for the <strong>Forwarding</strong> line and copy the public HTTPS URL it provides. It will look something like this: [https://your-unique-subdomain.ngrok-free.dev](https://your-unique-subdomain.ngrok-free.dev)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UvH-Dx-g8FYVeCGp4mybHQ.png" /><figcaption>Note: I had to login to ngrok dashboard to fetch a free auth token</figcaption></figure><p><strong>Step 3: Wire Up the GitHub Webhook</strong></p><p>Now let’s map GitHub events directly down our tunnel line:</p><ol><li>Open your target GitHub repository in your browser and click the <strong>Settings</strong> gear icon.</li><li>Select <strong>Webhooks</strong> from the left-side navigation panel and click <strong>Add webhook</strong>.</li><li>In the <strong>Payload URL</strong> box, paste your ngrok link and append /webhook onto the end:</li></ol><pre>https://your-unique-subdomain.ngrok-free.dev/webhook</pre><p>4. Change the <strong>Content type</strong> to <strong>application/json</strong>.</p><p>5. Under <em>Which events would you like to trigger this webhook?</em>, choose <strong>Let me select individual events</strong>. Uncheck everything and select <strong>Pull requests</strong> only.</p><p>6. Click <strong>Add webhook</strong> to save.</p><p><strong>Step 4: Fire Up the Engine &amp; Run a Test</strong></p><p>Back in your main project terminal window, inject your secret tokens directly into your environment context and start the server using Uvicorn:</p><pre># If using Windows PowerShell:<br>$env:GITHUB_TOKEN=&quot;ghp_YourActualGitHubToken&quot;<br>$env:GROQ_API_KEY=&quot;gsk_YourActualGroqKey&quot;<br><br>uvicorn app:app --reload --port 8000P</pre><p>Now, create a new branch in your repository and push a piece of intentionally buggy code (like hardcoded credentials, an unclosed file stream, or a weak crypto algorithm) to check the system. Click <strong>Create Pull Request</strong>.</p><p>Look back at your FastAPI console terminal window. You’ll instantly see your asynchronous worker take off:</p><pre>INFO:     140.82.115.152:0 - &quot;POST /webhook HTTP/1.1&quot; 200 OK<br>[Log] Successfully fetched PR diff from GitHub.<br>[Log] Sending diff data to Groq API...<br>[Log] Successfully received AI feedback from Groq.<br>[Log] GitHub API response status: 201</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*U7LFfKo3ozrsIQZ6AbJofg.png" /></figure><p>Refresh your GitHub PR conversation tab. Boom! Right on your timeline, you’ll find a beautifully formatted Markdown analysis detailing the architectural flaws, security hazards, and code optimization blocks with custom replacement blocks instantly available.</p><h3><strong>Demo: See the Llama in Action</strong></h3><p>This is the moment where the automation comes alive. To demonstrate the power of Llama 3.3, I intentionally pushed a piece of code full of architectural “traps” — hardcoded credentials, a weak hashing algorithm (MD5), resource leaks, and an extremely inefficient $O(N²)$ data processing loop.</p><h3>1. The Buggy Code Submission</h3><p>Here is what the Pull Request looked like. I changed about 40 lines of Python code, introducing critical flaws that no senior engineer should ever merge. The PR was opened, and immediately the GitHub webhook fired.</p><h3>2. The Instant AI Audit</h3><p>Less than <strong>four seconds later</strong>, before a human reviewer could even open the notification email, the Llama agent, operating via the FastAPI background worker, finalized its audit.</p><p>As you can see in the screenshot below, the AI posted a line-by-line breakdown directly onto the PR conversation timeline. It flawlessly identified:</p><ul><li><strong>Security Hazards:</strong> It flagged the hardcoded DATABASE_PASSWORD and recommended switching to os.environ.get().</li><li><strong>Performance Bottlenecks:</strong> It recognized the $O(N²)$ list processing bottleneck and provided the optimized set() replacement.</li><li><strong>Vulnerabilities:</strong> It correctly identified MD5 as broken for cryptographic purposes and forced an upgrade to SHA-256.</li></ul><p>This instant feedback loop transforms the code review process from a synchronous waiting game into an instantaneous, asynchronous optimization session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*icYdshnSv0xWyLNHAk0cPA.png" /></figure><p>Checkout the PR: <a href="https://github.com/ad-rinaline2/AI-PR-Reviewer/pull/1#event-27871170748"><em>https://github.com/ad-rinaline2/AI-PR-Reviewer/pull/1#event-27871170748</em></a></p><p>Check the last commit, you will understand the flaws it detected.</p><h4><strong>Key Takeaways &amp; What’s Next?</strong></h4><p>Building this automation highlighted just how easy it has become to integrate powerful, open-source AI models into day-to-day development pipelines without running up massive clouds bills. By utilizing FastAPI’s asynchronous BackgroundTasks, we bypass the strict execution timeout limits of webhooks while ensuring zero delay to our main request line.</p><p>If you want to take this layout even further, you can containerize the FastAPI app inside a Docker file and use GitHub Actions to deploy it straight up to Azure App Services to create a permanent, 24/7 server pipeline!</p><p><strong><em>Have questions on setting up the webhook configurations or tweaking your Llama reviewer prompt? Let’s chat down in the comments below!</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6c3650f5e07" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>