docs/Design/LessCode.md
This document records a measured plan for reducing WeKan's maintained source code without removing supported behaviour, translations, accessibility or tests. Fewer lines are useful only when they also leave fewer independent implementations to understand and keep consistent.
Measured on 2026-09-03 from JavaScript, Jade, CSS and MJS files below
client/, server/, imports/ and models/:
| Source | Files | Lines |
|---|---|---|
| JavaScript and MJS | 798 | 150,724 |
| CSS | 73 | 28,941 |
| Jade | 111 | 13,287 |
| Total | 982 | 192,952 |
Generated bundles, dependencies, translation JSON and tests are not included. The baseline is a navigation aid rather than a target to game: moving code to generated files or compressing formatting does not count as a reduction.
The largest promising areas found in the initial survey are:
| Area | Current evidence | Opportunity |
|---|---|---|
| Board themes | boardColors.css is 6,339 lines | Store theme values once and share structural rules |
| Language registry | languages.js is 1,724 lines | Generate repetitive registry entries from compact metadata |
| Large UI controllers | Several files have 1,400-2,900 lines | Extract genuinely repeated paging, forms and actions |
| Authorization | Rules occur in models, methods, publications and REST routes | Use one policy function per operation |
| Importers | Creator modules repeat entity creation pipelines | Normalize input, then persist through one pipeline |
| Retired paths | Dynamic Blaze references hide some unused code | Remove only with runtime and test evidence |
Splitting a large file, changing Jade to Svelte, minifying source, or moving logic into a dependency does not by itself satisfy this plan.
Each phase is completed and verified before the next begins. Record its before and after measurements below. Behavioural changes need positive and negative tests; visible changes also need an applicable UI or screenshot test. Preserve special cases instead of forcing them into an abstraction that makes the code harder to understand.
Small migrations are preferred. A phase may be stopped when measurement shows that its abstraction adds more complexity than it removes.
client/components/boards/boardColors.css repeats selectors and declarations
for every named theme. Introduce shared structural rules backed by CSS custom
properties, while retaining explicit overrides for gradients, image themes,
Apple Glass Pastel and other exceptional designs.
Steps:
Acceptance criteria:
boardColors.css has materially fewer declarations and bytes;Result:
boardColors.css decreased from 6,339 lines / 196,012 bytes / 1,266 rules /
2,216 declarations to 5,895 lines / 178,134 bytes / 1,058 rules / 2,064
declarations;themeAccents, boardTileTheme, allBoardsPage, publicBoardsPage,
headerBars, checkboxesAreSquare and appleGlassPastelTheme passed: 110
assertions in total;Status: completed in commit cd1039230.
Replace repetitive hand-written language registry objects with compact metadata and generated lazy imports. The public registry shape and language order must remain unchanged. Adding a language must still require all three integration points specified by the translation policy.
Acceptance criteria:
Result:
import() per language,
preserving Meteor's per-language split points;languages.js decreased from 1,724 lines / 34,873 bytes to 510 lines /
24,362 bytes;i18nLazyLoading, i18nLazyLoaded, newLanguageWiring, rtl and
changeLanguageColumns passed: 31 assertions in total.Status: completed in commit a3bc8155d.
Measure duplication in large UI files before extracting anything. Concentrate on repeated pagination, searches, menu data, modal lifecycle, form value collection and Meteor method result handling. Do not create generic helpers for code that merely looks similar but has different behaviour.
Acceptance criteria:
Result:
adjacentPage primitive now clamps page movement for All Boards, the
generic Admin Panel reports, event streams, office reports and all four
People paging contexts;tablePage 55, allBoardsPage 27, subscription lifetime 3 and grouped
offices 11);Status: completed in commit eb0e34786.
Inventory equivalent permission decisions across collection methods, Meteor methods, publications and REST endpoints. Move each equivalent decision into a pure shared policy and retain transport-specific error formatting at the edge.
Acceptance criteria:
Result:
canReadBoard policy now serves two DDP
publications, two HTTP attachment routes and fourteen position-history
method checks;Status: completed in commit e8c867b33.
Define a small internal board representation for importers. Source-specific modules parse and normalize their data; one tested writer creates users, boards, swimlanes, lists, cards, comments, checklists and attachments.
Acceptance criteria:
Result:
runImportPipeline implementation, which carries the created board ID and
normalizes absent optional collections to empty arrays;writeImportedEntity implementation now owns direct insertion, optional
timestamp touching and old-to-new ID recording for lists, swimlanes,
checklists and WeKan custom fields;Status: completed in commit 8b7115335.
Run static analysis as a candidate generator, then verify candidates against Blaze template names, dynamic imports, global registrations, server startup side effects and packaging entry points. Remove retired compatibility paths and unused feature code only after that inspection.
Acceptance criteria:
Result:
.disabled
suffix prevents Meteor from treating them as JavaScript. No import, template,
startup registration, package entry or application source referenced their
filenames or AttachmentsOld / AvatarsOld symbols;models/attachments_old.js.disabled and
models/avatars_old.js.disabled were removed: 148 tracked lines. These files
are recoverable from git history;attachmentBackwardCompatibility.js, the legacy attachment publication and
its HTTP route. Migration extraction and file-safety suites passed;meteor build .build-lesscode --directory completed successfully. Its only
diagnostics were existing asset-size and optional MongoDB dependency
warnings;WRITABLE_PATH reached Started your app and served at http://127.0.0.1:3999, after which it was stopped cleanly;.disabled
files were deliberately excluded from that baseline. The removal nevertheless
deletes 148 tracked, reviewable lines rather than moving or compressing them.Status: completed in commit e37717d07.
| Phase | Before | After | Tests | Result |
|---|---|---|---|---|
| Baseline | 192,952 lines | 191,220 lines | Not applicable | 1,732 fewer maintained lines |
| 1. Board themes | 6,339 lines / 196,012 bytes | 5,895 lines / 178,134 bytes | 110 assertions passed; browser unavailable | Completed (cd1039230) |
| 2. Language metadata | 1,724 lines / 34,873 bytes | 510 lines / 24,362 bytes | Registry parity and 31 assertions passed | Completed (a3bc8155d) |
| 3. UI mechanics | 191,284 maintained lines | 191,279 maintained lines | Primitive and 96 consumer assertions passed | Completed (eb0e34786) |
| 4. Authorization | 191,279 maintained lines | 191,248 maintained lines | 6 policy tests plus transport regressions passed | Completed (e8c867b33) |
| 5. Importers | 191,248 maintained lines | 191,220 maintained lines | 6 pipeline and 95 importer assertions passed | Completed (8b7115335) |
| 6. Removal | 148 tracked disabled lines | 0 tracked disabled lines | 709 Node suites, build and startup passed | Completed (e37717d07) |
All six phases are complete. The maintained JavaScript/MJS, Jade and CSS metric decreased from 192,952 to 191,220 lines: 1,732 fewer maintained lines. Phase 6 additionally removed 148 tracked disabled lines that were outside the baseline, for 1,880 deleted or avoided lines across the measured work.
The reductions came from fewer independent implementations, not from minification or changing template technology. Replacing all Jade/Blaze views with Svelte would temporarily increase code because both UI systems, adapters and migration tests would coexist; it is therefore not a code-reduction step by itself. Further work should repeat this measured approach on one duplicated behavior at a time and retain a change only when its tests and maintenance surface improve.