Skip to content

mandalnitish/nmai-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

114 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NMAI Current Affairs - Full Stack Website

A complete full-stack web application for current affairs and competitive exam preparation with Daily Current Affairs, MCQs, User Authentication, Admin Panel, and Google AdSense integration.

πŸš€ Features

Frontend

  • βœ… Responsive React-based UI
  • βœ… Daily Current Affairs with filtering & search
  • βœ… MCQ Practice with instant results
  • βœ… User Authentication (Register/Login)
  • βœ… User Dashboard with saved articles
  • βœ… Category-wise content organization
  • βœ… Exam-specific filtering (UPSC, SSC, Banking, etc.)
  • βœ… Newsletter subscription
  • βœ… SEO optimized pages
  • βœ… Google AdSense ready

Backend

  • βœ… RESTful API with Express.js
  • βœ… MongoDB database with Mongoose
  • βœ… JWT authentication
  • βœ… Role-based access control (User/Author/Admin)
  • βœ… Article management system
  • βœ… MCQ management with statistics
  • βœ… User profile management
  • βœ… Newsletter system
  • βœ… Admin dashboard

Admin Panel

  • βœ… Dashboard with statistics
  • βœ… Article creation & management
  • βœ… MCQ creation & management
  • βœ… User management
  • βœ… Content moderation

πŸ“‹ Prerequisites

  • Node.js (v14 or higher)
  • MongoDB (local or Atlas)
  • npm or yarn

πŸ› οΈ Installation

1. Clone the repository

git clone https://github.com/yourusername/nmai-website.git
cd nmai-website

2. Backend Setup

cd backend

# Install dependencies
npm install

# Create .env file
cp .env.example .env

# Edit .env with your configuration
nano .env

Required Environment Variables (.env):

PORT=5000
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/nmai-current-affairs
JWT_SECRET=your-super-secret-jwt-key-change-this
JWT_EXPIRE=7d
FRONTEND_URL=http://localhost:3000
ADMIN_EMAIL=admin@nmai.in
ADMIN_PASSWORD=Admin@123

For MongoDB Atlas (Production):

MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/nmai

3. Frontend Setup

cd ../frontend

# Install dependencies
npm install

πŸš€ Running the Application

Development Mode

Terminal 1 - Backend:

cd backend
npm run dev
# Server runs on http://localhost:5000

Terminal 2 - Frontend:

cd frontend
npm start
# App opens on http://localhost:3000

Production Build

Backend:

cd backend
npm start

Frontend:

cd frontend
npm run build
# Serve the build folder with a static server

πŸ“¦ Database Seeding (Optional)

To populate the database with sample data:

cd backend
npm run seed

This creates:

  • Sample articles
  • Sample MCQs
  • Admin user
  • Test users

πŸ”‘ Default Admin Credentials

Email: admin@nmai.in
Password: Admin@123

⚠️ IMPORTANT: Change these in production!

πŸ“ Project Structure

nmai-website/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ Article.js
β”‚   β”‚   β”œβ”€β”€ MCQ.js
β”‚   β”‚   └── User.js
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ articles.js
β”‚   β”‚   β”œβ”€β”€ mcqs.js
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   β”œβ”€β”€ users.js
β”‚   β”‚   β”œβ”€β”€ newsletter.js
β”‚   β”‚   └── admin.js
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   └── auth.js
β”‚   β”œβ”€β”€ .env.example
β”‚   β”œβ”€β”€ package.json
β”‚   └── server.js
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ App.js
β”‚   β”‚   └── index.js
β”‚   └── package.json
└── README.md

πŸ”Œ API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user
  • GET /api/auth/me - Get current user
  • PUT /api/auth/update-profile - Update profile
  • PUT /api/auth/change-password - Change password
  • POST /api/auth/forgot-password - Request password reset
  • POST /api/auth/reset-password/:token - Reset password

Articles

  • GET /api/articles - Get all articles (with filters)
  • GET /api/articles/latest - Get latest articles
  • GET /api/articles/trending - Get trending articles
  • GET /api/articles/:slug - Get single article
  • GET /api/articles/category/:category - Get by category
  • POST /api/articles - Create article (Admin/Author)
  • PUT /api/articles/:id - Update article (Admin/Author)
  • DELETE /api/articles/:id - Delete article (Admin)

MCQs

  • GET /api/mcqs - Get all MCQs (with filters)
  • GET /api/mcqs/daily-quiz - Get random 10 MCQs
  • POST /api/mcqs/submit - Submit quiz answers
  • GET /api/mcqs/categories - Get categories
  • GET /api/mcqs/stats - Get statistics
  • POST /api/mcqs - Create MCQ (Admin/Author)
  • PUT /api/mcqs/:id - Update MCQ (Admin)
  • DELETE /api/mcqs/:id - Delete MCQ (Admin)

Users

  • POST /api/users/save-article/:id - Save article
  • DELETE /api/users/save-article/:id - Unsave article
  • GET /api/users/saved-articles - Get saved articles
  • GET /api/users/quiz-history - Get quiz history

Newsletter

  • POST /api/newsletter/subscribe - Subscribe
  • POST /api/newsletter/unsubscribe - Unsubscribe

Admin

  • GET /api/admin/dashboard-stats - Dashboard statistics
  • GET /api/admin/users - Get all users
  • PUT /api/admin/users/:id - Update user
  • DELETE /api/admin/users/:id - Delete user

🎨 Frontend Components to Create

Core Components

  1. Navbar.js - Navigation header
  2. Footer.js - Footer with legal links
  3. ArticleCard.js - Article preview card
  4. MCQCard.js - MCQ question card
  5. CategoryFilter.js - Filter by category
  6. SearchBar.js - Search functionality

Pages

  1. Home.js - Homepage with latest articles
  2. CurrentAffairs.js - Daily current affairs list
  3. ArticleDetail.js - Single article view
  4. MCQPractice.js - MCQ practice page
  5. DailyQuiz.js - Daily quiz interface
  6. Login.js - Login page
  7. Register.js - Registration page
  8. Profile.js - User profile/dashboard
  9. AdminDashboard.js - Admin panel
  10. Legal pages (already created)

🎨 CSS Styling

The application uses:

  • Modern CSS3 with Flexbox/Grid
  • Responsive design (mobile-first)
  • Color scheme inspired by GKToday/DrishtiIAS
  • Google Fonts (Inter/Roboto)

πŸ”’ Security Features

  • Password hashing with bcrypt
  • JWT token authentication
  • HTTP-only cookies (optional)
  • Helmet.js security headers
  • Rate limiting
  • Input validation
  • XSS protection
  • CORS configuration

πŸ“± Responsive Design

  • Mobile-first approach
  • Breakpoints:
    • Mobile: < 768px
    • Tablet: 768px - 1024px
    • Desktop: > 1024px

πŸ’° Monetization (Google AdSense)

Setup Instructions:

  1. Get AdSense approval
  2. Add AdSense script to public/index.html:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-YOUR-ID"
     crossorigin="anonymous"></script>
  1. Add ad units in components:
<ins className="adsbygoogle"
     style={{display:'block'}}
     data-ad-client="ca-pub-YOUR-ID"
     data-ad-slot="YOUR-SLOT-ID"
     data-ad-format="auto"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

πŸš€ Deployment

Backend (Heroku/Railway/Render)

  1. Create account on deployment platform
  2. Connect GitHub repository
  3. Add environment variables
  4. Deploy

Frontend (Netlify/Vercel)

  1. Build production version
npm run build
  1. Deploy build folder to Netlify/Vercel
  2. Configure environment variables
  3. Set up custom domain

MongoDB (MongoDB Atlas)

  1. Create MongoDB Atlas account
  2. Create cluster
  3. Create database user
  4. Get connection string
  5. Update MONGODB_URI in .env

πŸ“Š MongoDB Collections

users

  • User accounts
  • Authentication data
  • Subscriptions
  • Saved articles
  • Quiz history

articles

  • Current affairs content
  • Metadata
  • Categories
  • Exam relevance
  • View counts

mcqs

  • Questions
  • Options
  • Correct answers
  • Explanations
  • Statistics

πŸ”§ Environment-Specific Configurations

Development

  • Detailed error messages
  • Hot reloading
  • CORS: http://localhost:3000
  • Debug mode ON

Production

  • Minified builds
  • Error tracking (Sentry)
  • CORS: Your domain
  • Debug mode OFF
  • HTTPS enforcement

πŸ“ˆ Analytics Integration

Google Analytics

Add to public/index.html:

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-YOUR-ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-YOUR-ID');
</script>

πŸ› Troubleshooting

MongoDB Connection Issues

# Check if MongoDB is running
sudo systemctl status mongod

# Start MongoDB
sudo systemctl start mongod

Port Already in Use

# Kill process on port 5000
npx kill-port 5000

# Or use different port in .env
PORT=5001

CORS Errors

  • Check FRONTEND_URL in backend .env
  • Verify CORS configuration in server.js

πŸ“ž Support

For issues or questions:

πŸ“„ License

MIT License - feel free to use for your own projects!

πŸ™ Credits

Inspired by:

⭐ Show Your Support

If this project helps you, please give it a star on GitHub!


Built with ❀️ for Competitive Exam Aspirants

About

NMAI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors