A technical guide to the Grid Weaver application's architecture, core logic, and components.
← Back to Grid Weaver AppUser Documentation →Grid Weaver is a Next.js application built with React, TypeScript, ShadCN UI components, and Tailwind CSS. It uses Immer for immutable state management.
/src/app: Next.js App Router pages (page.tsx, documentation/page.tsx, code-documentation/page.tsx). Global styles (globals.css) and layout (layout.tsx)./src/components: Reusable React components. UI primitives in /ui, application-specific components otherwise./src/hooks: useGridGenerator.ts (core logic), use-toast.ts, use-mobile.ts./src/lib: Utility functions (utils.ts)./src/types: TypeScript definitions (grid.ts).useGridGenerator.tsGridConfig):rows, cols: Global grid dimensions (numbers).rowGapValue, rowGapUnit, colGapValue, colGapUnit, justifyItems, alignItems.responsiveContainerStyles: Optional object storing Partial<ContainerStyleProperties> for 'tablet' and 'mobile' overrides for container gaps and alignments.items: Array of GridItemConfig objects. Each stores its base (desktop) layout and optionally, responsiveLayouts for tablet and mobile item-specific layout overrides.nextItemId, selectedItemId, activeBreakpoint.setActiveBreakpoint(breakpoint): Switches editing context.getEffectiveLayout(item, breakpoint): Computes item layout by layering base + responsive overrides.getEffectiveContainerStyles(breakpoint): Computes container styles (gaps, alignments) by layering base + responsive overrides.currentDisplayItems / currentEffectiveContainerStyles (Memoized): Provide data for the active breakpoint to UI components.setRows, setCols adjust item boundaries if needed.setRowGapValue, setColGapUnit, setJustifyItems, etc. These update base (Desktop) styles or responsive overrides in responsiveContainerStyles based on activeBreakpoint. They prune overrides if they match the inherited value.addGridItem, updateGridItem (handles base item properties or responsive layout overrides), removeGridItem (deletes item or clears breakpoint layout).clearGridItemsAndContainerStyles(): Contextual. Clears all desktop items & resets desktop container styles, or clears responsive overrides (items & container) for tablet/mobile.generatedCss (Memoized):.grid-container styles (base from Desktop effective styles).@media (max-width: 990px): Includes CSS for container style overrides (if different from Desktop) and item layout overrides (if different from Desktop).@media (max-width: 767px): Similar for Mobile, comparing against effective Tablet styles.generatedHtml (Memoized): Simple HTML with .grid-container and item divs with classes and inline background colors.generatedTailwindMarkup (Memoized):md: and lg: prefixes for differences).md:, lg: prefixes).GridWeaverApp.tsx: Main app component, initializes hook, passes state/callbacks. Manages "Clear" button logic.GridPreview.tsx: Renders interactive grid. Uses effective container styles for gaps. Handles item creation, selection, resizing.GridControls.tsx: Inputs for grid parameters. Receives effective container styles for the active breakpoint. Calls setters from hook.ItemControls.tsx: Inputs for selected item properties. Edits are contextual to activeBreakpoint.ResponsiveControls.tsx: Buttons to switch activeBreakpoint.CssOutput, HtmlOutput, TailwindMarkupOutput display generated code.src/types/grid.ts)ContainerStyleProperties: Defines shape for rowGapValue, rowGapUnit, colGapValue, colGapUnit, justifyItems, alignItems.GridConfig: Main state object. Holds global rows/cols, base (Desktop) container styles, and responsiveContainerStyles for tablet/mobile overrides. Also holds items array.GridItemConfig: Core item interface. Includes base layout properties and responsiveLayouts for 'tablet'/'mobile' item overrides.GridUnits, SelfAlignment, ItemLayoutProperties, BreakpointKey.The responsive design uses a "Desktop-first, with overrides" model for both container styles and item layouts:
GridControls are saved into gridConfig.responsiveContainerStyles.tablet.item.responsiveLayouts.tablet.responsiveContainerStyles.mobile and item.responsiveLayouts.mobile.getEffectiveContainerStyles and getEffectiveLayout compute the actual styles for any breakpoint by applying the hierarchy: Desktop -> Tablet Overrides -> Mobile Overrides.md:/lg: prefixes).GridPreview.tsxUses pointer events for item creation (Desktop only), selection, and resizing (with live snapping preview via resizePreviewLayout state).
globals.css for theme CSS variables.