Guidelines
Dark & Light Mode
Section titled “Dark & Light Mode”Mini-apps must work in both themes. The design system CSS handles this automatically when you use CSS variables and components:
- Use CSS variables (
var(--color-background),var(--color-foreground), etc.) instead of hardcoded colors - Use
@kinbot/componentswhich auto-adapt to the current theme - Never hardcode
#ffffffor#000000for backgrounds/text - Test both modes by toggling the theme in KinBot settings
/* ✅ Good */.my-element { background: var(--color-card); color: var(--color-foreground); }
/* ❌ Bad */.my-element { background: white; color: black; }Sidebar-Aware Design
Section titled “Sidebar-Aware Design”Mini-apps typically run in a side panel (320-600px wide). Design accordingly:
- Mobile-first layout — single column by default, expand with breakpoints
- Use responsive utilities —
md:grid-cols-2for wider views - Use
useBreakpoint()oruseMediaQuery()for JS-level responsive logic - Support full-page mode — use
isFullPagefromuseKinBot()to adjust layout - Avoid horizontal scrolling — keep content within the panel width
function App() { const { isFullPage } = useKinBot(); const bp = useBreakpoint();
return ( <Grid columns={isFullPage && bp !== "xs" ? 2 : 1} gap="16px"> <Sidebar /> <Content /> </Grid> );}Use Existing Components
Section titled “Use Existing Components”Before building custom UI, check if @kinbot/components has what you need. The library includes 50+ components covering most common patterns:
- DataGrid instead of building custom tables with sorting/pagination
- Form compound component instead of manual form state management
- Modal/Drawer instead of custom overlays
- Kanban for board layouts
- Charts (Bar, Line, Pie, SparkLine) for data visualization
Using built-in components ensures consistent styling, theme support, and accessibility.
Consult Examples
Section titled “Consult Examples”Look at existing mini-apps and templates for patterns:
- Use
get_mini_app_templatesto see available templates with full source code - Templates cover common patterns: dashboard, todo list, form, data viewer, kanban, responsive layout
Performance
Section titled “Performance”- Lazy load heavy content — use
useInfiniteScrollorusePaginationfor large datasets - Debounce search inputs — use
useDebounceto avoid excessive API calls - Use
useLocalStoragefor UI state that doesn’t need server sync (collapsed panels, sort preferences) - Avoid unnecessary re-renders — use
usePreviousto compare state changes
React Patterns
Section titled “React Patterns”- Always call
useKinBot()first and wait forready - Use
useStoragefor persistent state,useStatefor ephemeral UI state - Use
useAsyncfor mutations (POST, DELETE) to get loading/error states - Use
useApifor GET requests that auto-fetch on mount - Use JSX with
<script type="text/jsx">— it’s transpiled server-side, no build step needed
Backend Best Practices
Section titled “Backend Best Practices”- Keep
_server.jsfocused — one backend per app - Use
ctx.storagefor data persistence (same namespace as frontend) - Use
ctx.events.emit()for real-time updates instead of polling - Use
ctx.logfor debugging (tagged with app name in server logs)
File Organization
Section titled “File Organization”For complex apps, split code across multiple files:
index.html — Entry point + main app componentapp.json — Dependencies_server.js — Backend (if needed)styles.css — Custom styles (if needed)components/*.jsx — Additional React componentsReference them with relative paths:
<link rel="stylesheet" href="styles.css"><script type="text/jsx" src="components/sidebar.jsx"></script>Accessibility
Section titled “Accessibility”- Use semantic HTML and component props (
label,erroron inputs) - Support keyboard navigation (the component library handles this for most cases)
- Provide meaningful
alttext for images - Respect
prefers-reduced-motion(built-in animations do this automatically)