A simple, clean marketplace for buying and selling used books. Built with Next.js, Prisma, and SQLite.
- Authentication: Sign up, log in, and log out with email/password
- List Books: Sellers can list books with details (title, author, condition, description, price, image)
- Buy Books: Browse available books, search by title/author, and purchase books
- Platform Fee: Automatically calculates 10% platform fee on top of seller price
- Payment Flow: Manual payment via eSewa QR code
- Order Management: Track orders through payment verification and completion
- Admin Dashboard: Admin can verify payments and mark payouts as sent
- Frontend: Next.js 16 (App Router) + Tailwind CSS
- Backend: Next.js API Routes
- Database: SQLite with Prisma ORM
- Authentication: JWT with httpOnly cookies
- Validation: Zod
- Node.js 20.12+ (or use Node 20.19+ for latest Prisma)
- npm or yarn
- Clone the repository:
cd merokitab- Install dependencies:
npm install- Set up environment variables:
cp env.example .env.localEdit .env.local and update:
JWT_SECRET: Change to a long random stringADMIN_EMAIL: Email address that will have admin access (default: admin@merokitab.local)DATABASE_URL: SQLite database path (default: file:./dev.db)
- Run database migrations:
npm run prisma:migrate- Seed the database (optional):
npm run seedThis creates:
- Admin user:
admin@merokitab.local/admin123 - Test user:
user@example.com/user123 - Sample books
- Start the development server:
npm run dev- Open http://localhost:3000 in your browser.
merokitab/
├── prisma/
│ ├── schema.prisma # Database schema
│ ├── seed.ts # Seed script
│ └── migrations/ # Database migrations
├── src/
│ ├── app/ # Next.js App Router pages
│ │ ├── api/ # API routes
│ │ │ ├── auth/ # Authentication endpoints
│ │ │ ├── books/ # Book CRUD endpoints
│ │ │ ├── orders/ # Order management endpoints
│ │ │ └── admin/ # Admin endpoints
│ │ ├── admin/ # Admin dashboard page
│ │ ├── books/ # Book detail page
│ │ ├── login/ # Login page
│ │ ├── orders/ # Order payment page
│ │ ├── profile/ # User profile page
│ │ ├── sell/ # List book page
│ │ └── signup/ # Signup page
│ ├── components/ # React components
│ ├── lib/ # Utility functions
│ │ ├── db.ts # Prisma client
│ │ └── auth.ts # Authentication utilities
│ └── middleware.ts # Route protection middleware
└── public/ # Static assets
- Place your eSewa QR code image in the
publicfolder (e.g.,public/esewa-qr.png) - Edit
src/app/orders/[id]/payment/page.tsx - Replace the placeholder QR code section with:
<Image
src="/esewa-qr.png"
alt="eSewa QR Code"
width={256}
height={256}
className="mx-auto"
/>The platform fee is calculated as 10% of the seller price:
platformPrice = Math.ceil(sellerPrice * 1.1)This is implemented in:
src/app/api/books/route.ts(when creating a book)src/app/sell/page.tsx(displayed in the form)
To change the commission rate, update the multiplier (currently 1.1 for 10%) in both locations.
The admin email is set via the ADMIN_EMAIL environment variable. Users with this email automatically get admin privileges when they sign up.
📖 For detailed deployment instructions, see DEPLOYMENT.md
⚡ Quick start: See QUICK_DEPLOY.md for a 15-minute deployment guide
- Push your code to GitHub
- Import the project in Vercel
- Add environment variables:
DATABASE_URL: For production, use a hosted database or Vercel PostgresJWT_SECRET: Generate a secure random stringADMIN_EMAIL: Your admin email address
- Deploy
Note: SQLite works for development but for production on Vercel, consider:
- Using Vercel Postgres (free tier available)
- Or using a hosted SQLite solution
- Or switching to PostgreSQL
To use PostgreSQL:
- Update
prisma/schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}- Update your
DATABASE_URLto a PostgreSQL connection string - Run migrations:
npm run prisma:migrate
The app can be deployed to any platform that supports Next.js:
- Railway
- Render
- DigitalOcean App Platform
- AWS Amplify
Make sure to:
- Set environment variables
- Run database migrations
- Optionally seed the database
npm run prisma:studioOpens Prisma Studio at http://localhost:5555
npm run prisma:migratenpx prisma migrate resetPOST /api/auth/signup- Create accountPOST /api/auth/login- LoginPOST /api/auth/logout- LogoutGET /api/auth/me- Get current user
GET /api/books- List books (public, supports search query)POST /api/books- Create book (auth required)GET /api/books/[id]- Get book details (public)DELETE /api/books/[id]- Delete book (auth required, owner only)
GET /api/orders?type=buy|sell- Get user orders (auth required)POST /api/orders- Create order (auth required)GET /api/orders/[id]- Get order details (auth required)PATCH /api/orders/[id]- Update order status (auth required)
GET /api/admin/orders- Get pending orders (admin only)
- Password hashing with bcrypt
- JWT tokens stored in httpOnly cookies
- Route protection via middleware
- Users can only edit/delete their own books
- Users cannot buy their own books
- Admin-only routes protected
MIT
For issues or questions, please open an issue on GitHub.