FYBY AI

How the Inherited Service Fits Together

One repository read at commit 4f1c9a2: 92 source files, 41 test files, a year of history and one incident note. It is a sound service with one fragile path.

The question, as asked in the composer

How is this service put together, and where is it fragile?

Source
A service your team is about to inheritGitHub repository
Template
Codebase Architecture ReviewSoftware
Sections
17
Exhibits
16
Sources
1828 passages
Citations
181

Sample reportThe sources, passages and figures in this report are invented for illustration.

Four facts in the code make one stuck charge stop the whole service, unseen

Two conditions cause the stall; two more decide that no one sees it and that it leaves damage behind. Each rests on lines in the captured commit.

Sources src/server.ts, lines 12 to 301; src/payments/client.ts, lines 88 to 962; src/worker/queue.ts, lines 41 to 583; lines 60 to 744; docs/incidents/2026-03-14-stall.md, lines 1 to 125; lines 36 to 416; src/api/health.ts, lines 5 to 147; Dockerfile, lines 1 to 228

In Brief

  1. 1

    One worker runs every background job in turn, and the payment call it makes has no timeout.32

  2. 2

    That combination stopped every job for 47 minutes on 14 March, with 1,312 waiting, while /health stayed green.57

  3. 3

    A job interrupted by a restart is never picked up again; one charge was finished by hand.46

  4. 4

    The worker is the busiest module and the only one with no tests; the three stale dependencies sit on the same path.91011

  5. 5

    A timeout with an idempotency key, a lease on running jobs and a health check that sees the worker remove most of the risk.12

01Executive Summary

The service is a single process that answers requests and runs background jobs.1 Every request passes through one queue worker, so a stalled job holds up the whole service.3 The payment call that most jobs make has no timeout,2 the health check does not look at the worker,7 and the worker has no tests.10

This is not a hypothesis. On 14 March the gateway stopped answering and the queue grew to 1,312 waiting jobs over 47 minutes until someone restarted the process;5 one charge was left half-done and finished by hand.6 Three small changes remove most of that exposure. The rest of the code is in reasonable shape: strict types,15 54 per cent line coverage16 and a clean edge.

Exhibit 1

Three changes of small or medium effort remove most of the exposure

Each recommendation placed by the effort it takes and the risk it removes, judged from the code.

Sources src/payments/client.ts, lines 88 to 962; src/worker/queue.ts, lines 60 to 744; lines 41 to 583; src/api/health.ts, lines 5 to 147; tests/, folder listing10; src/server.ts, lines 64 to 8013; ci/deps-report.json, lines 1 to 21211; src/worker/jobs/export-report.ts, lines 22 to 4714

02Source Snapshot

Fact list

Repository
A service your team is about to inherit, captured at commit 4f1c9a2 on 2 October 2026.
Files read
92 source files, 16,720 lines, the package manifest, the migrations, the pipeline and the Dockerfile.18
Tests
Forty-one test files.10
History
Twelve months: 318 commits by 7 authors.9
Documents
One incident note, 14 March 2026.5
Not captured
Production logs, dashboards, and the gateway’s own documentation.

Exhibit 2

The service in five numbers

Sources src/worker/queue.ts, lines 41 to 583; docs/incidents/2026-03-14-stall.md, lines 1 to 125; src/db/pool.ts, lines 14 to 2217; coverage/coverage-summary.json, lines 1 to 6416; ci/deps-report.json, lines 1 to 21211

03Key Findings

Writes return at once and do their work on the queue.20 One worker runs every job in turn,3 so a slow payment call, which has no timeout, can stop all the others.2 When the process stops mid-job, the job is never picked up again.4

Three of the ten most-changed files are in src/worker, and none of them is tested.910 The three dependencies over two years old are the queue library, the gateway client and the scheduler: the path that failed in March.11

Exhibit 3

Three passages of the queue worker decide how the service fails

src/worker/queue.ts as captured, with the lines this report rests on marked.

