Skip to content

refactor: improve code structure for readability#11

Merged
Ryanakml merged 24 commits intomainfrom
phase/release-go-live
Mar 13, 2026
Merged

refactor: improve code structure for readability#11
Ryanakml merged 24 commits intomainfrom
phase/release-go-live

Conversation

@Ryanakml
Copy link
Copy Markdown
Owner

@Ryanakml Ryanakml commented Mar 9, 2026

Summary by CodeRabbit

  • Chores
    • Added explicit module entry points and type declarations for packaged artifacts to improve distribution.
    • Reworked build/typecheck scripts to run dependent package builds in a defined order before compiling the app and worker.
    • Simplified TypeScript output settings and narrowed includes to local sources; enabled project references for incremental builds.
    • Updated package exports to point to compiled distribution artifacts and added incremental build metadata.
    • Added root/base URL and path mappings for smoother module resolution.
    • Relaxed local package dependency ranges to wildcard for workspace resolution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds dist entrypoints and types for packages, shifts shared exports to built artifacts, enables composite builds/tsbuildinfo for config, tightens apps/api TypeScript output/include, and changes top-level and apps/api build/typecheck scripts to run ordered workspace builds for config/shared/llm before compiling apps. (50 words)

Changes

Cohort / File(s) Summary
API package manifest
apps/api/package.json
Added main: "dist/index.js" and types: "dist/index.d.ts"; build and typecheck now run workspace builds for @wa-chat/config and @wa-chat/shared before running tsc. Dependency versions for those packages set to *.
API tsconfig
apps/api/tsconfig.json
Set rootDir: "./src" and outDir: "./dist"; narrowed include to ["src"]; removed path mappings/baseUrl and commented options.
Root build orchestration
package.json
Replaced broad workspace build with an explicit ordered build chain: build packages/config, packages/shared, packages/llm first, then apps/api, apps/worker.
Config project (composite)
packages/config/tsconfig.json, packages/config/tsconfig.tsbuildinfo
Enabled composite: true and noEmit: false in tsconfig; added incremental build metadata file tsconfig.tsbuildinfo.
Shared package manifest
packages/shared/package.json
Changed main/types to ./dist/...; exports map updated from ./src/* to ./dist/* with "types", "import", and "default" entries.
LLM package changes
packages/llm/package.json, packages/llm/tsconfig.json
Dependency @wa-chat/shared bumped from ^0.0.1 to *; added noEmit: false in tsconfig.
Shared/LLM emit flags
packages/shared/tsconfig.json, packages/llm/tsconfig.json
Added noEmit: false to enable emissions during package builds.
Dashboard tsconfig
apps/dashboard/tsconfig.json
Added baseUrl: "." to compilerOptions for module resolution.
Root tsconfig paths
tsconfig.base.json
Added baseUrl and path mappings: @wa-chat/shared, @wa-chat/config, @wa-chat/llm → respective packages/*/src.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CI as Developer/CI
  participant Config as packages/config
  participant Shared as packages/shared
  participant LLM as packages/llm
  participant API as apps/api
  participant Worker as apps/worker

  CI->>Config: npm --workspace `@wa-chat/config` run build
  Note right of Config: compile (composite) -> dist\nwrites tsbuildinfo
  CI->>Shared: npm --workspace `@wa-chat/shared` run build
  Note right of Shared: compile -> dist
  CI->>LLM: npm --workspace `@wa-chat/llm` run build
  Note right of LLM: compile -> dist (depends on shared)
  CI->>API: npm --workspace apps/api run build
  Note right of API: runs prebuilt config/shared then tsc -> dist
  CI->>Worker: npm --workspace apps/worker run build
  Note right of Worker: builds after packages
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇 I hopped through paths and chased the build,
Tuned tsconfigs so outputs stood,
Composite crumbs and dist for all,
Chained my workspaces, neat and small,
🥕✨ Hop — compile — a tidy haul.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'refactor: improve code structure for readability' is too vague and generic. It does not specifically describe the actual changes, which involve configuring build and TypeScript settings across multiple packages and applications. Consider a more specific title that reflects the main changes, such as: 'refactor: configure TypeScript builds and update workspace dependencies' or 'refactor: set up composite builds and update package entry points'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch phase/release-go-live
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can enforce grammar and style rules using `languagetool`.

