Skip to content

Noa-GH/se_project_express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘• WTWR (What to Wear?) β€” Backend API

A production-ready Node.js/Express REST API for the WTWR applicationβ€”a weather-aware clothing recommendation system. Built with modular architecture, robust error handling, and MongoDB integration.

GitHub: Noa-GH/se_project_express


πŸ“‹ Table of Contents


🎯 Overview

WTWR is a RESTful backend service that powers a weather-based clothing recommendation platform. Users can:

  • Create & manage accounts with secure authentication
  • Browse clothing items filtered by weather conditions
  • Like/save favorite items for quick access
  • Build personalized wardrobes based on climate preferences

Built with scalability and clean architecture in mind, this API enforces strict data validation, implements proper error handling, and follows REST best practices.

Use Case: Perfect for weather-aware fashion apps, seasonal wardrobe planning, and climate-adapted shopping assistants.


🌐 Project Links


✨ Features

Core Functionality

  • βœ… User Management β€” Sign up, sign in, retrieve profile, update profile
  • βœ… Clothing Item CRUD β€” Create, read, and delete clothing items
  • βœ… Like System β€” Mark items as favorites with persistent storage
  • βœ… JWT Authentication β€” Secure endpoint protection with token-based auth
  • βœ… Data Validation β€” Schema enforcement with Mongoose
  • βœ… Error Handling β€” Centralized, standardized error responses
  • βœ… CORS Support β€” Cross-origin request handling

Architecture

  • βœ… MVC Pattern β€” Clear separation of concerns (Models, Controllers, Routes)
  • βœ… Middleware Pipeline β€” Auth, error handling, and request logging
  • βœ… Modular Routes β€” Organized endpoint management
  • βœ… Environment Config β€” Flexible configuration via .env

πŸ›  Tech Stack

Category Technology
Runtime Node.js
Framework Express.js v5
Database MongoDB
ODM Mongoose v8
Authentication JWT + bcryptjs
Validation Celebrate (Joi) + Validator.js + Mongoose schemas
Linting ESLint (Airbnb config)
Code Formatting Prettier
Dev Tools Nodemon
CORS Built-in CORS middleware

πŸš€ Getting Started

Prerequisites

1️⃣ Clone & Install

git clone https://github.com/Noa-GH/se_project_express.git
cd se_project_express
npm install

2️⃣ Configure Environment

Create a .env file in the root directory:

PORT=3001
DB_URL=mongodb://127.0.0.1:27017/wtwr_db
NODE_ENV=development
JWT_SECRET=your_jwt_secret_here

Environment Variables:

Variable Description Default
PORT Server listening port 3001
DB_URL MongoDB connection string mongodb://127.0.0.1:27017/wtwr_db
NODE_ENV Runtime environment development
JWT_SECRET Secret used to sign JWTs dev-fallback-secret (development)

3️⃣ Start the Server

Development mode (with auto-reload):

npm run dev

Production mode:

npm start

Lint code:

npm run lint

The server will start and connect to MongoDB. You should see the app logs in the console, for example:

Connect to MongoDB
Server running on port 3001

πŸ“‘ API Reference

Authentication Endpoints

Sign Up

POST /signup
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "securePassword123"
}

Response (201):

{
  "_id": "507f1f77bcf86cd799439011",
  "name": "John Doe",
  "email": "john@example.com"
}

Sign In

POST /signin
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "securePassword123"
}

Response (200):

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

User Endpoints (Protected πŸ”’)

Get Current User

GET /users/me
Authorization: Bearer {token}

Response (200):

{
  "_id": "507f1f77bcf86cd799439011",
  "name": "John Doe",
  "email": "john@example.com",
  "createdAt": "2024-01-15T10:30:00Z"
}

Update Current User

PATCH /users/me
Authorization: Bearer {token}
Content-Type: application/json

{
  "name": "Jane Doe",
  "email": "jane@example.com"
}

Response (200): Updated user object


Clothing Items Endpoints

Get All Items

GET /items

Response (200):

[
  {
    "_id": "507f1f77bcf86cd799439012",
    "name": "Winter Jacket",
    "imageUrl": "https://...",
    "weather": "cold",
    "season": "winter",
    "owner": "507f1f77bcf86cd799439011",
    "likes": ["507f1f77bcf86cd799439010"]
  }
]

Create Clothing Item (Protected πŸ”’)

POST /items
Authorization: Bearer {token}
Content-Type: application/json

{
  "name": "Summer T-Shirt",
  "imageUrl": "https://example.com/tshirt.jpg",
  "weather": "warm",
  "season": "summer"
}

Response (201): Created item object


Delete Clothing Item (Protected πŸ”’)

DELETE /items/:itemId
Authorization: Bearer {token}

Response (200):

{ "message": "Item deleted successfully" }

Like Item (Protected πŸ”’)

PUT /items/:itemId/likes
Authorization: Bearer {token}

Response (200):

{
  "_id": "507f1f77bcf86cd799439012",
  "name": "Winter Jacket",
  "likes": ["507f1f77bcf86cd799439011"]
}

Unlike Item (Protected πŸ”’)

DELETE /items/:itemId/likes
Authorization: Bearer {token}

Response (200): Updated item object with removed like


πŸ— Project Structure