Sources src/worker/queue.ts, lines 41 to 583; lines 60 to 744; lines 90 to 11819

04Evidence Table

Comparison table

FindingWhereRead fromStrength
One worker for every jobsrc/worker/queue.ts, lines 41 to 583CodeRead in code
Payment call without timeout or retrysrc/payments/client.ts, lines 88 to 962CodeRead in code
Running jobs are never reclaimedsrc/worker/queue.ts, lines 60 to 744CodeRead in code
Health check blind to the workersrc/api/health.ts, lines 5 to 147CodeRead in code
A 47-minute stall happeneddocs/incidents/2026-03-14-stall.md5DocumentDocumented
No idempotency key on the chargesrc/payments/client.ts, lines 60 to 8712CodeRead in code
No worker teststests/10ListingRead in listing
Three stale dependencies on the failing pathci/deps-report.json11ReportRead in report
The export can starve the poolexport-report.ts and pool.ts1417CodeInferred

05Architecture Overview

One process registers the routes, opens the database pool and starts the queue worker.1 The code is layered as an edge (src/api), three domain modules (orders, billing, accounts), the worker, two integrations (payments, notify), the data layer and a shared library.

The layering mostly holds. But the worker reaches into orders and billing while both of them enqueue work for it, which makes three import cycles, and the API reads the database directly in four places, past the domain.20

Exhibit 4

The layers mostly hold; the worker is tied into the domain by three import cycles

Each module sits in its layer; a line is an import from one module into another, with the number of import statements. Lit lines run both ways; dashed ones skip a layer. The rule under each module is its line coverage.

Imports to src/lib are not drawn: every module uses it. The API also enqueues jobs directly, three times. Counts are import statements between top-level folders of src/.

Sources src/server.ts, lines 12 to 301; Commit history, Twelve months to the captured commit9; src/api/routes.ts, lines 8 to 4020; src/payments/client.ts, lines 88 to 962; coverage/coverage-summary.json, lines 1 to 6416; tests/, folder listing10; src/db/pool.ts, lines 14 to 2217

Exhibit 5

Read across a row: what each module imports. The worker both uses and is used by orders and billing

Import statements from the row’s module into the column’s. A cell and its mirror both filled is a cycle.

Source src/server.ts, lines 12 to 301

06Module Map

Comparison table

ModuleRoleFilesLinesTestsCoverage
src/apiRoutes, auth, validation; every write becomes a job.183,420971%
src/ordersOrders and their items.142,880868%
src/billingCharges, invoices, proration, month-end run.112,310544%
src/accountsSign-in, sessions, customers.91,640677%
src/workerThe single queue worker and its seven job types.371,960None100%
src/paymentsCalls the payment gateway; webhooks.24820231%
src/notifyReceipts and mail.5610358%
src/dbConnection pool, repositories, 31 migrations.17162,140662%
src/libConfig, logging, retry helpers.8940249%
All of src/Nine modules9216,7204154%16

07Runtime and Build Model

The build compiles to dist/ and the container runs one process.188 The worker lives inside that process,1 so the API and the jobs share one event loop and one pool of ten connections.17 The container’s health check calls /health, which only asks the database.7

On SIGTERM the process exits without waiting for the running job,13 and every deploy is such a stop. The pipeline lints, type-checks and runs the tests on every push, but no step starts the worker.23

Exhibit 6

A deploy is a stop, and a stop abandons the job in hand

What src/server.ts does when the process starts and when it is told to stop.

Sources src/server.ts, lines 12 to 301; lines 64 to 8013; src/db/pool.ts, lines 14 to 2217; src/api/routes.ts, lines 112 to 14021; src/worker/queue.ts, lines 20 to 3422; lines 60 to 744; Dockerfile, lines 1 to 228

08Dependency Analysis

Comparison table

DependencyRolePinnedAgeBehindImported by
cronwheelScheduler0.9.838 months111 major1 file
joblineJob queue1.4.231 months112 majors4 files
paylink-sdkPayment gateway client2.0.127 months112 majors2 files
retrykitRetry with backoff4.0.012 monthsCurrentnotify and inventory sync, not payments11
The other 18HTTP, database, validation, logging and the restUnder two years24Current or one major

Exhibit 7

The three oldest dependencies are the queue, the gateway client and the scheduler: the path that failed

Age of the pinned release of each of the 22 runtime dependencies, in months at the captured commit. Lit: over two years.

Sources ci/deps-report.json, lines 1 to 21211; package.json, lines 10 to 3424

09Key Workflows

A write is two workflows. In the request, the route checks the session and the body, the orders module inserts the order and its job in one transaction, and the client gets 202 Accepted.2025 Later the worker polls the jobs table every 500 milliseconds,22 runs the charge and enqueues the receipt.3

A failed job is retried five times over 62 seconds and then marked dead.19 But a job that never fails, because its call never returns, never reaches that path: it stays running, and the worker with it.2 The incident note shows what that looks like.27

Exhibit 8

A job can leave every state but one: running, when its call never returns

The states the jobs table records and the transitions queue.ts makes. Dotted is a transition the code does not have.

Sources src/worker/queue.ts; src/payments/client.ts; docs/incidents/2026-03-14-stall.md; src/server.ts; src/db/migrations/; src/worker/jobs/index.ts9 passages
src/worker/queue.ts, lines 20 to 3422; lines 60 to 744; lines 90 to 11819; lines 41 to 583; src/payments/client.ts, lines 88 to 962; docs/incidents/2026-03-14-stall.md, lines 36 to 416; src/server.ts, lines 64 to 8013; src/db/migrations/, 007_jobs.sql, lines 1 to 1825; src/worker/jobs/index.ts, lines 1 to 3626

Exhibit 9

On 14 March the queue grew by about 28 jobs a minute for 47 minutes, and took 31 more to drain

Jobs waiting, from the incident note’s table, minute by minute after 14:00.

Source docs/incidents/2026-03-14-stall.md, lines 14 to 34, table 127

10Data Model and APIs

Thirty-one migrations build twelve tables; twenty-four of them can be reversed.28 The queue is a table in the same database, so a job and its order are written together, which is good; but the job’s payload names the order without a key, so nothing stops a job outliving its order.25

The API has forty-six routes, twenty-two of them writes and five open without sign-in.21

Exhibit 10

Twelve tables hold together by keys, except the queue: a job names its order but nothing binds them

The tables the 31 migrations create, with their key columns, joined where a foreign key exists.

Sources src/db/migrations/, 007_jobs.sql, lines 1 to 1825; folder listing28

Exhibit 11

Twenty-two of the forty-six routes write, and every write becomes a job

Routes registered in routes.ts by area and method.

Sources src/api/routes.ts, lines 112 to 14021; lines 8 to 4020

11Code Quality Signals

Checklist

4not met1unclear3metof 8 checks

  • Tests for the workerNot metNone in tests/.10
  • Timeouts on outside callsNot metThe payment call and the export have none.226
  • Graceful shutdownNot metExits without waiting for the running job.13
  • Dependencies kept currentNot metThree are over two years old.24
  • Reversible migrationsUnclear24 of 31 have a down step.28
  • Tests overallMetForty-one test files, 54 per cent line coverage.16
  • Strict type checkingMetstrict and unchecked index access on.15
  • Checks on every pushMetLint, type check, tests.23

Exhibit 12

The module that changes most is the one with no tests

Each module by how often its files changed in a year and how much of it the tests run; the area of a circle is its size in lines.

Changes count file changes in the commit history; coverage is the last recorded run in the repository.

Sources Commit history, Twelve months to the captured commit9; coverage/coverage-summary.json, lines 1 to 6416; tests/, folder listing10

Exhibit 13

Three of the ten most-changed files are in the worker, and none of the three is tested

File changes in twelve months for the ten busiest files; hatched files have no test.

Sources Commit history, Twelve months to the captured commit9; tests/, folder listing10

12Risks and Maintainability Assessment

The single worker is the fragile point: one stuck job holds up the second half of every write.3 The likeliest stuck job is a charge, which has no timeout,2 and when it is cleared by a restart the job is orphaned.4 Nothing would tell an operator: the health check stays green.7

Adding a retry is not enough on its own. The charge carries no idempotency key,12 so retrying a request that did reach the gateway could charge twice. The order is a timeout, then a key, then a bounded retry.

Exhibit 14

Five of six failures reach the charges; only the database going down is caught by the health check

What each failure the code allows takes with it. A cross stops the capability; a half mark slows or loses some of it.

Sources src/payments/client.ts, lines 88 to 962; src/worker/queue.ts, lines 60 to 744; lines 90 to 11819; src/worker/jobs/export-report.ts, lines 22 to 4714; src/worker/jobs/index.ts, lines 1 to 3626; src/api/health.ts, lines 5 to 147

13System Context

Flow diagram

Exhibit 15

One process faces three callers and four systems; only the payment call can hang it

The service in its surroundings, as the code names them. The worker shares the process and the pool with the API.

Sources src/payments/client.ts, lines 88 to 962; src/worker/jobs/index.ts, lines 1 to 3626; src/api/health.ts, lines 5 to 147; src/api/routes.ts, lines 112 to 14021; src/db/pool.ts, lines 14 to 2217; src/worker/queue.ts, lines 41 to 583; src/db/migrations/, folder listing28; Dockerfile, lines 1 to 228

14Request and Data Flow

Sequence diagram

Exhibit 16

A write is answered in one transaction; the charge happens later, on the one hop with no timeout

POST /orders followed through the code, message by message. The client has its answer before the charge is attempted.

Sources src/api/routes.ts, lines 8 to 4020; lines 112 to 14021; src/db/migrations/, 007_jobs.sql, lines 1 to 1825; src/worker/queue.ts, lines 20 to 3422; lines 41 to 583; src/payments/client.ts, lines 88 to 962; docs/incidents/2026-03-14-stall.md, lines 1 to 125; src/worker/jobs/index.ts, lines 1 to 3626

15Key Figures

Metrics

Workers
1For every job.3
Longest stall
47 min14 March, 1,312 jobs waiting.5
Database connections
10One pool for API and jobs.17
Line coverage
54%src/worker 0 per cent.16
Routes
4622 writes, each a job.21
Stale dependencies
3 of 22All on the payment path.11

16Open Questions

How long payment calls take in practice is not in the repository: the incident note records one hang, not a distribution.5 Whether the gateway honours an idempotency key, and for how long, is in its documentation, which was not captured.12 The month-end run has a fifteen-minute limit but no record of how long it usually takes.26

17Appendix

Line numbers refer to commit 4f1c9a2. Changes count file changes in the twelve months of history before it.9 Coverage is the last recorded run in the repository, not a run made for this report.16 Import counts are import statements between the top-level folders of src/.

Sources

What the run captured and read: 18 sources, 28 passages. Each passage is quoted as it stands in the source; the marked words are the ones the report relies on.

  1. src/server.tsCode fileTwo passages, cited 12 times

    1. 1Lines 12 to 30

      The server registers the routes, opens the database pool and starts the queue worker.
    2. 13Lines 64 to 80

      On SIGTERM the server stops accepting requests and exits; it does not wait for a job that is running.
  2. src/api/routes.tsCode fileTwo passages, cited 12 times

    1. 20Lines 8 to 40

      Every write route puts a job on the queue and returns at once.
    2. 21Lines 112 to 140

      Forty-six routes are registered: twenty-four read routes and twenty-two write routes; five need no sign-in.
  3. src/api/health.tsCode fileOne passage, cited 9 times

    1. 7Lines 5 to 14

      GET /health returns 200 when the database answers a query; it does not look at the worker.
  4. src/worker/queue.tsCode fileFour passages, cited 34 times

    1. 22Lines 20 to 34

      The worker polls the jobs table every 500 milliseconds and takes the oldest job whose run_after has passed.
    2. 3Lines 41 to 58

      A single worker takes jobs from the queue and runs each one to the end before it takes the next.
    3. 4Lines 60 to 74

      Jobs marked running when the process stops are left as they are; nothing returns them to the queue.
    4. 19Lines 90 to 118

      A failed job is retried up to five times, after 2, 4, 8, 16 and 32 seconds, and then marked dead.
  5. src/worker/jobs/index.tsCode fileOne passage, cited 6 times

    1. 26Lines 1 to 36

      Seven job types are registered. Five set timeoutMs; charge-order and export-report do not.
  6. src/worker/jobs/export-report.tsCode fileOne passage, cited 3 times

    1. 14Lines 22 to 47

      The export takes one connection from the pool and holds it while it streams every row of the month.
  7. src/payments/client.tsCode fileTwo passages, cited 19 times

    1. 12Lines 60 to 87

      The request body carries the order id and the amount; no idempotency key is set.
    2. 2Lines 88 to 96

      The payment request is sent with no timeout and is not retried.
  8. src/db/pool.tsCode fileOne passage, cited 9 times

    1. 17Lines 14 to 22

      One connection pool of ten connections serves the whole service.
  9. src/db/migrations/FolderTwo passages, cited 9 times

    1. 28Folder listing

      Thirty-one migrations create twelve tables; twenty-four of them have a down step.
    2. 25007_jobs.sql, lines 1 to 18

      The jobs table holds the queue: id, type, payload, state, attempts, run_after, locked_at, error. The payload is JSON and has no foreign key.
  10. package.jsonCode fileTwo passages, cited 5 times

    1. 24Lines 10 to 34

      Twenty-two runtime dependencies, three of them pinned to a version over two years old.
    2. 18Lines 4 to 9

      build runs the compiler into dist/; start runs node dist/server.js.
  11. ci/deps-report.jsonCode fileOne passage, cited 12 times

    1. 11Lines 1 to 212

      For each runtime dependency: the pinned version, the date it was released, the latest version and the files that import it.
  12. tests/FolderOne passage, cited 11 times

    1. 10Folder listing

      Forty-one test files; none for src/worker/.
  13. coverage/coverage-summary.jsonCode fileOne passage, cited 9 times

    1. 16Lines 1 to 64

      Line coverage by folder at the last recorded run, 54 per cent overall; src/worker 0 per cent.
  14. Commit historyCommit logOne passage, cited 7 times

    1. 9Twelve months to the captured commit

      504 file changes in 318 commits by 7 authors; src/worker/queue.ts changed in 58 of them.
  15. docs/incidents/2026-03-14-stall.mdMarkdown fileThree passages, cited 16 times

    1. 5Lines 1 to 12

      At 14:02 the payment gateway stopped answering. The worker waited on the open request until the process was restarted at 14:49; 1,312 jobs were waiting by then.
    2. 27Lines 14 to 34, table 1

      Jobs waiting, every five minutes from 14:00 to 15:20.
    3. 6Lines 36 to 41

      One charge stayed marked running after the restart and was finished by hand the next day.
  16. DockerfileCode fileOne passage, cited 4 times

    1. 8Lines 1 to 22

      One image, one process: node dist/server.js, with a health check on GET /health every 30 seconds.
  17. .ci/pipeline.ymlCode fileOne passage, cited twice

    1. 23Lines 1 to 48

      Lint, type check and the tests run on every push; no step starts the worker.
  18. tsconfig.jsonCode fileOne passage, cited twice

    1. 15Lines 2 to 14

      strict: true; noUncheckedIndexedAccess: true.

In the App