Configure the reviews.tools.languagetool setting to enable/disable rules and categories. Refer to the LanguageTool Community to learn more.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/api/package.json (1)

9-12: Keep typecheck non-emitting.

Using run build inside typecheck writes dependency artifacts and can dirty the workspace for a check-only command. Both dependency packages already expose typecheck, so reserve build for the emitting path only.

Suggested change
-    "typecheck": "npm --workspace `@wa-chat/config` run build && npm --workspace `@wa-chat/shared` run build && tsc --noEmit",
+    "typecheck": "npm --workspace `@wa-chat/config` run typecheck && npm --workspace `@wa-chat/shared` run typecheck && tsc --noEmit",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api/package.json` around lines 9 - 12, The "typecheck" script currently
runs emitting builds for dependencies; change it to call the dependencies'
non-emitting checks instead (use npm --workspace `@wa-chat/config` run typecheck
and npm --workspace `@wa-chat/shared` run typecheck) and keep the local tsc
--noEmit step so the "typecheck" script remains purely check-only; update the
package.json "typecheck" script accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/api/tsconfig.json`:
- Around line 8-9: The package export in packages/shared is pointing at
TypeScript source (./src/index.ts) which breaks NodeNext resolution; update
packages/shared/package.json's "exports" field so the package exports the built
artifacts (set "default" to ./dist/index.js and "types" to ./dist/index.d.ts)
instead of ./src/index.ts, rebuild the package so dist exists, and verify
apps/api can require/import `@wa-chat/shared` without loading TS source.

---

Nitpick comments:
In `@apps/api/package.json`:
- Around line 9-12: The "typecheck" script currently runs emitting builds for
dependencies; change it to call the dependencies' non-emitting checks instead
(use npm --workspace `@wa-chat/config` run typecheck and npm --workspace
`@wa-chat/shared` run typecheck) and keep the local tsc --noEmit step so the
"typecheck" script remains purely check-only; update the package.json
"typecheck" script accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc4e5c1a-ba9d-457e-99a9-1fd33fc1201e

📥 Commits

Reviewing files that changed from the base of the PR and between 426138f and dbc9fb9.

📒 Files selected for processing (3)
  • apps/api/package.json
  • apps/api/tsconfig.json
  • apps/api/tsconfig.tsbuildinfo

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package.json`:
- Line 14: The root package.json "build" script currently omits the dashboard
workspace; update the "build" script to include the dashboard workspace by
adding "-w apps/dashboard" alongside the existing workspaces (so the script runs
builds for packages/config, packages/shared, packages/llm, apps/api, apps/worker
and apps/dashboard). Ensure the modified "build" npm script preserves the
existing ordering and separators and matches the style of the other root
scripts.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 297da07b-a777-40b3-a834-15cd77ad7e56

📥 Commits

Reviewing files that changed from the base of the PR and between dbc9fb9 and 29e518b.

📒 Files selected for processing (7)
  • apps/api/tsconfig.tsbuildinfo
  • apps/worker/tsconfig.tsbuildinfo
  • package.json
  • packages/config/tsconfig.json
  • packages/config/tsconfig.tsbuildinfo
  • packages/llm/tsconfig.tsbuildinfo
  • packages/shared/package.json
✅ Files skipped from review due to trivial changes (1)
  • packages/config/tsconfig.tsbuildinfo

"test:e2e": "node --import tsx tests/e2e/webhook-to-outbound.e2e.test.ts && node --import tsx tests/e2e/duplicate-replay.e2e.test.ts && node --import tsx tests/e2e/escalation-handoff.e2e.test.ts",
"test:load": "node --import tsx tests/load/load-test.ts",
"build": "npm run build --workspaces",
"build": "npm run build -w packages/config -w packages/shared -w packages/llm && npm run build -w apps/api -w apps/worker",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
python - <<'PY'
import json
from pathlib import Path

for scope in ("apps", "packages"):
    for pkg_json in sorted(Path(scope).glob("*/package.json")):
        data = json.loads(pkg_json.read_text())
        build = data.get("scripts", {}).get("build", "<no build script>")
        print(f"{pkg_json.parent}: {build}")
PY

Repository: Ryanakml/ChatFuse

Length of output: 358


Fix root build script to include apps/dashboard.

The root build script on line 14 omits apps/dashboard, which has a production build (next build). This workspace will not be built when running the root build, even though it appears to be a release target given the dedicated root scripts on lines 15–17. Add -w apps/dashboard to the root build script to ensure it builds alongside the other workspaces.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` at line 14, The root package.json "build" script currently
omits the dashboard workspace; update the "build" script to include the
dashboard workspace by adding "-w apps/dashboard" alongside the existing
workspaces (so the script runs builds for packages/config, packages/shared,
packages/llm, apps/api, apps/worker and apps/dashboard). Ensure the modified
"build" npm script preserves the existing ordering and separators and matches
the style of the other root scripts.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/llm/package.json (1)

