Mosaik

πŸ“ Mosaik Folder Structure & Naming Conventions

This guide documents the folder structure and file naming conventions used in the Mosaik framework.

Mosaik follows a slot-driven, themeable, and hybrid-rendering architecture that encourages clean separation of concerns, modularity, and full SSR with interactivity.


🧠 Overview

src/
β”œβ”€β”€ app/                 # Next.js app directory (layouts, routes, SSR)
β”‚   └── mosaik/          # Main application namespace
β”‚       β”œβ”€β”€ [...section]/
β”‚       β”‚   └── page.tsx        # Entry point for pages in a section
β”‚       β”œβ”€β”€ layout.tsx          # Global app layout (SSR + slots)
β”‚       β”œβ”€β”€ routes.ts           # Async + static route declarations
β”‚       β”œβ”€β”€ state.ts            # Initial state definition
β”‚       └── reducers.ts         # App reducer for global state
β”œβ”€β”€ blocks/             # Smart components (business logic + slots)
β”‚   β”œβ”€β”€ ActionBar.tsx           # Uses actions, provides UI
β”‚   β”œβ”€β”€ ThemedComponent.tsx     # Renders theme-specific components
β”‚   └── hybrid/                 # Hybrid server/client components
β”‚       β”œβ”€β”€ SidebarContent.tsx         # Server wrapper
β”‚       β”œβ”€β”€ SidebarContentClient.tsx   # Client logic
β”‚       β”œβ”€β”€ SidebarActionBar.tsx       # Hydrated version of ActionBar
β”œβ”€β”€ components/         # Dumb/presentational components (unthemed)
β”‚   └── Icon.tsx                # Themed icon helper. Exports used icons.
β”œβ”€β”€ context/            # App-wide providers and hooks
β”‚   └── StateContext.tsx       # Global app state provider (Flux)
β”œβ”€β”€ lib/                # Utility functions and SSR/client helpers
β”‚   β”œβ”€β”€ hooks/                  # React hooks
β”‚   β”‚   └── useThemedComponent.ts
β”‚   β”œβ”€β”€ server/
β”‚   β”‚   └── getThemedComponent.ts     # Loads SSR component for theme
β”‚   └── util/
β”‚       └── getServerUIState.ts       # Parses UI state from cookies
β”œβ”€β”€ layouts/            # Layout components for views/pages
β”‚   └── DesktopColLayout.tsx         # Main desktop layout using slots
β”œβ”€β”€ slots/              # Slot definitions for each layout type
β”‚   β”œβ”€β”€ getDesktopSlots.tsx     # Desktop layout slots
β”‚   β”œβ”€β”€ getSectionSlots.tsx     # Section-specific slots
└── themes/             # Theme definitions (one folder per theme)
    └── default/
        └── {ComponentName}.tsx    # Tiny, purely visual

πŸ“‚ Folder Purposes

app/

Root application entrypoints for Next.js routing. Includes layouts and page-level handlers.

  • layout.tsx: Wraps the entire app (SSR) and injects global context + slots
  • routes.ts: Async + static route list for slot navigation
  • [...section]/: Dynamic route matcher for content pages by section

blocks/

Smart components that manage logic, context, or action orchestration.

  • Each *.tsx file is a block, typically using ThemedComponent, actions, or slots
  • hybrid/: Special folder for hybrid rendering (SSR + hydration)
    • ComponentName.tsx: Server wrapper
    • ComponentNameClient.tsx: Hydrated client logic

components/

Dumb, purely presentational components. Stateless, small, and styled via Tailwind or themes.

  • Should not depend on context or logic
  • Often wrapped by blocks/

context/

React contexts and providers, typically for app-wide state like StateProvider.

  • Follows a Redux-like pattern using actions and effects
  • Hydrated via cookies or server context

lib/

Utilities, shared helpers, and side-effect managers.

  • hooks/: Custom React hooks
  • server/: Server-only logic (e.g. getThemedComponent)
  • effects/: Components that trigger app logic on mount or update
  • util/: Shared logic like reading cookies or parsing UI state

layouts/

Layout shell components that use slots to arrange UI.

  • Purely structural β€” they don’t know about logic or theming
  • Used inside app/ layouts

modules/

Feature bundles that compose logic, slots, and UI into coherent modules.

  • e.g. App.tsx: wraps the whole app in providers
  • Slot.tsx: injects slot content into layout

slots/

Functions that return slot definitions as JSX.

  • Each getXSlots.tsx file describes what content goes into which slot
  • Allows server rendering of layout compositions based on context

themes/

Purely visual. Themed components, selected by name.

  • Loaded dynamically by ThemedComponent
  • Structure: themes/{themeName}/{ComponentName}.tsx

βœ… Naming Conventions

Name Type Convention Example
Block PascalCase .tsx ActionBar.tsx
Hybrid Component ComponentName.tsx (SSR) SidebarContent.tsx
Hybrid Client ComponentNameClient.tsx SidebarContentClient.tsx
Slot Getter getXSlots.tsx getDesktopSlots.tsx
Theme Component Matches block name themes/default/ActionBar.tsx

πŸ”— Learn More

Read the full architecture docs at:

πŸ‘‰ https://mosaik.javascript.moe/mosaik/slots-blocks-and-components


v0.0.1 β€” Mosaik Architecture Guide

v0.0.1
Mosaik