Skip to content

Sina-Hgs/AI-Powered-Frontend-Engineering-Presentation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”₯ AI-Powered Frontend Engineering: ChatGPT, Copilot, Cursor in Action

🧭 Overview

An advanced walkthrough of how to strategically use ChatGPT, GitHub Copilot, and Cursor for supercharging frontend development.

You’ll learn:

  • Differences between AI agents and chatbots
  • Advanced prompt engineering for each tool
  • Workflow design for AI-augmented coding
  • Full code examples (React + Tailwind)
  • Live coding walkthroughs for each tool
  • Tool-specific input vs output comparisons
  • Tips & tables on when and how to use each tool
  • Real-world AI tooling case studies

πŸ”„ Agent vs Chatbot

Feature AI Chatbot (e.g., ChatGPT) AI Agent (e.g., Cursor, Copilot)
Primary Mode Conversational, text-based Directly edits or autocompletes in your IDE
Context Awareness Maintains global context in chat Operates on current file/project context
Autonomy Responds to you Acts on your codebase proactively/reactively
Use Case Fit Planning, generating, refactoring Scaffolding, refactoring, editing live code
Examples ChatGPT, Claude Cursor, GitHub Copilot, Replit Ghostwriter

🧠 Writing Great Prompts: Tool-Specific Guidance

🧾 For ChatGPT (Chatbot)

Goal: Full solutions, architecture, reasoning, refactoring

Prompt Tips:

  • Be verbose and clear
  • List constraints and technologies
  • Ask for best practices or trade-offs
  • Use "you are a senior dev..." tone for quality output

Example Prompt:

You're a senior frontend engineer. Write a complete React component using Tailwind CSS that implements a responsive navbar:
- Hamburger icon on mobile
- useState toggle logic
- Semantic HTML and accessibility
- Mobile-first design with ARIA attributes
Explain accessibility and optimization considerations.

🧾 For Cursor (Agent)

Goal: Fast file-specific mutations

Prompt Tips:

  • Be surgical: "Edit this to..."
  • Avoid general tasks like "build X" β€” Cursor shines in modifying, not generating from scratch
  • Use commands like "extract", "make responsive", "animate"

Example Prompt:

Edit this component to:
- Add a mobile hamburger toggle using useState
- Hide/show nav links based on toggle
- Keep the logo and layout unchanged
- Animate menu open/close

🧾 For Copilot (Inline Agent)

Goal: Fast autocomplete based on your typing

Prompt Tips:

  • Start typing the code you want to see
  • Copilot learns from your patterns and file structure
  • Works great for loops, component scaffolds, props, Tailwind classes

Example Trigger:

