chore: reorganize backend folder structure — Phase 3 (REST API)
Merged
SA
3mo ago+944+944+012345678901234567890123456789-774-774-012345678901234567890123456789
Proposed changes
Phase 3 of the backend folder-structure migration: move the REST API framework and all REST endpoints into the responsibility-based server/api/ structure. Files move as-is — only import paths change, no refactoring.
Folder structure
Community — before
apps/meteor/
├── app/
│ ├── api/server/ REST API framework + endpoints
│ │ ├── ApiClass.ts api.ts api.helpers.ts router.ts definition.ts ajv.ts index.ts
│ │ ├── helpers/ (10)
│ │ ├── lib/ (21)
│ │ ├── middlewares/ (11)
│ │ ├── default/ (2)
│ │ └── v1/ (40 endpoint files)
│ └── livechat/
│ ├── server/api.ts ← imports/rest aggregator
│ ├── server/api/
│ │ ├── rest.ts ← v1 aggregator
│ │ ├── v1/ (14 omnichannel endpoints)
│ │ └── lib/ (14 helpers)
│ └── imports/server/rest/ (14 omnichannel endpoints)
└── server/ (no api/)
Community — after
apps/meteor/server/api/
├── ApiClass.ts api.ts api.helpers.ts router.ts definition.ts index.ts
├── validation/
│ └── ajv.ts
├── lib/ (31 — helpers + lib merged)
├── default/ (info.ts openApi.ts)
└── v1/
├── (40 endpoint files)
├── middlewares/ (11)
└── omnichannel/ livechat REST, flattened
├── index.ts ← aggregator (was livechat api.ts + api/rest.ts)
├── (28 endpoints; the imports/rest agent.ts → agentDepartments.ts)
└── lib/ (14 helpers)
→ app/api/server/ and app/livechat/server/api* removed
EE mirror — before / after (stays inside ee/)
Before
apps/meteor/ee/
├── app/
│ ├── api-enterprise/server/
│ │ ├── canned-responses.ts index.ts
│ │ ├── lib/canned-responses.js
│ │ └── middlewares/license.ts
│ └── livechat-enterprise/server/api/
│ ├── index.ts (+ 15 endpoint files)
│ └── lib/ (12 helpers)
└── server/api/ (already existed: audit.ts, chat.ts, …)
After
apps/meteor/ee/server/api/
├── (existing: audit.ts, chat.ts, federation.ts, …)
├── lib/
│ └── canned-responses.js
└── v1/
├── canned-responses.ts
├── middlewares/license.ts
└── omnichannel/
├── index.ts (+ 15 endpoint files)
└── lib/ (12 helpers)
→ ee/app/api-enterprise/ removed (index folded into ee/server/index.ts)
→ ee/app/livechat-enterprise/server/api/ moved out
Two commits for reviewability:
1. Community (app/api/server/ → server/api/)
- Framework files →
server/api/(ApiClass,api,router,definition, …) ajv.ts→server/api/validation/helpers/+lib/merged →server/api/lib/v1/→server/api/v1/,middlewares/→server/api/v1/middlewares/- All livechat community REST →
server/api/v1/omnichannel/(flat). Both former source dirs (livechat/server/api/v1/and the olderlivechat/imports/server/rest/) land here. The single filename collision (agent.ts) is resolved by renaming the imports/rest one toagentDepartments.ts(it only registerslivechat/agents/:agentId/departments). The two registration aggregators are folded intoserver/api/v1/omnichannel/index.ts, and theapp/livechat/serverAPI files are removed entirely.
2. EE mirror (within ee/, license boundary preserved — no file leaves ee/)
ee/app/livechat-enterprise/server/api/→ee/server/api/v1/omnichannel/ee/app/api-enterprise/server/→ee/server/api/(endpoint →v1/,lib/→api/lib/,middlewares/→v1/middlewares/)api-enterpriseindex aggregator folded intoee/server/index.tsand deleted
Migration-script hardening (mandatory per plan)
- License-boundary guard in
move-module.mjs+move-batch.mjs(refuses any move crossing theee/boundary) - Single-file and index-directory aware external-import rewriting (fixed two real bugs that broke post-
git mvimport updates) - Added
tests/to the import-scan dirs (caught bytsc, missed by lint)
Verification
yarn lint --quiet— clean (0 unresolved imports)tsc --noEmit --skipLibCheck— 0 errorsverify-no-old-imports.mjs— 0 stragglers for every Phase 3 path
[!NOTE]
Not run here (need a running server/DB): the REST API integration suite and manual endpoint smoke tests.
Commit-split caveat: the community move repoints the EE files it later relocates, so those import edits ride in commit 2 — the branch tip is fully green, but commit 1 alone isn't independently buildable for a few leaf EE API files.
🤖 Generated with Claude Code
Task: ARCH-2239