|
1 |
| -# This is the Backend of Supabase Hackathon |
| 1 | + |
| 2 | +<img src="https://github.com/user-attachments/assets/4d84857a-fa96-436c-a81c-0dd26a8a1aa7" alt="logo" width="200"/> |
| 3 | + |
| 4 | +[](https://github.com/QuizCast/backend/actions/workflows/azure-serveless.yml) |
| 5 | +[](https://supabase.com) |
| 6 | + |
| 7 | +# QuizCast Backend |
| 8 | + |
| 9 | +Welcome to the **QuizCast Backend** repository! This backend is built using Python's **FastAPI** framework, providing the core functionality and database management for the QuizCast platform. It handles user authentication, quiz management, leaderboard updates, and integrates seamlessly with **Supabase** for authentication, real-time database updates, and storage. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Features |
| 14 | + |
| 15 | +- **User Authentication:** Powered by Supabase (JWT tokens). |
| 16 | +- **Quiz Management:** Create quizzes, add questions, and share quiz keys. |
| 17 | +- **Real-time Updates:** Uses Supabase Realtime for live leaderboard updates and question broadcasts. |
| 18 | +- **Profile Picture Upload:** Hosts can upload profile images, stored in Supabase's S3 bucket. |
| 19 | +- **Docker Support:** Ready-to-use Docker container configuration for easy deployment. |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +1. Python 3.8+ installed. |
| 26 | +2. `pip` package manager. |
| 27 | +3. **Supabase** account and access to Supabase API. |
| 28 | +4. `docker` and `docker-compose` (optional, for containerized deployment). |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Setup Instructions |
| 33 | + |
| 34 | +### 1. Clone the Repository |
| 35 | +```bash |
| 36 | +git clone https://github.com/QuizCast/backend.git |
| 37 | +cd backend |
| 38 | +``` |
| 39 | + |
| 40 | +### 2. Create a Virtual Environment |
| 41 | +```bash |
| 42 | +python -m venv .venv |
| 43 | +source ./.venv/bin/activate # On Windows: venv\Scripts\activate |
| 44 | +``` |
| 45 | + |
| 46 | +### 3. Install Dependencies |
| 47 | +```bash |
| 48 | +pip install -r requirements.txt |
| 49 | +``` |
| 50 | + |
| 51 | +### 4. Configure Environment Variables |
| 52 | +Create a `.env` file in the root directory and add the following variables: |
| 53 | +``` |
| 54 | +SUPABASE_URL=<your_supabase_url> |
| 55 | +SUPABASE_KEY=<your_supabase_api_key> |
| 56 | +SUPABASE_BUCKET=<your_supabase_bucket_name> |
| 57 | +SUPABASE_JWT_SECRET=<your_supabase_jwt_secret> |
| 58 | +``` |
| 59 | + |
| 60 | +### 5. Run the Application |
| 61 | +You can start the server using the following command: |
| 62 | +```bash |
| 63 | +uvicorn app.main:app --host 0.0.0.0 --port 8000 |
| 64 | +``` |
| 65 | + |
| 66 | +Alternatively, use Docker for a containerized setup: |
| 67 | +```bash |
| 68 | +docker build -t quizcast-backend . |
| 69 | +docker run -p 8000:8000 quizcast-backend |
| 70 | +``` |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## API Documentation |
| 75 | + |
| 76 | +After starting the server, access the interactive API documentation (Swagger UI) at: |
| 77 | +``` |
| 78 | +http://127.0.0.1:8000/docs |
| 79 | +``` |
| 80 | +or the ReDoc version at: |
| 81 | +``` |
| 82 | +http://127.0.0.1:8000/redoc |
| 83 | +``` |
| 84 | + |
| 85 | +### Authentication Endpoints |
| 86 | +- `/authentication/signup` - Sign up users. |
| 87 | +- `/authentication/login` - Log in users. |
| 88 | +- `/authentication/logout` - Log out users. |
| 89 | + |
| 90 | +### User Endpoints |
| 91 | +- `/user/users` - Retrieve all users. |
| 92 | +- `/user/create_user` - Create a new user. |
| 93 | +- `/user/update_user` - Update user details. |
| 94 | +- `/user/get_user/{email}` - Retrieve user by email. |
| 95 | +- `/user/get_quizHistory/{user_id}` - Retrieve quiz history. |
| 96 | + |
| 97 | +### Quiz Endpoints |
| 98 | +- `/quiz/join` - Join a quiz. |
| 99 | +- `/quiz/updateScore` - Submit an answer and update score. |
| 100 | +- `/quiz/addQuestions` - Add questions to a quiz. |
| 101 | +- `/quiz/deleteRoom` - Delete a quiz room. |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +<img src="images/swaggerUI.png"></img> |
| 106 | + |
| 107 | +## Project Structure |
| 108 | + |
| 109 | +``` |
| 110 | +backend/ |
| 111 | +│ |
| 112 | +├── app/ |
| 113 | +│ ├── main.py # Entry point for the API |
| 114 | +| ├── api/ # Endpoints |
| 115 | +│ ├── core/ # Configurations |
| 116 | +│ ├── crud/ # Database Crud operations |
| 117 | +│ ├── db/ # Supabase client setup using PythonSDK |
| 118 | +| ├── schemas/ # Pydantic Schemas for validation |
| 119 | +| ├── utils/ |
| 120 | +│ |
| 121 | +├── Dockerfile # Docker configuration |
| 122 | +├── requirements.txt # Python dependencies |
| 123 | +├── .env # Environment variables |
| 124 | +├── startup.sh # Startup script for the FastAPP |
| 125 | +└── README.md # Project documentation |
| 126 | +``` |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## Contributing ❤️ |
| 131 | + |
| 132 | +We welcome contributions from the community! To get started: |
| 133 | + |
| 134 | +1. Fork the repository. |
| 135 | +2. Create a new branch: |
| 136 | + ```bash |
| 137 | + git checkout -b feature/your-feature-name |
| 138 | + ``` |
| 139 | +3. Commit your changes: |
| 140 | + ```bash |
| 141 | + git commit -m "Add some feature" |
| 142 | + ``` |
| 143 | +4. Push your branch: |
| 144 | + ```bash |
| 145 | + git push origin feature/your-feature-name |
| 146 | + ``` |
| 147 | +5. Create a pull request. |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## License |
| 152 | + |
| 153 | +This project is open-source and available under the MIT License. |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +## Contact |
| 158 | + |
| 159 | +For questions or feedback, feel free to reach out or open an issue. Happy coding! |
0 commit comments