Node.js/Express backend for the PetCare pet management platform.
- Install dependencies:
npm install
- Configure environment variables:
cp .env.example .env
# Edit .env with your configuration
- Start development server:
npm run dev
Create a .env
file with the following variables:
# Server Configuration
PORT=5000
NODE_ENV=development
# Database
MONGO_URI=mongodb://localhost:27017/petcare
# JWT Secrets
JWT_SECRET=your-super-secret-jwt-key-min-32-chars
JWT_REFRESH_SECRET=your-refresh-secret-key-min-32-chars
JWT_EXPIRES_IN=15m
JWT_REFRESH_EXPIRES_IN=7d
# Client Configuration
CLIENT_URL=http://localhost:5173
# Email Configuration (SMTP)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your-email@gmail.com
SMTP_PASS=your-app-password
# AI Integration
AI_API_KEY=your-openai-api-key
AI_PROVIDER=openai
# File Upload
UPLOAD_DIR=uploads
# Security
ENCRYPTION_KEY=your-32-character-encryption-key-here
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
# Optional: Redis for session storage
REDIS_URL=redis://localhost:6379
src/
βββ config/ # Configuration files
β βββ database.js # MongoDB connection
βββ controllers/ # Route handlers
βββ middlewares/ # Custom middleware
βββ models/ # Mongoose schemas
βββ routes/ # API routes
βββ services/ # Business logic
βββ sockets/ # Socket.IO handlers
βββ utils/ # Utility functions
βββ server.js # Application entry point
- User: User accounts with role-based access
- Pet: Pet profiles with health records
- Appointment: Vet appointment scheduling
- HealthRecord: Medical history tracking
- Shelter: Animal shelter profiles
- AdoptionListing: Pet adoption listings
- Product: Pet store products
- Order: E-commerce orders
- Rating: Review and rating system
- PaymentProvider: Payment gateway configuration
- ChatMessage: Real-time messaging
- Notification: System notifications
- AuditLog: Administrative action tracking
- Email Service: Transactional email notifications
- AI Service: Pet care AI assistant integration
- Payment Service: Payment processing abstraction
- Upload Service: File upload handling
- JWT authentication with refresh tokens
- Role-based access control (RBAC)
- Rate limiting on sensitive endpoints
- Input validation with Joi schemas
- Password hashing with bcryptjs
- Account lockout after failed attempts
- Audit logging for admin actions
- Encrypted storage of sensitive data
POST /register
- User registrationPOST /login
- User loginPOST /logout
- User logoutPOST /refresh
- Refresh access tokenPOST /forgot-password
- Request password resetPOST /reset-password/:token
- Reset passwordPOST /verify-email/:token
- Verify email addressGET /me
- Get current user profile
GET /profile
- Get user profilePUT /profile
- Update user profilePOST /avatar
- Upload user avatarDELETE /profile
- Delete user accountGET /vets
- Get verified veterinariansPOST /vet-verification
- Request vet verificationPUT /:id/verify-vet
- Approve vet verification (admin)PUT /:id/reject-vet
- Reject vet verification (admin)
GET /
- Get user's petsPOST /
- Create new petGET /:id
- Get pet detailsPUT /:id
- Update pet informationDELETE /:id
- Delete petPOST /:id/photos
- Upload pet photosGET /:id/health-records
- Get pet health recordsPOST /:id/health-records
- Create health record
GET /
- Get appointmentsPOST /
- Book new appointmentGET /:id
- Get appointment detailsPUT /:id
- Update appointmentDELETE /:id
- Cancel appointmentPUT /:id/accept
- Accept appointment (vet)PUT /:id/propose-time
- Propose time changePUT /:id/complete
- Complete appointmentPUT /:id/cancel
- Cancel appointment
GET /
- Get sheltersPOST /
- Create shelter profileGET /:id
- Get shelter detailsPUT /:id
- Update shelterDELETE /:id
- Delete shelterPUT /:id/verify
- Verify shelter (admin)PUT /:id/reject
- Reject shelter verification
GET /
- Get adoption listingsPOST /
- Create adoption listingGET /:id
- Get listing detailsPUT /:id
- Update listingDELETE /:id
- Delete listingPOST /:id/inquire
- Submit adoption inquiryPUT /:id/inquiries/:inquiryId
- Update inquiry statusPUT /:id/complete/:inquiryId
- Complete adoption
GET /
- Get productsPOST /
- Create product (admin/vendor)GET /:id
- Get product detailsPUT /:id
- Update productDELETE /:id
- Delete productGET /categories
- Get product categories
GET /
- Get ordersPOST /
- Create orderGET /:id
- Get order detailsPUT /:id
- Update orderPUT /:id/cancel
- Cancel orderPOST /:id/payment
- Process paymentPOST /:id/refund
- Process refund
GET /
- Get ratingsPOST /
- Create ratingPUT /:id
- Update ratingDELETE /:id
- Delete ratingPUT /:id/helpful
- Mark as helpfulPOST /:id/report
- Report ratingPUT /:id/moderate
- Moderate rating (admin)
GET /history
- Get chat historyPOST /send
- Send messagePUT /:id
- Edit messageDELETE /:id
- Delete messagePUT /read
- Mark messages as readGET /unread-count
- Get unread countGET /rooms
- Get chat rooms
POST /ask
- General AI queryPOST /pet-advice
- Pet-specific advicePOST /health-recommendations
- Health recommendationsGET /status
- AI service status
GET /dashboard
- Dashboard statisticsGET /payment-providers
- Get payment providersPOST /payment-providers
- Add payment providerPUT /payment-providers/:id
- Update providerDELETE /payment-providers/:id
- Delete providerGET /audit-logs
- Get audit logsPOST /broadcast
- Broadcast notificationGET /health
- System health checkGET /users
- Get all usersPUT /users/:id
- Update userDELETE /users/:id
- Delete user
POST /single
- Upload single filePOST /multiple
- Upload multiple filesDELETE /:filename
- Delete file
Socket.IO events for real-time communication:
join_chat
- Join chat roomsend_message
- Send chat messagemark_messages_read
- Mark messages as readrequest_chat
- Request chat with vetaccept_chat_request
- Accept chat requesttyping_start
- Start typing indicatortyping_stop
- Stop typing indicatoradmin_broadcast
- Admin broadcast messagepayment_completed
- Payment completion notification
new_notification
- New notification receivednew_message
- New chat messageappointment_confirmed
- Appointment confirmedappointment_cancelled
- Appointment cancelledpayment_confirmed
- Payment confirmedadmin_broadcast
- Admin broadcast messagechat_request
- New chat requestchat_request_accepted
- Chat request acceptedadoption_status_update
- Adoption status changepayment_provider_added
- New payment provider
Run tests:
npm test
Run tests with coverage:
npm run test:coverage
npm start
- Start production servernpm run dev
- Start development server with nodemonnpm test
- Run testsnpm run lint
- Run ESLintnpm run lint:fix
- Fix ESLint issues
- JWT tokens with short expiration (15 minutes)
- Refresh tokens with longer expiration (7 days)
- Role-based access control (owner, vet, shelter, admin)
- Account lockout after 5 failed login attempts
- Password hashing with bcryptjs (12 salt rounds)
- Sensitive data encryption (AES-256-CBC)
- Input validation and sanitization
- MongoDB injection prevention
- XSS protection
- Global rate limiting: 100 requests per 15 minutes
- Auth endpoints: 5 requests per 15 minutes
- AI endpoints: 20 requests per hour
- Set
NODE_ENV=production
- Configure production database URL
- Set secure JWT secrets
- Configure SMTP settings
- Set up file storage (local or S3)
- Use PM2 for process management
- Set up MongoDB replica set
- Configure reverse proxy (nginx)
- Enable SSL/TLS certificates
- Set up monitoring and logging
- Configure backup strategy
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 5000
CMD ["npm", "start"]
- Follow the existing code style
- Write tests for new features
- Update documentation
- Submit pull requests to develop branch
MIT License - see LICENSE file for details.