This repository contains the backend code for the Sri Ramkrishna Siksha Niketan project, handling user data, authentication, and various administrative functionalities to support the school's web portal.
- Multi-Role Authentication: Secure login system supporting Students, Teachers, Admin, and Alumni with role-based access control
- Google OAuth Integration: Single sign-on support for both users and alumni through Google authentication
- JWT Token Management: Secure token-based authentication with httpOnly cookies and refresh token support
- OTP Verification: Email-based OTP system for password reset and alumni login verification
- Password Security: Advanced password hashing using bcrypt with automatic password generation from Aadhar numbers
- Multi-User Support: Comprehensive user management for Students, Teachers, Administrators, and Alumni
- Student Admission Portal: Complete admission management system with PDF generation and email notifications
- Profile Management: Full CRUD operations for user profiles with image upload support via Cloudinary
- Class Management: Dynamic class assignment and year progression functionality
- Alumni Network: Dedicated alumni registration, verification, and management system
- Marks Submission: Digital marks entry and management system for teachers
- Result Calculation: Automated result generation for Primary (Beez to Class 4) and High School (Class 5 to 8) sections
- Student Records: Comprehensive student information management including grades, attendance, and academic history
- Admission Processing: Bulk admission processing with rank-based selection and automated user account creation
- Notice Board: School-wide notice management system with admin controls
- Blog System: Content management for school blogs with CRUD operations
- Push Notifications: Firebase Cloud Messaging (FCM) integration for real-time notifications
- Email System: Automated email notifications using Nodemailer for various school activities
- Real-Time Chat: Socket.io powered chat system with role-based messaging and message history
- Event Controller: Complete event lifecycle management with admin permissions
- Event Tracking: Historical tracking of event status changes with detailed audit logs
- Admission Events: Specialized handling for admission-related events and deadlines
- Activity Toggles: Dynamic event activation/deactivation with administrative controls
- Redis Caching: High-performance caching for frequently accessed data (alumni lists, user sessions)
- MongoDB Integration: Robust document-based data storage with Mongoose ODM
- PDF Generation: Automated PDF creation for admission forms, user details, and official documents
- File Management: Cloudinary integration for profile pictures and document storage
- Data Validation: Comprehensive input validation and sanitization across all endpoints
- Cross-Platform API: RESTful APIs supporting both web and mobile applications
- Token Storage: FCM token management for push notifications across devices
- Device Tracking: User device information tracking for security and analytics
- CORS Configuration: Cross-origin resource sharing setup for frontend integration
- Node.js and Express.js: Backend framework for RESTful API endpoints and middleware management
- MongoDB: NoSQL database for flexible document storage with Mongoose ODM for schema management
- Redis: In-memory data store for caching, session management, OTP storage, and real-time data synchronization
- JWT (JSON Web Tokens): Secure token-based authentication with refresh token support
- bcrypt: Advanced password hashing and salt generation for enhanced security
- Google OAuth 2.0: Single sign-on integration using Google Auth Library
- Firebase Admin SDK: Push notification management and user verification
- Nodemailer: SMTP email service for automated notifications (password recovery, admission confirmations, OTP delivery)
- Socket.io: Real-time bidirectional communication for chat functionality and live updates
- Firebase Cloud Messaging (FCM): Cross-platform push notification service
- Cloudinary: Cloud-based image and video management with automatic optimization and CDN delivery
- Multer: Middleware for handling multipart/form-data file uploads
- PDFKit: Dynamic PDF generation for admission forms, certificates, and reports
- Docker: Containerization for consistent development and production environments
- CORS: Cross-Origin Resource Sharing configuration for frontend integration
- Cookie-Parser: Secure HTTP cookie handling for authentication tokens
- Dotenv: Environment variable management for configuration secrets
- Axios: HTTP client for external API communications
- Form-Data: Multipart form data handling for file uploads
- Mongoose: MongoDB object modeling and schema validation
The project follows a well-organized MVC (Model-View-Controller) architecture with modular components:
SRSNBackend/
βββ backend/
β βββ π config/ # Database and Redis configuration
β β βββ db.js # MongoDB connection setup
β β βββ Redis.js # Redis client configuration
β β
β βββ π controller/ # Business logic handlers
β β βββ π Alumni/ # Alumni management controllers
β β β βββ AlumniApplicationView.js # View alumni applications
β β β βββ alumniDelete.js # Delete/reject alumni
β β β βββ AlumniDetails.js # Fetch alumni details
β β β βββ alumniEdit.js # Update alumni profiles
β β β βββ AlumniGoogleLogin.js # Google OAuth for alumni
β β β βββ alumniLogOut.js # Alumni logout functionality
β β β βββ alumniOtp.js # OTP-based alumni authentication
β β β βββ AlumniSearch.js # Search alumni records
β β β βββ alumniTemp.js # Temporary alumni registration
β β β βββ alumniVeri.js # Alumni verification/approval
β β β βββ AlumniView.js # List all alumni
β β β
β β βββ π Blog/ # Blog management
β β β βββ BlogCreate.js # Create new blog posts
β β β βββ BlogDelete.js # Delete blog posts
β β β βββ Blogfetch.js # Retrieve blog posts
β β β
β β βββ π EventControl/ # Event management system
β β β βββ π Admission/ # Admission-specific events
β β β β βββ AdmissionFetch.js # Fetch admission events
β β β βββ π General/ # General event management
β β β β βββ EventAdd.js # Create new events
β β β β βββ EventEdit.js # Edit existing events
β β β β βββ EventFetch.js # Retrieve events
β β β β βββ EventToggle.js # Toggle event status
β β β βββ π MarksSubmission/ # Marks-related events
β β β βββ MarksSubmissionFetch.js # Fetch marks events
β β β
β β βββ π Message/ # Communication system
β β β βββ Message.js # Handle messages
β β β
β β βββ π Notice/ # Notice board management
β β β βββ NoticeDelete.js # Delete notices
β β β βββ NoticeEntery.js # Create notices
β β β βββ Noticefetch.js # Fetch notices
β β β
β β βββ π TokenStore/ # FCM token management
β β β βββ send_message.js # Send push notifications
β β β βββ store_token.js # Store FCM tokens
β β β
β β βββ π User/ # User management controllers
β β β βββ CalculateResult.js # Academic result calculation
β β β βββ FetchUserProfile.js # Get user profile data
β β β βββ ForgotPassword.js # Password reset functionality
β β β βββ StudentFetch.js # Retrieve student data
β β β βββ StudentMarksSubmission.js # Submit student marks
β β β βββ Teacherfetch.js # Retrieve teacher data
β β β βββ UserChangeClass.js # Change student class
β β β βββ UserDelete.js # Delete user accounts
β β β βββ UserEdit.js # Edit user profiles
β β β βββ UserEditById.js # Edit user by ID
β β β βββ UserGoogleLogin.js # Google OAuth for users
β β β βββ UserLogin.js # User authentication
β β β βββ UserLogout.js # User logout
β β β βββ UserSignUp.js # User registration
β β β
β β βββ π UserAdmission/ # Student admission system
β β βββ UserAdmissionfetch.js # Fetch admission applications
β β βββ userAdmissionSearch.js # Search admission records
β β βββ UserAdmissionSignUp.js # Submit admission application
β β βββ UserAppicationDelete.js # Delete admission applications
β β βββ UserApplicationAdd.js # Add single admission
β β βββ userApplicationAddArray.js # Bulk admission processing
β β
β βββ π helper/ # Utility functions
β β βββ Class.js # Class-related utilities
β β βββ Mail.js # Email service helper
β β βββ PdfJenerator.js # PDF generation utilities
β β
β βββ π middlewares/ # Authentication & authorization
β β βββ authAlumniToken.js # Alumni token verification
β β βββ authToken.js # User token verification
β β βββ CheckAdmin.js # Admin role verification
β β βββ CheckTeacher.js # Teacher role verification
β β
β βββ π model/ # Database schemas
β β βββ π Alumni/ # Alumni data models
β β β βββ alumniTempModel.js # Temporary alumni applications
β β β βββ alumniVeriModel.js # Verified alumni records
β β βββ π Blog/ # Blog data models
β β β βββ BlogModel.js # Blog post schema
β β βββ π Chat/ # Chat system models
β β β βββ Chatmodel.js # Chat message schema
β β βββ π EventControl/ # Event data models
β β β βββ EventControl.js # Event schema
β β βββ π Notice/ # Notice board models
β β β βββ NoticeModel.js # Notice schema
β β βββ π Token/ # FCM token models
β β β βββ TokenModel.js # FCM token schema
β β βββ π User/ # User data models
β β βββ UserAdmissionModel.js # Admission application schema
β β βββ UserModel.js # Main user schema
β β
β βββ π public/ # Static assets
β β βββ Logo.png # School logo
β β
β βββ π routes/ # API route definitions
β β βββ index.js # Main route configuration
β β
β βββ π Socket/ # Real-time communication
β β βββ SocketHandler.js # Socket.io event handlers
β β
β βββ π utilis/ # Utility modules
β β βββ jwt.js # JWT token utilities
β β
β βββ π etc/secrets/ # Security configurations
β β βββ serviceAccountKey.json # Firebase service account
β β
β βββ π firebase.js # Firebase initialization
β βββ π index.js # Application entry point
β βββ π package.json # Dependencies and scripts
β βββ π Dockerfile # Docker configuration
β
βββ π README.md # Project documentation
βββ π LICENSE # License information
βββ π docker-compose.yml # Docker composition file
- Modular Design: Clear separation of concerns with dedicated folders for different functionalities
- Role-Based Structure: Separate handling for Students, Teachers, Admin, and Alumni
- Security Layer: Comprehensive middleware for authentication and authorization
- Real-Time Features: Dedicated Socket.io implementation for live communication
- Scalable Configuration: Environment-based configuration management
- Document Generation: Built-in PDF generation capabilities for official documents
POST /api/userSignUp- User registration with auto-generated passwordsPOST /api/userSignIn- Standard email/password authenticationPOST /api/userGoogleLogin- Google OAuth authenticationPOST /api/refresh-token- JWT token refreshPOST /api/userLogout- Secure user logoutPOST /api/forgotpasswordotpsend- Password reset OTP generationPOST /api/forgotpasswordotpverify- OTP verification for password resetPOST /api/resetpassword- Password reset with validation
GET /api/userProfile- Fetch authenticated user profilePUT /api/userEdit- Update user profile informationGET /api/studentFetch- Retrieve student recordsGET /api/teacherFetch- Retrieve teacher recordsPUT /api/chnageYearClass- Update student class/yearDELETE /api/deleteUser/:userId- Remove user accountPUT /api/userEditById- Admin-level user editing
POST /api/alumniTempSave- Submit alumni applicationPOST /api/alumniVeri- Approve/reject alumni applications (Auth Required)GET /api/alumniView- List all verified alumniDELETE /api/alumniDelete- Remove alumni record (Auth Required)POST /api/alumniSearch- Search alumni databaseGET /api/alumniApplicationView- View pending applicationsPOST /api/alumniOtp- Alumni OTP loginPOST /api/otpVerify- Verify alumni OTPGET /api/alumniDetails- Get alumni profile detailsPUT /api/alumniUpdateProfile- Update alumni profilePOST /api/alumniLogOut- Alumni logoutPOST /api/alumniGoogleLogin- Alumni Google authentication
POST /api/userMarksSubmission- Submit student marksGET /api/getResultPrimary- Calculate results for Beez to Class 4GET /api/getResultHigh- Calculate results for Class 5 to 8
POST /api/userAdmissionSignUp- Submit admission application with PDF generationGET /api/userAdmissionFetch- Fetch admission applications by classPOST /api/userAdmissionAdd- Process single admissionPOST /api/userAdmissionAddArray- Bulk admission processingDELETE /api/userAdmissionDelete- Delete admission applicationPOST /api/userAdmissionSearch- Search admission records
POST /api/noticeEntery- Create school noticesGET /api/noticeFetch- Retrieve all noticesDELETE /api/noticeDelete- Delete noticesPOST /api/blogAdd- Create blog postsGET /api/blogFetch- Retrieve blog postsDELETE /api/blogDelete- Delete blog postsPOST /api/message- Send messages
POST /api/eventAdd- Create new eventsPUT /api/eventEdit- Edit existing eventsGET /api/eventFetch- Retrieve eventsPUT /api/eventToggle- Toggle event statusGET /api/admissionFetch- Fetch admission eventsGET /api/marksSubmissionFetch- Fetch marks submission events
POST /api/save-token- Store FCM tokens for notificationsPOST /api/token-send-message- Send push notifications to all users
- Node.js (v14 or higher)
- MongoDB (local or cloud instance)
- Redis (local or cloud instance)
- Docker (optional, for containerized deployment)
1. Clone the Repository
git clone https://github.com/sandipto729/SRSNBackend.git
cd SRSNBackend/backend2. Install Dependencies
npm install3. Environment Configuration
Create a .env file in the backend directory with the following variables:
# Database Configuration
MONGO_URL=your_mongodb_connection_string
# Application Settings
PORT=8000
FRONTEND_URL=http://localhost:3000
NODE_ENV=development
# Authentication
TOKEN_SECRET_KEY=your_jwt_secret_key
GOOGLE_CLIENT_ID=your_google_oauth_client_id
# Email Configuration (Gmail)
PASSKEY=your_gmail_app_password
EMAIL_FROM=[email protected]
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your_redis_password
# Firebase Configuration
FIREBASE_PROJECT_ID=your_firebase_project_id4. Firebase Setup
- Download your Firebase service account key
- Place it at
backend/etc/secrets/serviceAccountKey.json - Ensure proper Firebase project configuration
5. Start the Development Server
npm start
# or for development with nodemon
npm run devThe server will start on http://localhost:8000
Prerequisites: Ensure Docker is installed on your system.
Quick Start with Docker
docker run -it \
-e MONGO_URL="your_mongodb_connection_string" \
-e TOKEN_SECRET_KEY="your_jwt_secret_key" \
-e PASSKEY="your_gmail_app_password" \
-e REDIS_PASSWORD="your_redis_password" \
-e REDIS_HOST="your_redis_host" \
-e REDIS_PORT="6379" \
-e FRONTEND_URL="http://localhost:3000" \
-e GOOGLE_CLIENT_ID="your_google_oauth_client_id" \
-p 8000:8000 \
sandipto729/srsnbackendUsing Docker Compose (Recommended for full stack)
version: '3.8'
services:
backend:
image: sandipto729/srsnbackend
ports:
- "8000:8000"
environment:
- MONGO_URL=mongodb://mongo:27017/srsn
- REDIS_HOST=redis
- REDIS_PORT=6379
- TOKEN_SECRET_KEY=your_secret_key
- PASSKEY=your_gmail_password
depends_on:
- mongo
- redis
mongo:
image: mongo:latest
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
redis:
image: redis:alpine
ports:
- "6379:6379"
volumes:
mongo_data:Access the Application
- Backend API:
http://localhost:8000 - API Documentation:
http://localhost:8000/api
Environment Variables for Production
NODE_ENV=production
MONGO_URL=mongodb+srv://username:[email protected]/database
REDIS_HOST=your-redis-cloud-host
REDIS_PORT=6380
REDIS_PASSWORD=your-redis-password
FRONTEND_URL=https://your-frontend-domain.comSecurity Considerations
- Use strong JWT secret keys
- Enable HTTPS in production
- Configure CORS properly for your domain
- Use environment-specific Firebase credentials
- Enable MongoDB authentication
- Use Redis AUTH for security
You can test the API endpoints using tools like:
- Postman: Import the API collection for comprehensive testing
- Thunder Client: VS Code extension for API testing
- cURL: Command-line testing examples
User Authentication
# User Registration
curl -X POST http://localhost:8000/api/userSignUp \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"[email protected]","aadharNo":"123456789012"}'
# User Login
curl -X POST http://localhost:8000/api/userSignIn \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"89012"}'Alumni Management
# View Alumni (requires auth)
curl -X GET http://localhost:8000/api/alumniView \
-H "Authorization: Bearer your_jwt_token"
# Alumni OTP Login
curl -X POST http://localhost:8000/api/alumniOtp \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]"}'# Start development server with hot reload
npm run dev
# Run tests (if available)
npm test
# Build for production
npm run build
# Check code style
npm run lint- Role-Based Access: Different permission levels for Admin, Teacher, Student, and Alumni
- Token Security: HTTP-only cookies with secure transmission
- Google OAuth: Seamless single sign-on integration
- OTP Verification: Email-based two-factor authentication
The system supports two different calculation methods:
- Primary Section (Beez to Class 4): Age-appropriate grading system
- High School Section (Class 5 to 8): Advanced academic evaluation
- Socket.io Integration: Live chat functionality
- Push Notifications: FCM-based instant notifications
- Message History: Persistent chat storage with MongoDB
- Role-Based Messaging: Different chat rooms for different user types
- PDF Generation: Automatic application form creation
- Email Integration: Confirmation emails with attachments
- Bulk Processing: Handle multiple admissions simultaneously
- Rank-Based Selection: Automated admission decisions based on performance
- Enable 2-Factor Authentication on your Gmail account
- Generate an App Password for the application
- Use the App Password as the
PASSKEYenvironment variable
- Create a Firebase project
- Enable Authentication and Cloud Messaging
- Download the service account key
- Configure FCM for push notifications
- Alumni Data: Cached for 2 minutes to improve performance
- Session Management: Store user sessions and OTPs
- Real-time Data: Cache frequently accessed information
-
User Collections: Separate collections for different user types
-
Event Tracking: Comprehensive audit logs for all activities
-
Document References: Efficient relationship management between collections
We welcome contributions to improve the SRSN Backend! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow the existing code style and structure
- Write clear, descriptive commit messages
- Include tests for new features when applicable
- Update documentation for any API changes
- Test your changes thoroughly before submitting
- π Bug fixes and performance improvements
- π Documentation enhancements
- π Security improvements
- π New feature development
- π§ͺ Test coverage expansion
- π¨ UI/UX improvements for API responses
- Sri Ramkrishna Siksha Niketan School administration for requirements and feedback
- Students and teachers who provided valuable user experience insights
- Open source community for the amazing tools and libraries
This comprehensive school management system is actively used by:
- Primary Section: Managing Beez, Ankur, and Kisholoy classes
- High School Section: Classes 1 through 8
- Alumni Network: 500+ registered alumni
- Staff Management: Teachers and administrative staff
- Student Count: 1000+ active students
- Daily active users: 200+
- API calls per day: 10,000+
- Documents generated: 50+ per week
- Push notifications sent: 1000+ per month
This project is licensed under the MIT License - see the LICENSE file for details.
- β Commercial use - Use this software commercially
- β Modification - Modify the source code
- β Distribution - Distribute the software
- β Private use - Use the software privately
- β License and copyright notice - Include the license in distributions
- β Liability - No warranty or liability
- β Warranty - No warranty provided
- Mobile App API: Enhanced endpoints for mobile application
- Advanced Analytics: Student performance analytics and reporting
- Video Conferencing: Integration with video calling for online classes
- Library Management: Book lending and return system
- Fee Management: Complete fee collection and payment tracking
- Examination System: Online examination and assessment tools
- Parent Portal: Dedicated parent access and communication system
- Attendance System: Automated attendance tracking with facial recognition
- GraphQL API: Alternative to REST for better performance
- Microservices: Service decomposition for better scalability
- Load Balancing: Support for high-availability deployments
- Advanced Caching: Multi-level caching strategies
- API Rate Limiting: Protection against abuse and overuse
- Comprehensive Testing: Unit, integration, and end-to-end tests
- CI/CD Pipeline: Automated testing and deployment
- Monitoring & Logging: Advanced application monitoring
We value your feedback and are here to help! If you have any questions, suggestions, or issues, please don't hesitate to reach out.
- Primary Developer: [email protected]
- Project Repository: GitHub Issues
- School Contact: Sri Ramkrishna Siksha Niketan School Administration
If you encounter any bugs or issues:
- Check existing GitHub Issues
- Create a new issue with detailed description
- Include steps to reproduce the problem
- Provide system information and error logs
Have an idea for improvement?
- Open a GitHub Issue with the
enhancementlabel - Describe the feature and its benefits
- Provide use cases and examples
- Discuss implementation approaches
- API Documentation: Available in the
/docsfolder (coming soon) - Code Comments: Comprehensive inline documentation
- Wiki: Check our GitHub Wiki for detailed guides
If this project helps you, please consider:
- β Starring the repository on GitHub
- π΄ Forking and contributing to the project
- π’ Sharing with others who might benefit
- π Writing about your experience
Thank you for your interest in the SRSN Backend project! Together, we're building better educational technology for everyone. Happy coding! π