mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-04-16 02:21:31 +00:00
* fix: remove project dependency from settings controller and onboarding * fix(settings): remove onClose prop from useSettingsController args * chore: tailwind classes order * refactor: move provider auth status management to custom hook * refactor: rename SessionProvider to LLMProvider * feat(frontend): support for @ alias based imports) * fix: replace init.sql with schema.js * fix: refactor database initialization to use schema.js for SQL statements * feat(server): add a real backend TypeScript build and enforce module boundaries The backend had started to grow beyond what the frontend-only tooling setup could support safely. We were still running server code directly from /server, linting mainly the client, and relying on path assumptions such as "../.." that only worked in the source layout. That created three problems: - backend alias imports were hard to resolve consistently in the editor, ESLint, and the runtime - server code had no enforced module boundary rules, so cross-module deep imports could bypass intended public entry points - building the backend into a separate output directory would break repo-level lookups for package.json, .env, dist, and public assets because those paths were derived from source-only relative assumptions This change makes the backend tooling explicit and runtime-safe. A dedicated backend TypeScript config now lives in server/tsconfig.json, with tsconfig.server.json reduced to a compatibility shim. This gives the language service and backend tooling a canonical project rooted in /server while still preserving top-level compatibility for any existing references. The backend alias mapping now resolves relative to /server, which avoids colliding with the frontend's "@/..." -> "src/*" mapping. The package scripts were updated so development runs through tsx with the backend tsconfig, build now produces a compiled backend in dist-server, and typecheck/lint cover both client and server. A new build-server.mjs script runs TypeScript and tsc-alias and cleans dist-server first, which prevents stale compiled files from shadowing current source files after refactors. To make the compiled backend behave the same as the source backend, runtime path resolution was centralized in server/utils/runtime-paths.js. Instead of assuming fixed relative paths from each module, server entry points now resolve the actual app root and server root at runtime. That keeps package.json, .env, dist, public, and default database paths stable whether code is executed from /server or from /dist-server/server. ESLint was expanded from a frontend-only setup into a backend-aware one. The backend now uses import resolution tied to the backend tsconfig so aliased imports resolve correctly in linting, import ordering matches the frontend style, and unused/duplicate imports are surfaced consistently. Most importantly, eslint-plugin-boundaries now enforces server module boundaries. Files under server/modules can no longer import another module's internals directly. Cross-module imports must go through that module's barrel file (index.ts/index.js). boundaries/no-unknown was also enabled so alias-resolution gaps cannot silently bypass the rule. Together, these changes make the backend buildable, keep runtime path resolution stable after compilation, align server tooling with the client where appropriate, and enforce a stricter modular architecture for server code. * fix: update package.json to include dist-server in files and remove tsconfig.server.json * refactor: remove build-server.mjs and inline its logic into package.json scripts * fix: update paths in package.json and bin.js to use dist-server directory * feat(eslint): add backend shared types and enforce compile-time contract for imports * fix(eslint): update shared types pattern --------- Co-authored-by: Haileyesus <something@gmail.com>
231 lines
10 KiB
JavaScript
231 lines
10 KiB
JavaScript
import js from "@eslint/js";
|
|
import tseslint from "typescript-eslint";
|
|
import react from "eslint-plugin-react";
|
|
import reactHooks from "eslint-plugin-react-hooks";
|
|
import reactRefresh from "eslint-plugin-react-refresh";
|
|
import { createNodeResolver, importX } from "eslint-plugin-import-x";
|
|
import { createTypeScriptImportResolver } from "eslint-import-resolver-typescript";
|
|
import boundaries from "eslint-plugin-boundaries";
|
|
import tailwindcss from "eslint-plugin-tailwindcss";
|
|
import unusedImports from "eslint-plugin-unused-imports";
|
|
import globals from "globals";
|
|
|
|
export default tseslint.config(
|
|
{
|
|
ignores: ["dist/**", "node_modules/**", "public/**"],
|
|
},
|
|
{
|
|
files: ["src/**/*.{ts,tsx,js,jsx}"],
|
|
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
|
plugins: {
|
|
react,
|
|
"react-hooks": reactHooks, // for following React rules such as dependencies in hooks, keys in lists, etc.
|
|
"react-refresh": reactRefresh, // for Vite HMR compatibility
|
|
"import-x": importX, // for import order/sorting. It also detercts circular dependencies and duplicate imports.
|
|
tailwindcss, // for detecting invalid Tailwind classnames and enforcing classname order
|
|
"unused-imports": unusedImports, // for detecting unused imports
|
|
},
|
|
languageOptions: {
|
|
globals: {
|
|
...globals.browser,
|
|
},
|
|
parserOptions: {
|
|
ecmaFeatures: { jsx: true },
|
|
},
|
|
},
|
|
settings: {
|
|
react: { version: "detect" },
|
|
},
|
|
rules: {
|
|
// --- Unused imports/vars ---
|
|
"unused-imports/no-unused-imports": "warn",
|
|
"unused-imports/no-unused-vars": [
|
|
"warn",
|
|
{
|
|
vars: "all",
|
|
varsIgnorePattern: "^_",
|
|
args: "after-used",
|
|
argsIgnorePattern: "^_",
|
|
},
|
|
],
|
|
"no-unused-vars": "off",
|
|
"@typescript-eslint/no-unused-vars": "off",
|
|
|
|
// --- React ---
|
|
"react/jsx-key": "warn",
|
|
"react/jsx-no-duplicate-props": "error",
|
|
"react/jsx-no-undef": "error",
|
|
"react/no-children-prop": "warn",
|
|
"react/no-danger-with-children": "error",
|
|
"react/no-direct-mutation-state": "error",
|
|
"react/no-unknown-property": "warn",
|
|
"react/react-in-jsx-scope": "off",
|
|
|
|
// --- React Hooks ---
|
|
"react-hooks/rules-of-hooks": "error",
|
|
"react-hooks/exhaustive-deps": "warn",
|
|
|
|
// --- React Refresh (Vite HMR) ---
|
|
"react-refresh/only-export-components": [
|
|
"warn",
|
|
{ allowConstantExport: true },
|
|
],
|
|
|
|
// --- Import ordering & hygiene ---
|
|
"import-x/no-duplicates": "warn",
|
|
"import-x/order": [
|
|
"warn",
|
|
{
|
|
groups: [
|
|
"builtin",
|
|
"external",
|
|
"internal",
|
|
"parent",
|
|
"sibling",
|
|
"index",
|
|
],
|
|
"newlines-between": "always",
|
|
},
|
|
],
|
|
|
|
// --- Tailwind CSS ---
|
|
"tailwindcss/classnames-order": "warn",
|
|
"tailwindcss/no-contradicting-classname": "warn",
|
|
"tailwindcss/no-unnecessary-arbitrary-value": "warn",
|
|
|
|
// --- Disabled base rules ---
|
|
"@typescript-eslint/no-explicit-any": "off",
|
|
"@typescript-eslint/no-require-imports": "off",
|
|
"no-case-declarations": "off",
|
|
"no-control-regex": "off",
|
|
"no-useless-escape": "off",
|
|
},
|
|
},
|
|
{
|
|
files: ["server/**/*.{js,ts}"], // apply this block only to backend source files
|
|
ignores: ["server/**/*.d.ts"], // skip generated declaration files in backend linting
|
|
plugins: {
|
|
boundaries, // enforce backend architecture boundaries (module-to-module contracts)
|
|
"import-x": importX, // keep import hygiene rules (duplicates, unresolved paths, etc.)
|
|
"unused-imports": unusedImports, // remove dead imports/variables from backend files
|
|
},
|
|
languageOptions: {
|
|
parser: tseslint.parser, // parse both JS and TS syntax in backend files
|
|
parserOptions: {
|
|
ecmaVersion: "latest", // support modern ECMAScript syntax in backend code
|
|
sourceType: "module", // treat backend files as ESM modules
|
|
},
|
|
globals: {
|
|
...globals.node, // expose Node.js globals such as process, Buffer, and __dirname equivalents
|
|
},
|
|
},
|
|
settings: {
|
|
"boundaries/include": ["server/**/*.{js,ts}"], // only analyze dependency boundaries inside backend files
|
|
"import/resolver": {
|
|
// boundaries resolves imports through eslint-module-utils, which reads the classic
|
|
// import/resolver setting instead of import-x/resolver-next.
|
|
typescript: {
|
|
project: ["server/tsconfig.json"], // resolve backend aliases using the canonical backend tsconfig
|
|
alwaysTryTypes: true, // keep normal TS package/type resolution working alongside aliases
|
|
},
|
|
node: {
|
|
extensions: [".mjs", ".cjs", ".js", ".json", ".node", ".ts", ".tsx"], // preserve Node-style fallback resolution for plain files
|
|
},
|
|
},
|
|
"import-x/resolver-next": [
|
|
// ESLint's import plugin does not read tsconfig path aliases on its own.
|
|
// This resolver teaches import-x how to understand the backend-only "@/*"
|
|
// mapping defined in server/tsconfig.json, which fixes false no-unresolved errors in editors.
|
|
createTypeScriptImportResolver({
|
|
project: ["server/tsconfig.json"], // point the resolver at the canonical backend tsconfig instead of the frontend one
|
|
alwaysTryTypes: true, // keep standard TypeScript package resolution working while backend aliases are enabled
|
|
}),
|
|
// Keep Node-style resolution available for normal package imports and plain relative JS files.
|
|
// The TypeScript resolver handles aliases, while the Node resolver preserves the expected fallback behavior.
|
|
createNodeResolver({
|
|
extensions: [".mjs", ".cjs", ".js", ".json", ".node", ".ts", ".tsx"],
|
|
}),
|
|
],
|
|
"boundaries/elements": [
|
|
{
|
|
type: "backend-shared-types", // shared backend type contract that modules may consume without creating runtime coupling
|
|
pattern: ["server/shared/types.{js,ts}"], // support the current shared types path
|
|
mode: "file", // treat the types file itself as the boundary element instead of the whole folder
|
|
},
|
|
{
|
|
type: "backend-module", // logical element name used by boundaries rules below
|
|
pattern: "server/modules/*", // each direct folder in server/modules is treated as one module boundary
|
|
mode: "folder", // classify dependencies at folder-module level (not per individual file)
|
|
capture: ["moduleName"], // capture the module folder name for messages/debugging/template use
|
|
},
|
|
],
|
|
},
|
|
rules: {
|
|
// --- Unused imports/vars (backend) ---
|
|
"unused-imports/no-unused-imports": "warn", // warn when imports are not used so they can be cleaned up
|
|
"unused-imports/no-unused-vars": "off", // keep backend signal focused on dead imports instead of local unused variables
|
|
|
|
// --- Import hygiene (backend) ---
|
|
"import-x/no-duplicates": "warn", // prevent duplicate import lines from the same module
|
|
"import-x/order": [
|
|
"warn", // keep backend import grouping/order consistent with the frontend config
|
|
{
|
|
groups: [
|
|
"builtin", // Node built-ins such as fs, path, and url come first
|
|
"external", // third-party packages come after built-ins
|
|
"internal", // aliased internal imports such as @/... come next
|
|
"parent", // ../ imports come after aliased internal imports
|
|
"sibling", // ./foo imports come after parent imports
|
|
"index", // bare ./ imports stay last
|
|
],
|
|
"newlines-between": "always", // require a blank line between import groups in backend files too
|
|
},
|
|
],
|
|
"import-x/no-unresolved": "error", // fail when an import path cannot be resolved
|
|
"import-x/no-useless-path-segments": "warn", // prefer cleaner paths (remove redundant ./ and ../ segments)
|
|
"import-x/no-absolute-path": "error", // disallow absolute filesystem imports in backend files
|
|
|
|
// --- General safety/style (backend) ---
|
|
eqeqeq: ["warn", "always", { null: "ignore" }], // avoid accidental coercion while still allowing x == null checks
|
|
|
|
// --- Architecture boundaries (backend modules) ---
|
|
"boundaries/dependencies": [
|
|
"error", // treat architecture violations as lint errors
|
|
{
|
|
default: "allow", // allow normal imports unless a rule below explicitly disallows them
|
|
checkInternals: false, // do not apply these cross-module rules to imports inside the same module
|
|
rules: [
|
|
{
|
|
from: { type: "backend-module" }, // modules may depend on the shared types contract only as erased type-only imports
|
|
to: { type: "backend-shared-types" },
|
|
disallow: {
|
|
dependency: { kind: ["value", "typeof"] },
|
|
}, // block runtime imports so shared types stay a compile-time contract instead of a hidden shared module
|
|
message:
|
|
"Backend modules may only use `import type` when importing from server/shared/types.ts (or server/types.ts).",
|
|
},
|
|
{
|
|
to: { type: "backend-module" }, // when importing anything that belongs to another backend module
|
|
disallow: { to: { internalPath: "**" } }, // block all direct/deep imports into module internals by default
|
|
message:
|
|
"Cross-module imports must go through that module's barrel file (server/modules/<module>/index.ts or index.js).", // explicit error message for architecture violations
|
|
},
|
|
{
|
|
to: { type: "backend-module" }, // same target scope as the disallow rule above
|
|
allow: {
|
|
to: {
|
|
internalPath: [
|
|
"index", // allow extensionless barrel imports resolved as module root index
|
|
"index.{js,mjs,cjs,ts,tsx}", // allow explicit index.* barrel file imports
|
|
],
|
|
},
|
|
}, // re-allow only public module entry points (barrel files)
|
|
},
|
|
],
|
|
},
|
|
],
|
|
"boundaries/no-unknown": "error", // fail fast if boundaries cannot classify a dependency, which prevents silent rule bypasses
|
|
},
|
|
}
|
|
);
|