This document provides the context, code style, and architectural rules for AI agents contributing to the KeraKit project. Adhering to these guidelines is mandatory to ensure code quality, consistency, and performance.
- Project: KeraKit
- Goal: To build a new, modern, and performant library for the Kera Desktop ecosystem.
- Context: This project supersedes
kerapi-oldandkera-desktop-old. These legacy projects serve only as a reference for existing functionality and user-facing features. - DO NOT migrate code directly from the old projects. All functionality must be re-implemented from scratch using the modern principles outlined below.
These are the non-negotiable rules for all code generation:
- No TypeScript: The project is strictly JavaScript only. Do not generate or suggest any TypeScript (
.ts,.tsx,interface,type, etc.). - Latest ECMAScript: Use the latest stable ECMAScript (ESM) features. All code must be written using ES Modules (
import/export). - Functional Programming (FP): This is a strong architectural preference.
- Immutability: Avoid mutations. Use non-mutating array methods (
map,filter,reduce,toSorted,toSpliced). UseObject.freezein development where appropriate. - Pure Functions: Strive for pure functions whenever possible.
- Composition: Favor function composition over class-based inheritance.
- State: Avoid
letin favor ofconst. Minimize and isolate state.
- Immutability: Avoid mutations. Use non-mutating array methods (
- Simplicity: Do not over-complicate the code. Prefer simple, clear, and readable solutions. Avoid clever "one-liners" that sacrifice readability.
- Performance: Performance is critical. Write efficient code, but avoid micro-optimizations. Focus on good algorithms, appropriate data structures, and avoiding unnecessary work.
- Tooling: The project uses
pnpm. All package management commands must usepnpm(e.g.,pnpm install,pnpm add,pnpm run).
JSDoc is mandatory for all files, functions, and complex data structures.
File Header:
All .js and .mjs files must begin with this JSDoc block:
/**
* @file Brief description of what this file does.
* @module KeraKit/YOUR_MODULE_NAME
* @copyright (C) 2025 Mutlu Can Yilmaz
* @license MIT
*/Type Definitions:
- Use lowercase
objectfor generic objects, notObject. - Use
Array<string>orstring[](preferArray<string>for consistency). - Use JSDoc typedefs for complex objects.
/**
* Represents a user configuration.
* @typedef {object} UserConfig
* @property {string} id - The user's unique identifier.
* @property {boolean} [isPremium] - Optional premium status.
*/Importing Types for JSDoc:
To use a type defined in another file, use @import at the top of the JSDoc block (not inline).
/**
* @import { UserConfig } from './userTypes.js'
*
* Processes a user's configuration.
*
* @param {UserConfig} config - The user config object.
* @returns {string} The processed ID.
*/
function processUser(config) {
return `processed-${config.id}`;
}- Modules: Always use
importandexport. Do not use CommonJS (require/module.exports). - Variables: Default to
const. Only useletwhen reassignment is necessary (and question if it can be refactored). - Functions: Prefer arrow functions (
const myFunc = () => {}) for most module-level functions and callbacks, especially when FP-style is desired. - Async/Await: Use
async/awaitfor asynchronous operations. Usetry...catchblocks for error handling. - Modern Features: Use optional chaining (
?.), nullish coalescing (??), and object/array destructuring where it improves clarity.