@katebtech/core
Core utilities, shared types, validation, security helpers, database utilities, and common functions.
KatebTech Core
Shared core utilities, primitive UI components, route builders, and foundational patterns for Kateb Tech projects.
Purpose
@katebtech/core contains reusable low-level building blocks used across Kateb Tech websites and apps.
It should stay focused on primitives, generic helpers, shared public types, and foundational patterns. Website-specific business logic, layouts, page sections, app data, SEO, and feature workflows belong in the consuming app or in a higher-level package.
Package Overview
This package provides:
- primitive UI components such as
Button,Header,P,List, and form controls - server action helpers for parsing
FormData, converting checkbox values, and returning validation errors - form security helpers for bot-trap checks, request validation, client IP lookup, and Cloudflare Turnstile verification
- shared route builders for auth, admin, blog, public, API, and public resource paths
- shared content assets and language statements
- date, database, SVG, URL, class name, RTL text, environment, and slug helpers
File Structure
src
├── button
├── content
├── date
├── db
├── form
│ ├── actions
│ ├── controls
│ ├── fields
│ └── security
├── routes
├── svg
├── typography
├── utils
└── index.ts| Folder | Purpose |
|---|---|
src/button | Button primitive and public button types. |
src/content | Shared content constants and reusable content display components. |
src/date | Date formatting and HTML date-input conversion helpers. |
src/db | Shared database helpers, such as the PostgreSQL client factory. |
src/form/actions | Server action helpers, form parsing, Zod error conversion, boolean conversion, and action types. |
src/form/controls | Reusable form UI primitives such as Input, Textarea, Select, Checkbox, and error components. |
src/form/fields | Shared form field-name constants such as CONTACT_FIELDS. |
src/form/security | Form security helpers and UI fields such as checkFormBotTrap and FormBotTrapFields. |
src/routes | Central route builders shared by websites and web apps. |
src/svg | SVG helpers and Kateb Tech app illustration exports. |
src/typography | Typography primitives such as Header and P. |
src/utils | General utilities such as cn, environment helpers, URLs, RTL checks, and slug helpers. |
Import Style
Prefer specific package subpaths when consuming package APIs:
import { Button } from "@katebtech/core/button";
import { KATEB_TECH_LOGO } from "@katebtech/core/content";
import { formatDateTimeAU } from "@katebtech/core/date";
import { createSqlClient } from "@katebtech/core/db";
import { parseActionFormData } from "@katebtech/core/form/actions";
import { Input } from "@katebtech/core/form/controls";
import { CONTACT_FIELDS } from "@katebtech/core/form/fields";
import { checkFormBotTrap } from "@katebtech/core/form/security";
import { adminRoutes } from "@katebtech/core/routes";
import { svgToDataUrl } from "@katebtech/core/svg";
import { Header } from "@katebtech/core/typography";
import { cn } from "@katebtech/core/utils";The root import is available for broad convenience, but package-level code should usually import from the narrow subpath that owns the API.
Inside this package, use relative imports:
import { FieldError } from "./FieldError";Avoid importing the package from itself:
import { FieldError } from "@katebtech/core/form/controls";Package Rules
Keep @katebtech/core small, reusable, and predictable.
- Export public components, helpers, and useful public types from each module
index.ts. - Keep internal implementation types private.
- Use PascalCase for React components.
- Use camelCase for functions and variables.
- Use UPPER_SNAKE_CASE for shared constants.
- Use descriptive file and folder names.
- Avoid
anyunless the API requires it. - Prefer explicit public types,
readonlydata, discriminated unions for result shapes, andas constfor useful literal types. - Use relative imports inside the package.
- Avoid circular dependencies.
- Do not depend on higher-level packages such as
@katebtech/layoutor app packages.
Dependency direction:
@katebtech/core
↓
@katebtech/layout
↓
@katebtech/pages or app packagesModule Documentation
Button
Exports:
ButtonButtonPropsButtonVariantButtonSize
Import:
import { Button } from "@katebtech/core/button";Use Button for shared button styling across button and Next.js link usage.
Content
Exports:
KATEB_TECH_LOGOListENGLISH_LANGUAGE_STATEMENTOTHER_LANGUAGES_STATEMENTEnglishLanguageKeyEgnlishLanguageKeydeprecated aliasOtherLanguageKeyOtherLanguageListProps
Import:
import { KATEB_TECH_LOGO, List } from "@katebtech/core/content";Use content exports for shared brand assets, reusable content lists, and shared language statements.
Date
Exports:
formatDateTimeAUtoLocalDateTimeInput
Import:
import { formatDateTimeAU, toLocalDateTimeInput } from "@katebtech/core/date";Use date helpers for shared Australian date-time formatting and date input conversion.
Database
Exports:
createSqlClientSqlFragment
Import:
import { createSqlClient, type SqlFragment } from "@katebtech/core/db";Use createSqlClient to create a PostgreSQL client with shared defaults. Application-specific tables, migrations, queries, and repository functions should stay inside the app that owns the data.
Form Actions
Exports:
parseActionFormDataparseFormDataformDataToObjecttoActionErrorstoActionErrors2toBooleanActionStateFieldErrorsBooleanKeysCamelizeKeysParseActionFormDataOptionsParseActionFormDataResultParseFormDataOptionsFormDataToObjectOptions
Import:
import { parseActionFormData, toBoolean } from "@katebtech/core/form/actions";
import type { ActionState } from "@katebtech/core/form/actions";Basic usage:
import { parseActionFormData } from "@katebtech/core/form/actions";
import { z } from "zod";
const schema = z.object({
email: z.email("Enter a valid email address."),
subscribe: z.boolean(),
});
export const submitForm = async (
_previousState: unknown,
formData: FormData,
) => {
const result = parseActionFormData({
formData,
schema,
booleanFields: ["subscribe"],
});
if (!result.ok) {
return result.state;
}
return {
ok: true,
message: "Submitted successfully.",
};
};Use these helpers inside server actions to keep form parsing, validation, and error shapes consistent.
Form Controls
Exports:
CheckboxFieldErrorFormErrorsMessageInputSelectTextareaCheckboxPropsFieldErrorPropsFormErrorsMessagePropsInputPropsSelectOptionSelectPropsTextareaProps
Import:
import {
Checkbox,
Input,
Select,
Textarea,
} from "@katebtech/core/form/controls";Basic usage:
<Input id="email" label="Email" type="email" required />
<Select
id="service"
label="Service"
options={[
{ value: "web-design", label: "Web Design" },
{ value: "seo", label: "SEO" },
]}
/>Use these components for reusable form UI. Select is a native select component; it submits the selected value and accepts a standard select onChange handler.
Form Fields
Exports:
CONTACT_FIELDS
Import:
import { CONTACT_FIELDS } from "@katebtech/core/form/fields";Use field constants to keep UI controls, validation schemas, and server actions aligned.
Form Security
Exports:
FormBotTrapFieldsTurnstileWidgetTURNSTILEcheckAllowedFormRequestcheckFormBotTrapgetClientIpverifyTurnstileTokenFormBotTrapFieldsPropsTurnstileActionTurnstileWidgetProps
Import:
import {
FormBotTrapFields,
TurnstileWidget,
checkAllowedFormRequest,
checkFormBotTrap,
getClientIp,
verifyTurnstileToken,
} from "@katebtech/core/form/security";Basic usage:
<form action={formAction} noValidate>
<FormBotTrapFields />
<TurnstileWidget siteKey={siteKey} action="contact-enquiry" />
<button type="submit">Submit</button>
</form>Application code remains responsible for allowed domains, Turnstile keys, validation, rate limiting, logging, email delivery, and application-specific database operations.
Routes
Exports:
adminRoutesapiRoutesauthRoutesblogRoutespublicResourcespublicRoutes- route constants
Import:
import { adminRoutes, authRoutes, blogRoutes } from "@katebtech/core/routes";Use route helpers instead of scattering hard-coded shared route strings through components, actions, redirects, navigation, or metadata.
SVG
Exports:
escapeSvgTextkatebTechnologyIllustrationsvgToDataUrl
Import:
import { katebTechnologyIllustration, svgToDataUrl } from "@katebtech/core/svg";Use SVG helpers for package-owned SVG rendering and data URL generation.
Typography
Exports:
HeaderPAsTagHeaderPropsHeadingAlignHeadingSizeParaSizePProps
Import:
import { Header, P } from "@katebtech/core/typography";Use typography components for shared heading and paragraph styling. Use as on Header for semantic heading structure.
Utils
Exports:
cnrequiredEnvisRTLTextslugifyunSlugify- URL helpers from
src/utils/url.ts
Import:
import { cn, getBaseUrl, requiredEnv, slugify } from "@katebtech/core/utils";Use utilities for class merging, environment checks, URL creation, RTL detection, and slug conversion.