How spongy01/question-paper-generator works
Project Type & Purpose
• This is a Node.js-based command-line application designed to generate custom question papers. It accepts user input for question paper parameters (via an interactive CLI or a JSON file) and uses a validation and generation pipeline to produce question papers. The project also supports reading questions from multiple JSON files specified in a configuration file.
File Structure
• The top-level directories include:
• Generator/ – Contains logic for question paper generation (questionGenerator.js and questionManager.js).
• IO_Module/ – Deals with input and output, handling file reading, requirement fetching, and writing the generated question paper.
• Validator/ – Handles the validation of the input requirements.
• data/ – Stores the question store JSON files.
• tests/ – Contains tests (using Jest) that verify the functionality of question generation and validation.
• docs/ – Contains generated documentation (including JSDoc outputs) and assets (fonts, scripts, styles).
• Configuration files like package.json, jsdoc.config.json, and utils.js centralize settings such as file paths for input data and output papers.
• The starting point is app.js, which drives the execution flow.
Architectural Components & Their Relationships
• “User Interface / Input Module”: Represents the input methods –
• Interactive CLI input or JSON file-based requirements (questionRequirements.json).
• “Validation Module” (Validator/validator.js): Receives the input requirements and validates them. It ensures that the required criteria (like marks distribution and difficulty percentages) are met.
• “Data Access Module”: Consists of:
• IO_Module/fileReader.js – Reads the question store from files listed in data_locations.json.
• IO_Module/requirementFetcher.js – Fetches user requirement.
• “Question Generation Module” (Generator/):
• questionGenerator.js takes validated requirements and applies generation logic (related to problems like subset-sum).
• questionManager.js coordinates the process.
• “Output Module”: (IO_Module/paperWriter.js) writes the generated paper into a JSON file in a designated output directory (configured in utils.js).
• “Configuration/Utils Module”: (utils.js) provides centralized configuration including paths and common settings.
Important Architectural Patterns & Design Principles
• Separation of Concerns: Each module (IO, Validator, Generator) is responsible for a distinct part of the pipeline.
• Modularity: Components are split into separate directories allowing independent development and possible future extension (e.g., adding more input methods or output formats).
• Configurable Behavior: Through utils.js and data_locations.json, the system’s behavior can be altered without modifying the business logic.
• Testing: The project includes a tests/ directory with Jest tests for critical modules.