A full-stack online Q&A (question-and-answer) web application allowing users to ask questions, provide answers, and interact with the community through voting and commenting systems.
- Question Management: Ask, view, and search questions
- Answer System: Provide answers to questions with voting capabilities
- Comment System: Add comments to answers
- Tag System: Categorize questions with tags
- User Authentication: Registration, login, and profile management
- Search Functionality: Search questions by keywords and tags
- Voting System: Upvote/downvote answers
- User Profiles: Manage user information, bio, and website
- Role-based Access: Different user roles (admin, regular user)
- Real-time Updates: Dynamic content updates
- Responsive Design: Mobile-friendly interface
- API Documentation: Swagger/OpenAPI documentation
- Rate Limiting: API request limiting for security
- Input Validation: Comprehensive form validation
- Error Handling: Centralized error management
- React 18 with TypeScript
- Material-UI (MUI) for component library
- React Router for navigation
- Axios for API communication
- React Context for state management
- Node.js with Express.js
- TypeScript for type safety
- MongoDB with Mongoose ODM
- JWT for authentication
- bcrypt for password hashing
- express-rate-limit for rate limiting
- Swagger UI for API documentation
- Jest for unit testing
- Cypress for end-to-end testing
- BDD (Behavior Driven Development) with Cucumber
fake-stack-overflow/
βββ client/ # React frontend application
β βββ src/
β β βββ components/ # React components
β β βββ contexts/ # React context providers
β β βββ hooks/ # Custom React hooks
β β βββ services/ # API service functions
β β βββ types/ # TypeScript type definitions
β β βββ utils/ # Utility functions
β βββ cypress/ # E2E testing
β βββ public/ # Static assets
βββ server/ # Node.js backend application
β βββ controllers/ # Route controllers
β βββ models/ # MongoDB models and schemas
β βββ routes/ # API routes
β βββ middleware/ # Custom middleware
β βββ utils/ # Utility functions
β βββ tests/ # Unit tests
β βββ openapi.yaml # API documentation
βββ README.md
- Node.js (v14 or higher)
- MongoDB (v4.4 or higher)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd fake-stack-overflow
-
Install dependencies
# Install server dependencies cd server npm install # Install client dependencies cd ../client npm install
-
Environment Configuration
Create a
.envfile in the server directory:PORT=8000 MONGODB_URI=mongodb://127.0.0.1:27017/fake_so JWT_SECRET=your-secret-key CLIENT_URL=http://localhost:3000
-
Database Setup
# Start MongoDB service # Then populate the database with sample data cd server npm run populate_db mongodb://127.0.0.1:27017/fake_so
-
Start the Application
# Terminal 1: Start the backend server cd server npm start # Terminal 2: Start the frontend client cd client npm start
-
Access the Application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/api-docs
npm start # Start the server
npm run dev # Start server in development mode
npm test # Run unit tests
npm run populate_db # Populate database with sample data
npm run remove_db # Remove/reset databasenpm start # Start the React development server
npm run build # Build for production
npm test # Run tests
npm run cypress # Run E2E tests# Run server unit tests
cd server
npm test
# Run client unit tests
cd client
npm test# Run Cypress E2E tests
cd client
npm run cypress:run
# Open Cypress test runner
npm run cypress:openPOST /auth/register- Register new userPOST /auth/login- User loginPOST /auth/logout- User logout
GET /question- Get all questionsPOST /question- Create new questionGET /question/:id- Get specific questionPUT /question/:id- Update question
POST /answer- Create new answerPUT /answer/:id/vote- Vote on answerPOST /answer/:id/addComment- Add comment to answer
GET /tag- Get all tags with question counts
GET /user/profile- Get user profilePUT /user/updateProfile- Update user profile
For complete API documentation, visit /api-docs when the server is running.
The application uses JWT-based authentication with the following features:
- User registration and login
- Role-based access control
- Protected routes for authenticated users
- Session management with HTTP-only cookies
- Inspired by Stack Overflow's design and functionality
- Built with modern web development best practices
- Comprehensive testing coverage with Cypress and Jest
Happy coding! π