SnapVault is a backend service that allows users to search and save images from the Unsplash API, tag them, and retrieve personalized search history. Built with Node.js, Express, PostgreSQL, and Sequelize ORM, this project demonstrates solid RESTful API design, validation, and test coverage.
- Features
- Tech Stack
- API Endpoints
- Postman Collection
- Installation & Setup
- Testing
- Live API Deployment
- Folder Structure
- Credits
- π Search images from Unsplash API by keyword
- π€ Create users (username & email)
- πΎ Save selected photos with descriptions and tags
- π·οΈ Tagging system (max 5 tags per photo)
- ποΈ Search saved photos by tag with sorting by date
- π΅οΈββοΈ Track and retrieve user's search history
- β Comprehensive validations and error handling
- π§ͺ Unit and integration tests with Jest & Supertest
- Backend: Node.js, Express.js
- Database: PostgreSQL (via Supabase)
- ORM: Sequelize
- API Integration: Unsplash API
- Testing: Jest, Supertest
- Deployment: Vercel
POST /api/users
{
"username": "johndoe",
"email": "johndoe@example.com"
}{
"message": "User created successfully",
"user": {
"id": 1,
"username": "johndoe",
"email": "johndoe@example.com",
"createdAt": "...",
"updatedAt": "..."
}
}GET /api/photos/search?query=nature
{
"results": [
{
"imageUrl": "https://images.unsplash.com/photo-1",
"description": "Beautiful sunshine"
"altDescription": "Beautiful nature scene"
},
...
]
}POST /api/photos
{
"imageUrl": "https://images.unsplash.com/photo-abc",
"description": "Sunset by the beach",
"altDescription": "sunset beach view",
"tags": ["sunset", "beach"],
"userId": 1
}{
"message": "Photo saved successfully"
}POST /api/photos/:photoId/tags
{
"tags": ["newTag", "ocean"]
}{
"message": "Tags added successfully"
}GET /api/photos/tag/search?tags=sunset&sort=ASC&userId=1
{
"photos": [
{
"imageUrl": "https://images.unsplash.com/photo-xyz",
"description": "Sunset from rooftop",
"dateSaved": "2025-05-28T17:41:33.903Z",
"tags": ["sunset", "sky"]
},
...
]
}GET /api/search-history?userId=1
{
"searchHistory": [
{ "query": "sunset", "timestamp": "2025-05-26T12:31:00Z" },
{ "query": "mountain", "timestamp": "2025-05-26T14:05:00Z" },
...
]
}You can test all SnapVault API endpoints using the Postman collection:
-
Clone the repository
git clone https://github.com/ajmal92786/SnapVault-Backend.git cd SnapVault-Backend -
Install dependencies
npm install
-
Set up
.envfile
Create a.envfile in the root directory with the following credentials:DB_USERNAME=your_user DB_PASSWORD=your_password DB_NAME=your_db DB_HOST=your_host.supabase.co DB_PORT=5432 PORT=3000 UNSPLASH_ACCESS_KEY=your_unsplash_api_key
-
Run migrations (if using sequelize-cli)
npx sequelize-cli db:migrate
-
Start the server
npm start
SnapVault uses Jest and Supertest for unit and integration testing.
.env.test is not committed to GitHub. Create one using the provided template:
# .env.test
DB_USERNAME=your_user
DB_PASSWORD=your_password
DB_NAME=your_db
DB_HOST=your_host.supabase.co
DB_PORT=5432
PORT=3000
UNSPLASH_ACCESS_KEY=your_unsplash_api_keyMake sure package.json contains:
"scripts": {
"test": "cross-env NODE_ENV=test jest --runInBand"
}npm run testTest coverage includes:
- β Validation logic
- β Service methods
- β Controller behavior
- β API route integration
All APIs are live and can be accessed at:
π Base URL: https://snap-vault-backend-ajmal-razas-projects.vercel.app
βββ __tests__/ # Test files (controllers, routes, services, validations)
βββ config/ # Sequelize & environment config
βββ migrations/ # Sequelize CLI migration files
βββ models/ # Sequelize models (User, Photo, Tag, SearchHistory)
βββ src/ # Source code
β βββ controllers/ # Handles request logic
β βββ services/ # Contains reusable business logic
β βββ routes/ # API route definitions
β βββ validations/ # Input validation functions
βββ .env # Secrets and environment variables
βββ .env.test # Secrets and environment variables for testing
βββ .gitignore # Prevents sensitive or bulky files from being tracked
βββ index.js
βββ package-lock.json # Exact versions of installed packages
βββ package.json # Project dependencies and scripts
βββ README.md
βββ server.js # App entry point
- Made with β€οΈ by MOHD AJMAL RAZA
- GitHub: github.com/ajmal92786
This project is for educational purposes. You can reuse parts freely.