const Navbar = () => {
  return (
    <nav className="bg-gray-800 p-4 flex justify-between items-center">
      <div className="font-bold text-xl">Logo</div>

Copilot will suggest the rest inline as you type.


πŸ” Tool Comparison by Output

🧾 Shared Prompt:

β€œCreate a responsive navbar in React using Tailwind CSS. It should show a hamburger menu on small screens and full nav links on desktop. Add toggle logic for the menu.”


βœ… ChatGPT Output

import { useState } from 'react';

const Navbar = () => {
  const [open, setOpen] = useState(false);

  return (
    <nav className="flex items-center justify-between flex-wrap bg-gray-800 p-4 text-white">
      <div className="text-xl font-bold">Logo</div>
      <button 
        className="lg:hidden block" 
        onClick={() => setOpen(!open)}
        aria-label="Toggle navigation"
      >
        ☰
      </button>
      <ul className={`${open ? 'block' : 'hidden'} lg:flex space-x-4`}>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </nav>
  );
};

export default Navbar;

βœ… Cursor Output

import { useState } from 'react';

const Navbar = () => {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <nav className="bg-gray-900 text-white p-4 flex items-center justify-between">
      <div className="text-lg font-bold">Logo</div>
      <div className="lg:hidden" onClick={() => setIsOpen(!isOpen)}>☰</div>
      <div className={`${isOpen ? 'block' : 'hidden'} w-full lg:flex lg:items-center lg:w-auto`}>
        <ul className="flex flex-col lg:flex-row gap-4 mt-2 lg:mt-0">
          <li><a href="#">Home</a></li>
          <li><a href="#">Projects</a></li>
          <li><a href="#">Contact</a></li>
        </ul>
      </div>
    </nav>
  );
};

export default Navbar;

βœ… Copilot Output

<nav className="flex items-center justify-between p-4">
  <div className="text-xl font-bold">Logo</div>
  <button className="lg:hidden">☰</button>
  <ul className="hidden lg:flex space-x-4">
    <li>Home</li>
    <li>About</li>
    <li>Contact</li>
  </ul>
</nav>

βš–οΈ Output Comparison Table

Feature Copilot Cursor ChatGPT
Toggle Logic ❌ None βœ… useState + toggle logic βœ… useState + ARIA
Full Component ❌ Partial JSX βœ… Complete w/ logic βœ… Complete + explanations
Contextual Editing ❌ βœ… File-aware edits ❌ (text only)
Accessibility ❌ ⚠️ Sometimes βœ… Always
Ideal Usage Fast typing Refactor/modify existing code Design & generate full features

πŸ§ͺ Three Input Prompts for Same Goal, Highlighting Each Tool

🧠 For ChatGPT (Architecture & Explanation)

Write a complete responsive navbar in React using Tailwind. Add toggle logic with useState. Include accessible markup and explain your design decisions.

πŸ› οΈ For Cursor (Code Refactor)

Make this navbar responsive with Tailwind. Add a hamburger menu with toggle state. Animate the open/close.

⚑ For Copilot (Rapid Scaffold)

const Navbar = () => {
  const [open, setOpen] = useState(false);
  return (
    <nav className="bg-white p-4 flex justify-between items-center">

Copilot continues from here automatically.


πŸ‘¨β€πŸ’» Live Coding Walkthrough

🧠 1. ChatGPT Flow

Prompt:

Write a full responsive React + Tailwind navbar with hamburger toggle, useState, semantic HTML, accessibility, transitions. Explain each part.

πŸ“¦ Output:

  • Full JSX
  • Tailwind classes
  • Toggle logic
  • Accessibility built-in

πŸ› οΈ 2. Cursor Flow

Initial Code:

const Navbar = () => {
  return (
    <nav>
      <div>Logo</div>
      <ul>
        <li>Home</li>
        <li>About</li>
        <li>Contact</li>
      </ul>
    </nav>
  );
};

Cursor Prompt:

Edit this to make the nav responsive with Tailwind, add a hamburger menu with state toggle.

🧠 Output:

  • Tailwind layout
  • Toggle logic
  • Inline update β€” no copy-paste needed

⚑ 3. Copilot Flow

Type:

const Navbar = () => {
  const [open, setOpen] = useState(false);
  return (
    <nav className="bg-white p-4 flex justify-between items-center">
      <div className="font-bold text-xl">Logo</div>

Copilot will:

  • Auto-fill toggle button
  • Auto-fill nav links
  • Predict layout classes

🧡 When to Use What?

Phase Tool Why
🎨 Design Architecture ChatGPT Best for complete features with constraints
πŸ› οΈ Code Mutation Cursor Knows your code context, edits smartly
⚑ Scaffolding UI Copilot Super-fast at inline JSX and Tailwind prediction

πŸš€ Final Takeaways

  • Use ChatGPT for entire components and architectural thinking
  • Use Cursor for fast refactor, live mutation, and cleanup
  • Use Copilot to fill in repetitive logic, markup, and classnames
  • Mix & match! Combine tools for optimal flow
  • Advanced prompt engineering is key β€” learn to speak AI fluently

πŸ§ͺ Git Integration + AI Testing Agents

🧰 1. Git-Aware Coding with Cursor

Cursor is deeply integrated with Git. Here's how you can use it to improve your Git workflows:

πŸ”Ή AI Diff Review

  • Cursor can summarize staged changes:

    Prompt: "Summarize these changes and write a commit message."
    

    βœ… Ideal for reviewing large PRs or understanding teammate commits.

πŸ”Ή Commit Message Generation

  • Cursor can auto-generate high-quality, conventional commits:

    Prompt: "Generate a semantic commit message for these changes."
    Output: "feat(navbar): add responsive toggle menu using Tailwind and useState"
    

πŸ”Ή Use AI to Refactor with Context

  • Ask Cursor:

    Prompt: "Refactor the code to follow the Single Responsibility Principle. Only change this file."
    
  • After refactor, auto-generate:

    Prompt: "Summarize the diff and generate a commit."
    

πŸ§ͺ 2. AI Testing Agent Integration

Using ChatGPT or Copilot to write tests:

βœ… Test Writing Example

Prompt for ChatGPT:

Write unit tests in React Testing Library for a navbar component that:
- Toggles menu with a button
- Has different layouts for mobile and desktop
- Uses useState

Output:

import { render, fireEvent, screen } from '@testing-library/react';
import Navbar from './Navbar';

test('shows menu on mobile toggle', () => {
  render(<Navbar />);
  const button = screen.getByLabelText(/toggle navigation/i);
  fireEvent.click(button);
  expect(screen.getByText(/home/i)).toBeVisible();
});

πŸ”— Git Hook with AI (Advanced Workflow)

Using tools like Husky + Cursor CLI or OpenAI API:

prepare-commit-msg Git Hook

#!/bin/sh
diff=$(git diff --cached)
msg=$(echo "$diff" | curl -X POST https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4",
    "messages": [{"role": "user", "content": "Write a semantic commit message for this diff:\n'"$diff"'"}]
  }' | jq -r '.choices[0].message.content')

echo "$msg" > $1

πŸ“Š Case Studies: AI in Real Commit Workflows

🧩 Case 1: ChatGPT-Assisted Refactor & Docs

Task:

  • Refactor a large FormWizard component
  • Document every step

Prompt:

Refactor this React component into smaller parts:
- StepController
- StepProgressBar
- WizardForm

Each with props defined. Add JSDoc comments.

ChatGPT Output:

  • 3 components
  • JSDoc
  • Better separation of concerns

Commit Generated:

refactor(form): split FormWizard into subcomponents with clear props and docs

πŸ”„ Case 2: Cursor Commit Generation

Before:

<Button onClick={toggle}>Open</Button>
{show && <Sidebar />}

Prompt:

Refactor to use useReducer instead of useState for toggle.

Cursor Output:

  • Added reducer
  • Cleaner toggle logic

Prompt (afterwards):

Summarize the diff and write a commit message.

Commit:

refactor(ui): replace useState with useReducer for sidebar toggle

✍️ Case 3: Copilot-Fueled Boilerplate with ChatGPT Commit

Flow:

  • Copilot used to scaffold a Next.js API route
  • ChatGPT used to write the commit summary

Prompt:

Write a commit message for this endpoint creation:
- /api/send-email
- Uses nodemailer
- Validates input

Commit:

feat(api): add /send-email endpoint with input validation and nodemailer integration

🧠 Takeaway

  • ChatGPT: Best for semantic commit messages and code documentation
  • Cursor: Git-aware, ideal for local diffs, commit summaries, and edits
  • Copilot: Fast scaffolding β†’ use with Git hooks + external summarization

πŸ” Advanced AI-Powered Frontend Engineering Topics

1. 🧠 AI-Driven Component Architecture Design

Use GPT to translate product requirements or UI wireframes into reusable component trees using Atomic Design principles.

Prompt

Given this user story: "Users can upload and crop a profile picture on mobile and desktop", generate a component hierarchy using Atomic Design. Include props and responsibilities.

Output

Atoms: Button, Input, ImagePreview
Molecules: ImageUploadInput (Input + Preview), CropperToolbar
Organisms: ProfileImageUploader
Props:
  - onUpload: (file: File) => void
  - aspectRatio: number
  - onCrop: (cropData: object) => void

Bonus

Feed GPT screenshots from Figma (via vision tools) or describe your design manually.


2. πŸ“š Auto-Generating Storybook Stories

Use Case

Automate your component documentation and showcase states quickly with GPT.

Prompt

Write a Storybook story for a ToggleSwitch component with the following props:
- checked (boolean)
- onChange (function)
- disabled (boolean)

Output

import React from 'react';
import { ToggleSwitch } from './ToggleSwitch';

export default {
  title: 'Components/ToggleSwitch',
  component: ToggleSwitch,
};

export const Default = () => <ToggleSwitch checked={false} onChange={() => {}} />;
export const Checked = () => <ToggleSwitch checked={true} onChange={() => {}} />;
export const Disabled = () => <ToggleSwitch disabled={true} checked={false} onChange={() => {}} />;

3. πŸ”§ Refactoring Legacy Codebases with AI

Input

Legacy code example:

class Modal extends React.Component {
  state = { open: false };
  toggle = () => this.setState({ open: !this.state.open });

  render() {
    return this.state.open ? <div>{this.props.children}</div> : null;
  }
}

Prompt

Convert this class-based Modal to a functional component using hooks. Add JSDoc and split toggle logic into a separate hook.

Output

import { useState } from 'react';

/** useModal manages open/close state for modal dialogs */
export const useModal = () => {
  const [open, setOpen] = useState(false);
  const toggle = () => setOpen(prev => !prev);
  return { open, toggle };
};

export const Modal = ({ children }) => {
  const { open } = useModal();
  return open ? <div>{children}</div> : null;
};

4. πŸ§ͺ AI Agents for End-to-End Testing

Prompt

Write Playwright tests for a login + checkout flow in an e-commerce app.

Output

test('user can login and checkout', async ({ page }) => {
  await page.goto('/login');
  await page.fill('#email', 'test@ai.com');
  await page.fill('#password', '123456');
  await page.click('button[type=submit]');

  await page.goto('/shop');
  await page.click('text=Add to Cart');
  await page.goto('/cart');
  await page.click('text=Checkout');
  await expect(page).toHaveURL('/confirmation');
});

5. ♿️ AI-Powered Accessibility Checks

Prompt

Check this HTML snippet for accessibility issues and suggest fixes:
<button>πŸ”</button>

Output

Issue: Button has no accessible name.
Fix: Add aria-label or text.
<button aria-label="Search">πŸ”</button>

You can chain prompts:

Now generate a table summarizing all WCAG 2.1 violations found.

7. 🧡 Prompt Engineering Strategies

Few-Shot Prompting

Here are two examples of commits:
- feat(button): add loading state to async buttons
- fix(navbar): hide overflow menu in Safari

Now generate a message for:
Diff: Added error message display to LoginForm on 401 response

Chain-of-Thought Prompt

Let's reason step by step:
1. Define the component name and purpose.
2. Declare the prop types.
3. Implement the component.
4. Write a test file.

This helps guide the model through a structured, high-quality output.


8. πŸ“ Team Prompt Libraries

Create an internal prompt library your team can pull from. Categories:

  • Code Style: "Convert this to a reducer pattern using switch-case."
  • Test Writing: "Write unit tests for this using Jest and RTL."
  • Docs: "Add JSDoc to all functions and interfaces."

Bonus Tooling

Use Notion/Markdown synced with VS Code snippets for real-time usage.


9. βš™οΈ Agent Chains (Auto-Build-Test-Deploy)

Use LangChain or Shell scripting + GPT APIs to create full CI-like chains.

Workflow

# 1. Generate component
generate_component.sh "LoginForm with email/password, form validation"

# 2. Generate test
generate_test.sh LoginForm

# 3. Ask GPT to format + commit
gpt_commit.sh

Example GPT Prompt

Summarize changes, write a commit message, and list test coverage gaps.

10. 🎨 Extracting Design Tokens from Tailwind or Figma

Prompt

Extract a design token JSON from this Tailwind config:
- Colors: gray, blue
- Font size: sm, base, lg
- Spacing: 2, 4, 8

Output

{
  "color": {
    "gray": "#6b7280",
    "blue": "#3b82f6"
  },
  "fontSize": {
    "sm": "0.875rem",
    "base": "1rem",
    "lg": "1.125rem"
  },
  "spacing": {
    "2": "0.5rem",
    "4": "1rem",
    "8": "2rem"
  }
}

Can be fed into:


About

A Presentation on AI-Powered Frontend Engineering: ChatGPT, Copilot, Cursor in Action, originally presented at a Code-Cafe session

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors