Skip to content

Ritiksh19/CivicSwap

Repository files navigation

CivicSwap ๐Ÿ˜๏ธ

Hyper-Local Resource Exchange Platform

A community-driven web platform enabling neighbors to lend, borrow, and gift everyday items and services โ€” without ever leaving their neighborhood.

React Node.js MongoDB Vite Tailwind CSS JWT Leaflet Vercel Railway Brevo


๐Ÿ“– About

CivicSwap addresses a common urban coordination failure: households collectively own enormous quantities of items (tools, kitchenware, books, camping gear, appliances) that sit unused 95% of the time, while neighbors spend money buying or renting those very same items nearby.

CivicSwap transforms idle household resources into shared community capital by connecting neighbors through a structured, trustworthy platform anchored to real geographic locations.


๐ŸŒ Live Demo

Service URL
Frontend https://civicswap-frontend.vercel.app
Backend API https://civicswap-backend.up.railway.app/api
Health Check https://civicswap-backend.up.railway.app/api/health

โœจ Features

  • ๐Ÿ—บ๏ธ Hyper-Local Discovery โ€” Interactive Leaflet.js map with adjustable radius (0.5โ€“10 km) to find available items near your location
  • ๐Ÿ”„ Borrow Lifecycle Management โ€” Structured 6-state workflow: Request โ†’ Approval โ†’ ON_LOAN โ†’ Return โ†’ Rating โ†’ Closed
  • โญ Reputation & Rating System โ€” Transparent trust scores calculated as weighted averages from completed transactions
  • ๐Ÿ“ง Automated Email Notifications โ€” Brevo REST API triggers emails at every stage of the borrow lifecycle
  • ๐Ÿ” Search & Category Filters โ€” Find items by keyword, category (Tools, Books, Kitchenware, Electronics, etc.), distance, or date
  • ๐Ÿ“ฑ Responsive UI โ€” Premium Airbnb-inspired design with parallax, hover effects, and smooth transitions โ€” works on desktop, tablet, and mobile
  • ๐Ÿ”’ JWT Authentication โ€” Secure stateless session management with bcrypt password hashing
  • ๐Ÿ“ Browser Geolocation โ€” Auto-detect user location during registration and item posting
  • ๐Ÿ›ก๏ธ Overlap Validation โ€” Prevents double-booking of items on conflicting dates

๐Ÿงฑ Tech Stack

Layer Technology
Frontend Framework React 18 + Vite
Styling Tailwind CSS (CDN)
Maps Leaflet.js + React-Leaflet + MongoDB $nearSphere
Backend Node.js + Express.js
Database MongoDB + Mongoose (MongoDB Atlas)
Authentication JWT (jsonwebtoken) + bcryptjs
Email Service Brevo REST API (via Axios over HTTPS)
HTTP Client Axios (frontend + backend)
Frontend Hosting Vercel
Backend Hosting Railway
Version Control Git & GitHub
API Testing Thunder Client (VS Code Extension)
IDE Visual Studio Code

๐Ÿ—‚๏ธ System Modules

  1. User Authentication โ€” Registration, login, JWT session management, home location setup (lat/lng via browser Geolocation API)
  2. Geographic Discovery โ€” Leaflet.js interactive map, radius-based item filtering using MongoDB $nearSphere, adjustable radius slider (0.5โ€“10 km)
  3. Item Management โ€” Post/edit listings with title, description, category, location, and status (AVAILABLE / ON_LOAN / UNAVAILABLE)
  4. Borrow Lifecycle โ€” 6-state machine: PENDING โ†’ APPROVED โ†’ ON_LOAN โ†’ RETURNED โ†’ CLOSED (or REJECTED); conflict detection for overlapping bookings
  5. Reputation & Rating โ€” Star ratings (1โ€“5) after each completed transaction; weighted average reputation scores displayed on user profiles
  6. Notifications โ€” Automated emails via Brevo REST API for request submission, approval/rejection, return confirmation, and rating prompts
  7. Database Management โ€” MongoDB with Mongoose ODM, 2dsphere geo-indexes, FK-style references, and scheduling conflict validation
  8. Search & Filter โ€” Keyword search, category filter, sort by distance, integrated with geographic radius
  9. Responsive UI โ€” Premium dark-themed dashboard with item cards, status badges, transaction history, map view, and user profiles

๐Ÿ“ Project Structure

CivicSwap/
โ”œโ”€โ”€ civicswap-backend/
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ db.js                    # MongoDB Atlas connection
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ”œโ”€โ”€ User.js                  # User schema with geo-location + bcrypt
โ”‚   โ”‚   โ”œโ”€โ”€ Item.js                  # Item schema with 2dsphere index
โ”‚   โ”‚   โ”œโ”€โ”€ Transaction.js           # 6-state lifecycle model
โ”‚   โ”‚   โ””โ”€โ”€ Rating.js                # Rating with unique constraint
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ”œโ”€โ”€ authController.js        # Register, login, profile
โ”‚   โ”‚   โ”œโ”€โ”€ itemController.js        # CRUD + geo-filter
โ”‚   โ”‚   โ”œโ”€โ”€ transactionController.js # Full borrow lifecycle + email triggers
โ”‚   โ”‚   โ””โ”€โ”€ ratingController.js      # Ratings + auto reputation update
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ authRoutes.js
โ”‚   โ”‚   โ”œโ”€โ”€ itemRoutes.js
โ”‚   โ”‚   โ”œโ”€โ”€ transactionRoutes.js
โ”‚   โ”‚   โ””โ”€โ”€ ratingRoutes.js
โ”‚   โ”œโ”€โ”€ middleware/
โ”‚   โ”‚   โ””โ”€โ”€ authMiddleware.js        # JWT token verification
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ sendEmail.js             # Brevo REST API email utility
โ”‚   โ”‚   โ””โ”€โ”€ keepAlive.js             # Health ping utility
โ”‚   โ”œโ”€โ”€ .env
โ”‚   โ””โ”€โ”€ server.js
โ”‚
โ””โ”€โ”€ civicswap-frontend/
    โ”œโ”€โ”€ src/
    โ”‚   โ”œโ”€โ”€ components/
    โ”‚   โ”‚   โ”œโ”€โ”€ Navbar.jsx            # Auth-aware navbar with scroll effect
    โ”‚   โ”‚   โ”œโ”€โ”€ ItemCard.jsx
    โ”‚   โ”‚   โ””โ”€โ”€ ProtectedRoute.jsx    # JWT-protected route wrapper
    โ”‚   โ”œโ”€โ”€ context/
    โ”‚   โ”‚   โ””โ”€โ”€ AuthContext.jsx       # Global JWT + user state
    โ”‚   โ”œโ”€โ”€ pages/
    โ”‚   โ”‚   โ”œโ”€โ”€ HomePage.jsx          # Parallax hero, stats, features
    โ”‚   โ”‚   โ”œโ”€โ”€ LoginPage.jsx         # Split layout with animated form
    โ”‚   โ”‚   โ”œโ”€โ”€ RegisterPage.jsx      # Geolocation-enabled registration
    โ”‚   โ”‚   โ”œโ”€โ”€ DashboardPage.jsx     # Stats cards + recent activity
    โ”‚   โ”‚   โ”œโ”€โ”€ ItemListPage.jsx      # Search + filter + geo-sorted grid
    โ”‚   โ”‚   โ”œโ”€โ”€ ItemDetailPage.jsx    # Item info + borrow request form
    โ”‚   โ”‚   โ”œโ”€โ”€ CreateItemPage.jsx    # Category selector + location detect
    โ”‚   โ”‚   โ”œโ”€โ”€ EditItemPage.jsx      # Pre-filled form + status toggle
    โ”‚   โ”‚   โ”œโ”€โ”€ MapPage.jsx           # Leaflet.js map + radius slider
    โ”‚   โ”‚   โ”œโ”€โ”€ ProfilePage.jsx       # Reputation + items + reviews
    โ”‚   โ”‚   โ”œโ”€โ”€ EditProfilePage.jsx   # Name, bio, password, location
    โ”‚   โ”‚   โ”œโ”€โ”€ TransactionPage.jsx   # Activity + incoming requests tabs
    โ”‚   โ”‚   โ””โ”€โ”€ RatingPage.jsx        # Interactive star rating
    โ”‚   โ””โ”€โ”€ utils/
    โ”‚       โ””โ”€โ”€ axios.js              # Axios instance with JWT injection
    โ”œโ”€โ”€ vercel.json                   # SPA routing fix for Vercel
    โ””โ”€โ”€ index.html

โš™๏ธ Hardware Requirements

  • Computer/Laptop with minimum 4 GB RAM (8 GB recommended)
  • Internet connection (for APIs, map tiles, MongoDB Atlas, deployment)
  • Minimum 20 GB free disk space for development environment and database
  • Smartphone (optional) โ€” for testing the responsive mobile interface

๐Ÿ’ป Software Requirements

  • OS: Windows 10/11 / Ubuntu 20.04+ / macOS
  • Runtime: Node.js 18+
  • Package Manager: npm
  • Database: MongoDB 6+ (local) or MongoDB Atlas (cloud)
  • Git & GitHub
  • Web Browser: Google Chrome / Mozilla Firefox

๐Ÿš€ Getting Started

Prerequisites

Make sure you have Node.js 18+ and npm installed:

node --version
npm --version

Backend Setup

# 1. Clone the repository
git clone https://github.com/<your-username>/civicswap.git
cd civicswap/civicswap-backend

# 2. Install dependencies
npm install

# 3. Configure environment variables
cp .env.example .env
# Edit .env with your credentials

.env configuration:

PORT=5000
MONGO_URI=mongodb://localhost:27017/civicswap
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRE=7d
EMAIL_FROM=your_email@gmail.com
BREVO_API_KEY=your_brevo_api_key
NODE_ENV=development
# 4. Start the backend server
npm run dev

Backend runs at http://localhost:5000

Frontend Setup

# 1. Navigate to frontend directory
cd ../civicswap-frontend

# 2. Install dependencies
npm install

# 3. Update API base URL in src/utils/axios.js
# baseURL: 'http://localhost:5000/api'

# 4. Start the frontend dev server
npm run dev

Frontend runs at http://localhost:5173


๐Ÿ“ก API Reference

Auth

Method Endpoint Access Description
POST /api/auth/register Public Register user with location
POST /api/auth/login Public Login, returns JWT token
GET /api/auth/profile Private Get logged-in user profile
PUT /api/auth/profile Private Update name, bio, password, location

Items

Method Endpoint Access Description
GET /api/items Private Get items with optional geo-filter
POST /api/items Private Create new item listing
GET /api/items/:id Private Get single item with owner details
PUT /api/items/:id Private Update item (owner only)
DELETE /api/items/:id Private Delete item (owner only)

Geo-filter params: ?latitude=28.59&longitude=78.55&radius=5&category=Tools&search=drill

Transactions

Method Endpoint Access Description
POST /api/transactions Private Create borrow request
GET /api/transactions/my Private Get all my transactions
GET /api/transactions/requests Private Get incoming PENDING requests
PUT /api/transactions/:id/approve Private Approve request (lender only)
PUT /api/transactions/:id/reject Private Reject request (lender only)
PUT /api/transactions/:id/return Private Mark item as returned

Ratings

Method Endpoint Access Description
POST /api/ratings Private Submit rating after return
GET /api/ratings/user/:id Private Get all ratings for a user

๐Ÿ”ฎ Future Scope

  • WhatsApp / Telegram Integration โ€” Borrow notifications directly on preferred messaging apps
  • AI-Based Recommendations โ€” Suggest items based on borrowing history, location, and community preferences
  • Mobile App โ€” Dedicated Android & iOS app with push notifications and real-time map updates
  • Tiered Trust Badges โ€” "Verified Neighbor", "Top Lender" badges + penalty flags for late returns
  • Payment Gateway โ€” Optional damage deposits via Razorpay / PayPal for high-value items
  • Community Forums & Events โ€” Discussion boards and neighborhood events section
  • Advanced Analytics Dashboard โ€” Admin dashboard for usage stats, popular categories, and community health metrics
  • SMS Notifications โ€” Brevo SMS API integration for real-time transaction alerts

๐Ÿ“š References


๐Ÿ‘ค Author

Harshit Trivedi Ritik Sharma


CivicSwap โ€” Reducing unnecessary consumption, one neighborhood at a time. ๐ŸŒฑ

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors