Singleton
javascriptShare one global instance for application-wide coordination.
src/lib/patterns/javascript/singleton.tsAtomic Next.js boilerplate
A ready starting point for App Router projects with atomic UI folders, Redux Toolkit wiring, strict TypeScript, and a practical map of JavaScript, React, Next.js, and performance patterns.
Patterns are examples and defaults, not mandatory architecture. Apply them where they solve a concrete problem.
Share one global instance for application-wide coordination.
src/lib/patterns/javascript/singleton.tsIntercept reads and writes to another object.
src/lib/patterns/javascript/proxy.tsShare behavior through a prototype object.
src/lib/patterns/javascript/prototype.tsNotify subscribed listeners when an event occurs.
src/lib/patterns/javascript/observer.tsExpose a small API while keeping implementation details private.
src/lib/patterns/javascript/module.tsAdd reusable behavior to objects without inheritance.
src/lib/patterns/javascript/mixin.tsRoute work through a central pipeline instead of coupling callers.
src/lib/patterns/javascript/mediatorMiddleware.tsReuse existing instances for repeated identical values.
src/lib/patterns/javascript/flyweight.tsCreate objects through a function that hides construction details.
src/lib/patterns/javascript/factory.tsImport critical code eagerly at module load time.
Use regular ES module imports for above-the-fold dependencies.Load code on demand with import() or next/dynamic.
src/lib/patterns/react/rendering.tsDefer non-critical resources until a section enters the viewport.
src/features/patterns/hooks/useIntersection.tsLoad optional code after explicit user intent.
Wire dynamic import calls inside click, focus, or hover handlers.Use routes as natural JavaScript bundle boundaries.
Next.js App Router creates route-level chunks by default.Split application code into smaller reusable chunks.
Prefer route boundaries, dynamic imports, and isolated feature modules.Push or preload critical assets, render quickly, precache, and lazy load the rest.
Use Next prefetching, metadata links, route splitting, and lazy components.Let the bundler remove unused exports.
Keep modules side-effect-light and prefer named exports for utilities.Tell the browser about critical resources early.
Use Next metadata or explicit link rel="preload" for critical assets.Fetch likely future resources before they are requested.
Use next/link prefetching for likely navigation paths.Load external scripts intentionally to protect page responsiveness.
Use next/script strategies and avoid blocking critical rendering.Render only visible rows for very large lists.
Adopt a virtualization library when lists become large enough to need it.Reduce transferred JavaScript bytes with compression.
Deploy behind compression-enabled hosting such as Vercel or a CDN.Use the View Transitions API for continuity between UI states.
Guard document.startViewTransition before using browser-only transitions.Prioritize the resources needed for the first usable screen.
Keep the initial route server-rendered and push non-critical work behind lazy boundaries.Keep data and orchestration separate from rendering components.
src/features/patterns/containers/PatternExplorerContainer.tsxWrap a component to add reusable behavior through props.
src/lib/patterns/react/withPatternTelemetry.tsxPass rendering control as a function prop.
src/lib/patterns/react/RenderPropData.tsxReuse stateful behavior with functions.
src/features/patterns/hooks/usePatternFilter.tsCompose related components that cooperate through shared context.
src/lib/patterns/react/CompoundTabs.tsxRender interactive UI in the browser with client components.
Use "use client" components for browser-only state and events.Generate HTML on the server for each request when data is dynamic.
Use server components or dynamic route rendering in Next.js.Pre-render stable HTML at build time.
Next.js statically renders routes by default when possible.Refresh static content after deployment.
Use fetch revalidate or route segment revalidate in Next.js.Hydrate less important interactive regions later.
Use server components first, then lazy client islands for lower-priority UI.Stream HTML chunks as the server resolves them.
Use Suspense boundaries and loading.tsx files in the App Router.Render components on the server without shipping their JavaScript.
Keep route and template components server-side unless interactivity is needed.Use Next.js primitives that protect loading, layout, and responsiveness metrics.
Prefer next/image, next/font, next/script, and route-level streaming.Use modern React stack defaults for routing, rendering, state, and data fetching.
This boilerplate uses App Router, server/client component boundaries, and Redux Toolkit.