A comprehensive medicine store API built with Node.js, Express, Prisma, and PostgreSQL. Features JWT authentication, role-based access control, and complete e-commerce functionality.
- JWT Authentication: Secure token-based authentication with immediate login (no email verification)
- Medicine Management: Complete medicine catalog with categories and stock management
- Order System: Order placement and management with status tracking
- Review System: Customer reviews and ratings for medicines
- Category Management: Medicine categories for better organization
- Admin Panel: User management and platform statistics
- Seller Dashboard: Seller medicine and order management with analytics
- Search & Filtering: Advanced medicine search with multiple filters
- Role-based Access: Customer, Seller, and Admin role management
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: PostgreSQL with Prisma ORM
- Authentication: Custom JWT implementation with bcrypt
- Validation: Zod for request validation
- Development: tsx for TypeScript execution
- Deployment: Vercel
src/
├── app.ts # Express app configuration
├── server.ts # Server entry point
├── lib/
│ ├── auth.ts # Better Auth configuration (minimal)
│ └── prisma.ts # Database client setup
├── middlewares/
│ ├── auth.ts # JWT authentication middleware
│ ├── globalErrorHandler.ts # Global error handling
│ ├── notFound.ts # 404 handler
│ └── roleValidation.ts # Role validation middleware
├── modules/
│ ├── auth/ # Authentication module
│ │ ├── auth.controller.ts
│ │ ├── auth.service.ts
│ │ └── auth.router.ts
│ ├── medicine/ # Medicine management module
│ ├── order/ # Order management module
│ ├── review/ # Review system module
│ ├── category/ # Category management module
│ ├── seller/ # Seller management module
│ └── admin/ # Admin management module
├── helpers/
│ └── paginationSortingHelper.ts # Pagination utility
└── scripts/
├── seedAdmin.ts # Admin user seeding script
└── seedDatabase.ts # Database seeding script
prisma/
├── schema.prisma # Prisma schema with all models
└── migrations/ # Database migration files
- Node.js (v18+)
- PostgreSQL database (Neon recommended)
- npm or yarn package manager
-
Clone the repository
git clone <repository-url> cd MediStoreBackend
-
Install dependencies
npm install
-
Environment Setup
cp .env.example .env
Update
.envwith your configuration:DATABASE_URL="postgresql://username:password@host:port/database?sslmode=require" PORT=3000 APP_URL="http://localhost:4000" BETTER_AUTH_SECRET="your-super-secret-jwt-key" NODE_ENV="development"
-
Database Setup
# Generate Prisma client npx prisma generate # Push database schema npx prisma db push # Seed admin user and categories npx tsx src/scripts/seedAdmin.ts # Seed sample data npx tsx src/scripts/seedDatabase.ts
-
Start Development Server
npm run dev
The server will start at http://localhost:3000
Live API: https://medi-store-backend-sigma.vercel.app
# Deploy to production
vercel --prod- Production:
https://medi-store-backend-sigma.vercel.app - Development:
http://localhost:3000
POST /api/auth/register- Register new userPOST /api/auth/login- Login user (returns JWT token)GET /api/auth/me- Get current userPOST /api/auth/sign-out- Logout user
Authorization: Bearer <jwt-token>
GET /api/medicines- Get all medicines (with filtering)GET /api/medicines/:id- Get medicine details
GET /api/categories- Get all categoriesGET /api/categories/:id- Get category detailsPOST /api/categories- Create category (admin only)PUT /api/categories/:id- Update category (admin only)DELETE /api/categories/:id- Delete category (admin only)
POST /api/orders- Create new orderGET /api/orders- Get user's ordersGET /api/orders/:id- Get order details
POST /api/reviews- Create reviewGET /api/reviews/medicine/:medicineId- Get medicine reviewsPUT /api/reviews/:id- Update reviewDELETE /api/reviews/:id- Delete review
GET /api/seller/profile- Get seller profilePUT /api/seller/profile- Update seller profileGET /api/seller/medicines- Get seller's medicinesPOST /api/seller/medicines- Add new medicinePUT /api/seller/medicines/:id- Update medicineDELETE /api/seller/medicines/:id- Delete medicineGET /api/seller/orders- Get seller's ordersPATCH /api/seller/orders/:id/status- Update order statusGET /api/seller/dashboard- Get seller dashboard stats
GET /api/admin/users- Get all usersPATCH /api/admin/users/:id- Update user statusGET /api/admin/dashboard- Get dashboard statisticsGET /api/admin/orders- Get all ordersGET /api/admin/sellers- Get all sellers
- Registration: User registers with email/password → Account created with
emailVerified: true - Login: User logs in → Receives JWT token (24h expiry)
- API Requests: Include
Authorization: Bearer <token>header - Token Validation: Server validates JWT and extracts user info
- Logout: Invalidates session in database
- User: Authentication and profile (CUSTOMER, SELLER, ADMIN roles)
- Medicine: Product catalog with pricing, stock, categories
- Category: Medicine organization
- Order: Customer orders with shipping details
- OrderItem: Individual items within orders
- Review: Customer reviews and ratings
- Session: JWT session management
- Account: Credential storage with hashed passwords
- Email:
admin@medistore.com - Password:
admin123
- Email:
john.customer@email.com - Password:
customer123
- Email:
pharma.one@email.com - Password:
seller123
- JWT Tokens: Secure stateless authentication
- Password Hashing: bcrypt with salt rounds
- Role-based Access: Customer, Seller, Admin permissions
- Input Validation: Request data validation with Zod
- CORS Configuration: Cross-origin request handling
- Error Handling: Secure error responses
- Session Management: Token expiration and invalidation
# Seed admin user and categories
npx tsx src/scripts/seedAdmin.ts
# Seed complete database
npx tsx src/scripts/seedDatabase.ts- 1 Admin user
- 5 Customer users
- 5 Seller users
- 8 Categories (Pain Relief, Antibiotics, Vitamins, etc.)
- 8 Medicines with proper stock and pricing
- 4 Orders with different statuses
- 5 Reviews with ratings and comments
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLintDATABASE_URL="postgresql://localhost:5432/medistore"
PORT=3000
APP_URL="http://localhost:4000"
BETTER_AUTH_SECRET="your-jwt-secret"
NODE_ENV="development"DATABASE_URL="your-production-database-url"
PORT=3000
APP_URL="your-frontend-url"
BETTER_AUTH_SECRET="your-production-jwt-secret"
NODE_ENV="production"- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is for educational purposes. Feel free to use it as a learning resource.