CrootJS Coding Conventions

These rules are mandatory for any code built with CrootJS — whether written by hand or generated by an AI coding agent (Claude Code, Cursor, Copilot, etc). They apply to CrootJS’s own repos (lib, docs, examples, crootjs.github.io) and to any project that imports CrootJS.

1. Separate HTML, CSS, and JS into their own files

A page should look like this:

<!-- index.html -->
<link rel="stylesheet" href="style.css">
...
<button class="copy-btn">Copy</button>
...
<script type="module" src="script.js"></script>
// script.js
document.querySelectorAll('.copy-btn').forEach(btn => {
    btn.addEventListener('click', () => { /* ... */ });
});

Not like this:

<!-- don't -->
<style> .copy-btn { ... } </style>
<button style="color: blue" onclick="doThing()">Copy</button>
<script> function doThing() { ... } </script>

One exception: loading a third-party library from its own CDN (e.g. Lucide icons, SweetAlert2) via a plain <script src="..."> tag is fine — that’s an external dependency, not inline application logic.

2. JavaScript must be loaded as an ES module

Every .js file your page owns must be loaded with type="module":

<script type="module" src="script.js"></script>

Never as a plain classic script. This matches how CrootJS itself is distributed (import { x } from "https://cdn.jsdelivr.net/gh/crootjs/lib@<version>/module.js") and keeps the whole page in strict-mode ES module scope — no accidental globals.

One exception: integrity.js, the file that installs the import map with SRI hashes for CrootJS modules, is a classic script (<script src="integrity.js"></script>), the first script in <head>. An import map must exist before any module starts loading; Firefox ignores one added later, so a module can’t install it, and an inline <script type="importmap"> would break rule 1. The file holds only the import map, no other logic.

3. Import CrootJS from a pinned CDN version

import { getJSON, postJSON } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.43/api.js";

4. No AI slop

Code generated by an AI agent must be as deliberate as hand-written code. These rules are checked in review; breaking one is a reason to reject the change.

  1. Never invent an API. Before calling any CrootJS function, check its name, parameter order, and options against llms.txt or the module’s docs page for the pinned version. If what you need does not exist, write it explicitly in your own code — don’t guess an option and hope.
  2. Use what CrootJS already has. api.js for requests, element.js for DOM by ID, router.js for page routing, table.js for data tables, chart.js for charts, markdown.js for Markdown, qr.js for QR codes, openapi.js for API documentation, map.js for maps, model3d.js for 3D, toast.js for notifications, croot.css and icons.css for styling and icons. Don’t re-implement them, and don’t add a library that duplicates them (Leaflet, Three.js, axios, jQuery, DataTables, Chart.js, marked, Swagger UI, js-yaml, Bootstrap/Bulma, icon fonts).
  3. No dead weight. No unused imports, variables, or functions; no commented-out code; no TODO/placeholder stubs; no “example” functions nobody calls; no files that aren’t needed.
  4. Comments explain why, not what. Don’t narrate each line (// get the value, // import CrootJS). Comment the reason behind a non-obvious choice, in the same language as the rest of the project.
  5. No fake content. No lorem ipsum in finished pages, no invented statistics, testimonials, or claims (“trusted by thousands of developers”). Sample data is labelled as sample data.
  6. Handle errors that can actually happen. Follow each function’s contract (e.g. api.js reports network failure as status: 0); don’t wrap everything in try/catch that swallows errors, and don’t add checks for states that cannot occur.
  7. Stay in scope. Change only what the task needs. Don’t rename, reformat, or restyle unrelated code; don’t “improve” things nobody asked about.
  8. Real HTML, not div soup. Buttons are <button>, inputs have <label>s, everything works with the keyboard and at phone width. No decoration that wasn’t asked for (gradients, emoji, animations; see No “AI look”).
  9. Verify before saying “done”. Open the page through a local server, check the browser console has no errors, and try the feature — including at phone width and with touch if it’s interactive. Say plainly what you did not test.
  10. Pin and minimise dependencies. Exact version tags only (never @latest), and only the modules the page uses.

Quick check before handing work back: Does every CrootJS call exist as written? Is every line used? Did I run it? Did I change anything I wasn’t asked to?

5. No “AI look”

Pages generated by AI tend to look the same, and people notice. A CrootJS page should look like it was made for its users, not like a template. Start from croot.css, the optional ui.css components, a themes.css theme, and the page patterns, and change them only where the product needs it.

Don’t Do instead
Purple/indigo-to-blue gradients, gradient text in headings One accent color from the theme (--croot-accent), used sparingly for links, the primary button, and the current item
Glassmorphism (backdrop-filter: blur), glows, floating blobs Plain surfaces (--croot-surface) separated by borders (--croot-border) and whitespace
Shadows and big rounded corners on every card The theme’s --croot-radius; a shadow only on things that float (dialogs, menus)
Emoji as icons, icons in colored circles icons.css icons next to text, or no icon at all
Three identical feature cards with an icon, a title, and two lines A short list or a table that says what the product does; real screenshots, labelled
Web fonts like Inter or Poppins by default The system font stack from croot.css, or a theme’s heading font
Hero sections with a slogan and two buttons on every page Put the task first: a back-office page opens on its data, a form on its first field
Marketing copy (“seamless”, “blazing fast”, “trusted by thousands”) Plain sentences about what the page does; no invented numbers or testimonials
Animations on scroll, hover lifts, spinning loaders .skeleton while loading, and motion only where it explains a change (respect prefers-reduced-motion)
Colour as the only signal (red/green badges) Text plus colour: “Naik 4%”, “Gagal”, aria-current, icons with labels

Check before handing back: Would this page look out of place next to the CrootJS docs and examples? Could you tell which tool generated it? If yes, remove the decoration until it can’t.

6. A 404.html next to every index.html

Every site (the folder that holds the site’s index.html, usually the repo root on GitHub Pages) must also have a 404.html in the same folder. GitHub Pages and most static hosts show it for every address that doesn’t exist in that site, instead of their own generic error page.

For AI coding agents

If you (an AI agent) are building or editing a page that uses CrootJS, drop CLAUDE.md into the project root — Claude Code (and compatible agents that read a root instructions file) will pick these rules up automatically:

curl -o CLAUDE.md https://raw.githubusercontent.com/crootjs/lib/main/CLAUDE.md

Read it in a browser at croot.js.org/lib/CLAUDE.