--- name: enterprise-web-code description: Enterprise-ready web development for Next.js 16, React, and TypeScript incorporating Kaizen (continuous improvement) and Monozukuri (meticulous craftsmanship) principles. Use this skill when building web applications, APIs, React components, Next.js projects, or when the user requests clean, efficient, fast, simple, elegant, enterprise-grade, bulletproof, or production-ready web code. This skill enforces modern web best practices, TypeScript patterns, React optimization, security, and performance. --- # Enterprise Web Development Build bulletproof, enterprise-ready web applications that embody Kaizen (continuous improvement) and Monozukuri (meticulous craftsmanship) principles. This skill guides development of clean, efficient, performant Next.js 16 and React code that is simple, elegant, and built to last. ## Core Philosophy **Kaizen (改善)**: Continuous improvement through incremental refinement **Monozukuri (ものづくり)**: The art of making things with meticulous attention to quality and craftsmanship These principles translate to web code that is: - **Clean**: Self-documenting, readable, and maintainable - **Efficient**: Optimized bundles and minimal runtime overhead - **Fast**: Performance-first architecture with sub-second load times - **Simple**: Complexity only where justified - **Elegant**: Beautiful solutions that feel inevitable ## Web Development Workflow ### 1. Understand Requirements Deeply Before writing code: - Clarify user experience and functionality goals - Identify edge cases and error scenarios - Consider responsive design and accessibility (WCAG 2.1) - Understand performance budgets and SEO requirements - Plan for internationalization if needed ### 2. Design Before Implementation Plan the architecture: - Choose appropriate Next.js rendering strategy (SSR, SSG, ISR, CSR) - Design component hierarchy and data flow - Plan API routes and data fetching patterns - Consider state management needs (Server Components, Context, Zustand) - Plan for type safety with TypeScript ### 3. Write Code with Craftsmanship **Simplicity First** - Prefer Server Components over Client Components - Use native Web APIs when possible - Avoid premature abstraction - Keep components focused and composable - YAGNI (You Aren't Gonna Need It) **Clean Code Standards** - Meaningful, descriptive names (components, functions, variables) - Components should have single responsibility - Keep components under 200 lines - Extract complex logic into custom hooks - Use early returns to reduce nesting - Comments explain WHY, not WHAT **TypeScript Best Practices** - Use strict mode (`"strict": true`) - Avoid `any` - use `unknown` or proper types - Define interfaces for component props - Use type inference where obvious - Leverage discriminated unions for state - Use Zod for runtime validation **Error Handling** - Use Error Boundaries for React errors - Implement proper error pages (error.tsx, not-found.tsx) - Validate user inputs on client AND server - Provide actionable error messages - Log errors with proper context - Handle loading and error states **Security Mindset** - Sanitize user inputs (prevent XSS) - Use CSRF tokens for mutations - Implement proper authentication (NextAuth.js) - Validate all API inputs with Zod - Use environment variables for secrets - Set proper security headers - Implement rate limiting ### 4. Optimize for Web Performance **Next.js 16 Optimization** - Use Server Components by default - Implement streaming with Suspense - Optimize images with next/image - Use dynamic imports for code splitting - Implement Partial Prerendering (PPR) - Leverage Turbopack for fast builds **React Performance** - Minimize client-side JavaScript - Use React.memo for expensive components - Implement virtual scrolling for long lists - Debounce/throttle event handlers - Avoid inline function definitions in JSX - Use useCallback and useMemo judiciously **Bundle Optimization** - Tree-shake unused code - Use dynamic imports for large dependencies - Analyze bundle with @next/bundle-analyzer - Remove unused dependencies - Use barrel exports carefully (they prevent tree-shaking) **Asset Optimization** - Optimize images (WebP, AVIF formats) - Lazy load images below the fold - Use SVG for icons - Implement font optimization (next/font) - Minimize CSS with CSS modules or Tailwind **Caching Strategy** - Configure proper Cache-Control headers - Use Next.js caching (fetch cache, unstable_cache) - Implement stale-while-revalidate - Use CDN for static assets - Consider Redis for server-side caching ### 5. Ensure Robustness **Comprehensive Testing** - Unit tests for utility functions (Vitest) - Component tests with React Testing Library - E2E tests for critical flows (Playwright) - Visual regression tests (Percy/Chromatic) - API route tests **Accessibility (A11y)** - Semantic HTML elements - ARIA labels where needed - Keyboard navigation support - Screen reader testing - Color contrast compliance (WCAG AA) - Focus management **Progressive Enhancement** - Core functionality works without JS - Graceful degradation - Loading states for all async operations - Optimistic UI updates - Error recovery strategies **Monitoring and Observability** - Implement error tracking (Sentry) - Add performance monitoring (Vercel Analytics) - Log important user actions - Track Core Web Vitals - Set up alerts for errors and performance ### 6. Refine Through Kaizen Continuously improve: - Review and refactor components - Eliminate duplicate code - Improve component composition - Update dependencies regularly - Address technical debt incrementally - Monitor performance metrics ## Code Quality Standards ### File and Folder Structure ``` app/ ├── (auth)/ # Route groups │ ├── login/ │ └── register/ ├── (marketing)/ │ ├── page.tsx │ └── layout.tsx ├── api/ # API routes │ └── users/ │ └── route.ts ├── dashboard/ │ ├── page.tsx │ ├── loading.tsx │ └── error.tsx ├── layout.tsx # Root layout └── globals.css components/ ├── ui/ # Reusable UI components │ ├── button.tsx │ ├── card.tsx │ └── input.tsx └── features/ # Feature-specific components ├── auth/ └── dashboard/ lib/ ├── db.ts # Database client ├── auth.ts # Auth utilities ├── utils.ts # Helper functions └── validations.ts # Zod schemas hooks/ # Custom React hooks ├── use-user.ts └── use-debounce.ts types/ # TypeScript types └── index.ts ``` ### Naming Conventions **Components**: PascalCase (`UserProfile.tsx`, `NavigationBar.tsx`) **Files**: kebab-case for non-components (`api-client.ts`, `use-auth.ts`) **Functions**: camelCase (`fetchUser`, `calculateTotal`, `handleSubmit`) **Constants**: UPPER_SNAKE_CASE (`API_URL`, `MAX_RETRIES`) **Types/Interfaces**: PascalCase (`User`, `ApiResponse`, `ButtonProps`) **Props interfaces**: ComponentNameProps (`ButtonProps`, `CardProps`) ### Component Patterns ```typescript // GOOD: Server Component (default) export default async function UserProfile({ userId }: { userId: string }) { const user = await db.user.findUnique({ where: { id: userId } }); return (