se_project_express/
β”œβ”€β”€ πŸ“„ app.js                      # Express app entry point
β”œβ”€β”€ πŸ“„ package.json                # Project metadata & dependencies
β”œβ”€β”€ πŸ“„ .env                        # Environment variables (create this)
β”œβ”€β”€ πŸ“„ README.md                   # This file
β”œβ”€β”€ πŸ“„ sprint.txt                  # Project sprint notes
β”‚
β”œβ”€β”€ πŸ“ controllers/                # Business logic
β”‚   β”œβ”€β”€ clothingItems.js           # Item CRUD handlers
β”‚   └── users.js                   # Auth & user handlers
β”‚
β”œβ”€β”€ πŸ“ models/                     # Database schemas
β”‚   β”œβ”€β”€ clothingItem.model.js      # Clothing item schema
β”‚   └── user.model.js              # User schema with validation
β”‚
β”œβ”€β”€ πŸ“ routes/                     # API route definitions
β”‚   β”œβ”€β”€ index.js                   # Main router
β”‚   β”œβ”€β”€ users.js                   # User routes
β”‚   └── clothingItems.js           # Item routes
β”‚
β”œβ”€β”€ πŸ“ middlewares/                # Custom middleware
β”‚   └── auth.js                    # JWT authentication
β”‚
β”œβ”€β”€ πŸ“ utils/                      # Utility functions
β”‚   β”œβ”€β”€ config.js                  # Configuration helpers
β”‚   └── errors.js                  # Error codes & messages
β”‚
└── πŸ“ demos/                      # Demo screenshots & guides
    β”œβ”€β”€ API_DEMO.md                # API usage examples
    └── SCREENSHOTS.md             # Feature screenshots guide

🎨 Architecture

Request Flow Diagram

HTTP Request
    ↓
[Express Middleware] (CORS, JSON parsing)
    ↓
[Routes] (Route matching)
    ↓
[Auth Middleware] (JWT verification, if protected)
    ↓
[Controllers] (Business logic)
    ↓
[Models] (Database operations)
    ↓
[MongoDB] (Persistent storage)
    ↓
HTTP Response

MVC Pattern

  • Models (/models) β€” Define data schemas and validation rules
  • Controllers (/controllers) β€” Handle request processing and business logic
  • Routes (/routes) β€” Define API endpoints and map to controllers
  • Middleware (/middlewares) β€” Auth, error handling, request preprocessing

⚠️ Error Handling

The API returns standardized error responses:

{
  "message": "Error description",
  "statusCode": 400
}

Common Status Codes

Code Meaning Example
200 βœ… Success Successful item fetch
201 βœ… Created User/item successfully created
400 ❌ Bad Request Invalid input data
401 πŸ”’ Unauthorized Missing/invalid token
404 ❌ Not Found Item/user doesn't exist
409 ⚠️ Conflict Duplicate email on signup
500 πŸ’₯ Server Error Unexpected error

πŸ”’ Authentication Flow

  1. Sign Up β†’ User creates account β†’ Server generates JWT
  2. Sign In β†’ User logs in β†’ Server returns JWT token
  3. Protected Routes β†’ Client includes Authorization: Bearer {token}
  4. Auth Middleware β†’ Verifies token β†’ Extracts user ID
  5. Controller Logic β†’ Uses user ID from token

Example Header:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

πŸ› Debugging

Enable Verbose Logging

DEBUG=* npm run dev

Check MongoDB Connection

mongosh "mongodb://127.0.0.1:27017/wtwr_db"

Test Endpoints with cURL

# Get all items
curl http://localhost:3001/items

# Sign up
curl -X POST http://localhost:3001/signup \
  -H "Content-Type: application/json" \
  -d '{"name":"John","email":"john@test.com","password":"pass123"}'

πŸ“Έ Demo Features

Visual Walkthroughs

See SCREENSHOTS.md for:

  • API Request/Response Examples with screenshots
  • Authentication Flow diagram
  • Feature Demonstrations

Quick Start Video Steps

  1. Sign Up β†’ POST /signup with name, email, password
  2. Get Token β†’ POST /signin to receive JWT
  3. Create Items β†’ POST /items with authentication
  4. Browse Items β†’ GET /items (public endpoint)
  5. Like Items β†’ PUT /items/:itemId/likes with authentication

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Style

Run ESLint before committing:

npm run lint

πŸ“ License

This project is licensed under the ISC License β€” see LICENSE file for details.


πŸ‘€ Author

Noah Ford β€” GitHub Profile


πŸ“ž Support


Last updated: May 2026 | Made with ❀️ for the WTWR project . β”œβ”€β”€ controllers # Request handlers β”œβ”€β”€ models # Mongoose schemas β”œβ”€β”€ routes # API route definitions β”œβ”€β”€ middlewares # Error handling & validation β”œβ”€β”€ utils # Helper functions


---

## ⚠️ Error Handling

The API uses centralized error handling middleware to ensure consistent responses.

Typical response format:

```json
{
  "message": "Error description"
}

πŸ§ͺ Future Improvements

  • Rate limiting & security middleware
  • Logging (Winston / Morgan)
  • Docker containerization

πŸ“ˆ Why This Project Matters

This backend demonstrates real-world API design patterns, including:

  • Separation of concerns
  • Scalable folder structure
  • Data validation and integrity
  • RESTful resource modeling

πŸ“ License

MIT

About

React back-end application WTWR

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages