This is a Quiz App API built using Flask and SQLAlchemy, deployed on AWS EC2 using Docker and GitHub Actions CI/CD.
Watch the demo video:
-
User Authentication:
- Register new users.
- Log in and generate API keys for authenticated access.
- Log out and invalidate API keys.
-
Quiz Management:
- Create quizzes (public or private).
- Add questions to quizzes (can be done by access to API keys)
- Retrieve quizzes and questions.
- Attempt quizzes and receive a score.
-
Public Quizzes:
- Browse and attempt public quizzes created by other users.
-
User Dashboard:
- View quizzes created by the logged-in user.
- View quiz attempts and scores.
-
Database Management:
- Reset the database to its initial state.
-
CI/CD with GitHub Actions: Automated build, push, and deployment to AWS.
-
Dockerized Deployment: App runs inside a Docker container on EC2.
-
Secure API & Infrastructure: Uses GitHub Secrets, SSH authentication, and AWS Security Groups.
This project is automatically deployed to AWS EC2 using GitHub Actions and Docker.
-
GitHub Actions detects changes pushed to the repository.
-
The workflow:
- Builds a Docker image of the application.
- Pushes the latest image to Docker Hub.
- Connects to AWS EC2 via SSH.
- Pulls the latest container and restarts the app.
-
The app is accessible at:
http://<your-ec2-public-ip>
- Python 3.x
- Flask
- Flask-SQLAlchemy
- SQLite (for local storage)
- Postman (for API testing)
To deploy on AWS EC2, use Docker.
- Build the Docker image:
docker build -t quiz-app . - Run the container:
docker run -d -p 5000:5000 quiz-app
- Push to Docker Hub:
docker tag quiz-app your-dockerhub-username/quiz-app:latest docker push your-dockerhub-username/quiz-app:latest
- SSH Private Key (
AWS_PRIVATE_KEY): Used to authenticate with EC2. - EC2 Host (
AWS_EC2_HOST): Stores the EC2 public IP address securely.
- Only allows HTTP (port 80) & SSH (port 22) access.
- SSH restricted to GitHub Actions IP (for security).
-
Clone the repository:
git clone https://github.com/your-username/your-repo-name.git cd your-repo-name -
Install dependencies:
pip install flask flask-sqlalchemy
-
Run the Flask app:
python app.py
The API will be available at
http://<your-ec2-public-ip>/.
-
Register a User
POST /api/register{ "username": "vibha", "password": "securepassword123" } -
Log In
POST /api/login{ "username": "vibha", "password": "securepassword123" } -
Log Out
POST /api/logout
-
Create a Quiz
POST /api/create-quiz{ "title": "Cloud Computing Quiz", "is_public": true }Headers:
API-Key: <your_api_key> -
Get All Quizzes (Public)
GET /api/public-quizzes -
Get Quizzes Created by the User
GET /api/quizzesHeaders:API-Key: <your_api_key> -
Get a Quiz with Questions
GET /api/quiz/{quiz_id}Headers:API-Key: <your_api_key>(required for private quizzes)
- Add a Question to a Quiz
POST /api/add-questionHeaders:{ "quiz_id": 1, "text": "What is not a programming language?", "options": ["C", "C++", "Python", "Snake"], "correct_answer": "Snake" }API-Key: <your_api_key>
- Attempt a Quiz
POST /api/quiz/{quiz_id}/attemptHeaders:{ "answers": {"1": "Snake", "2": "Python"} }API-Key: <your_api_key>
- Reset the Database
POST /reset-db
This API was tested using Postman. To test it yourself:
- Open Postman.
- Click Import, then select Raw text.
- Paste the following URL and import it:
http://<your-ec2-public-ip>/ - Run the requests and check the responses.
Alternatively, you can manually create the requests in Postman using the endpoint details provided above.
-
Register a User:
- Use the
/api/registerendpoint to create a new user. - Save the
api_keyreturned in the response for authenticated requests.
- Use the
-
Log In:
- Use the
/api/loginendpoint to log in and get a newapi_key.
- Use the
-
Create a Quiz:
- Use the
/api/create-quizendpoint to create a new quiz. - Set
is_publictotrueif you want the quiz to be visible to all users.
- Use the
-
Add Questions:
- Use the
/api/add-questionendpoint to add questions to a quiz.
- Use the
-
Attempt a Quiz:
- Use the
/api/quiz/{quiz_id}/attemptendpoint to attempt a quiz and receive a score.
- Use the
-
View Public Quizzes:
- Use the
/api/public-quizzesendpoint to browse and attempt public quizzes.
- Use the
- Backend: Python (Flask, SQLAlchemy)
- Database: SQLite (for local testing)
- Containerization: Docker
- CI/CD: GitHub Actions
- Hosting: AWS EC2
- Security: SSH, GitHub Secrets, AWS Security Groups
This project is licensed under the MIT License. See the LICENSE file for details.