A full-stack Survey / Feedback Application built using the MERN stack with a clean MVC architecture, JWT authentication, real-time response tracking using Socket.io, and data visualization using Chart.js.
- React - UI library
- Vite - Build tool
- Tailwind CSS - Styling
- Chart.js - Data visualization
- Socket.io Client - Real-time updates
- Axios - HTTP client
- React Router - Routing
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database (with Mongoose)
- Socket.io - Real-time communication
- JWT - Authentication
- bcryptjs - Password hashing
This project follows the MVC (ModelβViewβController) pattern:
- Model β MongoDB schemas
- View β React UI components
- Controller β Express business logic
- Realtime Layer β Socket.io
- Analytics Layer β Chart.js
- User registration and login
- JWT-based authentication
- Protected routes
- Secure password hashing
- Create surveys with dynamic questions
- Support for Multiple Choice (MCQ) and Short Answer (Text) questions
- View all your surveys in a beautiful card layout
- Shareable survey links for public access
- Live response count updates
- Real-time analytics dashboard
- Multi-user synchronization
- Visual charts (Pie & Bar charts) for MCQ questions
- Text response viewer for short answers
- Professional and modern UI with Tailwind CSS
- Responsive design
- Intuitive navigation
- Copy shareable links with one click
Survey App/
βββ server/ # Backend
β βββ src/
β β βββ config/ # Database & Socket configuration
β β βββ models/ # MongoDB schemas
β β βββ controllers/ # Business logic
β β βββ routes/ # API routes
β β βββ middleware/ # Auth middleware
β β βββ services/ # JWT & Analytics services
β β βββ app.js # Express app setup
β β βββ server.js # Server entry point
β βββ package.json
β
βββ client/ # Frontend
βββ src/
β βββ api/ # Axios configuration
β βββ services/ # API service functions
β βββ context/ # Auth context
β βββ pages/ # Page components
β βββ App.jsx # Main app component
β βββ main.jsx # Entry point
βββ package.json
- Node.js (v16 or higher)
- MongoDB (local or MongoDB Atlas)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd "Survey App"
-
Set up the Backend
cd server npm install -
Configure Environment Variables
Create a
.envfile in theserverdirectory:PORT=5000 MONGO_URI=mongodb://localhost:27017/survey_app JWT_SECRET=your_super_secret_jwt_key_change_this_in_production CLIENT_URL=http://localhost:5173
-
Set up the Frontend
cd ../client npm install -
Configure Frontend Environment (Optional)
Create a
.envfile in theclientdirectory:VITE_API_URL=http://localhost:5000/api
-
Start MongoDB
- Make sure MongoDB is running on your system
- Or use MongoDB Atlas and update the
MONGO_URIin.env
-
Start the Backend Server
cd server npm run devThe server will run on
http://localhost:5000 -
Start the Frontend Development Server
cd client npm run devThe client will run on
http://localhost:5173 -
Open your browser Navigate to
http://localhost:5173
- Click on "Register" to create a new account
- Or "Login" if you already have an account
- Fill in your details and submit
- After logging in, you'll see your dashboard
- Click "Create Survey" button
- Enter survey title and description (optional)
- Add questions:
- Select question type (Multiple Choice or Short Answer)
- Enter the question text
- For MCQ: Add at least 2 options
- For Text: No options needed
- Click "Create Survey" when done
- All your surveys are displayed as cards on the dashboard
- Each card shows the survey title, description, and creation date
- Click "View Analytics" to see real-time analytics
- Go to the Analytics page for any survey
- Click "Copy Shareable Link" button
- Share the link with others
- Anyone with the link can fill out the survey
- Click "View Analytics" on any survey card
- See total response count
- For MCQ questions: View Pie and Bar charts
- For Text questions: View all text responses
- Analytics update in real-time when new responses are submitted
- Use the shareable link to access a survey
- Answer all questions
- Submit your response
- The analytics will update in real-time for the survey creator
POST /api/auth/register- Register a new userPOST /api/auth/login- Login user
POST /api/surveys- Create a new survey (Protected)GET /api/surveys- Get all surveys for logged-in user (Protected)GET /api/surveys/:id- Get survey by IDGET /api/surveys/link/:link- Get survey by shareable link
POST /api/responses- Submit a survey response
GET /api/analytics/:surveyId- Get analytics for a survey (Protected)
- JWT tokens are stored in localStorage
- Tokens are automatically included in API requests
- Protected routes require authentication
- Tokens expire after 7 days
- When a response is submitted, all connected analytics dashboards update automatically
- Uses Socket.io for real-time communication
- No page refresh needed to see new responses
- Modern gradient designs
- Smooth transitions and hover effects
- Responsive layout for all screen sizes
- Clean and intuitive interface
- Professional color scheme
npm run dev- Start development server with auto-reloadnpm start- Start production server
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production build
- The application prevents duplicate responses using user identifiers
- Surveys are automatically published when created
- All surveys have unique shareable links
- Real-time updates work across multiple browser tabs/windows
-
MongoDB Connection Error
- Ensure MongoDB is running
- Check your
MONGO_URIin.env
-
Port Already in Use
- Change the
PORTin server.env - Update
VITE_API_URLin client.envaccordingly
- Change the
-
Socket.io Connection Issues
- Ensure backend server is running
- Check CORS settings in
server/src/app.js
-
Authentication Issues
- Clear localStorage and try logging in again
- Check JWT_SECRET in server
.env
This project is open source and available for educational purposes.
Built with β€οΈ using MERN stack
Happy Surveying! π