A robust backend service for navRaah, a comprehensive bus tracking and scheduling application. Built with modern Node.js technologies to provide seamless transit management capabilities.
- π Secure Authentication - JWT-based auth with refresh tokens
- π Bus Management - Complete CRUD operations for bus fleet
- πΊοΈ Route Planning - Dynamic route creation and management
- π Schedule Management - Flexible scheduling system
- π¬ Feedback System - User feedback collection and management
- π Stop Management - Bus stop creation and tracking
- π₯ User-Bus Relations - Link users with specific buses
- π§ Email Integration - Password recovery via email
navRaah_backend/
βββ src/
β βββ server.js # Application entry point
β βββ controllers/ # Business logic layer
β β βββ UserController.js
β β βββ BusController.js
β β βββ RouteController.js
β β βββ FeedbackController.js
β β βββ ScheduleController.js
β β βββ UserBusController.js
β β βββ StopController.js
β βββ routes/ # API route definitions
β βββ models/ # MongoDB schemas
β βββ middleware/ # Authentication & validation
βββ .env # Environment variables
βββ package.json
βββ README.md
Ensure you have the following installed:
- Node.js v18 or higher
- MongoDB (Local installation or MongoDB Atlas)
- npm or yarn package manager
-
Clone the repository
git clone https://github.com/vansh-000/navRaah_backend.git cd navRaah_backend -
Install dependencies
npm install
-
Environment configuration
Create a
.envfile in the root directory:# Server Configuration PORT=5000 NODE_ENV=development # Database MONGO_URI=mongodb://localhost:27017/navraah # Or for MongoDB Atlas: # MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/navraah # JWT Configuration JWT_SECRET=your_super_secure_jwt_secret_key_here JWT_REFRESH_SECRET=your_super_secure_refresh_secret_key_here JWT_EXPIRES_IN=15m JWT_REFRESH_EXPIRES_IN=7d # Email Configuration (for password reset) EMAIL_USER=your_email@example.com EMAIL_PASS=your_app_specific_password EMAIL_SERVICE=gmail
-
Start the server
# Development mode with auto-reload npm run dev # Production mode npm start
The server will start on http://localhost:5000 (or your specified PORT).
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
api/users/register |
Create new user account | β |
POST |
api/users/login |
User authentication | β |
POST |
api/users/refresh-token |
Refresh access token | β |
POST |
api/users/logout |
Clear authentication tokens | β |
POST |
api/users/forgot-password |
Send password reset email | β |
POST |
api/users/reset-password |
Reset password with token | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
api/users/me |
Get current user profile | β |
PUT |
api/users/me |
Update user profile | β |
DELETE |
api/usersme |
Delete user account | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
api/bus |
Add new bus | β |
PUT |
api/bus/:id |
Update bus details | β |
DELETE |
api/bus/:id |
Delete bus | β |
GET |
api/bus |
Get all buses | β |
GET |
api/bus/:id |
Get bus by identifier | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/api/route |
Create new route | β |
PUT |
/api/route/:id |
Update route | β |
DELETE |
/api/route/:id |
Delete route | β |
GET |
/api/route |
Get all routes | β |
GET |
/api/route/:id |
Get route by identifier | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
api/schedule |
Create new schedule | β |
PUT |
api/schedule/:scheduleId |
Update schedule | β |
DELETE |
api/schedule/:scheduleId |
Delete schedule | β |
GET |
api/schedule |
Get all schedules | β |
GET |
api/schedule/bus/:busId |
Get schedules by bus | β |
GET |
api/schedule/route/:routeId |
Get schedules by route | β |
GET |
api/schedule/:scheduleId |
Get schedule by ID | β |
GET |
api/schedule//bus/:busId/route/:routeId |
Get schedule by Bus and Route | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
api/feedback |
Submit feedback | β |
PUT |
api/feedback/:feedbackId |
Update feedback | β |
DELETE |
api/feedback/:feedbackId |
Delete feedback | β |
GET |
api/feedback |
Get all feedback | β |
GET |
api/feedback/user/:userId |
Get user's feedback | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
api/stop |
Add new stop | β |
PUT |
api/stop/:id |
Update stop | β |
DELETE |
api/stop/:id |
Delete stop | β |
GET |
api/stop |
Get all stops | β |
GET |
api/stop/:id |
Get stop by ID | β |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
api/userBus |
Link user with bus | β |
PUT |
api/userBus/:userId |
Update user-bus relation | β |
DELETE |
api/userBus/:userId |
Remove user-bus link | β |
GET |
api/userBus |
Get all user-bus relations | β |
GET |
api/userBus/:userId |
Get user's linked buses | β |
- Node.js - JavaScript runtime environment
- Express.js - Web application framework
- Mongoose - MongoDB object modeling
- MongoDB - NoSQL document database
- MongoDB Atlas - Cloud database service (optional)
- JWT (jsonwebtoken) - Token-based authentication
- bcrypt - Password hashing
- cookie-parser - Cookie parsing middleware
- cors - Cross-origin resource sharing
- Nodemailer - Email sending functionality
- Gmail SMTP - Email service provider
- Nodemon - Development server with auto-restart
- dotenv - Environment variable management
| Variable | Description | Required | Default |
|---|---|---|---|
PORT |
Server port number | No | 5000 |
MONGODB_URI |
MongoDB connection string | Yes | - |
REFRESH_TOKEN_SECRET |
Refresh token secret | Yes | - |
REFRESH_TOKEN_EXPIRY |
Refresh token expiry | Yes | 10d |
ACCESS_TOKEN_SECRET |
Access token secret | Yes | - |
ACCESS_TOKEN_EXPIRY |
Access token expiry | Yes | 1d |
FRONTEND_URL |
URL of the frontend | Yes | http://localhost:3000 |
CORS_ORIGIN |
CORS URL | Yes | - |
SMTP_MAIL |
Email service username | Yes | - |
SMTP_APP_PASS |
Email service password | Yes | - |
SMTP_HOST |
Email service host | Yes | smtp.gmail.com |
SMTP_PORT |
Email service port | Yes | 587 |
The application uses the following main collections:
- users - User account information
- buses - Bus fleet data
- routes - Route definitions
- schedules - Bus schedules
- stops - Bus stop locations
- feedback - User feedback
- userbuses - User-bus relationships
{
"scripts": {
"start": "node src/server.js",
"dev": "nodemon src/server.js",
"test": "jest",
"lint": "eslint src/",
"lint:fix": "eslint src/ --fix"
}
}-
Set environment variables
export NODE_ENV=production export MONGO_URI=your_production_mongodb_uri export JWT_SECRET=your_production_jwt_secret # ... other variables
-
Install production dependencies
npm ci --only=production
-
Start the application
npm start
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 5000
CMD ["npm", "start"]# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m 'Add amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
- Follow ESLint configuration
- Write meaningful commit messages
- Add tests for new features
- Update documentation as needed
- Database Indexing - Optimized queries with proper indexes
- Request Validation - Input validation middleware
- Error Handling - Comprehensive error handling system
- Logging - Structured logging for debugging
Connection Errors
# Check MongoDB connection
mongosh "your_connection_string"
# Verify environment variables
echo $MONGO_URIAuthentication Issues
# Check JWT token expiry
# Verify JWT_SECRET is set correctlyEmail Service Errors
# Verify email credentials
# Check app-specific password for Gmail- GitHub Issues: Report bugs or request features
- Email: navraahi@gmail.com
| Profile | Name | GitHub | Role |
|---|---|---|---|
| Vansh Verma | @vansh-000 | Backend Admin and Developer | |
| Sneha Kumari | @Snehaaa-Kri | Backend Developer | |
| Srishti Sethi | @srishtisethi28 | Backend Developer |
Vansh Verma
- GitHub: @vansh-000
- LinkedIn: Vansh Verma
- Email: vermavansh7777@gmail.com
β Star this repository if you find it helpful!
Made with β€οΈ for the transit community