This is the backend of the AI Research Assistant project. It is a FastAPI project that provides the API for the Chrome extension and web frontend.
- Paper Processing: Extract and analyze academic papers from various sources
- AI Integration: OpenAI GPT-4 and Anthropic Claude for paper summarization
- Vector Search: Semantic search using embeddings and Pinecone
- Citation Networks: Build and analyze citation relationships
- Background Processing: Async paper processing with Celery
- Authentication: JWT-based user authentication
- Database: PostgreSQL with SQLAlchemy ORM
To get started clone the repository and run the following commands:
git clone <repository-url>
cd ai-research-assistant/backendThis project uses UV to manage the virtual environment, packages and the project itself. To install UV run the following command:
curl -LsSf https://astral.sh/uv/install.sh | shAfter installing UV, you can run the following command to install all the project requirements:
uv syncThis should create a virtual environment and install all the requirements.
Create a .env file in the backend directory:
cp .env.example .env
# Edit .env with your configurationRequired environment variables:
DATABASE_URL: PostgreSQL connection stringREDIS_URL: Redis connection stringOPENAI_API_KEY: OpenAI API keyPINECONE_API_KEY: Pinecone API keySECRET_KEY: JWT secret key
Run database migrations:
# Create migration
uv run alembic revision --autogenerate -m "Initial migration"
# Apply migrations
uv run alembic upgrade headTo run the project:
# Development mode with auto-reload
uv run fastapi dev app/main.py
# Production mode
uv run fastapi run app/main.pyThe API will be available at http://localhost:8000
API Documentation will be available at http://localhost:8000/docs
Start Celery workers for background processing:
# Start worker
uv run celery -A app.services.celery_app worker --loglevel=info
# Start flower for monitoring (optional)
uv run celery -A app.services.celery_app flowerTo add a new dependency to the project:
uv add <package-name>For development dependencies:
uv add --dev <package-name>Run all tests:
uv run pytestRun specific test types:
# Unit tests only
uv run pytest tests/unit
# Integration tests only
uv run pytest tests/integration
# Specific test file
uv run pytest tests/unit/test_paper_service.pyRun linting and formatting:
# Install pre-commit hooks
uv run pre-commit install
# Run all checks
uv run pre-commit run --all-files
# Run specific tools
uv run ruff check .
uv run black .
uv run mypy .app/
├── api/ # API routes and endpoints
│ ├── decorators.py # Route decorators
│ └── v1/ # API version 1
├── app_instance.py # FastAPI app instance
├── core/ # Core functionality
│ ├── config.py # Configuration settings
│ ├── security.py # Authentication & authorization
│ └── app_logging.py # Logging configuration
├── db/ # Database layer
│ ├── models.py # SQLAlchemy models
│ ├── database.py # Database connection
│ └── queries/ # Database queries
├── schemas/ # Pydantic models
├── services/ # Business logic
│ ├── ai_service.py # AI integration
│ ├── paper_service.py # Paper processing
│ └── celery_app.py # Background tasks
├── utils/ # Utility functions
└── main.py # Application entry point
POST /api/v1/auth/register- User registrationPOST /api/v1/auth/login- User loginGET /api/v1/auth/me- Get current user
POST /api/v1/papers/- Add paper from URLGET /api/v1/papers/{paper_id}- Get paper detailsPOST /api/v1/papers/search- Search papersGET /api/v1/papers/{paper_id}/summary- Get AI summary
GET /api/v1/knowledge/- Get user's knowledge entriesPOST /api/v1/knowledge/- Create knowledge entryGET /api/v1/knowledge/search- Semantic search
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
MIT License