Practice & Assessment
Test your understanding of Code Structure and Organization
Multiple Choice Questions
6What is the primary advantage of feature-based folder structure over layer-based?
What is a barrel file (index.js) used for in module organization?
The 'newspaper rule' for file organization means:
Which technique correctly breaks a circular dependency between user.service and email.service?
Why should business logic never directly import database code?
Where should a test file for 'users/user.service.js' ideally be located?
Coding Challenges
1Restructure a Flat Codebase into Feature Modules
You are given a flat project with 20 JavaScript files all dumped in a single src/ directory (userController.js, orderModel.js, paymentService.js, emailHelper.js, etc.). Input: the provided flat-project/ directory. Output: restructured-project/ organized by feature (users/, orders/, payments/) with barrel index.js files for each module, all imports updated to use the new paths, and a STRUCTURE.md file explaining each folder's responsibility. The application must run identically after restructuring. Estimated time: 30 minutes.
Mini Project
E-commerce API Structure Audit and Redesign
You are given a working but poorly structured e-commerce API with circular dependencies between product and order modules, business logic mixed into route handlers, all files in a single src/ folder, and no barrel exports. Your task: redesign the folder structure using feature-based organization, extract all business logic into pure functions separate from Express route handlers, break all circular dependencies using parameter passing or shared utility modules, add barrel index.js files to each feature module, and draw a module dependency graph (as ASCII art in a deps.md file) showing that dependencies now flow in only one direction. All existing API endpoints must respond identically after restructuring.
