- Home
- Skills
- Frontend & Web Apps
- Nextjs Architect
Nextjs Architect
Refactor Next.js and React directories by splitting large components and extracting logic into hooks and services.
Free
Nextjs Architect
Example session with this skill installed
Refactor the /components/dashboard directory. It has a massive DashboardView.tsx file with inline fetch calls and a lot of state.
- Read your context and instructions
- Compiled the nextjs architect
- Generated the UI component
Refactor plan for /components/dashboard has been completed and verified. I have extracted logic into hooks, moved API calls to services, and enforced component colocation.
Refactor Results
| Metric | Details |
|---|---|
| Files Created | 8 files (3 components, 2 hooks, 1 service, 2 barrels) |
| Components | DashboardHeader, StatGrid, ActivityChart |
| Hooks | useDashboardData, useFilterState |
| Services | dashboardApi.ts (fetchStats, fetchActivity) |
| Directives | Moved "use client" from DashboardView.tsx to ActivityChart.tsx |
// components/dashboard/_services/dashboardApi.ts
export const fetchStats = async (userId: string): Promise<Stats[]> => {
const res = await fetch(`/api/stats?userId=${userId}`);
if (!res.ok) throw new Error("Failed to fetch stats");
return res.json();
};
// components/dashboard/_hooks/useDashboardData.ts
import { useState, useEffect } from "react";
import { fetchStats } from "../_services";
export const useDashboardData = (userId: string) => {
const [stats, setStats] = useState<Stats[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetchStats(userId).then(setStats).finally(() => setLoading(false));
}, [userId]);
return { stats, loading };
};
Next steps
- Review the
_components/index.tsbarrel exports to ensure only public components are exposed. - Run
npm run testto verify that the logic remains consistent after extraction. - Check the
ActivityChartcomponent to confirm the"use client"boundary is correctly placed.
DashboardView.tsx
TSX · React component
Example file from a real run - the skill writes it into your workspace.
Connects securely to your tools. The creator never sees your data.
About this skill
Stop struggling with bloated Next.js files and messy "use client" directives. This skill systematically refactors your React directories to enforce clean architecture and colocation best practices.
What it does
- Component splitting identifies files over 80 lines or deeply nested JSX to break them into manageable units.
- Logic extraction moves state, effects, and complex handlers into custom hooks within a dedicated
_hooks/directory. - Service layer creation pulls all API calls and HTTP client usage into typed service functions.
- Client boundary optimization moves the
"use client"directive to leaf components to maximize server-side rendering. - Automatic grouping creates subdirectories for components with three or more exclusive dependencies to hide implementation details.
How it works
- Analyze: The skill scans your target directory to map component relationships, hooks, and API usage.
- Plan: It generates a comprehensive refactor plan, including a tree preview of the new structure and proposed splits.
- Execute: After your approval, it creates
_components/,_hooks/, and_services/folders and migrates code. - Verify: It runs TypeScript checks, linters, and build scripts to ensure no breaking changes were introduced.
Frameworks & tools
Works with Next.js (App and Pages Router) and plain React projects. Supports TypeScript, JavaScript, and various package managers like npm, pnpm, and Bun.
Why this beats prompting it yourself
Writing prompts to manage complex file moves often results in broken imports or inconsistent folder structures. This skill uses strict rules for colocation and transitive dependencies, ensuring your architecture remains predictable and scalable without manual cleanup.
Use cases
- Cleanup technical debt by refactoring 500-line "god components" into modular units.
- Migrate to App Router by optimizing client/server component boundaries for better performance.
- Standardize directories across a team by enforcing one-component-per-file and barrel exports.
Known limitations
Does not support automatic migration of state management libraries like Redux or XState. Requires a functional build/lint setup to verify the refactor successfully.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 17 days ago
- Free with an Agensi account
- Software
Node.jstsc
Permissions
What's inside
Frequently Asked Questions
New in Frontend & Web Apps
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Frontend & Web Apps.