<?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 Shreyash Srivastava on Medium]]></title>
        <description><![CDATA[Stories by Shreyash Srivastava on Medium]]></description>
        <link>https://medium.com/@ShreyashSri?source=rss-aeabb9e3193b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*76I8vxnZfJQ34MtdfCa8Rw.png</url>
            <title>Stories by Shreyash Srivastava on Medium</title>
            <link>https://medium.com/@ShreyashSri?source=rss-aeabb9e3193b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:03:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ShreyashSri/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[Production was down]]></title>
            <link>https://medium.com/@ShreyashSri/bad-things-might-happen-if-you-ignore-this-143f6ba3e210?source=rss-aeabb9e3193b------2</link>
            <guid isPermaLink="false">https://medium.com/p/143f6ba3e210</guid>
            <dc:creator><![CDATA[Shreyash Srivastava]]></dc:creator>
            <pubDate>Thu, 18 Sep 2025 09:51:30 GMT</pubDate>
            <atom:updated>2026-10-18T19:36:35.150Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*3RrcZGS5DR5WORchC0mvPw.png" /></figure><h3>Hello Everyone! 👋🏻</h3><p>I’m <strong>Shreyash Srivastava</strong>, a 2nd year CSE student at DSCE and yes it’s time for another blog. A lot of things happened in last few months, So before I begin I will just share this image here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ZDSt4FK8_Y3RISfh.jpg" /></figure><h3>A Quick Catch-Up</h3><p>I was awarded <strong>LiFT</strong> Scholarship from <strong>Linux foundation</strong>, was working on a project for our club (<a href="https://careers.pointblank.club/">check it out!</a>) also I recently got an internship at an early stage startup and got the opportunity to work with one of my seniors at <a href="https://pointblank.club/">Pointblank</a>.<br>The company basically provides a platform for educators and students. Teachers can create assignments, activities, and other learning materials using interesting AI features like image generation, case study analysis, and presentation makers. Students can then use these materials to practice, learn, and receive personalized feedback. We also have a community page where teachers can share their creations with a wider audience.<br>So, One of the first tasks that I was assigned was to implement a credit system to limit the AI usage in our product. Until then, users on any plan could use our AI features an unlimited number of times. So my job was to introduce limits to manage the usage.</p><h3>My Approach</h3><p>In order to implement this feature what I thought of was to create a tokens collections(as we were using firebase) which will consists of userId, plan and the number of credits/tokens a user has.<br>And created a custom hook which will check if the user has tokens to make a request and it will also help in deducting the tokens after every successful call.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*uYLL71-8LnoIjx1t.png" /><figcaption>Development</figcaption></figure><p>Now what I did was, wherever the call to our AI service was made I added a check to see the number of tokens the user has and deducted the credits after every successful call, and wherever the function was called i made sure that it will pass the userId from frontend and will authenticate the user at backend with help of that userId so I can check if the user exists or has the credits or not.<br>I made the changes and raised the PR to our development environment it was merged and everything was working, sounds too good right? Lol here comes the fun part....</p><h3>The Chaos</h3><p>It was <strong>1:09 AM</strong> in night, I was going to sleep and then I received some messages,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/0*76xvc_gXKLStmX47.png" /><figcaption>Uh-</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/0*vrk8xrX93bztgDcD.png" /><figcaption>Oh no-</figcaption></figure><p>Yes, <strong>The production was down</strong>. (Remember the T-shirt xD)<br>So, what happened was as my senior (who was in a hackathon at that time) was busy, I myself pushed some changes to both repositories and I didn’t know that We <strong>DO NOT</strong> have development/staging branch for <strong>backend repository</strong> and we were using this for <strong>both</strong> production and development environment T-T.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*JBae-EQPH-_qiL_k.png" /><figcaption>………….</figcaption></figure><h3>The Issue</h3><p>As I mentioned earlier what I did was pass the userId to backend in order to verify if the user exists in our database or not, right? But now as the frontend changes were not in production environment and I pushed my changes in backend it was expecting userId to be passed and due to this it was unable to find the user and the entire service was down T-T</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*cKXrzFewd3-krFU2.png" /><figcaption>T-T</figcaption></figure><h3>Aftermath</h3><p>In order to fix this, we immediately reverted the backend changes to get the platform back online. And after a proper round of testing with both the new frontend and backend on a staging environment, we successfully rolled out the credit system.<br>We also created a separate staging branch to ensure this thing never happens again. It was also a great learning experience for me as I’ll never forget: <strong>Always Ask, Never Assume</strong>. I should have confirmed once before pushing the changes.<br>And after that everything went fine, it was all good and happy.<br>(I again crashed prod after two days as I forgot to create token documents for existing users in production database)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=143f6ba3e210" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swagger? What’s that?]]></title>
            <link>https://medium.com/@ShreyashSri/swagger-whats-that-2377ba6d8e17?source=rss-aeabb9e3193b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2377ba6d8e17</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[swagger]]></category>
            <dc:creator><![CDATA[Shreyash Srivastava]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 22:05:18 GMT</pubDate>
            <atom:updated>2025-03-17T22:05:18.540Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hello Everyone! 👋🏻</h3><p>I’m <strong>Shreyash Srivastava</strong>, a 1st-year CSE student at DSCE and I’m back again with a new blog! (You can also check my previous one <a href="https://medium.com/@ShreyashSri/my-experience-participating-in-kwoc-b87d197d4728">here</a>)</p><p>So the main inspiration behind this blog was I recently worked on an issue with a friend of mine, which was a new one for us so I wanted to share my experience and how I was able to solve it ! (Also my first sem just ended and I was free :P). Let’s begin…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*GjNw0Trac494eHp4undOkQ.jpeg" /></figure><p>Documenting APIs is one of the most important aspects of building scalable and maintainable web applications. Recently, We were given a task of adding Swagger documentation to a <a href="https://pointblank.club/">Next.js website</a>. And before that we need to know some basics:</p><h3>What is an API?</h3><p>At its core, an API (Application Programming Interface) is a set of rules that allows different software applications to communicate with one another. It defines how data is exchanged between systems, including the methods used to request and send data. APIs are crucial in modern web development, allowing services to interact with each other seamlessly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*PlCiYbKY8MbUGNNJz1tiaQ.png" /></figure><h3>What are API Endpoints?</h3><p>API endpoints are like doorways through which we access various functionalities within an API. Each endpoint corresponds to a specific URL that serves a particular function or resource. For instance, in a blogging platform, your API might have these endpoints:</p><ul><li>GET /posts – Retrieve a list of all blog posts</li><li>POST /posts – Create a new blog post</li><li>GET /posts/{id} – Fetch a specific blog post by ID</li></ul><p>Endpoints are the building blocks of an API, and documenting them is critical for ensuring other developers can use your API effectively.</p><h3>What is Swagger?</h3><p>Swagger is an open-source framework designed for building and documenting RESTful APIs. It gives us a user-friendly interface to visualize and interact with our API endpoints. Swagger documentation is usually written in the OpenAPI Specification (previously known as Swagger Specification), a standardized format for describing REST APIs.</p><p>With Swagger, we can:</p><ul><li>Automatically generate comprehensive API documentation.</li><li>Test API endpoints directly from the documentation.</li><li>Share API specifications with your team or external developers.</li></ul><p>Swagger documentation is essential for a few key reasons:</p><ul><li><strong>For API Consumers</strong>: Developers can easily understand how to use your API.</li><li><strong>For Testing</strong>: You can test your endpoints directly from the documentation.</li><li><strong>For Maintainability</strong>: Keeping your API documentation updated is much simpler with Swagger.</li></ul><h3>How to Add Swagger in Next.js</h3><p>Next.js is a powerful React framework for building server-rendered applications. Adding Swagger to a Next.js app involves a few steps:</p><ul><li>Installing necessary dependencies</li><li>Adding Swagger annotations to your API routes</li><li>Generating a Swagger JSON file</li><li>Setting up middleware or a library to serve the Swagger UI</li></ul><h3>Our Process: Adding Comments and Creating a swagger.ts File</h3><p>The first thing was adding JSDoc comments to all the API routes. These comments describe the purpose, parameters, and responses for each endpoint. For instance, in thisroute.ts file for the /api/members endpoint, my friend added the Swagger annotations like this:</p><pre>/**<br> * @swagger<br> * /api/members:<br> *   get:<br> *     summary: Retrieve all members<br> *     description: Fetches all members from the database and returns their details.<br> *     tags:<br> *      - Members<br> *     responses:<br> *       200:<br> *         description: A list of all members<br> *         content:<br> *           application/json:<br> *             schema:<br> *               type: array<br> *               items:<br> *                 type: object<br> *                 properties:<br> *                   id:<br> *                     type: string<br> *                   name:<br> *                     type: string<br> *                   role:<br> *                     type: string<br> *                   company:<br> *                     type: string<br> *                   year:<br> *                     type: string<br> *                   linkedInUrl:<br> *                     type: string<br> *                   imageUrl:<br> *                     type: string<br> *       500:<br> *         description: Internal server error<br> */<br>export async function GET() {<br>  // Implementation here...<br>}</pre><p>Once the comments were to all the routes, we need to consolidated the Swagger definitions into a single swagger.ts file. I used the next-swagger-doc library to generate the Swagger specification like so:</p><pre>import { createSwaggerSpec } from &#39;next-swagger-doc&#39;;<br>export const swaggerOptions = {<br>  definition: {<br>    openapi: &#39;3.0.0&#39;,<br>    info: {<br>      title: &#39;Next.js API Documentation&#39;,<br>      version: &#39;1.0.0&#39;,<br>      description: &#39;API documentation for the application endpoints&#39;,<br>    },<br>    servers: [<br>      { url: &#39;http://localhost:3000&#39;, description: &#39;Development server&#39; },<br>    ],<br>    tags: [<br>      { name: &#39;Members&#39;, description: &#39;Member data management endpoints&#39; },<br>      //all the tags should be added here...............    <br>],<br>  },<br>  apis: [&#39;./app/(default)/api/members/route.ts&#39;],<br>      //all the apis used........<br>};<br>export const getApiDocs = async () =&gt; {<br>  return createSwaggerSpec(swaggerOptions);<br>};</pre><p>In this file, I set up the basic structure for the Swagger documentation — such as the API title, version, and server URL — and pointed to the locations of the API routes with Swagger annotations.</p><h3>The Middleware Solution</h3><p>Now, here’s where things got tricky. Next.js doesn’t natively serve Swagger documentation out of the box. I needed to find a way to expose the Swagger JSON file through an endpoint like /api/docs.</p><p>To solve this, I created a route.ts file that generates and serves the Swagger JSON:</p><pre>import { getApiDocs } from &#39;@/lib/swagger&#39;;<br>import { NextResponse } from &#39;next/server&#39;;<br>export async function GET(request: Request) {<br>  try {<br>    const spec = await getApiDocs();<br>    return NextResponse.json(spec, {<br>      headers: {<br>        &#39;Content-Type&#39;: &#39;application/json&#39;,<br>        &#39;Access-Control-Allow-Origin&#39;: &#39;*&#39;,<br>      },<br>    });<br>  } catch (error) {<br>    console.error(&#39;Error generating API docs:&#39;, error);<br>    return NextResponse.json(<br>      { error: &#39;Failed to generate API documentation&#39; },<br>      { status: 500 }<br>    );<br>  }<br>}</pre><p>The middleware makes sure that the Swagger JSON is available at the /api/docs endpoint. But I ran into a CORS issue while trying to access the Swagger JSON. To fix this, I created a middleware that sets the correct headers for CORS:</p><pre>import { NextResponse } from &#39;next/server&#39;;<br>import type { NextRequest } from &#39;next/server&#39;;<br>export function middleware(request: NextRequest) {<br>  if (request.nextUrl.pathname === &#39;/api/docs&#39;) {<br>    return NextResponse.next({<br>      headers: {<br>        &#39;Content-Type&#39;: &#39;application/json&#39;,<br>        &#39;Access-Control-Allow-Origin&#39;: &#39;*&#39;,<br>      },<br>    });<br>  }<br>  return NextResponse.next();<br>}</pre><p>With this, the /api/docs route was working fine, and I was able to handle cross-origin requests without issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*JrzPbTnxAfhmOTZNa6eX-w.png" /></figure><h3>Displaying API Endpoints as JSON</h3><p>After setting up the middleware, visiting /api/docs returned the Swagger JSON. This JSON followed the OpenAPI Specification and contained all the details I had defined in the JSDoc comments. It became the foundation for generating a Swagger UI.</p><h3>Wrapping Everything with next-swagger</h3><p>Next, I wanted to make the Swagger documentation more interactive and visually appealing. I used the next-swagger module, which wraps the Swagger JSON and provides a beautiful, interactive UI for the documentation.</p><p>Here’s how I set it up:</p><ol><li>Install the library:</li></ol><pre>npm install next-swagger</pre><p>2. Create a Dynamic Swagger UI Component</p><p>Since the swagger-ui-react library is not compatible with server-side rendering (SSR), I used <strong>dynamic imports</strong> to load the SwaggerUI component only on the client side. Here’s how I did it in the page.tsx file:</p><pre>const SwaggerUI = dynamic(() =&gt; import(&quot;swagger-ui-react&quot;), {<br>  ssr: false,<br>  loading: () =&gt; &lt;p&gt;Loading API Documentation...&lt;/p&gt;,<br>});</pre><p><strong>3</strong>. Fetch Swagger JSON and Render the UI</p><p>In the page.tsx file, I fetched the Swagger JSON from the /api/docs endpoint and rendered it using the SwaggerUI component:</p><pre>export default function ApiDoc() {<br>  const [swaggerConfig, setSwaggerConfig] = useState&lt;any&gt;(null);<br>  useEffect(() =&gt; {<br>    fetch(&quot;/api/docs&quot;)<br>      .then((res) =&gt; res.json())<br>      .then((data) =&gt; setSwaggerConfig(data));<br>  }, []);<br>  if (!swaggerConfig) return &lt;p&gt;Loading API documentation...&lt;/p&gt;;<br>  return (<br>    &lt;div className=&quot;swagger-wrapper&quot;&gt;<br>      &lt;SwaggerUI spec={swaggerConfig} /&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Now, visiting /swagger would display an interactive Swagger UI, allowing users to explore and test the API endpoints right from the documentation.</p><h3>Creating layout.tsx for Swagger UI</h3><p>To render the Swagger UI within the Next.js app.</p><ol><li>layout.tsx to define the layout:</li></ol><pre>export default function SwaggerLayout({ children }: { children: React.ReactNode }) {<br>  return (<br>    &lt;html&gt;<br>      &lt;body style={{ margin: 0, padding: 0 }}&gt;{children}&lt;/body&gt;<br>    &lt;/html&gt;<br>  );<br>}</pre><p>With these files, the Swagger documentation was neatly integrated into the Next.js app, providing a polished, user-friendly experience for API consumers.</p><h3>Conclusion</h3><p>Adding Swagger documentation to the website was a rewarding experience. It not only made the code more maintainable but also made it easier for other developers to understand and use the APIs. Here’s a quick recap of what we did:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*rsP6NWkzrpwHjuIPjBA1Jw.png" /></figure><p>If you’re working on a Next.js project, I highly recommend integrating Swagger documentation. It’s a small effort that can go a long way in making your API more usable and easier to maintain. Happy coding!</p><p>Feel free to share your thoughts or questions in the comments below. If you’ve already added Swagger to your project, I’d love to hear about your experience!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2377ba6d8e17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Experience Participating in KWoC]]></title>
            <link>https://medium.com/@ShreyashSri/my-experience-participating-in-kwoc-b87d197d4728?source=rss-aeabb9e3193b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b87d197d4728</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[kharagpur-winter-of-code]]></category>
            <dc:creator><![CDATA[Shreyash Srivastava]]></dc:creator>
            <pubDate>Sat, 18 Jan 2025 17:24:22 GMT</pubDate>
            <atom:updated>2025-01-18T17:34:13.490Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Hello Everyone! </strong>👋🏻</h3><p>I’m <strong>Shreyash Srivastava</strong>, a 1st-year CSE student at DSCE. This is my first blog. So, here’s the thing: I participated in Kharagpur Winter of Code and it was such great experience that I wanted to share it.</p><p>The idea for this blog came to me as I saw my seniors writing blogs about the things they are doing and as it was important for KWoC, So here it is:</p><h3>Introduction to KWoC</h3><p><a href="https://kwoc.kossiitkgp.org/">Kharagpur Winter of Code (KWoC)</a> is a 5-week long online program for students who are new to open source software development. The program not only helps students to get involved in open source, but also prepares them for many open source summer programs; Google Summer of Code being one of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8UsmI7L9ILcJHmgvxG_sOw.png" /><figcaption>KWoC</figcaption></figure><h3>Choosing a Project</h3><p>The first step in KWoC was to explore the list of projects. The variety was overwhelming, ranging from web development to kernel systems and everything in between. I chose a web development project as I already had some experience in this field.</p><p><strong>Projects worked on:</strong></p><p><a href="https://github.com/Rakesh9100/Eventica"><em>Eventica</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZdU2px21-Gq6ijVEDUlFg.png" /></figure><h3>First Steps and Challenges</h3><p>Starting with an open-source project can be intimidating. The first task was to set up the development environment and understand the codebase. This involved reading the documentation, exploring the project’s structure, and sometimes even fixing setup-related issues.</p><h3>Learnings</h3><p><strong>Version Control:</strong> Gained proficiency in Git and GitHub, learning how to manage branches, resolve conflicts, and contribute via pull requests, which made collaborating on open-source projects seamless.</p><p><strong>Communication:</strong> Improved my ability to frame technical problems and solutions clearly, enabling better collaboration with mentors.</p><p><strong>Problem-Solving:</strong> Enhanced my debugging skills, learning to approach and resolve issues methodically and creatively across different aspects of the project.</p><p><strong>CSS:</strong> Deepened my understanding of CSS, including using variables for consistent design, applying animations, and enhancing user interfaces with shadows to create a polished look.</p><p><strong>Responsive Design:</strong> Mastered the use of media queries to ensure websites adapt to various screen sizes, improving user experience across devices.</p><p><strong>JavaScript:</strong> Strengthened my JavaScript skills, particularly in handling interactive elements like toggling menus and other user interactions efficiently.</p><p><strong>Open-Source Workflow:</strong> Learned the full open-source contribution process, from identifying issues to submitting pull requests, giving me insight into how collaborative development works in real-world projects.</p><h3>Pull Requests and Issues Worked On</h3><p>PRs Raised: 3</p><p><strong>Issues Worked On:</strong></p><p><em>Enhancing Send Message Button:</em></p><p>The website had a theme switcher feature, but the send message button was not following it. I fixed this by adding var( — primary-color) to ensure consistency and further enhanced the button with shadows and click animations. Working on this issue as my first PR introduced me to the workflow of using Git and GitHub effectively, including creating branches, committing changes, and submitting a pull request.</p><p><a href="https://github.com/Rakesh9100/Eventica/pull/18">Enhanced the send message button by ShreyashSri · Pull Request #18 · Rakesh9100/Eventica</a></p><p><em>Making the Website Fully Responsive:</em></p><p>The website’s containers were messy on smaller devices, and the header would lose its fixed position. I resolved this by adding a hamburger menu for navigation on smaller screens and used the @media tag for responsiveness. Also implemented JavaScript to enhance the interactivity of the hamburger menu. This PR taught me the importance of responsive design and how to debug layout issues efficiently.</p><p><a href="https://github.com/Rakesh9100/Eventica/pull/24">Made the website fully responsive by ShreyashSri · Pull Request #24 · Rakesh9100/Eventica</a></p><p><em>Fixing the Hamburger Icon Not Showing Close Button:</em></p><p>The hamburger icon didn’t had a close button, which created confusion for users. I addressed this by adding a close button to the menu and writing JavaScript to close the menu when users clicked the button or anywhere outside the menu. This PR highlighted the importance of user-friendly interfaces and handling edge cases in functionality.</p><p><a href="https://github.com/Rakesh9100/Eventica/pull/68">Fixed the hamburger icon not showing close button by ShreyashSri · Pull Request #68 · Rakesh9100/Eventica</a></p><h3>The Community and Support</h3><p>One of the highlights of KWoC was the community. The mentors were incredibly supportive and patient, guiding us through the process without making us feel overwhelmed. Fellow participants were equally enthusiastic, and the collaborative environment made the experience enjoyable.</p><h3>Takeaways</h3><p>Participating in KWoC was a transformative experience. It not only enhanced my technical skills but also boosted my confidence in contributing to open source. I learnt the way of communicating with mentors and all the people associated with this.</p><h3>Conclusion</h3><p>KWoC is more than just a coding program; it’s a platform to grow, learn, and connect with like-minded individuals. If you’re passionate about coding and eager to explore open-source, I highly recommend participating in KWoC. It’s an experience you’ll cherish for a lifetime!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b87d197d4728" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>