
- Set up project structure with FastAPI and SQLite - Create models for users, questions, and quizzes - Implement Alembic migrations with seed data - Add user authentication with JWT - Implement question management endpoints - Implement quiz creation and management - Add quiz-taking and scoring functionality - Set up API documentation and health check endpoint - Update README with comprehensive documentation
Bible Quiz App API
A FastAPI-based REST API for a Bible Quiz application with user management, questions, and quiz features.
Features
- User Management: Registration, authentication, and profile management
- Questions Management: Create and manage Bible-related questions with multiple-choice options
- Quiz Management: Create quizzes from questions with customizable settings
- Quiz Taking: Take quizzes and receive scores
- Bible Data: Pre-loaded with Bible books and categorization
Tech Stack
- Framework: FastAPI (Python)
- Database: SQLite
- ORM: SQLAlchemy
- Migrations: Alembic
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: Bcrypt
API Documentation
The API documentation is available at:
- Swagger UI:
/docs
- ReDoc:
/redoc
- OpenAPI JSON:
/openapi.json
Setup and Installation
Prerequisites
- Python 3.8+
- pip (Python package manager)
Installation
- Clone the repository:
git clone <repository-url>
cd biblequizappapi
- Create and activate a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Setup environment variables (create a
.env
file in the root directory):
SECRET_KEY=your_secret_key_here
ACCESS_TOKEN_EXPIRE_MINUTES=60
Database Setup
- Initialize the database and run migrations:
alembic upgrade head
Running the API
- Start the server:
uvicorn main:app --reload
- The API will be available at
http://localhost:8000
Environment Variables
Variable | Description | Default Value |
---|---|---|
SECRET_KEY | Secret key for JWT token generation | "change_this_secret_key_in_production" |
ACCESS_TOKEN_EXPIRE_MINUTES | JWT token expiration time in minutes | 60 |
API Endpoints
Health Check
GET /health
- Check API health
Authentication
POST /api/v1/auth/register
- Register a new userPOST /api/v1/auth/login
- Login with username and password (OAuth2 form)POST /api/v1/auth/login/json
- Login with username and password (JSON)GET /api/v1/auth/me
- Get current user information
Users
GET /api/v1/users/
- List users (admin only)POST /api/v1/users/
- Create user (admin only)GET /api/v1/users/{user_id}
- Get user detailsPUT /api/v1/users/{user_id}
- Update user
Questions
GET /api/v1/questions/
- List questions (with filtering options)POST /api/v1/questions/
- Create question (admin only)GET /api/v1/questions/{question_id}
- Get question detailsPUT /api/v1/questions/{question_id}
- Update question (admin only)DELETE /api/v1/questions/{question_id}
- Delete question (admin only)GET /api/v1/questions/categories/
- List question categoriesGET /api/v1/questions/difficulties/
- List question difficultiesGET /api/v1/questions/bible-books/
- List Bible books
Quizzes
GET /api/v1/quizzes/
- List quizzes (public and user's own)POST /api/v1/quizzes/
- Create quizGET /api/v1/quizzes/{quiz_id}
- Get quiz detailsPUT /api/v1/quizzes/{quiz_id}
- Update quizDELETE /api/v1/quizzes/{quiz_id}
- Delete quizGET /api/v1/quizzes/attempts/
- List user's quiz attemptsPOST /api/v1/quizzes/{quiz_id}/start
- Start a new quiz attemptGET /api/v1/quizzes/attempts/{attempt_id}
- Get quiz attempt detailsPOST /api/v1/quizzes/attempts/{attempt_id}/submit/{question_id}
- Submit answer for a quiz questionPOST /api/v1/quizzes/attempts/{attempt_id}/complete
- Complete quiz and get score
Development
Code Structure
.
├── alembic.ini # Alembic configuration file
├── app/ # Application package
│ ├── api/ # API endpoints
│ │ ├── deps.py # Dependencies (auth, etc.)
│ │ └── v1/ # API version 1
│ │ ├── api.py # API router
│ │ └── endpoints/ # Endpoint modules
│ ├── core/ # Core functionality
│ │ ├── config.py # Configuration settings
│ │ └── security.py # Security utilities
│ ├── db/ # Database
│ │ └── session.py # DB session management
│ ├── models/ # SQLAlchemy models
│ ├── schemas/ # Pydantic schemas
│ └── services/ # Business logic
├── migrations/ # Alembic migrations
├── main.py # Application entry point
└── requirements.txt # Project dependencies
Running Tests
pytest
License
Description
Languages
Python
99.3%
Mako
0.7%