15-15: Prefer explicit versions or workspace specs over bare * for internal dependencies.

@wa-chat/shared with "*" can float to any published version, reducing reproducibility. While the root workspace is marked private: true, using an explicit version (e.g., "1.0.0" or a narrow range) or a workspace-aware spec (if npm version supports it) makes intent clearer and dependencies more predictable across installs. This pattern appears across multiple packages in the monorepo—consider standardizing the approach.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/llm/package.json` at line 15, The dependency entry
"@wa-chat/shared": "*" in package.json is too permissive; replace the bare "*"
with either a concrete semver (e.g., "1.0.0" or "^1.0.0") or a workspace-aware
spec (e.g., "workspace:^1.0.0" or "workspace:*" if your npm/yarn supports it) to
pin intent and restore reproducibility; update the dependency string in the
package.json where "@wa-chat/shared" is declared and apply the same pattern
consistently across other packages that currently use "*" so the monorepo uses
explicit versions or workspace specs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/shared/package.json`:
- Around line 5-11: Update the workspace TypeScript path mappings so imports
resolve to the new package entrypoint instead of the source; specifically remove
or change any tsconfig "paths" that map "@wa-chat/shared" (found in
tsconfig.base.json, apps/dashboard/tsconfig.json, tests/tsconfig.json) from
pointing to "packages/shared/src/*" to point at the built entry (or delete the
mapping so Node/TS uses the package "exports" and resolves to ./dist/index.js);
ensure downstream test and app configs no longer bypass the package manifest by
resolving the package name to its dist output.

---

Nitpick comments:
In `@packages/llm/package.json`:
- Line 15: The dependency entry "@wa-chat/shared": "*" in package.json is too
permissive; replace the bare "*" with either a concrete semver (e.g., "1.0.0" or
"^1.0.0") or a workspace-aware spec (e.g., "workspace:^1.0.0" or "workspace:*"
if your npm/yarn supports it) to pin intent and restore reproducibility; update
the dependency string in the package.json where "@wa-chat/shared" is declared
and apply the same pattern consistently across other packages that currently use
"*" so the monorepo uses explicit versions or workspace specs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 19959125-44cd-46f3-91a7-eb6f4e6730e4

📥 Commits

Reviewing files that changed from the base of the PR and between b1b704a and b5d09f2.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • apps/api/package.json
  • packages/llm/package.json
  • packages/shared/package.json

Comment on lines +5 to +11
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

The new dist entrypoint is still bypassed by current TS path aliases.

tsconfig.base.json, apps/dashboard/tsconfig.json, and tests/tsconfig.json still map @wa-chat/shared to packages/shared/src..., so workspace builds/tests continue importing raw TS instead of ./dist/index.js. That means this manifest change is not actually exercised locally, and package-boundary mismatches can slip through until external consumption. Please update or remove those path mappings before relying on these dist exports.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/shared/package.json` around lines 5 - 11, Update the workspace
TypeScript path mappings so imports resolve to the new package entrypoint
instead of the source; specifically remove or change any tsconfig "paths" that
map "@wa-chat/shared" (found in tsconfig.base.json,
apps/dashboard/tsconfig.json, tests/tsconfig.json) from pointing to
"packages/shared/src/*" to point at the built entry (or delete the mapping so
Node/TS uses the package "exports" and resolves to ./dist/index.js); ensure
downstream test and app configs no longer bypass the package manifest by
resolving the package name to its dist output.

@Ryanakml Ryanakml force-pushed the phase/release-go-live branch from 49c479b to 69be47e Compare March 11, 2026 08:24
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat-fuse-dashboard Ready Ready Preview, Comment Mar 13, 2026 6:15pm

@Ryanakml Ryanakml merged commit 2dd3152 into main Mar 13, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant