Backend Architecture
Middleware and DI: free-recall review
Retrieval beats re-reading. For each prompt, say or write a full answer from memory before you open the model answer — the effort of recall is what fixes the unit’s two axes in long-term memory.
Reconstruct the unit’s spine without looking back: the request vs wiring axes, the middleware contract, the composition root, the three injection scopes and their traps, the testing seam, and what a container does in production.
- 01What are the request axis and the wiring axis, and why is naming the axis a senior reflex?
- 02State the Express middleware contract and the two ways it is broken.
- 03What is inversion of control, what does the composition root do, and why is a service locator an anti-pattern?
- 04Name the three DI scopes, the trap each invites, and the rule that avoids both main traps.
- 05What is the test seam, and what is the difference between a fake and a mock?
- 06What does a DI container do under the hood, why do circular dependencies break it, and why prefer eager startup?
If you reconstructed each answer from memory, you hold the unit’s spine: name the axis first; on the request axis a middleware does exactly one of pass/terminate/forward and order is a security-and-cost boundary; on the wiring axis classes declare needs and a composition root supplies them; default to stateless singletons and escalate scope only when forced; DI’s payoff is the seam where you fake what you own and mock the boundaries you don’t; and a container is that composition root mechanized — topologically sorting the graph, refusing cycles, and failing fast at boot.