A modern, real-time social media platform exclusively for Indian university students with .edu.in email verification. Built with Node.js, Express, MongoDB, and Socket.IO for seamless real-time interactions.
- π Secure Authentication: .edu.in email verification with session management
- π€ Advanced User Profiles: Custom avatars, bio, privacy settings, campus affiliation
- π Rich Posts System: Create, like, comment, and interact with posts in real-time
- οΈ Content Moderation: Report system, admin controls, and user management
- π± Responsive Design: Mobile-first modern UI with professional styling
- π Flash Notifications: Success/error messaging throughout the app
- π Admin Dashboard: User management, content moderation, and analytics
- Colors: Crimson Red (#B22222) + Off-White (#FAF9F6) + Deep Gray (#2E2E2E)
- Typography: Inter font family for modern, clean appearance
- Style: Professional, student-friendly interface with smooth animations
- Node.js (v16 or higher)
- MongoDB (v4.4 or higher)
- Git
-
Clone the repository
git clone <repository-url> cd BackendPro
-
Install dependencies
npm install
-
Environment Setup
cp .env.example .env
Configure your
.envfile with these variables:# Server Configuration PORT=4000 NODE_ENV=development # Database Configuration MONGODB_URI=mongodb://localhost:27017/campus_connect # Security Keys (Generate strong keys for production) JWT_SECRET=your_super_secure_jwt_secret_key_here_minimum_32_characters SESSION_SECRET=your_super_secure_session_secret_key_here_minimum_32_characters # Optional: AES-256 key (base64) used to encrypt passwords stored temporarily in sessions PASSWORD_SESSION_KEY=<BASE64_32_BYTE_KEY> # Email Configuration (for .edu.in verification) EMAIL_HOST=smtp.gmail.com EMAIL_PORT=587 EMAIL_SECURE=false EMAIL_USER=[email protected] EMAIL_PASS=your_app_password EMAIL_FROM=[email protected] EMAIL_FROM_NAME=UConnect Campus # Rate Limiting (optional - currently disabled) RATE_LIMIT_WINDOW_MS=900000 RATE_LIMIT_MAX_REQUESTS=100 # Optional: Redis (sessions & cache) # REDIS_URL=redis://127.0.0.1:6379 # SESSION_STORE=redis
-
Start MongoDB
# On Windows net start MongoDB # On macOS/Linux sudo systemctl start mongod
-
Seed the database (optional)
npm run seed
-
Start the application
# Development mode (with auto-restart) npm run dev # Production mode npm start
-
Access the application Open your browser and navigate to
http://localhost:4000
For local development, you can run the app over HTTPS so the browser shows 'Secure' instead of 'Not Secure'. The project includes a helper script and npm shortcuts that generate a certificate in the certs/ folder:
- Try
mkcert(recommended):
# generate a locally-trusted certificate with mkcert
npm run cert:mkcert:generateThis will use mkcert (if present) to generate a certificate and key at certs/server.crt and certs/server.key and should be trusted by your system/browser.
- Use the OpenSSL fallback (if mkcert is not installed):
# generate a self-signed cert with OpenSSL (includes SANs for localhost and 127.0.0.1)
npm run cert:generateThe script will warn you if certs already exist; use --force (or npm run cert:generate:force) to regenerate.
Alternatively, you can run the generator script directly:
# Generate a certificate (OpenSSL or mkcert) directly with Node
node scripts/generate-self-signed-cert.js
# For mkcert preference or force regeneration, use flags:
node scripts/generate-self-signed-cert.js --mkcert
node scripts/generate-self-signed-cert.js --force- Start the server using the generated certs (defaults to
certs/server.crtandcerts/server.key):
# Development mode β certs are loaded automatically if present
npm run dev
# Or set custom cert path and key explicitly
SSL_CERT_PATH=/path/to/server.crt SSL_KEY_PATH=/path/to/server.key npm run dev- If you used
mkcertand the cert is still not trusted in the browser, double-check mkcert CA installation:
mkcert -install-
Note: self-signed certificates (OpenSSL fallback) will still show as untrusted unless you add them to your trust store or use
mkcert. -
The project ignores
certs/by default to avoid committing local certs to the repo. If you are switching between machines, regenerate certs on each machine.
Redis is optional but recommended for sessions, caching, and better performance. If you want to enable Redis-backed session storage, follow these steps.
- Start Redis (Docker):
docker run --name uconnect-redis -p 6379:6379 -d redis:7- Optional: Start RedisInsight (Docker web GUI):
docker run --name redisinsight -d -p 8001:8001 -e RDIS_URL=redis://host.docker.internal:6379 redislabs/redisinsight:latest- Enable Redis in this app by setting
REDIS_URLorSESSION_STORE=redisin.env:
REDIS_URL=redis://127.0.0.1:6379
SESSION_STORE=redis- Restart your app and log in / register β you should see session keys (prefixed
sess:) and cached keys appear in RedisInsight.
Tip: To remove old sessions from Redis during testing, run:
redis-cli --scan --pattern 'sess:*' | xargs -r redis-cli delFor email verification to work properly:
-
Gmail Setup (Recommended):
- Enable 2-factor authentication on your Gmail account
- Generate an App Password: https://support.google.com/accounts/answer/185833
- Use your Gmail address for
EMAIL_USER - Use the App Password for
EMAIL_PASS
-
Other SMTP Providers:
- Update
EMAIL_HOSTandEMAIL_PORTaccordingly - Set
EMAIL_SECURE=truefor SSL connections
- Update
- Generate strong, unique secrets for
JWT_SECRETandSESSION_SECRET - Use environment variables for all sensitive data
- Enable HTTPS in production with proper SSL certificates
To make your local development HTTPS connections show 'Secure' in browsers, install mkcert and generate a trusted certificate:
# Install mkcert (macOS, using Homebrew)
brew install mkcert
brew install nss # for firefox
mkcert -install
# Generate a certificate for localhost
mkcert -cert-file certs/server.crt -key-file certs/server.key localhost 127.0.0.1 ::1The repo includes a generator (scripts/generate-self-signed-cert.js) that will try mkcert and fall back to OpenSSL with SANs if needed.
BackendPro/
βββ app.js # Main application entry point
βββ package.json # Dependencies and scripts
βββ .env.example # Environment variables template
βββ config/ # Configuration modules
β βββ database.js # MongoDB connection setup
β βββ session.js # Session configuration
β βββ cors.js # CORS settings
β βββ helmet.js # Security headers
βββ models/ # Database models
β βββ User.js # User model with authentication
β βββ Post.js # Post model with interactions
βββ routes/ # Express route handlers
β βββ auth.js # Authentication routes
β βββ posts.js # Posts CRUD operations
β βββ users.js # User profile management
β βββ admin.js # Admin panel routes
β βββ settings.js # User settings routes
βββ middleware/ # Custom middleware
β βββ auth.js # Authentication middleware
β βββ errorHandler.js # Error handling
β βββ upload.js # File upload handling
β βββ uploadImages.js # Image processing
βββ services/ # Business logic services
β βββ emailService.js # Email sending service
βββ startup/ # Application startup
β βββ server.js # HTTP server & Socket.IO setup
βββ utils/ # Utility functions
β βββ smartUrl.js # URL detection utilities
βββ views/ # EJS templates
β βββ layout.ejs # Main layout template
β βββ index.ejs # Landing page
β βββ error.ejs # Error pages
β βββ auth/ # Authentication pages
β β βββ login.ejs
β β βββ register.ejs
β β βββ verify-email.ejs
β βββ posts/ # Posts-related pages
β β βββ feed.ejs
β β βββ create.ejs
β β βββ single.ejs
β β βββ categories.ejs
β βββ users/ # User profile pages
β β βββ profile.ejs
β β βββ settings/
β β βββ profile.ejs
β β βββ account.ejs
β β βββ password.ejs
β βββ admin/ # Admin pages
β βββ partials/ # Reusable components
β βββ navbar.ejs
β βββ flash-messages.ejs
β βββ footer.ejs
β βββ default-body.ejs
βββ public/ # Static assets
β βββ css/ # Stylesheets
β βββ js/ # Client-side JavaScript
β βββ images/ # Static images
β βββ uploads/ # User uploaded files
β β βββ avatars/
β β βββ posts/
β βββ videos/ # Video assets
βββ scripts/ # Utility scripts
βββ seedDatabase.js # Database seeding
-
Registration & Verification:
- Use your .edu.in email address
- Complete email verification process
- Set up your profile with avatar and bio
-
Creating & Interacting with Posts:
- Share thoughts, questions, or announcements
- Like and comment on posts in real-time
- Use rich text formatting
-
Profile Management:
- Customize your avatar (upload or generate)
- Manage privacy settings
- Update personal information
-
Access Admin Panel (
/admin):- Login with admin credentials
- Monitor platform activity
-
User Management:
- View all registered users
- Activate/deactivate accounts
- Manually verify users if needed
-
Content Moderation:
- Review reported posts
- Remove inappropriate content
- Monitor real-time activity
- Email Domain Verification: Only .edu.in addresses accepted
- Password Security: Strong password requirements with bcrypt hashing
- Session Management: Secure session handling with MongoDB store
- Rate Limiting: Configurable protection against abuse (currently disabled)
- Input Validation: Comprehensive validation using express-validator
- File Upload Security: Image processing and size limits
- Content Security Policy: XSS protection via Helmet
- Data Sanitization: HTML sanitization for user content
- During registration, the app stores a
pendingRegistrationobject in the session while the user verifies their email. Previously this contained the plaintext password which could appear in RedisInsight. To protect privacy, the application now encrypts the password using AES-GCM before saving to the session, and decrypts it only when creating the user in the database.
Set a strong PASSWORD_SESSION_KEY (base64) in your .env to secure the encrypted password stored in sessions. Example generator:
openssl rand -base64 32Add to .env like:
PASSWORD_SESSION_KEY=<BASE64_KEY>If PASSWORD_SESSION_KEY is not set, the server will derive an encryption key from SESSION_SECRET (not recommended for production).
Important: Clean any legacy session data with plaintext passwords from Redis using the earlier
redis-cli --scancommand.
npm start # Start production server
npm run dev # Start development server (with nodemon)
npm run seed # Seed database with sample data
npm test # Run tests with coverage
npm run lint # Run ESLint for code quality
### Session performance & Redis benchmark
We included a Jest benchmark to compare Redis vs Mongo session set/get latencies: `tests/session.performance.test.js`.
Run it like this (make sure Redis & Mongo are running):
```bash
REDIS_URL=redis://127.0.0.1:6379 MONGODB_URI=mongodb://127.0.0.1:27017/uconnect_test npm run test:perf:sessionYou can increase the number of iterations with SESSION_BENCH_ITER:
SESSION_BENCH_ITER=500 REDIS_URL=redis://127.0.0.1:6379 MONGODB_URI=mongodb://127.0.0.1:27017/uconnect_test npm run test:perf:session
### Sample Accounts (After Seeding)
**Admin Account**:
- Email: `[email protected]`
- Password: `AdminPass123!`
**Student Accounts**:
- Email: `[email protected]`
- Password: `StudentPass123!`
- Email: `[email protected]`
- Password: `StudentPass123!`
## π Deployment
### Production Checklist
- [ ] Set `NODE_ENV=production`
- [ ] Use strong, unique secrets for JWT and session
- [ ] Configure HTTPS with SSL certificates
- [ ] Set up MongoDB Atlas or production database
- [ ] Configure production email service
- [ ] Set up monitoring and logging
- [ ] Configure reverse proxy (nginx/Apache)
- [ ] Enable rate limiting
- [ ] Set up backup strategies
### Environment Variables for Production
```env
NODE_ENV=production
PORT=4000
MONGODB_URI=mongodb+srv://username:[email protected]/campus_connect
JWT_SECRET=your_production_jwt_secret_minimum_32_chars
SESSION_SECRET=your_production_session_secret_minimum_32_chars
EMAIL_HOST=your_smtp_host
EMAIL_PORT=587
EMAIL_SECURE=false
EMAIL_USER=your_production_email
EMAIL_PASS=your_production_email_password
[email protected]
EMAIL_FROM_NAME=UConnect Campus
- Advanced user profiles
- Post categories and filtering
- Push notifications
- Mobile app (React Native)
- Events system with RSVP
- Official announcements from universities
- Club and organization pages
- Study group formation
- Resource sharing
- Search and hashtags
- Voice notes and audio posts
- Anonymous posting mode
- Advanced analytics dashboard
- API for third-party integrations
- 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 existing code style and modular structure
- Write meaningful commit messages
- Add tests for new features
- Update documentation as needed
- Use the established config/middleware pattern
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the Issues page on GitHub
- Create a new issue with detailed information
- Include error logs and steps to reproduce
- Contact the development team
- Built with Node.js, Express.js, MongoDB, and Socket.IO
- Real-time features powered by Socket.IO
- Security best practices from OWASP guidelines
- UI design inspired by modern social platforms
- Community feedback from Indian university students
UConnect v2 - Connecting students, fostering community, building the future. πβ‘"# UConnect-v2"