Refactor the monolithic index.ts into modular Express routers
Description
The entire application — middleware, every route, all in-memory stores, and the error handler — lives in a single ~600-line src/index.ts. This makes the file hard to test in isolation and to extend. This issue decomposes it into Express Router modules, middleware modules, and store modules, while keeping the default-exported app and all current behavior identical.
Requirements and context
- Repository scope:
StableRoute-Org/Stableroute-backend only.
- Create
src/routes/ (e.g. pairs.ts, quote.ts, webhooks.ts, apiKeys.ts, admin.ts, meta.ts), src/middleware/ (rate limit, request id, security headers, timing, pause), and src/stores/ for the in-memory maps.
- Keep
src/index.ts as the composition root that mounts routers and exports app.
- Preserve every route path, status code, and JSON body exactly so existing tests pass unchanged.
- No behavior change — this is a pure structural refactor.
Suggested execution
- Fork the repo and create a branch
git checkout -b refactor/architecture-13-modular-routers
- Implement changes
- Write code in: create the new modules under
src/routes/, src/middleware/, src/stores/; trim src/index.ts to composition.
- Write comprehensive tests in:
src/__tests__/index.test.ts must still pass; add focused unit tests per router module.
- Add documentation: add a module map to
README.md.
- Add TSDoc on each exported router/middleware.
- Validate security: confirm middleware ordering (pause → rate limit → timing → headers → request id) is preserved.
- Test and commit
Test and commit
- Run
npm run build, npm run lint, and npm test.
- Cover edge cases: middleware order regression, route mounting, 404 fallback still last.
- Paste full
npm test output in the PR.
Example commit message
refactor: split index.ts into routers, middleware, and stores
Guidelines
- Minimum 95 percent test coverage for impacted code.
- Clear, reviewer-focused documentation.
- Timeframe: 96 hours.
Community & contribution rewards
- 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
- ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.
Refactor the monolithic index.ts into modular Express routers
Description
The entire application — middleware, every route, all in-memory stores, and the error handler — lives in a single ~600-line
src/index.ts. This makes the file hard to test in isolation and to extend. This issue decomposes it into ExpressRoutermodules, middleware modules, and store modules, while keeping the default-exportedappand all current behavior identical.Requirements and context
StableRoute-Org/Stableroute-backendonly.src/routes/(e.g.pairs.ts,quote.ts,webhooks.ts,apiKeys.ts,admin.ts,meta.ts),src/middleware/(rate limit, request id, security headers, timing, pause), andsrc/stores/for the in-memory maps.src/index.tsas the composition root that mounts routers and exportsapp.Suggested execution
git checkout -b refactor/architecture-13-modular-routerssrc/routes/,src/middleware/,src/stores/; trimsrc/index.tsto composition.src/__tests__/index.test.tsmust still pass; add focused unit tests per router module.README.md.Test and commit
npm run build,npm run lint, andnpm test.npm testoutput in the PR.Example commit message
refactor: split index.ts into routers, middleware, and storesGuidelines
Community & contribution rewards