A privacy-first, group-focused study platform backend built with FastAPI, PostgreSQL, and modern web technologies.
- User Authentication & Authorization: JWT-based auth with refresh tokens
- Group Management: Create and manage study groups with different visibility levels
- Real-time Messaging: WebSocket support for group chat
- AI-Powered Quiz Generation: Generate quizzes using OpenAI/Anthropic APIs
- Note Sharing: Collaborative note-taking with version control
- Action Items: Track study tasks and assignments
- File Storage: S3-compatible file uploads for attachments
- RESTful API: Complete REST API with OpenAPI documentation
- Framework: FastAPI (Python 3.11+)
- Database: PostgreSQL with SQLAlchemy ORM
- Authentication: JWT tokens with bcrypt password hashing
- Real-time: WebSockets for live communication
- File Storage: S3-compatible storage (AWS S3, MinIO)
- AI Integration: OpenAI GPT, Anthropic Claude
- Containerization: Docker support
- Database Migrations: Alembic
- Python 3.11+
- PostgreSQL 12+
- Redis (optional, for caching)
- Docker (optional)
git clone <your-repo-url>
cd study-hub-backend# Copy environment template
cp env.example .env
# Edit .env with your configuration
nano .env# Create PostgreSQL database
createdb studyhub
# Create database user (optional)
sudo -u postgres psql
CREATE USER studyhub_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE studyhub TO studyhub_user;
GRANT ALL PRIVILEGES ON SCHEMA public TO studyhub_user;
GRANT CREATE ON SCHEMA public TO studyhub_user;
ALTER SCHEMA public OWNER TO studyhub_user;
\q# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Generate initial migration
alembic revision --autogenerate -m "Initial migration"
# Apply migrations
alembic upgrade head# Development mode
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# Production mode
uvicorn app.main:app --host 0.0.0.0 --port 8000Once the server is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql+asyncpg://username:password@localhost:5432/studyhub |
SECRET_KEY |
JWT secret key | your-super-secret-jwt-key-change-this-in-production |
ALLOWED_ORIGINS |
CORS allowed origins | http://localhost:3000,http://localhost:5173 |
DEBUG |
Debug mode | true |
ENVIRONMENT |
Environment type | development |
- PostgreSQL: Primary database
- Redis: Optional, for caching and background tasks
- S3/MinIO: File storage (optional)
# Build the image
docker build -t study-hub-backend .
# Run with environment file
docker run -p 8000:8000 --env-file .env study-hub-backendversion: '3.8'
services:
backend:
build: .
ports:
- "8000:8000"
environment:
- DATABASE_URL=postgresql+asyncpg://postgres:password@db:5432/studyhub
depends_on:
- db
- redis
db:
image: postgres:15
environment:
POSTGRES_DB: studyhub
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
volumes:
postgres_data:- JWT-based authentication with refresh tokens
- Password hashing with bcrypt
- CORS protection
- Input validation with Pydantic
- SQL injection protection with SQLAlchemy ORM
- Environment-based configuration
backend/
βββ app/
β βββ api/v1/endpoints/ # API endpoints
β βββ core/ # Core configuration
β βββ models/ # Database models
β βββ schemas/ # Pydantic schemas
β βββ services/ # Business logic
β βββ websocket/ # WebSocket handlers
βββ alembic/ # Database migrations
βββ tests/ # Test files
βββ Dockerfile # Docker configuration
βββ requirements.txt # Python dependencies
βββ alembic.ini # Alembic configuration
# Run tests
pytest
# Run with coverage
pytest --cov=app
# Run specific test file
pytest tests/test_auth.pyPOST /api/v1/auth/register- User registrationPOST /api/v1/auth/login- User loginPOST /api/v1/auth/refresh- Refresh token
GET /api/v1/groups/- List user groupsPOST /api/v1/groups/- Create groupGET /api/v1/groups/{id}- Get group detailsPUT /api/v1/groups/{id}- Update group
POST /api/v1/messages/- Send messageGET /api/v1/messages/group/{id}- Get group messagesPOST /api/v1/messages/upload-audio- Upload audio message
POST /api/v1/quizzes/generate- Generate AI quizPOST /api/v1/quizzes/- Create manual quizGET /api/v1/quizzes/group/{id}- Get group quizzes
POST /api/v1/notes/- Create noteGET /api/v1/notes/group/{id}- Get group notesPUT /api/v1/notes/{id}- Update note
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is proprietary software. All rights reserved.
For support and questions:
- Create an issue in the repository
- Contact the development team
- Initial release
- User authentication and authorization
- Group management
- Real-time messaging
- AI-powered quiz generation
- Note sharing and collaboration
- Action items tracking
- File storage integration
Study Hub - Empowering collaborative learning through technology.