Script Valley
Writing Clean Code: Naming, Functions & Structure
Code Structure and Organization/Assessment

Practice & Assessment

Test your understanding of Code Structure and Organization

Multiple Choice Questions

6
1

What is the primary advantage of feature-based folder structure over layer-based?

2

What is a barrel file (index.js) used for in module organization?

3

The 'newspaper rule' for file organization means:

4

Which technique correctly breaks a circular dependency between user.service and email.service?

5

Why should business logic never directly import database code?

6

Where should a test file for 'users/user.service.js' ideally be located?

Coding Challenges

1
1

Restructure 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.

Medium

Mini Project

1

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.

Hard
Practice & Assessment โ€” Code Structure and Organization โ€” Writing Clean Code: Naming, Functions & Structure โ€” Script Valley โ€” Script Valley