Unit 2 Code Review
In this assignment, you will learn to conduct effective code reviews by examining your teammates' Express.js practice websites directly on GitHub. Code review is a fundamental skill in professional development that helps teams maintain quality, catch issues early, and share knowledge.
You will learn what to look for in Express.js code, practice using GitHub's review tools, and provide constructive feedback to help your teammates improve their projects. Since your teammates may be at different stages of MVC refactoring, you'll learn to evaluate code at various levels of organization.
Understanding What to Look For
Before reviewing code, you need to know what constitutes good vs. problematic Express.js code. Here are the key areas and common issues, organized by whether the code has been refactored to MVC architecture or not.
Feature Removal Issues (All Projects Should Address)
Regardless of refactoring progress, all projects should have removed the products feature as part of the MVC assignment. Check for:
❌ Products Feature Not Properly Removed
-
Route handlers still exist: Look in
server.jsor controller files for any routes like/products -
Navigation links remain: Check
views/partials/header.ejsfor product page links -
View files not deleted: Look for
products.ejsor similar files in views directory - Commented-out code: Products code that was commented out instead of deleted
✅ Products Feature Properly Removed
- No product-related routes anywhere in the codebase
- Navigation menus updated to remove product links
- All product-related template files deleted
- No leftover commented-out product code
Pre-Refactoring Code Issues
If your teammate hasn't started MVC refactoring yet, watch for these traditional Express.js issues:
❌ Poor Structure (Monolithic)
[project-root]
├── server.js # Everything in one file
├── style.css # Should be in public/css/
├── home.ejs # Should be in views/
└── logo.png # Should be in public/images/
❌ Common Problems in server.js
// Unnecessary 'next' parameter
app.get('/catalog', (req, res, next) => {
res.render('catalog'); // next is never used
});
// Poor variable names
const x = req.params.cat;
const y = req.query.sort || 'def';
// Missing validation
app.get('/catalog/:id', (req, res) => {
const courseId = req.params.id; // What if this is invalid?
res.render('course-detail', { id: courseId });
});
Post-Refactoring Code Issues (MVC Architecture)
If your teammate has started or completed MVC refactoring, look for these organization and architecture issues:
❌ Poor MVC Organization
[project-root]
├── src/
│ ├── controllers/
│ │ └── everything.js # All controllers in one file
│ ├── models/
│ │ └── data.js # Generic naming
│ └── middleware/
│ └── stuff.js # Unclear purpose
└── server.js
✅ Good MVC Structure
[project-root]
├── src/
│ ├── controllers/
│ │ ├── catalog/
│ │ │ └── catalog.js
│ │ ├── index.js
│ │ └── routes.js
│ ├── models/
│ │ └── catalog/
│ │ └── catalog.js
│ ├── middleware/
│ │ └── global.js
│ └── views/
└── server.js
❌ Controllers with Mixed Concerns
// Controller doing too much
export const catalogPage = (req, res) => {
// Data should be in models, not controllers
const courses = {
'CS121': { title: 'Intro Programming' },
'CS162': { title: 'Intro CS' }
};
// Business logic should be in models too
const sortedCourses = Object.values(courses).sort((a, b) =>
a.title.localeCompare(b.title)
);
res.render('catalog', { courses: sortedCourses });
};
✅ Clean Controller Implementation
import { getAllCourses } from '../../models/catalog/catalog.js';
export const catalogPage = (req, res) => {
const courses = getAllCourses(); // Data comes from model
res.render('catalog', {
title: 'Course Catalog',
courses: courses
});
};
❌ Middleware Split Unnecessarily
// Multiple middleware functions doing similar things
app.use(addImportantLocalVariables);
app.use(addOptionalLocalVariables);
app.use(addMoreStuff);
✅ Consolidated Middleware
// Single middleware that handles all res.locals setup
app.use(addLocalVariables);
Quick Practice
Look at this code and identify issues (this could be found in either a monolithic server.js or a controller file):
app.get('/catalog/:cat/:id', (req, res, next) => {
const c = req.params.cat;
const i = req.params.id;
if(c==='courses'){
res.render('course-detail',{category:c,id:i});
}else{
res.send('Not found');
}
});
Click to see the issues
- Unused
nextparameter → Remove from the function header - Poor variable names (
c,i) → Use full names likecategoryandid - Inconsistent formatting → Add blank lines and indentation consistently
- Using
res.send()→ Useres.render()and actually render an error page or template - No validation for
req.params.id→ Add validation or fail gracefully
Communication Guidelines
Write issues and feedback as if you're helping a teammate, not grading them. Remember that code at different stages of refactoring requires different types of feedback:
Be Helpful and Adaptive
- Explain why: "This could cause errors if users enter invalid data" or "MVC separation makes the code more maintainable"
- Suggest solutions: Show the fix, don't just point out problems
-
Be specific: "Line 23 in server.js" or "catalogPage function in src/controllers/catalog/catalog.js"
- You can reference a specific line of code in this issue by linking it directly. Hover over the line number, click the … (ellipsis), and select "Reference in new issue". GitHub will automatically create an issue with a direct link to that line of code.
- Stay positive: Point out what works well alongside what needs improvement
- Be understanding: If someone is mid-refactor, acknowledge their progress while suggesting improvements
Keep It Simple
- Focus on the most important issues that will help them learn
- Don't create issues for minor formatting preferences
- If you're unsure about their refactoring approach, ask questions rather than making assumptions
- Prioritize functional issues over stylistic ones
Examples of Good Feedback Tone
- Encouraging: "Great job starting the MVC refactoring! I noticed one small issue with the controller structure..."
- Educational: "This works, but moving the data to a model file would follow MVC principles better because..."
- Constructive: "I see you haven't started the MVC refactor yet. Here are some areas to focus on when you do..."
Assignment Instructions
1. Get Repository Links
Share your GitHub repository link with your teammates and get at least two repository links to review. You will review these entirely through GitHub's web interface.
2. Review Using GitHub
For each repository, navigate through the files using GitHub's web interface. Since teammates may be at different stages of MVC refactoring, adapt your review approach:
For All Projects (Regardless of Refactoring Status):
- Project structure: Check the main repository view for proper organization
- Products feature removal: Verify products functionality has been completely removed
- Navigation: Check that header/navigation doesn't link to non-existent pages
If Project Is Not Yet Refactored:
- server.js: Review route implementations and middleware setup
- views/ directory: Check EJS templates and partials organization
- public/ directory: Verify static files are properly organized
If Project Has Started/Completed MVC Refactoring:
- src/controllers/: Review controller organization and separation of concerns
- src/models/: Check that data and business logic are properly separated
- src/middleware/global.js: Verify consolidated middleware is properly implemented
- src/views/: Check template organization
- server.js: Should be clean and focused on configuration only
- Import/export statements: Check for correct file paths and consistent patterns
3. Create GitHub Issues
When you find significant problems, create GitHub issues. Here's how:
- Navigate to the file with the issue
- Click the line number where the problem occurs
- Click the three dots (…) that appear
- Select "Reference in new issue"
- Write a clear title and description
4. Writing Good GitHub Issues
Keep GitHub issues simple and helpful. Here are examples of well-written issues for both types of projects:
Example 1: Products Feature Not Removed
Products route still exists after refactoring
Found a products route that should have been removed as part of the MVC assignment cleanup:
```javascript
app.get('/products', (req, res) => {
// This entire route should be deleted
});
```
Please remove this route completely, along with:
- Any products link in your navigation
- The products.ejs template file if it exists
- Any products-related variables or data
Example 2: MVC Organization Issue
Controller contains data that should be in models
The catalogPage controller is storing course data directly instead of using the model layer:
```javascript
// This data should be moved to src/models/catalog/catalog.js
const courses = { 'CS121': { title: 'Intro' } };
```
Consider moving this data to your catalog model and importing it:
```javascript
import { getAllCourses } from '../../models/catalog/catalog.js';
const courses = getAllCourses();
```
Example 3: Traditional Code Quality Issue
Unused next parameter in catalog route
The catalog route includes a `next` parameter but never uses it:
```javascript
// Change this:
app.get('/catalog', (req, res, next) => {
// To this:
app.get('/catalog', (req, res) => {
```
This follows Express best practices and makes the code cleaner.
Example 4: Import Path Issue (MVC Projects)
Incorrect import path in routes.js
The import statement for the catalog controller appears to have an incorrect path:
```javascript
// Check if this path is correct
import { catalogPage } from './catalog.js';
```
Based on your directory structure, it should probably be:
```javascript
import { catalogPage } from './catalog/catalog.js';
```
Create 2-3 meaningful issues per repository you review. Focus on issues that would actually improve the code, whether they are related to MVC organization or general code quality.
Review Checklist
Since you may have limited experience performing code reviews, use this comprehensive checklist as a guide to conducting a thorough review. This detailed guidance will help you identify issues you might otherwise miss and develop the systematic approach that professional developers use. Only check on items that are relevant to your teammate's current refactoring progress:
Feature Cleanup (All Projects)
- Products routes completely removed from server.js or controllers
- Products navigation links removed from header.ejs
- Products template files deleted
- No commented-out products code remaining
Traditional Express.js Code (If Not Yet Refactored)
- Route handlers use correct parameters (no unused
next) - Static middleware configured:
app.use(express.static('public')) - Parameters accessed via
req.paramsandreq.query - Templates rendered with
res.render() - Error handling present
- CSS files in
public/css/ - Images in
public/images/ - EJS files in
views/ - Partials in
views/partials/
MVC Architecture (If Refactoring Started/Completed)
- Controllers separated into logical files in
src/controllers/ - Models contain data and business logic in
src/models/ - Middleware organized in
src/middleware/global.js - Consolidated middleware function (not unnecessarily split)
- Views moved to
src/views/ - Routes file properly imports controllers and middleware
- Server.js focused on configuration, not business logic
- Import/export statements use correct file paths
- Controllers don't contain hard-coded data (use models instead)
- Error handler shows different information in production vs development
Code Quality (All Projects)
- Variable names are clear (not
x,y,data) - Consistent formatting and indentation
- No obvious duplicated code
- Proper error handling
EJS Templates (All Projects)
- Correct EJS syntax (
<%= %>,<%- include() %>) - Partials included properly
- Variables used correctly
- No broken links or missing template references
Assignment Submission Template
Fill out the form below and click the download button at the bottom. A new page will open and automatically prompt you to print as a PDF. Submit that PDF to your instructor. Take care to provide professional, well-written responses that clearly explain the technical concepts. This assignment demonstrates your ability to articulate technical concepts clearly in written form:
- What you learned about code quality from reviewing others' work
- How reviewing both traditional and MVC-structured code affected your understanding
- What you discovered about the benefits and challenges of code organization
- How this experience will help you write better code yourself
- How you approached giving constructive feedback to teammates at different stages of refactoring
Keep in mind that your ability to write clearly and communicate professionally will be evaluated in this assignment. It's important to express your ideas in an articulate and comprehensive manner.
Final Steps
- Complete your reviews and create GitHub issues as described above
- Create your submission document using the form above as a guideline
- Submit the PDF to Canvas
- Notify your teammates that you have finished reviewing their code and they can check their GitHub issues
Key Concepts Summary
This assignment taught you to systematically evaluate Express.js code at different stages of organization, use GitHub's collaboration tools, and provide constructive technical feedback. You learned to adapt your review approach based on whether code follows traditional monolithic structure or modern MVC architecture.
The experience of reviewing code at different refactoring stages helps you understand the evolution of code organization and the benefits that proper architecture provides. These skills are essential in professional development where code review helps maintain quality and share knowledge among team members.
You also practiced identifying when features should be removed during refactoring, which is an important skill in maintaining clean, purposeful codebases as requirements evolve.