Case Study: How I Built My 3D Interactive Portfolio with Next.js and Three.js
A deep dive into the architecture and technology behind my personal portfolio, covering the integration of Next.js for performance and Three.js for immersive 3D visuals.
Utsav Khatri
Full Stack Developer
The Vision: More Than Just a Static Page
When I decided to build my personal portfolio, my primary goal was to create an experience, not just a webpage. I wanted to build a platform that not only lists my skills and projects but actively demonstrates them. The vision was to merge the performance and SEO benefits of a modern web framework with the immersive, engaging nature of 3D graphics.
This led me to choose a powerful combination: Next.js for the core application structure and Three.js (via @react-three/fiber
) for the interactive 3D background.
Core Technologies
- Framework: Next.js 14 (App Router)
- 3D Rendering: Three.js &
@react-three/fiber
- Styling: Tailwind CSS with shadcn/ui
- Animations: GSAP (GreenSock Animation Platform) & Motion One
- Deployment: Vercel
The Challenge: Merging Performance and 3D
The biggest technical challenge was integrating a complex, animated Three.js scene as a background without sacrificing the site's performance and Core Web Vitals. A heavy 3D scene can easily lead to long load times and a sluggish user experience.
My Solution:
1. Dynamic Loading & Lazy Mounting
The MatrixRain
component is the heaviest part of the site. I configured it to be dynamically loaded. More importantly, using GSAP's ScrollTrigger, the component is completely unmounted from the React tree when the user scrolls past the first few sections. This frees up GPU and CPU resources entirely, ensuring the rest of the page remains fast.
2. Performance Monitoring
I used @react-three/drei
's PerformanceMonitor
to automatically downgrade the 3D scene's quality on slower devices, ensuring a smooth experience for all users.
3. Static First
The core content of the portfolio (text, project cards) is statically generated by Next.js. This means the critical information is available to the user and search engines instantly, while the 3D scene loads in the background.
Here's a simplified look at the conditional mounting logic:
// src/components/layout/PageClient.tsx
// State to control if the 3D scene is mounted
const [isMatrixMounted, setIsMatrixMounted] = useState(true);
useGSAP(
() => {
// ... GSAP and ScrollTrigger setup ...
const opacityTrigger = ScrollTrigger.create({
trigger: sections, // The third section of the page
start: 'top bottom',
end: 'top center',
scrub: true,
// When the user scrolls far enough, unmount the component
onLeave: () => setIsMatrixMounted(false),
// When they scroll back up, re-mount it
onLeaveBack: () => setIsMatrixMounted(true),
});
// ...
},
{ scope: mainContainerRef }
);
return (
// ...
<div ref={matrixContainerRef}>
{isMatrixMounted && <MatrixRain cameraControls={cameraControlsRef.current} />}
</div>
// ...
);
What I Learned
- Performance is a Feature: A cool animation is worthless if it makes the site unusable. Prioritizing performance from day one was key.
- The Power of Ecosystems: The combination of Next.js for structure and the
pmndrs
ecosystem (@react-three/fiber
,@react-three/drei
) for 3D is a testament to the power of the React community. - SEO is Not an Afterthought: By building with Next.js and implementing a robust sitemap and structured data strategy, I ensured the site was built to rank from its inception.
This project was a fantastic learning experience that solidified my skills in frontend architecture, performance optimization, and creating visually compelling user interfaces.

Utsav Khatri
Full Stack Developer & Technical Writer
Passionate about building high-performance web applications and sharing knowledge through technical writing. I specialize in React, Next.js, and modern web technologies. Always exploring new tools and techniques to create better digital experiences.
Explore More Topics
Continue Reading
Discover more articles on similar topics that might interest you
Case Study: Building Note Sync Pro with Next.js, Convex, and Gemini AI
A deep dive into the architecture of Note Sync Pro, a modern blog platform featuring a full-stack TypeScript environment, real-time database with Convex, and an AI writing assistant powered by Google Gemini.
React 19 is Officially Here: A Look at the `use` Hook and Actions
The wait is over. React 19 has landed, bringing powerful new client and server features. We'll explore the game-changing `use` hook for data fetching and the seamless integration of Server Actions.
UI Engineering: The Shift from 'What' to 'How'
The role of a UI Engineer has evolved far beyond translating mockups into code. Today, it's about building robust, scalable, and accessible systems. This is a deep dive into the modern responsibilities that define the craft.