file-organizer-mcp 3.1.5 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (430) hide show
  1. package/ARCHITECTURE.md +676 -607
  2. package/CHANGELOG.md +273 -229
  3. package/README.md +887 -835
  4. package/dist/scripts/security-gates/path-traversal-fuzz.d.ts +23 -0
  5. package/dist/scripts/security-gates/path-traversal-fuzz.d.ts.map +1 -0
  6. package/dist/scripts/security-gates/path-traversal-fuzz.js +563 -0
  7. package/dist/scripts/security-gates/path-traversal-fuzz.js.map +1 -0
  8. package/dist/scripts/security-gates/run-all.d.ts +28 -0
  9. package/dist/scripts/security-gates/run-all.d.ts.map +1 -0
  10. package/dist/scripts/security-gates/run-all.js +248 -0
  11. package/dist/scripts/security-gates/run-all.js.map +1 -0
  12. package/dist/scripts/security-gates/sensitive-file-test.d.ts +23 -0
  13. package/dist/scripts/security-gates/sensitive-file-test.d.ts.map +1 -0
  14. package/dist/scripts/security-gates/sensitive-file-test.js +467 -0
  15. package/dist/scripts/security-gates/sensitive-file-test.js.map +1 -0
  16. package/dist/scripts/security-gates/static-analysis.d.ts +38 -0
  17. package/dist/scripts/security-gates/static-analysis.d.ts.map +1 -0
  18. package/dist/scripts/security-gates/static-analysis.js +489 -0
  19. package/dist/scripts/security-gates/static-analysis.js.map +1 -0
  20. package/dist/scripts/security-gates/toctou-test.d.ts +15 -0
  21. package/dist/scripts/security-gates/toctou-test.d.ts.map +1 -0
  22. package/dist/scripts/security-gates/toctou-test.js +438 -0
  23. package/dist/scripts/security-gates/toctou-test.js.map +1 -0
  24. package/dist/src/config.d.ts.map +1 -0
  25. package/dist/{config.js → src/config.js} +16 -16
  26. package/dist/src/config.js.map +1 -0
  27. package/dist/{constants.d.ts → src/constants.d.ts} +1 -1
  28. package/dist/src/constants.d.ts.map +1 -0
  29. package/dist/{constants.js → src/constants.js} +1 -1
  30. package/dist/src/constants.js.map +1 -0
  31. package/dist/src/errors.d.ts.map +1 -0
  32. package/dist/src/errors.js.map +1 -0
  33. package/dist/{index.d.ts → src/index.d.ts} +2 -2
  34. package/dist/src/index.d.ts.map +1 -0
  35. package/dist/{index.js → src/index.js} +97 -97
  36. package/dist/src/index.js.map +1 -0
  37. package/dist/src/readers/errors.d.ts +71 -0
  38. package/dist/src/readers/errors.d.ts.map +1 -0
  39. package/dist/src/readers/errors.js +106 -0
  40. package/dist/src/readers/errors.js.map +1 -0
  41. package/dist/src/readers/factory.d.ts +74 -0
  42. package/dist/src/readers/factory.d.ts.map +1 -0
  43. package/dist/src/readers/factory.js +102 -0
  44. package/dist/src/readers/factory.js.map +1 -0
  45. package/dist/src/readers/index.d.ts +22 -0
  46. package/dist/src/readers/index.d.ts.map +1 -0
  47. package/dist/src/readers/index.js +20 -0
  48. package/dist/src/readers/index.js.map +1 -0
  49. package/dist/src/readers/interfaces/audit-logger.d.ts +76 -0
  50. package/dist/src/readers/interfaces/audit-logger.d.ts.map +1 -0
  51. package/dist/src/readers/interfaces/audit-logger.js +8 -0
  52. package/dist/src/readers/interfaces/audit-logger.js.map +1 -0
  53. package/dist/src/readers/result.d.ts +86 -0
  54. package/dist/src/readers/result.d.ts.map +1 -0
  55. package/dist/src/readers/result.js +100 -0
  56. package/dist/src/readers/result.js.map +1 -0
  57. package/dist/src/readers/secure-file-reader.d.ts +216 -0
  58. package/dist/src/readers/secure-file-reader.d.ts.map +1 -0
  59. package/dist/src/readers/secure-file-reader.js +586 -0
  60. package/dist/src/readers/secure-file-reader.js.map +1 -0
  61. package/dist/src/readers/security/audit-logger.service.d.ts +200 -0
  62. package/dist/src/readers/security/audit-logger.service.d.ts.map +1 -0
  63. package/dist/src/readers/security/audit-logger.service.js +269 -0
  64. package/dist/src/readers/security/audit-logger.service.js.map +1 -0
  65. package/dist/src/readers/security/index.d.ts +160 -0
  66. package/dist/src/readers/security/index.d.ts.map +1 -0
  67. package/dist/src/readers/security/index.js +159 -0
  68. package/dist/src/readers/security/index.js.map +1 -0
  69. package/dist/src/readers/security/rate-limited-reader.d.ts +216 -0
  70. package/dist/src/readers/security/rate-limited-reader.d.ts.map +1 -0
  71. package/dist/src/readers/security/rate-limited-reader.js +331 -0
  72. package/dist/src/readers/security/rate-limited-reader.js.map +1 -0
  73. package/dist/src/readers/security/sensitive-file-patterns.d.ts +127 -0
  74. package/dist/src/readers/security/sensitive-file-patterns.d.ts.map +1 -0
  75. package/dist/src/readers/security/sensitive-file-patterns.js +293 -0
  76. package/dist/src/readers/security/sensitive-file-patterns.js.map +1 -0
  77. package/dist/src/readers/types.d.ts +89 -0
  78. package/dist/src/readers/types.d.ts.map +1 -0
  79. package/dist/src/readers/types.js +39 -0
  80. package/dist/src/readers/types.js.map +1 -0
  81. package/dist/{schemas → src/schemas}/common.schemas.d.ts +1 -1
  82. package/dist/src/schemas/common.schemas.d.ts.map +1 -0
  83. package/dist/{schemas → src/schemas}/common.schemas.js +1 -1
  84. package/dist/src/schemas/common.schemas.js.map +1 -0
  85. package/dist/{schemas → src/schemas}/index.d.ts +1 -1
  86. package/dist/src/schemas/index.d.ts.map +1 -0
  87. package/dist/{schemas → src/schemas}/index.js +1 -1
  88. package/dist/src/schemas/index.js.map +1 -0
  89. package/dist/{schemas → src/schemas}/organize.schemas.d.ts +1 -1
  90. package/dist/src/schemas/organize.schemas.d.ts.map +1 -0
  91. package/dist/{schemas → src/schemas}/organize.schemas.js +1 -1
  92. package/dist/src/schemas/organize.schemas.js.map +1 -0
  93. package/dist/src/schemas/rename.schemas.d.ts.map +1 -0
  94. package/dist/src/schemas/rename.schemas.js.map +1 -0
  95. package/dist/{schemas → src/schemas}/scan.schemas.d.ts +1 -1
  96. package/dist/src/schemas/scan.schemas.d.ts.map +1 -0
  97. package/dist/{schemas → src/schemas}/scan.schemas.js +1 -1
  98. package/dist/src/schemas/scan.schemas.js.map +1 -0
  99. package/dist/{schemas → src/schemas}/security.schemas.d.ts +1 -1
  100. package/dist/src/schemas/security.schemas.d.ts.map +1 -0
  101. package/dist/{schemas → src/schemas}/security.schemas.js +1 -1
  102. package/dist/src/schemas/security.schemas.js.map +1 -0
  103. package/dist/src/server.d.ts +10 -0
  104. package/dist/src/server.d.ts.map +1 -0
  105. package/dist/{server.js → src/server.js} +41 -35
  106. package/dist/src/server.js.map +1 -0
  107. package/dist/{services → src/services}/auto-organize.service.d.ts +1 -1
  108. package/dist/src/services/auto-organize.service.d.ts.map +1 -0
  109. package/dist/{services → src/services}/auto-organize.service.js +1 -1
  110. package/dist/src/services/auto-organize.service.js.map +1 -0
  111. package/dist/{services → src/services}/categorizer.service.d.ts +1 -1
  112. package/dist/src/services/categorizer.service.d.ts.map +1 -0
  113. package/dist/{services → src/services}/categorizer.service.js +1 -1
  114. package/dist/src/services/categorizer.service.js.map +1 -0
  115. package/dist/{services → src/services}/duplicate-finder.service.d.ts +1 -1
  116. package/dist/src/services/duplicate-finder.service.d.ts.map +1 -0
  117. package/dist/{services → src/services}/duplicate-finder.service.js +1 -1
  118. package/dist/src/services/duplicate-finder.service.js.map +1 -0
  119. package/dist/{services → src/services}/file-scanner.service.d.ts +1 -1
  120. package/dist/src/services/file-scanner.service.d.ts.map +1 -0
  121. package/dist/{services → src/services}/file-scanner.service.js +1 -1
  122. package/dist/src/services/file-scanner.service.js.map +1 -0
  123. package/dist/{services → src/services}/hash-calculator.service.d.ts +1 -1
  124. package/dist/src/services/hash-calculator.service.d.ts.map +1 -0
  125. package/dist/{services → src/services}/hash-calculator.service.js +1 -1
  126. package/dist/src/services/hash-calculator.service.js.map +1 -0
  127. package/dist/{services → src/services}/index.d.ts +1 -1
  128. package/dist/src/services/index.d.ts.map +1 -0
  129. package/dist/{services → src/services}/index.js +1 -1
  130. package/dist/src/services/index.js.map +1 -0
  131. package/dist/src/services/metadata.service.d.ts.map +1 -0
  132. package/dist/src/services/metadata.service.js.map +1 -0
  133. package/dist/{services → src/services}/organizer.service.d.ts +1 -1
  134. package/dist/src/services/organizer.service.d.ts.map +1 -0
  135. package/dist/{services → src/services}/organizer.service.js +1 -1
  136. package/dist/src/services/organizer.service.js.map +1 -0
  137. package/dist/{services → src/services}/path-validator.service.d.ts +1 -1
  138. package/dist/src/services/path-validator.service.d.ts.map +1 -0
  139. package/dist/{services → src/services}/path-validator.service.js +1 -1
  140. package/dist/src/services/path-validator.service.js.map +1 -0
  141. package/dist/{services → src/services}/renaming.service.d.ts +1 -1
  142. package/dist/src/services/renaming.service.d.ts.map +1 -0
  143. package/dist/{services → src/services}/renaming.service.js +1 -1
  144. package/dist/src/services/renaming.service.js.map +1 -0
  145. package/dist/{services → src/services}/rollback.service.d.ts +1 -1
  146. package/dist/src/services/rollback.service.d.ts.map +1 -0
  147. package/dist/{services → src/services}/rollback.service.js +1 -1
  148. package/dist/src/services/rollback.service.js.map +1 -0
  149. package/dist/{services → src/services}/scheduler-state.service.d.ts +1 -1
  150. package/dist/src/services/scheduler-state.service.d.ts.map +1 -0
  151. package/dist/{services → src/services}/scheduler-state.service.js +1 -1
  152. package/dist/src/services/scheduler-state.service.js.map +1 -0
  153. package/dist/{services → src/services}/security/rate-limiter.service.d.ts +1 -1
  154. package/dist/src/services/security/rate-limiter.service.d.ts.map +1 -0
  155. package/dist/{services → src/services}/security/rate-limiter.service.js +1 -1
  156. package/dist/src/services/security/rate-limiter.service.js.map +1 -0
  157. package/dist/{services → src/services}/streaming-scanner.service.d.ts +1 -1
  158. package/dist/src/services/streaming-scanner.service.d.ts.map +1 -0
  159. package/dist/{services → src/services}/streaming-scanner.service.js +1 -1
  160. package/dist/src/services/streaming-scanner.service.js.map +1 -0
  161. package/dist/{tools → src/tools}/duplicate-management.d.ts +1 -1
  162. package/dist/src/tools/duplicate-management.d.ts.map +1 -0
  163. package/dist/{tools → src/tools}/duplicate-management.js +18 -18
  164. package/dist/src/tools/duplicate-management.js.map +1 -0
  165. package/dist/{tools → src/tools}/file-analysis.d.ts +1 -1
  166. package/dist/src/tools/file-analysis.d.ts.map +1 -0
  167. package/dist/{tools → src/tools}/file-analysis.js +3 -3
  168. package/dist/src/tools/file-analysis.js.map +1 -0
  169. package/dist/{tools → src/tools}/file-categorization.d.ts +1 -1
  170. package/dist/src/tools/file-categorization.d.ts.map +1 -0
  171. package/dist/{tools → src/tools}/file-categorization.js +3 -3
  172. package/dist/src/tools/file-categorization.js.map +1 -0
  173. package/dist/{tools → src/tools}/file-duplicates.d.ts +1 -1
  174. package/dist/src/tools/file-duplicates.d.ts.map +1 -0
  175. package/dist/{tools → src/tools}/file-duplicates.js +8 -8
  176. package/dist/src/tools/file-duplicates.js.map +1 -0
  177. package/dist/{tools → src/tools}/file-listing.d.ts +1 -1
  178. package/dist/src/tools/file-listing.d.ts.map +1 -0
  179. package/dist/{tools → src/tools}/file-listing.js +7 -7
  180. package/dist/src/tools/file-listing.js.map +1 -0
  181. package/dist/{tools → src/tools}/file-management.d.ts +1 -1
  182. package/dist/src/tools/file-management.d.ts.map +1 -0
  183. package/dist/{tools → src/tools}/file-management.js +3 -3
  184. package/dist/src/tools/file-management.js.map +1 -0
  185. package/dist/{tools → src/tools}/file-organization.d.ts +1 -1
  186. package/dist/src/tools/file-organization.d.ts.map +1 -0
  187. package/dist/{tools → src/tools}/file-organization.js +14 -14
  188. package/dist/src/tools/file-organization.js.map +1 -0
  189. package/dist/src/tools/file-reader.tool.d.ts +70 -0
  190. package/dist/src/tools/file-reader.tool.d.ts.map +1 -0
  191. package/dist/src/tools/file-reader.tool.js +310 -0
  192. package/dist/src/tools/file-reader.tool.js.map +1 -0
  193. package/dist/{tools → src/tools}/file-renaming.d.ts +1 -1
  194. package/dist/src/tools/file-renaming.d.ts.map +1 -0
  195. package/dist/{tools → src/tools}/file-renaming.js +1 -1
  196. package/dist/src/tools/file-renaming.js.map +1 -0
  197. package/dist/{tools → src/tools}/file-scanning.d.ts +1 -1
  198. package/dist/src/tools/file-scanning.d.ts.map +1 -0
  199. package/dist/{tools → src/tools}/file-scanning.js +8 -8
  200. package/dist/src/tools/file-scanning.js.map +1 -0
  201. package/dist/{tools → src/tools}/index.d.ts +24 -22
  202. package/dist/src/tools/index.d.ts.map +1 -0
  203. package/dist/{tools → src/tools}/index.js +30 -27
  204. package/dist/src/tools/index.js.map +1 -0
  205. package/dist/{tools → src/tools}/metadata-inspection.d.ts +1 -1
  206. package/dist/src/tools/metadata-inspection.d.ts.map +1 -0
  207. package/dist/{tools → src/tools}/metadata-inspection.js +1 -1
  208. package/dist/src/tools/metadata-inspection.js.map +1 -0
  209. package/dist/{tools → src/tools}/organization-preview.d.ts +1 -1
  210. package/dist/src/tools/organization-preview.d.ts.map +1 -0
  211. package/dist/{tools → src/tools}/organization-preview.js +16 -16
  212. package/dist/src/tools/organization-preview.js.map +1 -0
  213. package/dist/{tools → src/tools}/rollback.d.ts +1 -1
  214. package/dist/src/tools/rollback.d.ts.map +1 -0
  215. package/dist/{tools → src/tools}/rollback.js +7 -7
  216. package/dist/src/tools/rollback.js.map +1 -0
  217. package/dist/{tools → src/tools}/watch.tool.d.ts +1 -1
  218. package/dist/src/tools/watch.tool.d.ts.map +1 -0
  219. package/dist/{tools → src/tools}/watch.tool.js +14 -14
  220. package/dist/src/tools/watch.tool.js.map +1 -0
  221. package/dist/src/tui/client-detector.d.ts.map +1 -0
  222. package/dist/src/tui/client-detector.js.map +1 -0
  223. package/dist/{index.d.ts.map → src/tui/index.d.ts.map} +1 -1
  224. package/dist/src/tui/index.js.map +1 -0
  225. package/dist/{tui → src/tui}/screens.d.ts.map +1 -1
  226. package/dist/{tui → src/tui}/screens.js.map +1 -1
  227. package/dist/src/tui/setup-wizard.d.ts.map +1 -0
  228. package/dist/src/tui/setup-wizard.js.map +1 -0
  229. package/dist/{types.d.ts → src/types.d.ts} +1 -1
  230. package/dist/src/types.d.ts.map +1 -0
  231. package/dist/{types.js → src/types.js} +1 -1
  232. package/dist/src/types.js.map +1 -0
  233. package/dist/{utils → src/utils}/cron-utils.d.ts +1 -1
  234. package/dist/src/utils/cron-utils.d.ts.map +1 -0
  235. package/dist/{utils → src/utils}/cron-utils.js +1 -1
  236. package/dist/src/utils/cron-utils.js.map +1 -0
  237. package/dist/src/utils/diagnostics.d.ts.map +1 -0
  238. package/dist/src/utils/diagnostics.js.map +1 -0
  239. package/dist/{utils → src/utils}/error-handler.d.ts +1 -1
  240. package/dist/src/utils/error-handler.d.ts.map +1 -0
  241. package/dist/{utils → src/utils}/error-handler.js +11 -11
  242. package/dist/src/utils/error-handler.js.map +1 -0
  243. package/dist/{utils → src/utils}/file-utils.d.ts +1 -1
  244. package/dist/src/utils/file-utils.d.ts.map +1 -0
  245. package/dist/{utils → src/utils}/file-utils.js +1 -1
  246. package/dist/src/utils/file-utils.js.map +1 -0
  247. package/dist/{utils → src/utils}/formatters.d.ts +1 -1
  248. package/dist/src/utils/formatters.d.ts.map +1 -0
  249. package/dist/{utils → src/utils}/formatters.js +1 -1
  250. package/dist/src/utils/formatters.js.map +1 -0
  251. package/dist/{utils → src/utils}/index.d.ts +1 -1
  252. package/dist/src/utils/index.d.ts.map +1 -0
  253. package/dist/{utils → src/utils}/index.js +1 -1
  254. package/dist/src/utils/index.js.map +1 -0
  255. package/dist/{utils → src/utils}/logger.d.ts +1 -1
  256. package/dist/src/utils/logger.d.ts.map +1 -0
  257. package/dist/{utils → src/utils}/logger.js +1 -1
  258. package/dist/src/utils/logger.js.map +1 -0
  259. package/dist/{utils → src/utils}/path-security.d.ts +1 -1
  260. package/dist/src/utils/path-security.d.ts.map +1 -0
  261. package/dist/{utils → src/utils}/path-security.js +1 -1
  262. package/dist/src/utils/path-security.js.map +1 -0
  263. package/package.json +111 -111
  264. package/dist/config.d.ts.map +0 -1
  265. package/dist/config.js.map +0 -1
  266. package/dist/constants.d.ts.map +0 -1
  267. package/dist/constants.js.map +0 -1
  268. package/dist/errors.d.ts.map +0 -1
  269. package/dist/errors.js.map +0 -1
  270. package/dist/index.js.map +0 -1
  271. package/dist/schemas/common.schemas.d.ts.map +0 -1
  272. package/dist/schemas/common.schemas.js.map +0 -1
  273. package/dist/schemas/index.d.ts.map +0 -1
  274. package/dist/schemas/index.js.map +0 -1
  275. package/dist/schemas/organize.schemas.d.ts.map +0 -1
  276. package/dist/schemas/organize.schemas.js.map +0 -1
  277. package/dist/schemas/rename.schemas.d.ts.map +0 -1
  278. package/dist/schemas/rename.schemas.js.map +0 -1
  279. package/dist/schemas/scan.schemas.d.ts.map +0 -1
  280. package/dist/schemas/scan.schemas.js.map +0 -1
  281. package/dist/schemas/security.schemas.d.ts.map +0 -1
  282. package/dist/schemas/security.schemas.js.map +0 -1
  283. package/dist/server.d.ts +0 -10
  284. package/dist/server.d.ts.map +0 -1
  285. package/dist/server.js.map +0 -1
  286. package/dist/services/auto-organize.service.d.ts.map +0 -1
  287. package/dist/services/auto-organize.service.js.map +0 -1
  288. package/dist/services/categorizer.service.d.ts.map +0 -1
  289. package/dist/services/categorizer.service.js.map +0 -1
  290. package/dist/services/duplicate-finder.service.d.ts.map +0 -1
  291. package/dist/services/duplicate-finder.service.js.map +0 -1
  292. package/dist/services/file-scanner.service.d.ts.map +0 -1
  293. package/dist/services/file-scanner.service.js.map +0 -1
  294. package/dist/services/hash-calculator.service.d.ts.map +0 -1
  295. package/dist/services/hash-calculator.service.js.map +0 -1
  296. package/dist/services/index.d.ts.map +0 -1
  297. package/dist/services/index.js.map +0 -1
  298. package/dist/services/metadata.service.d.ts.map +0 -1
  299. package/dist/services/metadata.service.js.map +0 -1
  300. package/dist/services/organizer.service.d.ts.map +0 -1
  301. package/dist/services/organizer.service.js.map +0 -1
  302. package/dist/services/path-validator.service.d.ts.map +0 -1
  303. package/dist/services/path-validator.service.js.map +0 -1
  304. package/dist/services/renaming.service.d.ts.map +0 -1
  305. package/dist/services/renaming.service.js.map +0 -1
  306. package/dist/services/rollback.service.d.ts.map +0 -1
  307. package/dist/services/rollback.service.js.map +0 -1
  308. package/dist/services/scheduler-state.service.d.ts.map +0 -1
  309. package/dist/services/scheduler-state.service.js.map +0 -1
  310. package/dist/services/security/rate-limiter.service.d.ts.map +0 -1
  311. package/dist/services/security/rate-limiter.service.js.map +0 -1
  312. package/dist/services/streaming-scanner.service.d.ts.map +0 -1
  313. package/dist/services/streaming-scanner.service.js.map +0 -1
  314. package/dist/tests/test-dryrun.d.ts +0 -2
  315. package/dist/tests/test-dryrun.d.ts.map +0 -1
  316. package/dist/tests/test-dryrun.js +0 -56
  317. package/dist/tests/test-dryrun.js.map +0 -1
  318. package/dist/tests/test-duplicate-scoring.d.ts +0 -2
  319. package/dist/tests/test-duplicate-scoring.d.ts.map +0 -1
  320. package/dist/tests/test-duplicate-scoring.js +0 -84
  321. package/dist/tests/test-duplicate-scoring.js.map +0 -1
  322. package/dist/tests/test-edge-cases.d.ts +0 -10
  323. package/dist/tests/test-edge-cases.d.ts.map +0 -1
  324. package/dist/tests/test-edge-cases.js +0 -129
  325. package/dist/tests/test-edge-cases.js.map +0 -1
  326. package/dist/tests/test-filename-conflict.d.ts +0 -2
  327. package/dist/tests/test-filename-conflict.d.ts.map +0 -1
  328. package/dist/tests/test-filename-conflict.js +0 -72
  329. package/dist/tests/test-filename-conflict.js.map +0 -1
  330. package/dist/tests/test-overwrite-bug.d.ts +0 -2
  331. package/dist/tests/test-overwrite-bug.d.ts.map +0 -1
  332. package/dist/tests/test-overwrite-bug.js +0 -75
  333. package/dist/tests/test-overwrite-bug.js.map +0 -1
  334. package/dist/tests/test-pagination.d.ts +0 -7
  335. package/dist/tests/test-pagination.d.ts.map +0 -1
  336. package/dist/tests/test-pagination.js +0 -105
  337. package/dist/tests/test-pagination.js.map +0 -1
  338. package/dist/tests/test-phase1.d.ts +0 -7
  339. package/dist/tests/test-phase1.d.ts.map +0 -1
  340. package/dist/tests/test-phase1.js +0 -47
  341. package/dist/tests/test-phase1.js.map +0 -1
  342. package/dist/tests/test-phase3-advanced.d.ts +0 -2
  343. package/dist/tests/test-phase3-advanced.d.ts.map +0 -1
  344. package/dist/tests/test-phase3-advanced.js +0 -82
  345. package/dist/tests/test-phase3-advanced.js.map +0 -1
  346. package/dist/tests/test-phase3.d.ts +0 -2
  347. package/dist/tests/test-phase3.d.ts.map +0 -1
  348. package/dist/tests/test-phase3.js +0 -87
  349. package/dist/tests/test-phase3.js.map +0 -1
  350. package/dist/tests/test-rollback-fix.d.ts +0 -2
  351. package/dist/tests/test-rollback-fix.d.ts.map +0 -1
  352. package/dist/tests/test-rollback-fix.js +0 -89
  353. package/dist/tests/test-rollback-fix.js.map +0 -1
  354. package/dist/tests/test-security-enhanced.d.ts +0 -2
  355. package/dist/tests/test-security-enhanced.d.ts.map +0 -1
  356. package/dist/tests/test-security-enhanced.js +0 -44
  357. package/dist/tests/test-security-enhanced.js.map +0 -1
  358. package/dist/tests/test-security.d.ts +0 -2
  359. package/dist/tests/test-security.d.ts.map +0 -1
  360. package/dist/tests/test-security.js +0 -60
  361. package/dist/tests/test-security.js.map +0 -1
  362. package/dist/tools/duplicate-management.d.ts.map +0 -1
  363. package/dist/tools/duplicate-management.js.map +0 -1
  364. package/dist/tools/file-analysis.d.ts.map +0 -1
  365. package/dist/tools/file-analysis.js.map +0 -1
  366. package/dist/tools/file-categorization.d.ts.map +0 -1
  367. package/dist/tools/file-categorization.js.map +0 -1
  368. package/dist/tools/file-duplicates.d.ts.map +0 -1
  369. package/dist/tools/file-duplicates.js.map +0 -1
  370. package/dist/tools/file-listing.d.ts.map +0 -1
  371. package/dist/tools/file-listing.js.map +0 -1
  372. package/dist/tools/file-management.d.ts.map +0 -1
  373. package/dist/tools/file-management.js.map +0 -1
  374. package/dist/tools/file-organization.d.ts.map +0 -1
  375. package/dist/tools/file-organization.js.map +0 -1
  376. package/dist/tools/file-renaming.d.ts.map +0 -1
  377. package/dist/tools/file-renaming.js.map +0 -1
  378. package/dist/tools/file-scanning.d.ts.map +0 -1
  379. package/dist/tools/file-scanning.js.map +0 -1
  380. package/dist/tools/index.d.ts.map +0 -1
  381. package/dist/tools/index.js.map +0 -1
  382. package/dist/tools/metadata-inspection.d.ts.map +0 -1
  383. package/dist/tools/metadata-inspection.js.map +0 -1
  384. package/dist/tools/organization-preview.d.ts.map +0 -1
  385. package/dist/tools/organization-preview.js.map +0 -1
  386. package/dist/tools/rollback.d.ts.map +0 -1
  387. package/dist/tools/rollback.js.map +0 -1
  388. package/dist/tools/watch.tool.d.ts.map +0 -1
  389. package/dist/tools/watch.tool.js.map +0 -1
  390. package/dist/tui/client-detector.d.ts.map +0 -1
  391. package/dist/tui/client-detector.js.map +0 -1
  392. package/dist/tui/index.d.ts.map +0 -1
  393. package/dist/tui/index.js.map +0 -1
  394. package/dist/tui/setup-wizard.d.ts.map +0 -1
  395. package/dist/tui/setup-wizard.js.map +0 -1
  396. package/dist/types.d.ts.map +0 -1
  397. package/dist/types.js.map +0 -1
  398. package/dist/utils/cron-utils.d.ts.map +0 -1
  399. package/dist/utils/cron-utils.js.map +0 -1
  400. package/dist/utils/diagnostics.d.ts.map +0 -1
  401. package/dist/utils/diagnostics.js.map +0 -1
  402. package/dist/utils/error-handler.d.ts.map +0 -1
  403. package/dist/utils/error-handler.js.map +0 -1
  404. package/dist/utils/file-utils.d.ts.map +0 -1
  405. package/dist/utils/file-utils.js.map +0 -1
  406. package/dist/utils/formatters.d.ts.map +0 -1
  407. package/dist/utils/formatters.js.map +0 -1
  408. package/dist/utils/index.d.ts.map +0 -1
  409. package/dist/utils/index.js.map +0 -1
  410. package/dist/utils/logger.d.ts.map +0 -1
  411. package/dist/utils/logger.js.map +0 -1
  412. package/dist/utils/path-security.d.ts.map +0 -1
  413. package/dist/utils/path-security.js.map +0 -1
  414. /package/dist/{config.d.ts → src/config.d.ts} +0 -0
  415. /package/dist/{errors.d.ts → src/errors.d.ts} +0 -0
  416. /package/dist/{errors.js → src/errors.js} +0 -0
  417. /package/dist/{schemas → src/schemas}/rename.schemas.d.ts +0 -0
  418. /package/dist/{schemas → src/schemas}/rename.schemas.js +0 -0
  419. /package/dist/{services → src/services}/metadata.service.d.ts +0 -0
  420. /package/dist/{services → src/services}/metadata.service.js +0 -0
  421. /package/dist/{tui → src/tui}/client-detector.d.ts +0 -0
  422. /package/dist/{tui → src/tui}/client-detector.js +0 -0
  423. /package/dist/{tui → src/tui}/index.d.ts +0 -0
  424. /package/dist/{tui → src/tui}/index.js +0 -0
  425. /package/dist/{tui → src/tui}/screens.d.ts +0 -0
  426. /package/dist/{tui → src/tui}/screens.js +0 -0
  427. /package/dist/{tui → src/tui}/setup-wizard.d.ts +0 -0
  428. /package/dist/{tui → src/tui}/setup-wizard.js +0 -0
  429. /package/dist/{utils → src/utils}/diagnostics.d.ts +0 -0
  430. /package/dist/{utils → src/utils}/diagnostics.js +0 -0
