A full-stack application built with FastAPI backend and React frontend for creating, managing, and taking quizzes.
- User Authentication: Register, login, and manage user profiles
- Quiz Management: Create, edit, and delete quizzes
- Question Bank: Add various types of questions to quizzes
- Quiz Attempts: Track user attempts and performance
- Admin Dashboard: Manage users and content
- Responsive UI: Modern interface that works on all devices
- FastAPI: High-performance Python web framework
- MongoDB: NoSQL database for flexible data storage
- JWT Authentication: Secure user authentication
- Pydantic: Data validation and settings management
- React: UI library for building interactive user interfaces
- Tailwind CSS: Utility-first CSS framework
- Axios: HTTP client for API requests
- React Router: Navigation for single-page applications
- Python 3.8+
- Node.js 14+
- MongoDB (or MongoDB Atlas account)
-
Clone the repository:
git clone https://github.com/yourusername/QuizAPI-FastAPI-Backend.git cd QuizAPI-FastAPI-Backend -
Create and activate a virtual environment:
python -m venv venv # On Windows venv\Scripts\activate # On Unix or MacOS source venv/bin/activate
-
Install dependencies:
cd quizapi pip install -r requirements.txt -
Create a
.envfile in the root directory with the following variables:MONGODB_URL=your_mongodb_connection_string MONGODB_DATABASE=quizdb SECRET_KEY=your_secret_key ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 DEBUG=true ENVIRONMENT=development FRONTEND_URL=http://localhost:3000 -
Run the backend server:
uvicorn app.main:app --reload
-
Navigate to the frontend directory:
cd quizapi/frontend -
Install dependencies:
npm install
-
Create a
.envfile with the following:VITE_API_BASE_URL=http://localhost:8000/api -
Start the development server:
npm run dev
-
Create a new Web Service on Render
-
Connect your GitHub repository
-
Configure the following settings:
- Name: quizapi-backend (or your preferred name)
- Runtime: Python 3
- Build Command:
pip install -r quizapi/requirements.txt - Start Command:
cd quizapi && uvicorn app.main:app --host 0.0.0.0 --port $PORT - Root Directory: (leave empty)
-
Add the following environment variables:
MONGODB_URL=your_mongodb_connection_string MONGODB_DATABASE=quizdb SECRET_KEY=your_secret_key ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 DEBUG=false ENVIRONMENT=production FRONTEND_URL=https://your-frontend-url.vercel.app -
For MongoDB Atlas connectivity, you may need to:
- Ensure your MongoDB Atlas cluster allows connections from Render's IP addresses
- Update your connection string to include proper SSL configuration:
MONGODB_URL=mongodb+srv://username:[email protected]/quizdb?retryWrites=true&w=majority&ssl=true&ssl_cert_reqs=CERT_NONE
-
Create a new project on Vercel
-
Connect your GitHub repository
-
Configure the following:
- Framework Preset: Vite
- Root Directory: quizapi/frontend
- Build Command:
npm run build - Output Directory: dist
-
Add the following environment variable:
VITE_API_BASE_URL=https://your-backend-url.onrender.com/api
If you're experiencing CORS errors after deployment, check that:
-
Your backend's CORS configuration is correctly set up to allow your frontend domain:
# In app/main.py frontend_url = os.environ.get("FRONTEND_URL", "http://localhost:3000") origins = [ "http://localhost:3000", frontend_url, ] app.add_middleware( CORSMiddleware, allow_origins=origins, # Use the list instead of ["*"] for production allow_credentials=True, allow_methods=["*"], allow_headers=["*"], )
-
Your frontend is using the correct API URL (check
.envfiles)
If you're experiencing MongoDB connection errors:
- Ensure your MongoDB Atlas cluster allows connections from anywhere (0.0.0.0/0) during testing
- Check if your MongoDB Atlas cluster requires a specific MongoDB version
- Update the connection string to include proper SSL parameters:
MONGODB_URL=mongodb+srv://username:[email protected]/quizdb?retryWrites=true&w=majority&tls=true
When the backend is running, you can access the Swagger UI documentation at:
- Local: http://localhost:8000/docs
- Deployed: https://your-backend-url.onrender.com/docs