π 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 + slotsroutes.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 usingThemedComponent
,actions
, orslots
hybrid/
: Special folder for hybrid rendering (SSR + hydration)ComponentName.tsx
: Server wrapperComponentNameClient.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 hooksserver/
: Server-only logic (e.g.getThemedComponent
)effects/
: Components that trigger app logic on mount or updateutil/
: 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