Skip to content

mohdajmalraza/SnapVault-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Έ SnapVault – Photo Storage & Search Backend

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.


πŸ“š Table of Contents


πŸš€ Features

  • πŸ” 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

πŸ› οΈ Tech Stack

  • Backend: Node.js, Express.js
  • Database: PostgreSQL (via Supabase)
  • ORM: Sequelize
  • API Integration: Unsplash API
  • Testing: Jest, Supertest
  • Deployment: Vercel

πŸ“¬ API Endpoints

πŸ‘€ Create User

POST /api/users

➑️ Sample Request

{
  "username": "johndoe",
  "email": "johndoe@example.com"
}

βœ… Sample Response

{
  "message": "User created successfully",
  "user": {
    "id": 1,
    "username": "johndoe",
    "email": "johndoe@example.com",
    "createdAt": "...",
    "updatedAt": "..."
  }
}

πŸ” Search Images (Unsplash)

GET /api/photos/search?query=nature

βœ… Sample Response

{
  "results": [
    {
      "imageUrl": "https://images.unsplash.com/photo-1",
      "description": "Beautiful sunshine"
      "altDescription": "Beautiful nature scene"
    },
    ...
  ]
}

πŸ’Ύ Save Photo

POST /api/photos

➑️ Sample Request

{
  "imageUrl": "https://images.unsplash.com/photo-abc",
  "description": "Sunset by the beach",
  "altDescription": "sunset beach view",
  "tags": ["sunset", "beach"],
  "userId": 1
}

βœ… Sample Response

{
  "message": "Photo saved successfully"
}

βž• Add Tags to Photo

POST /api/photos/:photoId/tags

➑️ Sample Request

{
  "tags": ["newTag", "ocean"]
}

βœ… Sample Response

{
  "message": "Tags added successfully"
}

🏷️ Search by Tag

GET /api/photos/tag/search?tags=sunset&sort=ASC&userId=1

βœ… Sample Response

{
  "photos": [
    {
      "imageUrl": "https://images.unsplash.com/photo-xyz",
      "description": "Sunset from rooftop",
      "dateSaved": "2025-05-28T17:41:33.903Z",
      "tags": ["sunset", "sky"]
    },
    ...
  ]
}

πŸ“œ Get Search History

GET /api/search-history?userId=1

βœ… Sample Response

{
  "searchHistory": [
    { "query": "sunset", "timestamp": "2025-05-26T12:31:00Z" },
    { "query": "mountain", "timestamp": "2025-05-26T14:05:00Z" },
    ...
  ]
}

πŸ“¬ Postman Collection

You can test all SnapVault API endpoints using the Postman collection:


πŸ”§ Installation & Setup

  1. Clone the repository

    git clone https://github.com/ajmal92786/SnapVault-Backend.git
    cd SnapVault-Backend
  2. Install dependencies

    npm install
  3. Set up .env file
    Create a .env file 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
  4. Run migrations (if using sequelize-cli)

    npx sequelize-cli db:migrate
  5. Start the server

    npm start

πŸ§ͺ Testing

SnapVault uses Jest and Supertest for unit and integration testing.

βž• Setup .env.test

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

Make sure package.json contains:

"scripts": {
  "test": "cross-env NODE_ENV=test jest --runInBand"
}

βœ… Run tests

npm run test

Test coverage includes:

  • βœ… Validation logic
  • βœ… Service methods
  • βœ… Controller behavior
  • βœ… API route integration

πŸš€ Live API Deployment

All APIs are live and can be accessed at:

πŸ‘‰ Base URL: https://snap-vault-backend-ajmal-razas-projects.vercel.app


πŸ“ Folder Structure

β”œβ”€β”€ __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

πŸ™Œ Credits


πŸ“„ License

This project is for educational purposes. You can reuse parts freely.

About

πŸ–ΌοΈ A Photo Curation App using Node.js, Express & Sequelize. Users can search photos via Unsplash API, save them to collections, tag images, and track search history.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors