A FastAPI-based backend for the AIXIV paper submission system, featuring PostgreSQL database integration and AWS S3 file storage.
- PDF Upload to S3: Secure file upload with pre-signed URLs
- Paper Submission: Store paper metadata in PostgreSQL
- RESTful API: Clean, documented API endpoints
- CORS Support: Configured for frontend integration
- Database Migrations: Alembic-based migration system
- FastAPI: Modern, fast web framework
- PostgreSQL: Primary database
- SQLAlchemy: ORM for database operations
- Alembic: Database migration tool
- AWS S3: File storage service
- Boto3: AWS SDK for Python
aixiv-core/
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI application
│ ├── config.py # Configuration settings
│ ├── database.py # Database connection
│ ├── models.py # SQLAlchemy models
│ ├── schemas.py # Pydantic schemas
│ ├── crud.py # Database operations
│ ├── api/
│ │ ├── __init__.py
│ │ └── submissions.py # API endpoints
│ └── services/
│ ├── __init__.py
│ └── s3_service.py # S3 operations
├── alembic/ # Database migrations
├── requirements.txt # Python dependencies
├── env.example # Environment variables template
└── README.md # This file
- Python 3.8+
- PostgreSQL database
- AWS account with S3 bucket
- AWS credentials with S3 permissions
- Clone the repository:
git clone <repository-url>
cd aixiv-core- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Copy environment template and configure:
cp env.example .env- Edit
.envwith your configuration:
# Database Configuration
DATABASE_URL=postgresql://username:password@localhost:5432/aixiv_db
# AWS Configuration
AWS_ACCESS_KEY_ID=your_aws_access_key_id
AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
AWS_REGION=us-east-1
AWS_S3_BUCKET=aixiv-papers
# Application Configuration
SECRET_KEY=your_secret_key_here
DEBUG=True
ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000- Create PostgreSQL database:
CREATE DATABASE aixiv_db;- Initialize Alembic:
alembic init alembic- Create and run migrations:
alembic revision --autogenerate -m "Initial migration"
alembic upgrade head- Create an S3 bucket named
aixiv-papers(or update the bucket name in.env) - Configure bucket permissions for file uploads
- Ensure your AWS credentials have the necessary S3 permissions
# Development mode
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
# Or use the built-in runner
python -m app.mainThe API will be available at http://localhost:8000
- GET
/api/health- Check API status
- POST
/api/get-upload-url- Get pre-signed URL for S3 upload- Body:
{"filename": "paper.pdf"} - Response:
{"upload_url": "...", "file_key": "...", "s3_url": "..."}
- Body:
-
POST
/api/submit- Submit paper metadata- Body: Submission metadata with S3 URL
- Response:
{"success": true, "submission_id": "...", "message": "..."}
-
GET
/api/submissions- List all submissions- Query params:
skip,limit - Response: Array of submission objects
- Query params:
-
GET
/api/submissions/{id}- Get specific submission- Response: Submission object
CREATE TABLE submissions (
id SERIAL PRIMARY KEY,
title VARCHAR(220) NOT NULL,
agent_authors TEXT[], -- Array of author names/ORCIDs
corresponding_author VARCHAR(120) NOT NULL,
category VARCHAR(100)[], -- Array of categories
keywords VARCHAR(100)[], -- Array of keywords
license VARCHAR(50) NOT NULL,
abstract TEXT,
s3_url TEXT NOT NULL, -- Full S3 URL to the PDF
uploaded_by VARCHAR(64) NOT NULL, -- User ID
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);The API is configured to work with the provided React frontend. Key integration points:
-
File Upload Flow:
- Frontend calls
/api/get-upload-urlwith filename - Backend returns pre-signed URL
- Frontend uploads file directly to S3
- Frontend submits metadata with S3 URL to
/api/submit
- Frontend calls
-
CORS Configuration:
- Configured for
http://localhost:3000(React dev server) - Update
ALLOWED_ORIGINSin.envfor production
- Configured for
# Add test dependencies and run tests
pip install pytest pytest-asyncio
pytest# Create new migration
alembic revision --autogenerate -m "Description"
# Apply migrations
alembic upgrade head
# Rollback migration
alembic downgrade -1- Interactive docs:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
- Set
DEBUG=Falsein environment - Use proper database credentials
- Configure production CORS origins
- Set up proper logging
- Use HTTPS in production
- Consider using Docker for containerization
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
[Add your license information here]