package/ARCHITECTURE.md CHANGED
@@ -1,607 +1,676 @@
1
- # Architecture Documentation
2
-
3
- ## 🏗️ System Overview
4
-
5
- File Organizer MCP is a security-hardened Model Context Protocol (MCP) server that provides intelligent file organization capabilities to Large Language Models (LLMs). The architecture follows a layered service pattern with comprehensive security validation at every level.
6
-
7
- ### Core Principles
8
-
9
- 1. **Security First** - Multi-layer validation and sanitization
10
- 2. **Service Isolation** - Clear separation of concerns
11
- 3. **Type Safety** - Strict TypeScript with Zod validation
12
- 4. **Testability** - Dependency injection and modular design
13
- 5. **Performance** - Streaming operations and resource limits
14
-
15
- ## 📐 Architecture Layers
16
-
17
- ```
18
- ┌─────────────────────────────────────────────────────────────┐
19
- │ MCP Client (LLM) │
20
- └─────────────────────────┬───────────────────────────────────┘
21
- │ JSON-RPC 2.0
22
- ┌─────────────────────────▼───────────────────────────────────┐
23
- │ MCP Server Layer │
24
- │ (server.ts - Protocol Handler) │
25
- └─────────────────────────┬───────────────────────────────────┘
26
-
27
- ┌─────────────────────────▼───────────────────────────────────┐
28
- │ Tools Layer │
29
- │ ┌──────────┬──────────┬───────────┬─────────────┐ │
30
- │ │ Scan │ Organize │ Duplicate │ Categorize │ │
31
- │ │ Files │ Files │ Find │ Files │ │
32
- │ └──────────┴──────────┴───────────┴─────────────┘ │
33
- └─────────────────────────┬───────────────────────────────────┘
34
-
35
- ┌─────────────────────────▼───────────────────────────────────┐
36
- │ Services Layer │
37
- │ ┌────────────┬──────────────┬─────────────┬──────────┐ │
38
- │ │ Path │ Organizer │ Hash │ Scanner │ │
39
- │ │ Validator │ Service │ Calculator │ Service │ │
40
- │ └────────────┴──────────────┴─────────────┴──────────┘ │
41
- └─────────────────────────┬───────────────────────────────────┘
42
-
43
- ┌─────────────────────────▼───────────────────────────────────┐
44
- │ Utils Layer │
45
- │ ┌──────────┬──────────┬───────────┬──────────┐ │
46
- │ │ Logger │ Error │ File │ Format- │ │
47
- │ │ │ Handler │ Utils │ ters │ │
48
- │ └──────────┴──────────┴───────────┴──────────┘ │
49
- └─────────────────────────┬───────────────────────────────────┘
50
-
51
- ┌─────────────────────────▼───────────────────────────────────┐
52
- │ File System │
53
- └─────────────────────────────────────────────────────────────┘
54
- ```
55
-
56
- ## 🔐 Security Architecture
57
-
58
- ### 8-Layer Path Validation Pipeline
59
-
60
- Every file path goes through these validation layers:
61
-
62
- ```typescript
63
- Input Path
64
-
65
- 1. Type Validation (Zod Schema)
66
-
67
- 2. Null Byte & Basic Sanitization
68
-
69
- 3. Path Normalization & Windows Case Adjustment
70
-
71
- 4. Traversal Sequence Prevention (../)
72
-
73
- 5. Absolute Path Resolution
74
-
75
- 6. Security Check (Whitelist & Blacklist)
76
-
77
- 7. Symlink Resolution & Target Validation
78
-
79
- 8. Existence & Access Check
80
-
81
- Validated Path ✅
82
- ```
83
-
84
- **Implementation:** [`src/services/path-validator.service.ts`](file:///c:/Users/NewAdmin/Desktop/File-Organizer-MCP/src/services/path-validator.service.ts)
85
-
86
- ### Race Condition Mitigation (TOCTOU Protection) - v3.1.4 Updates
87
-
88
- **Problem:** Time-of-Check-Time-of-Use vulnerabilities can occur when a file is checked, then used later, allowing an attacker to swap the file between operations.
89
-
90
- **v3.1.4 TOCTOU Fixes and Race Condition Prevention:**
91
-
92
- 1. **File Descriptor Validation**
93
- - Open files with `O_NOFOLLOW` flag to prevent symlink attacks
94
- - Use file descriptors directly rather than path strings after initial validation
95
- - Release file handles immediately after use to minimize attack window
96
-
97
- 2. **Atomic File Operations**
98
- - Use `COPYFILE_EXCL` flag for atomic copy operations (fails if destination exists)
99
- - Use `O_EXCL` flag when creating files to prevent race conditions
100
- - Utilize `rename()` for atomic moves within the same filesystem
101
-
102
- 3. **Retry Logic with Jitter**
103
- - Implement exponential backoff with random jitter for retry operations
104
- - Maximum 3 retries with increasing delays (10ms, 50ms, 100ms)
105
- - Fail fast after retries to prevent denial-of-service
106
-
107
- 4. **Safe Overwrite Pattern**
108
- - Write to temporary file in target directory first
109
- - Sync file to disk before atomic rename
110
- - Move existing file to backup before replacing
111
-
112
- ```typescript
113
- // Safe overwrite with atomic rename
114
- const tempPath = path.join(targetDir, `.tmp_${Date.now()}_${basename}`);
115
- await fs.writeFile(tempPath, content);
116
- await fs.rename(tempPath, targetPath); // Atomic on same filesystem
117
- ```
118
-
119
- 5. **Verification After Operations**
120
- - Re-validate file stats after critical operations
121
- - Verify file hash matches expected value after write
122
- - Check file permissions haven't changed unexpectedly
123
-
124
- **Limitations:**
125
-
126
- - File deletion on Windows uses path-based locking (not file descriptor)
127
- - Symlinks are blocked for security but may limit legitimate use cases
128
-
129
- ### Resource Protection
130
-
131
- ```typescript
132
- // Security Constants
133
- const SECURITY_LIMITS = {
134
- MAX_FILE_SIZE: 100 * 1024 * 1024, // 100 MB
135
- MAX_FILES: 10000, // Per operation
136
- MAX_DEPTH: 10, // Directory recursion
137
- MAX_PATH_LENGTH: 4096, // Characters
138
- };
139
- ```
140
-
141
- ## 📦 Core Components
142
-
143
- ### 1. Server Layer (`server.ts`)
144
-
145
- **Responsibility:** MCP protocol handling and tool registration
146
-
147
- ```typescript
148
- // Key responsibilities:
149
- - Initialize MCP server
150
- - Register tools with schemas
151
- - Handle tool invocations
152
- - Manage error responses
153
- - Coordinate with services
154
- ```
155
-
156
- **Key Features:**
157
-
158
- - Automatic tool discovery from `tools/` directory
159
- - Structured response formatting (JSON/Markdown)
160
- - Centralized error handling
161
-
162
- ### 2. Tools Layer (`tools/`)
163
-
164
- **Responsibility:** MCP tool implementations (user-facing API)
165
-
166
- Each tool follows this pattern:
167
-
168
- ```typescript
169
- export const toolDefinition: ToolDefinition = {
170
- name: 'tool_name',
171
- description: 'What it does',
172
- inputSchema: ZodSchema, // Validation
173
- };
174
-
175
- export async function handleTool(args: ToolArgs): Promise<ToolResponse> {
176
- // 1. Validate inputs (Zod)
177
- // 2. Validate security (PathValidator)
178
- // 3. Call service layer
179
- // 4. Format response
180
- // 5. Handle errors
181
- }
182
- ```
183
-
184
- **Available Tools:**
185
-
186
- 1. **List Files in Directory** (`file_organizer_list_files`)
187
- 2. **Scan Directory for Detailed Info** (`file_organizer_scan_directory`)
188
- 3. **Categorize Files by Type** (`file_organizer_categorize_files`)
189
- 4. **Find Largest Files** (`file_organizer_find_largest_files`)
190
- 5. **Find Duplicate Files** (`file_organizer_find_duplicate_files`)
191
- 6. **Preview File Organization Plan** (`file_organizer_preview_organization`)
192
- 7. **Get Available File Categories** (`file_organizer_get_categories`)
193
- 8. **Analyze Duplicate Files with Smart Recommendations** (`file_organizer_analyze_duplicates`)
194
- 9. **Organize Files** (`file_organizer_organize_files`)
195
- 10. **Set Custom Organization Rules** (`file_organizer_set_custom_rules`)
196
- 11. **Delete Duplicate Files** (`file_organizer_delete_duplicates`)
197
- 12. **Undo Last Organization Operation** (`file_organizer_undo_last_operation`)
198
-
199
- ### 3. Services Layer (`services/`)
200
-
201
- **Responsibility:** Core business logic
202
-
203
- **Service Versions:** All services v3.1.3 or v3.1.4
204
-
205
- #### PathValidatorService (v3.1.3)
206
-
207
- ```typescript
208
- class PathValidatorService {
209
- // Multi-layer path validation
210
- async validateStrictPath(inputPath: unknown, options?: ValidatePathOptions): Promise<string>;
211
-
212
- // Symlink resolution
213
- async resolvePath(path: string): Promise<string>;
214
-
215
- // Containment checking
216
- isPathWithinRoots(path: string, roots: string[]): boolean;
217
- }
218
- ```
219
-
220
- #### OrganizerService (v3.1.4)
221
-
222
- ```typescript
223
- class OrganizerService {
224
- // Generate organization plan
225
- async generateOrganizationPlan(
226
- directory: string,
227
- files: FileWithSize[],
228
- strategy?: ConflictStrategy // 'rename' | 'skip' | 'overwrite' | 'overwrite_if_newer'
229
- ): Promise<OrganizationPlan>;
230
-
231
- // Execute organization with safety guarantees
232
- async organize(
233
- directory: string,
234
- files: FileWithSize[],
235
- options?: OrganizeOptions
236
- ): Promise<OrganizeResult>;
237
-
238
- // Safety mechanisms:
239
- // 1. File descriptor validation before move
240
- // 2. Atomic copy with COPYFILE_EXCL (race-safe)
241
- // 3. Automatic backup to .file-organizer-backups/ on overwrite
242
- // 4. Retry loop for race condition recovery
243
- }
244
- ```
245
-
246
- #### HashCalculatorService
247
-
248
- ```typescript
249
- class HashCalculatorService {
250
- // Streaming hash calculation
251
- async calculateHash(filePath: string): Promise<string>;
252
-
253
- // Find duplicates (memory-safe)
254
- async findDuplicates(files: FileWithSize[]): Promise<DuplicateGroup[]>;
255
- }
256
- ```
257
-
258
- #### FileScannerService (v3.1.4)
259
-
260
- ```typescript
261
- class FileScannerService {
262
- // Recursive directory scanning
263
- async getAllFiles(directory: string, options?: ScanOptions): Promise<FileWithSize[]>;
264
-
265
- // Size calculation
266
- async calculateDirectorySize(directory: string): Promise<number>;
267
- }
268
- ```
269
-
270
- #### CategorizerService
271
-
272
- ```typescript
273
- class CategorizerService {
274
- // File categorization
275
- getCategory(fileName: string): CategoryName;
276
-
277
- // Custom rules support
278
- setCustomRules(rules: CategoryRule[]): void;
279
-
280
- // Category statistics
281
- categorizeFiles(files: FileWithSize[]): CategoryBreakdown;
282
- }
283
- ```
284
-
285
- #### RollbackService (v3.1.4)
286
-
287
- ```typescript
288
- class RollbackService {
289
- // Create rollback manifest
290
- async createManifest(actions: OrganizeAction[]): Promise<string>;
291
-
292
- // Execute rollback
293
- async rollback(manifestId: string): Promise<RollbackResult>;
294
-
295
- // List available rollbacks
296
- async listRollbacks(): Promise<RollbackManifest[]>;
297
- }
298
- ```
299
-
300
- ### 4. Utils Layer (`utils/`)
301
-
302
- **Responsibility:** Shared utility functions
303
-
304
- #### Logger
305
-
306
- ```typescript
307
- class Logger {
308
- // Structured JSON logging to stderr (MCP stdio protocol)
309
- debug(message: string, context?: Record<string, any>): void;
310
- info(message: string, context?: Record<string, any>): void;
311
- warn(message: string, context?: Record<string, any>): void;
312
- error(message: string, error?: Error, context?: Record<string, any>): void;
313
-
314
- // Features:
315
- // - ISO 8601 timestamps
316
- // - Configurable log levels (debug/info/warn/error)
317
- // - Error stack traces for error logs
318
- // - JSON format for machine parsing
319
- }
320
- ```
321
-
322
- - **error-handler.ts** - Centralized error handling
323
- - **file-utils.ts** - File system helpers
324
- - **formatters.ts** - Data formatting (bytes, dates, etc.)
325
-
326
- ### 5. Schemas Layer (`schemas/`)
327
-
328
- **Responsibility:** Input validation using Zod
329
-
330
- ```typescript
331
- // Example: Path validation
332
- export const PathSchema = z
333
- .string()
334
- .min(1, 'Path cannot be empty')
335
- .max(4096, 'Path exceeds maximum length')
336
- .refine((path) => !path.includes('\0'), 'Path contains null bytes');
337
- ```
338
-
339
- ## 🔄 Data Flow
340
-
341
- ### Example: Organize Files Operation
342
-
343
- ```
344
- 1. LLM Request
345
-
346
- 2. MCP Server (server.ts)
347
- - Parse JSON-RPC request
348
- - Route to organize tool
349
-
350
- 3. Tool Handler (tools/file-organization.ts)
351
- - Validate args with Zod
352
- - Call PathValidatorService
353
-
354
- 4. PathValidatorService
355
- - 7-layer validation
356
- - Return validated path
357
-
358
- 5. FileScannerService
359
- - Scan directory
360
- - Apply resource limits
361
-
362
- 6. CategorizerService
363
- - Categorize each file
364
-
365
- 7. OrganizerService
366
- - Generate organization plan
367
- - Check conflicts
368
- - Execute moves (if not dry run)
369
-
370
- 8. RollbackService
371
- - Create rollback manifest
372
-
373
- 9. Tool Handler
374
- - Format response (JSON/Markdown)
375
-
376
- 10. MCP Server
377
- - Send JSON-RPC response
378
-
379
- 11. LLM receives result
380
- ```
381
-
382
- ## 💾 File Organization
383
-
384
- ### Source Structure
385
-
386
- ```
387
- src/
388
- ├── server.ts # MCP server entry point
389
- ├── index.ts # Main entry point
390
- ├── types.ts # TypeScript type definitions
391
- ├── constants.ts # Application constants
392
- ├── config.ts # Configuration management
393
-
394
- ├── services/ # Core business logic
395
- │ ├── path-validator.service.ts
396
- │ ├── organizer.service.ts
397
- │ ├── hash-calculator.service.ts
398
- │ ├── file-scanner.service.ts
399
- │ ├── categorizer.service.ts
400
- │ └── rollback.service.ts
401
-
402
- ├── tools/ # MCP tool implementations
403
- │ ├── file-scanning.ts
404
- │ ├── file-organization.ts
405
- │ ├── file-duplicates.ts
406
- │ ├── file-categorization.ts
407
- │ └── ...
408
-
409
- ├── schemas/ # Zod validation schemas
410
- │ ├── security.schemas.ts
411
- │ ├── common.schemas.ts
412
- │ ├── scan.schemas.ts
413
- │ └── organize.schemas.ts
414
-
415
- └── utils/ # Shared utilities
416
- ├── logger.ts
417
- ├── error-handler.ts
418
- ├── file-utils.ts
419
- └── formatters.ts
420
- ```
421
-
422
- ## 🧪 Testing Architecture
423
-
424
- ### Test Structure
425
-
426
- ```
427
- tests/
428
- ├── unit/ # Unit tests for services
429
- ├── services/
430
- │ ├── path-validator.test.ts
431
- │ │ ├── organizer.test.ts
432
- │ └── ...
433
- └── utils/
434
-
435
- ├── integration/ # Integration tests for tools
436
- ├── tools/
437
- │ └── organize.test.ts
438
- └── edge-cases.test.ts
439
-
440
- └── performance/ # Performance benchmarks
441
- └── performance.test.ts
442
- ```
443
-
444
- ### Test Philosophy
445
-
446
- 1. **Unit Tests** - Test services in isolation
447
- 2. **Integration Tests** - Test complete workflows
448
- 3. **Security Tests** - Validate all security controls
449
- 4. **Performance Tests** - Ensure scalability
450
-
451
- ## 🚀 Performance Considerations
452
-
453
- ### Streaming Operations
454
-
455
- Large files are processed using streams to avoid memory exhaustion:
456
-
457
- ```typescript
458
- // Hash calculation uses streams
459
- const hash = crypto.createHash('sha256');
460
- const stream = createReadStream(filePath, { highWaterMark: 64 * 1024 });
461
- stream.on('data', (chunk) => hash.update(chunk));
462
- ```
463
-
464
- ### Resource Limits
465
-
466
- ```typescript
467
- // Enforced at multiple levels:
468
- - File size: Skip files > 100MB for hashing
469
- - File count: Max 10,000 files per operation
470
- - Recursion depth: Max 10 levels
471
- - Path length: Max 4,096 characters
472
- ```
473
-
474
- ### Caching Strategy
475
-
476
- - Category mappings cached in-memory
477
- - File stats cached during single operation
478
- - No persistent caching (stateless design)
479
-
480
- ## 🔧 Configuration
481
-
482
- ### Configuration System (`config.ts`)
483
-
484
- The server uses a platform-aware configuration system that combines hardcoded defaults with user customization.
485
-
486
- **Structure:**
487
-
488
- ```typescript
489
- export const CONFIG = {
490
- VERSION: '3.1.5',
491
-
492
- security: {
493
- enablePathValidation: true,
494
- allowCustomDirectories: true,
495
- logAccess: true,
496
- maxScanDepth: 10,
497
- maxFilesPerOperation: 10000,
498
- },
499
-
500
- paths: {
501
- defaultAllowed: getDefaultAllowedDirs(), // Platform-aware safe directories
502
- customAllowed: loadCustomAllowedDirs(), // User-defined from config.json
503
- alwaysBlocked: getAlwaysBlockedPatterns(), // System protection patterns
504
- },
505
- };
506
- ```
507
-
508
- **Default Allowed Directories:**
509
-
510
- - **Windows:** Desktop, Documents, Downloads, Pictures, Videos, Music, OneDrive, Projects
511
- - **macOS:** Desktop, Documents, Downloads, Movies, Music, Pictures, iCloud Drive, Projects
512
- - **Linux:** Desktop, Documents, Downloads, Music, Pictures, Videos, ~/dev, ~/workspace
513
-
514
- **User Configuration:**
515
-
516
- - **Windows:** `%APPDATA%\file-organizer-mcp\config.json`
517
- - **macOS:** `~/Library/Application Support/file-organizer-mcp/config.json`
518
- - **Linux:** `~/.config/file-organizer-mcp/config.json`
519
-
520
- **Config File Format:**
521
-
522
- ```json
523
- {
524
- "customAllowedDirectories": ["C:\\Users\\Name\\CustomFolder", "D:\\Projects"],
525
- "settings": {
526
- "maxScanDepth": 10,
527
- "logAccess": true
528
- }
529
- }
530
- ```
531
-
532
- ## 🎯 Design Patterns
533
-
534
- ### Dependency Injection
535
-
536
- ```typescript
537
- // Services receive dependencies via constructor
538
- class OrganizerService {
539
- constructor(
540
- private categorizer: CategorizerService,
541
- private rollback?: RollbackService
542
- ) {}
543
- }
544
- ```
545
-
546
- ### Error Handling
547
-
548
- ```typescript
549
- // Centralized error handling
550
- try {
551
- const result = await operation();
552
- } catch (error) {
553
- return createErrorResponse(error);
554
- }
555
- ```
556
-
557
- ### Type Safety
558
-
559
- ```typescript
560
- // Strict types with Zod runtime validation
561
- const ArgsSchema = z.object({
562
- directory: PathSchema,
563
- dry_run: z.boolean().optional(),
564
- });
565
-
566
- type Args = z.infer<typeof ArgsSchema>;
567
- ```
568
-
569
- ## 📊 Monitoring & Logging
570
-
571
- ### Structured Logging
572
-
573
- ```json
574
- {
575
- "timestamp": "2026-02-08T00:00:00.000Z",
576
- "level": "info",
577
- "message": "Created rollback manifest: uuid (6 actions)"
578
- }
579
- ```
580
-
581
- ### Log Levels
582
-
583
- - `error` - Critical failures
584
- - `warn` - Recoverable issues (e.g., skipped files)
585
- - `info` - Operation milestones
586
- - `debug` - Detailed diagnostics
587
-
588
- ## 🔮 Future Architecture Changes
589
-
590
- ### Planned Improvements
591
-
592
- 1. **Plugin System** - Allow custom categorization rules
593
- 2. **Database Layer** - Persistent state for large operations
594
- 3. **Queue System** - Background processing for large directories
595
- 4. **Metrics Collection** - Performance monitoring
596
- 5. **Multi-language Support** - i18n infrastructure
597
-
598
- ## 📚 References
599
-
600
- - [Model Context Protocol Spec](https://modelcontextprotocol.io)
601
- - [Zod Documentation](https://zod.dev)
602
- - [TypeScript Handbook](https://www.typescriptlang.org/docs)
603
-
604
- ---
605
-
606
- **Last Updated:** February 8, 2026
607
- **Version:** 3.1.5
1
+ # Architecture Documentation
2
+
3
+ ## 🏗️ System Overview
4
+
5
+ File Organizer MCP is a security-hardened Model Context Protocol (MCP) server that provides intelligent file organization capabilities to Large Language Models (LLMs). The architecture follows a layered service pattern with comprehensive security validation at every level.
6
+
7
+ ### Core Principles
8
+
9
+ 1. **Security First** - Multi-layer validation and sanitization
10
+ 2. **Service Isolation** - Clear separation of concerns
11
+ 3. **Type Safety** - Strict TypeScript with Zod validation
12
+ 4. **Testability** - Dependency injection and modular design
13
+ 5. **Performance** - Streaming operations and resource limits
14
+
15
+ ## 📐 Architecture Layers
16
+
17
+ ```
18
+ ┌─────────────────────────────────────────────────────────────┐
19
+ │ MCP Client (LLM) │
20
+ └─────────────────────────┬───────────────────────────────────┘
21
+ │ JSON-RPC 2.0
22
+ ┌─────────────────────────▼───────────────────────────────────┐
23
+ │ MCP Server Layer │
24
+ │ (server.ts - Protocol Handler) │
25
+ └─────────────────────────┬───────────────────────────────────┘
26
+
27
+ ┌─────────────────────────▼───────────────────────────────────┐
28
+ │ Tools Layer │
29
+ │ ┌──────────┬──────────┬───────────┬─────────────┐ │
30
+ │ │ Scan │ Organize │ Duplicate │ Categorize │ │
31
+ │ │ Files │ Files │ Find │ Files │ │
32
+ │ └──────────┴──────────┴───────────┴─────────────┘ │
33
+ └─────────────────────────┬───────────────────────────────────┘
34
+
35
+ ┌─────────────────────────▼───────────────────────────────────┐
36
+ │ Services Layer │
37
+ │ ┌────────────┬──────────────┬─────────────┬──────────┐ │
38
+ │ │ Path │ Organizer │ Hash │ Scanner │ │
39
+ │ │ Validator │ Service │ Calculator │ Service │ │
40
+ │ └────────────┴──────────────┴─────────────┴──────────┘ │
41
+ └─────────────────────────┬───────────────────────────────────┘
42
+
43
+ ┌─────────────────────────▼───────────────────────────────────┐
44
+ │ Utils Layer │
45
+ │ ┌──────────┬──────────┬───────────┬──────────┐ │
46
+ │ │ Logger │ Error │ File │ Format- │ │
47
+ │ │ │ Handler │ Utils │ ters │ │
48
+ │ └──────────┴──────────┴───────────┴──────────┘ │
49
+ └─────────────────────────┬───────────────────────────────────┘
50
+
51
+ ┌─────────────────────────▼───────────────────────────────────┐
52
+ │ File System │
53
+ └─────────────────────────────────────────────────────────────┘
54
+ ```
55
+
56
+ ## 🔐 Security Architecture
57
+
58
+ ### 8-Layer Path Validation Pipeline
59
+
60
+ Every file path goes through these validation layers:
61
+
62
+ ```typescript
63
+ Input Path
64
+
65
+ 1. Type Validation (Zod Schema)
66
+
67
+ 2. Null Byte & Basic Sanitization
68
+
69
+ 3. Path Normalization & Windows Case Adjustment
70
+
71
+ 4. Traversal Sequence Prevention (../)
72
+
73
+ 5. Absolute Path Resolution
74
+
75
+ 6. Security Check (Whitelist & Blacklist)
76
+
77
+ 7. Symlink Resolution & Target Validation
78
+
79
+ 8. Existence & Access Check
80
+
81
+ Validated Path ✅
82
+ ```
83
+
84
+ **Implementation:** [`src/services/path-validator.service.ts`](file:///c:/Users/NewAdmin/Desktop/File-Organizer-MCP/src/services/path-validator.service.ts)
85
+
86
+ ### Race Condition Mitigation (TOCTOU Protection) - v3.1.4 Updates
87
+
88
+ **Problem:** Time-of-Check-Time-of-Use vulnerabilities can occur when a file is checked, then used later, allowing an attacker to swap the file between operations.
89
+
90
+ **v3.1.4 TOCTOU Fixes and Race Condition Prevention:**
91
+
92
+ 1. **File Descriptor Validation**
93
+ - Open files with `O_NOFOLLOW` flag to prevent symlink attacks
94
+ - Use file descriptors directly rather than path strings after initial validation
95
+ - Release file handles immediately after use to minimize attack window
96
+
97
+ 2. **Atomic File Operations**
98
+ - Use `COPYFILE_EXCL` flag for atomic copy operations (fails if destination exists)
99
+ - Use `O_EXCL` flag when creating files to prevent race conditions
100
+ - Utilize `rename()` for atomic moves within the same filesystem
101
+
102
+ 3. **Retry Logic with Jitter**
103
+ - Implement exponential backoff with random jitter for retry operations
104
+ - Maximum 3 retries with increasing delays (10ms, 50ms, 100ms)
105
+ - Fail fast after retries to prevent denial-of-service
106
+
107
+ 4. **Safe Overwrite Pattern**
108
+ - Write to temporary file in target directory first
109
+ - Sync file to disk before atomic rename
110
+ - Move existing file to backup before replacing
111
+
112
+ ```typescript
113
+ // Safe overwrite with atomic rename
114
+ const tempPath = path.join(targetDir, `.tmp_${Date.now()}_${basename}`);
115
+ await fs.writeFile(tempPath, content);
116
+ await fs.rename(tempPath, targetPath); // Atomic on same filesystem
117
+ ```
118
+
119
+ 5. **Verification After Operations**
120
+ - Re-validate file stats after critical operations
121
+ - Verify file hash matches expected value after write
122
+ - Check file permissions haven't changed unexpectedly
123
+
124
+ **Limitations:**
125
+
126
+ - File deletion on Windows uses path-based locking (not file descriptor)
127
+ - Symlinks are blocked for security but may limit legitimate use cases
128
+
129
+ ### Resource Protection
130
+
131
+ ```typescript
132
+ // Security Constants
133
+ const SECURITY_LIMITS = {
134
+ MAX_FILE_SIZE: 100 * 1024 * 1024, // 100 MB
135
+ MAX_FILES: 10000, // Per operation
136
+ MAX_DEPTH: 10, // Directory recursion
137
+ MAX_PATH_LENGTH: 4096, // Characters
138
+ };
139
+ ```
140
+
141
+ ## 📦 Core Components
142
+
143
+ ### 1. Server Layer (`server.ts`)
144
+
145
+ **Responsibility:** MCP protocol handling and tool registration
146
+
147
+ ```typescript
148
+ // Key responsibilities:
149
+ - Initialize MCP server
150
+ - Register tools with schemas
151
+ - Handle tool invocations
152
+ - Manage error responses
153
+ - Coordinate with services
154
+ ```
155
+
156
+ **Key Features:**
157
+
158
+ - Automatic tool discovery from `tools/` directory
159
+ - Structured response formatting (JSON/Markdown)
160
+ - Centralized error handling
161
+
162
+ ### 2. Tools Layer (`tools/`)
163
+
164
+ **Responsibility:** MCP tool implementations (user-facing API)
165
+
166
+ Each tool follows this pattern:
167
+
168
+ ```typescript
169
+ export const toolDefinition: ToolDefinition = {
170
+ name: 'tool_name',
171
+ description: 'What it does',
172
+ inputSchema: ZodSchema, // Validation
173
+ };
174
+
175
+ export async function handleTool(args: ToolArgs): Promise<ToolResponse> {
176
+ // 1. Validate inputs (Zod)
177
+ // 2. Validate security (PathValidator)
178
+ // 3. Call service layer
179
+ // 4. Format response
180
+ // 5. Handle errors
181
+ }
182
+ ```
183
+
184
+ **Available Tools:**
185
+
186
+ 1. **List Files in Directory** (`file_organizer_list_files`)
187
+ 2. **Scan Directory for Detailed Info** (`file_organizer_scan_directory`)
188
+ 3. **Categorize Files by Type** (`file_organizer_categorize_files`)
189
+ 4. **Find Largest Files** (`file_organizer_find_largest_files`)
190
+ 5. **Find Duplicate Files** (`file_organizer_find_duplicate_files`)
191
+ 6. **Preview File Organization Plan** (`file_organizer_preview_organization`)
192
+ 7. **Get Available File Categories** (`file_organizer_get_categories`)
193
+ 8. **Analyze Duplicate Files with Smart Recommendations** (`file_organizer_analyze_duplicates`)
194
+ 9. **Organize Files** (`file_organizer_organize_files`)
195
+ 10. **Set Custom Organization Rules** (`file_organizer_set_custom_rules`)
196
+ 11. **Delete Duplicate Files** (`file_organizer_delete_duplicates`)
197
+ 12. **Undo Last Organization Operation** (`file_organizer_undo_last_operation`)
198
+
199
+ ### 3. Services Layer (`services/`)
200
+
201
+ **Responsibility:** Core business logic
202
+
203
+ **Service Versions:** All services v3.1.3 or v3.1.4
204
+
205
+ #### PathValidatorService (v3.1.3)
206
+
207
+ ```typescript
208
+ class PathValidatorService {
209
+ // Multi-layer path validation
210
+ async validateStrictPath(inputPath: unknown, options?: ValidatePathOptions): Promise<string>;
211
+
212
+ // Symlink resolution
213
+ async resolvePath(path: string): Promise<string>;
214
+
215
+ // Containment checking
216
+ isPathWithinRoots(path: string, roots: string[]): boolean;
217
+ }
218
+ ```
219
+
220
+ #### OrganizerService (v3.1.4)
221
+
222
+ ```typescript
223
+ class OrganizerService {
224
+ // Generate organization plan
225
+ async generateOrganizationPlan(
226
+ directory: string,
227
+ files: FileWithSize[],
228
+ strategy?: ConflictStrategy // 'rename' | 'skip' | 'overwrite' | 'overwrite_if_newer'
229
+ ): Promise<OrganizationPlan>;
230
+
231
+ // Execute organization with safety guarantees
232
+ async organize(
233
+ directory: string,
234
+ files: FileWithSize[],
235
+ options?: OrganizeOptions
236
+ ): Promise<OrganizeResult>;
237
+
238
+ // Safety mechanisms:
239
+ // 1. File descriptor validation before move
240
+ // 2. Atomic copy with COPYFILE_EXCL (race-safe)
241
+ // 3. Automatic backup to .file-organizer-backups/ on overwrite
242
+ // 4. Retry loop for race condition recovery
243
+ }
244
+ ```
245
+
246
+ #### HashCalculatorService
247
+
248
+ ```typescript
249
+ class HashCalculatorService {
250
+ // Streaming hash calculation
251
+ async calculateHash(filePath: string): Promise<string>;
252
+
253
+ // Find duplicates (memory-safe)
254
+ async findDuplicates(files: FileWithSize[]): Promise<DuplicateGroup[]>;
255
+ }
256
+ ```
257
+
258
+ #### FileScannerService (v3.1.4)
259
+
260
+ ```typescript
261
+ class FileScannerService {
262
+ // Recursive directory scanning
263
+ async getAllFiles(directory: string, options?: ScanOptions): Promise<FileWithSize[]>;
264
+
265
+ // Size calculation
266
+ async calculateDirectorySize(directory: string): Promise<number>;
267
+ }
268
+ ```
269
+
270
+ #### CategorizerService
271
+
272
+ ```typescript
273
+ class CategorizerService {
274
+ // File categorization
275
+ getCategory(fileName: string): CategoryName;
276
+
277
+ // Custom rules support
278
+ setCustomRules(rules: CategoryRule[]): void;
279
+
280
+ // Category statistics
281
+ categorizeFiles(files: FileWithSize[]): CategoryBreakdown;
282
+ }
283
+ ```
284
+
285
+ #### RollbackService (v3.1.4)
286
+
287
+ ```typescript
288
+ class RollbackService {
289
+ // Create rollback manifest
290
+ async createManifest(actions: OrganizeAction[]): Promise<string>;
291
+
292
+ // Execute rollback
293
+ async rollback(manifestId: string): Promise<RollbackResult>;
294
+
295
+ // List available rollbacks
296
+ async listRollbacks(): Promise<RollbackManifest[]>;
297
+ }
298
+ ```
299
+
300
+ ### 4. File Reader Module (`readers/`) ⭐ NEW in v3.2.0
301
+
302
+ **Responsibility:** Secure file reading with comprehensive security controls
303
+
304
+ **Architecture:** 3-layer security architecture with Result-based error handling
305
+
306
+ #### SecureFileReader
307
+
308
+ ```typescript
309
+ class SecureFileReader {
310
+ // Read file with full security validation
311
+ async read(
312
+ filePath: string,
313
+ options?: Partial<FileReadOptions>
314
+ ): Promise<Result<FileReadResult, FileReadError>>;
315
+
316
+ // Create readable stream for large files
317
+ async readStream(
318
+ filePath: string,
319
+ options?: Partial<FileReadOptions>
320
+ ): Promise<Result<Readable, FileReadError>>;
321
+
322
+ // Read raw buffer (binary data)
323
+ async readBuffer(
324
+ filePath: string,
325
+ options?: Partial<FileReadOptions>
326
+ ): Promise<Result<Buffer, FileReadError>>;
327
+ }
328
+ ```
329
+
330
+ **Security Layers:**
331
+
332
+ 1. **Layer 1 - Input Validation:**
333
+ - Path validation using PathValidatorService
334
+ - Sensitive file pattern checking (47+ patterns)
335
+ - Zod schema validation for inputs
336
+
337
+ 2. **Layer 2 - Security Controls:**
338
+ - Rate limiting (120 req/min, 2000 req/hour)
339
+ - Audit logging (all operations logged)
340
+ - Size limits (default 10MB, max 100MB)
341
+
342
+ 3. **Layer 3 - Execution:**
343
+ - TOCTOU-safe file opening with O_NOFOLLOW
344
+ - SHA-256 checksum calculation
345
+ - Streaming for large files (>100KB)
346
+
347
+ **Error Types:**
348
+
349
+ - `FileNotFoundError` - File doesn't exist
350
+ - `FileAccessDeniedError` - Permission denied or sensitive file
351
+ - `FileTooLargeError` - Exceeds size limit
352
+ - `PathValidationError` - Security check failed
353
+ - `RateLimitError` - Too many requests
354
+
355
+ #### FileReaderFactory
356
+
357
+ ```typescript
358
+ class FileReaderFactory {
359
+ // Create with default settings
360
+ static createDefault(): SecureFileReader;
361
+
362
+ // Create with custom options
363
+ static createWithOptions(options: ReaderOptions): SecureFileReader;
364
+ }
365
+ ```
366
+
367
+ **Integration:** The File Reader is exposed via the `file_organizer_read_file` MCP tool with Zod schema validation.
368
+
369
+ ### 5. Utils Layer (`utils/`)
370
+
371
+ **Responsibility:** Shared utility functions
372
+
373
+ #### Logger
374
+
375
+ ```typescript
376
+ class Logger {
377
+ // Structured JSON logging to stderr (MCP stdio protocol)
378
+ debug(message: string, context?: Record<string, any>): void;
379
+ info(message: string, context?: Record<string, any>): void;
380
+ warn(message: string, context?: Record<string, any>): void;
381
+ error(message: string, error?: Error, context?: Record<string, any>): void;
382
+
383
+ // Features:
384
+ // - ISO 8601 timestamps
385
+ // - Configurable log levels (debug/info/warn/error)
386
+ // - Error stack traces for error logs
387
+ // - JSON format for machine parsing
388
+ }
389
+ ```
390
+
391
+ - **error-handler.ts** - Centralized error handling
392
+ - **file-utils.ts** - File system helpers
393
+ - **formatters.ts** - Data formatting (bytes, dates, etc.)
394
+
395
+ ### 5. Schemas Layer (`schemas/`)
396
+
397
+ **Responsibility:** Input validation using Zod
398
+
399
+ ```typescript
400
+ // Example: Path validation
401
+ export const PathSchema = z
402
+ .string()
403
+ .min(1, 'Path cannot be empty')
404
+ .max(4096, 'Path exceeds maximum length')
405
+ .refine((path) => !path.includes('\0'), 'Path contains null bytes');
406
+ ```
407
+
408
+ ## 🔄 Data Flow
409
+
410
+ ### Example: Organize Files Operation
411
+
412
+ ```
413
+ 1. LLM Request
414
+
415
+ 2. MCP Server (server.ts)
416
+ - Parse JSON-RPC request
417
+ - Route to organize tool
418
+
419
+ 3. Tool Handler (tools/file-organization.ts)
420
+ - Validate args with Zod
421
+ - Call PathValidatorService
422
+
423
+ 4. PathValidatorService
424
+ - 7-layer validation
425
+ - Return validated path
426
+
427
+ 5. FileScannerService
428
+ - Scan directory
429
+ - Apply resource limits
430
+
431
+ 6. CategorizerService
432
+ - Categorize each file
433
+
434
+ 7. OrganizerService
435
+ - Generate organization plan
436
+ - Check conflicts
437
+ - Execute moves (if not dry run)
438
+
439
+ 8. RollbackService
440
+ - Create rollback manifest
441
+
442
+ 9. Tool Handler
443
+ - Format response (JSON/Markdown)
444
+
445
+ 10. MCP Server
446
+ - Send JSON-RPC response
447
+
448
+ 11. LLM receives result
449
+ ```
450
+
451
+ ## 💾 File Organization
452
+
453
+ ### Source Structure
454
+
455
+ ```
456
+ src/
457
+ ├── server.ts # MCP server entry point
458
+ ├── index.ts # Main entry point
459
+ ├── types.ts # TypeScript type definitions
460
+ ├── constants.ts # Application constants
461
+ ├── config.ts # Configuration management
462
+
463
+ ├── services/ # Core business logic
464
+ │ ├── path-validator.service.ts
465
+ │ ├── organizer.service.ts
466
+ │ ├── hash-calculator.service.ts
467
+ │ ├── file-scanner.service.ts
468
+ │ ├── categorizer.service.ts
469
+ │ └── rollback.service.ts
470
+
471
+ ├── tools/ # MCP tool implementations
472
+ │ ├── file-scanning.ts
473
+ │ ├── file-organization.ts
474
+ │ ├── file-duplicates.ts
475
+ │ ├── file-categorization.ts
476
+ │ └── ...
477
+
478
+ ├── schemas/ # Zod validation schemas
479
+ │ ├── security.schemas.ts
480
+ │ ├── common.schemas.ts
481
+ │ ├── scan.schemas.ts
482
+ │ └── organize.schemas.ts
483
+
484
+ └── utils/ # Shared utilities
485
+ ├── logger.ts
486
+ ├── error-handler.ts
487
+ ├── file-utils.ts
488
+ └── formatters.ts
489
+ ```
490
+
491
+ ## 🧪 Testing Architecture
492
+
493
+ ### Test Structure
494
+
495
+ ```
496
+ tests/
497
+ ├── unit/ # Unit tests for services
498
+ │ ├── services/
499
+ │ │ ├── path-validator.test.ts
500
+ │ │ ├── organizer.test.ts
501
+ │ │ └── ...
502
+ │ └── utils/
503
+
504
+ ├── integration/ # Integration tests for tools
505
+ │ ├── tools/
506
+ │ │ └── organize.test.ts
507
+ │ └── edge-cases.test.ts
508
+
509
+ └── performance/ # Performance benchmarks
510
+ └── performance.test.ts
511
+ ```
512
+
513
+ ### Test Philosophy
514
+
515
+ 1. **Unit Tests** - Test services in isolation
516
+ 2. **Integration Tests** - Test complete workflows
517
+ 3. **Security Tests** - Validate all security controls
518
+ 4. **Performance Tests** - Ensure scalability
519
+
520
+ ## 🚀 Performance Considerations
521
+
522
+ ### Streaming Operations
523
+
524
+ Large files are processed using streams to avoid memory exhaustion:
525
+
526
+ ```typescript
527
+ // Hash calculation uses streams
528
+ const hash = crypto.createHash('sha256');
529
+ const stream = createReadStream(filePath, { highWaterMark: 64 * 1024 });
530
+ stream.on('data', (chunk) => hash.update(chunk));
531
+ ```
532
+
533
+ ### Resource Limits
534
+
535
+ ```typescript
536
+ // Enforced at multiple levels:
537
+ - File size: Skip files > 100MB for hashing
538
+ - File count: Max 10,000 files per operation
539
+ - Recursion depth: Max 10 levels
540
+ - Path length: Max 4,096 characters
541
+ ```
542
+
543
+ ### Caching Strategy
544
+
545
+ - Category mappings cached in-memory
546
+ - File stats cached during single operation
547
+ - No persistent caching (stateless design)
548
+
549
+ ## 🔧 Configuration
550
+
551
+ ### Configuration System (`config.ts`)
552
+
553
+ The server uses a platform-aware configuration system that combines hardcoded defaults with user customization.
554
+
555
+ **Structure:**
556
+
557
+ ```typescript
558
+ export const CONFIG = {
559
+ VERSION: '3.1.5',
560
+
561
+ security: {
562
+ enablePathValidation: true,
563
+ allowCustomDirectories: true,
564
+ logAccess: true,
565
+ maxScanDepth: 10,
566
+ maxFilesPerOperation: 10000,
567
+ },
568
+
569
+ paths: {
570
+ defaultAllowed: getDefaultAllowedDirs(), // Platform-aware safe directories
571
+ customAllowed: loadCustomAllowedDirs(), // User-defined from config.json
572
+ alwaysBlocked: getAlwaysBlockedPatterns(), // System protection patterns
573
+ },
574
+ };
575
+ ```
576
+
577
+ **Default Allowed Directories:**
578
+
579
+ - **Windows:** Desktop, Documents, Downloads, Pictures, Videos, Music, OneDrive, Projects
580
+ - **macOS:** Desktop, Documents, Downloads, Movies, Music, Pictures, iCloud Drive, Projects
581
+ - **Linux:** Desktop, Documents, Downloads, Music, Pictures, Videos, ~/dev, ~/workspace
582
+
583
+ **User Configuration:**
584
+
585
+ - **Windows:** `%APPDATA%\file-organizer-mcp\config.json`
586
+ - **macOS:** `~/Library/Application Support/file-organizer-mcp/config.json`
587
+ - **Linux:** `~/.config/file-organizer-mcp/config.json`
588
+
589
+ **Config File Format:**
590
+
591
+ ```json
592
+ {
593
+ "customAllowedDirectories": ["C:\\Users\\Name\\CustomFolder", "D:\\Projects"],
594
+ "settings": {
595
+ "maxScanDepth": 10,
596
+ "logAccess": true
597
+ }
598
+ }
599
+ ```
600
+
601
+ ## 🎯 Design Patterns
602
+
603
+ ### Dependency Injection
604
+
605
+ ```typescript
606
+ // Services receive dependencies via constructor
607
+ class OrganizerService {
608
+ constructor(
609
+ private categorizer: CategorizerService,
610
+ private rollback?: RollbackService
611
+ ) {}
612
+ }
613
+ ```
614
+
615
+ ### Error Handling
616
+
617
+ ```typescript
618
+ // Centralized error handling
619
+ try {
620
+ const result = await operation();
621
+ } catch (error) {
622
+ return createErrorResponse(error);
623
+ }
624
+ ```
625
+
626
+ ### Type Safety
627
+
628
+ ```typescript
629
+ // Strict types with Zod runtime validation
630
+ const ArgsSchema = z.object({
631
+ directory: PathSchema,
632
+ dry_run: z.boolean().optional(),
633
+ });
634
+
635
+ type Args = z.infer<typeof ArgsSchema>;
636
+ ```
637
+
638
+ ## 📊 Monitoring & Logging
639
+
640
+ ### Structured Logging
641
+
642
+ ```json
643
+ {
644
+ "timestamp": "2026-02-08T00:00:00.000Z",
645
+ "level": "info",
646
+ "message": "Created rollback manifest: uuid (6 actions)"
647
+ }
648
+ ```
649
+
650
+ ### Log Levels
651
+
652
+ - `error` - Critical failures
653
+ - `warn` - Recoverable issues (e.g., skipped files)
654
+ - `info` - Operation milestones
655
+ - `debug` - Detailed diagnostics
656
+
657
+ ## 🔮 Future Architecture Changes
658
+
659
+ ### Planned Improvements
660
+
661
+ 1. **Plugin System** - Allow custom categorization rules
662
+ 2. **Database Layer** - Persistent state for large operations
663
+ 3. **Queue System** - Background processing for large directories
664
+ 4. **Metrics Collection** - Performance monitoring
665
+ 5. **Multi-language Support** - i18n infrastructure
666
+
667
+ ## 📚 References
668
+
669
+ - [Model Context Protocol Spec](https://modelcontextprotocol.io)
670
+ - [Zod Documentation](https://zod.dev)
671
+ - [TypeScript Handbook](https://www.typescriptlang.org/docs)
672
+
673
+ ---
674
+
675
+ **Last Updated:** February 8, 2026
676
+ **Version:** 3.1.5