This project is a distributed file system backend built with FastAPI, Celery, and Redis. It supports Google OAuth authentication, file upload to Pinata (IPFS), asynchronous ZIP processing, and file management endpoints.
- User authentication via Google OAuth
- File upload and storage on Pinata (IPFS)
- Asynchronous ZIP compression using Celery
- Download original or ZIP-compressed files
- File management: list, rename, and get file info
- Dockerized for local and production use
- Linters and type checking: black, isort, flake8, mypy
- Unit, integration, and E2E tests with pytest (coverage >85%)
- Caching for list/info endpoints (not for streaming responses)
instashare/
├── api/
│ ├── __init__.py
│ ├── config.py
│ ├── database.py
│ ├── external_services/
│ │ └── pinata.py
│ ├── main.py
│ ├── models/
│ ├── routers/
│ ├── schemas/
│ ├── services/
│ └── utils/
├── tests/
│ ├── unit/
│ ├── integration/
│ └── e2e/
├── requirements.txt
├── docker-compose.yml
├── Dockerfile
├── README.md
└── ...
python -m venv .venv
source .venv/bin/activatepip install --no-cache-dir -r requirements.txtdocker run -d -p 6379:6379 redis:alpineCreate a .env file in your project root:
# Pinata Configuration
PINATA_API_KEY=your_pinata_key
PINATA_API_SECRET=your_pinata_secret
# Google OAuth (you'll need to create these)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
# Redis (for local development)
REDIS_URL=redis://localhost:6379You can run the entire stack (FastAPI, Celery worker, Celery beat, Redis) using Docker and Docker Compose.
docker-compose up --build- FastAPI docs: http://localhost:8000/docs
docker-compose downYou can run code quality tools or tests inside the app container:
docker-compose run --rm app black .
docker-compose run --rm app flake8 .
docker-compose run --rm app mypy api/
docker-compose run --rm app pytestuvicorn api.main:app --reload --host 0.0.0.0 --port 8000celery -A api.services.celery_app worker --loglevel=infocelery -A api.services.celery_app beat --loglevel=info- User uploads file → File saved to Pinata → DB record created → Celery task queued
- Celery worker picks up task → Downloads file → Creates ZIP → Uploads ZIP → Updates DB
- User can download original or ZIP version
Visit: http://localhost:8000/docs
- Go to
/auth/loginin your browser. - Complete Google login.
- Your session cookie will be set in your browser.
- Use
POST /api/v1/files/uploadto upload a file. - Check the response for
ipfs_hashandid. - Watch the Celery worker terminal for processing logs.
- Check the file status in the database.
GET /api/v1/files— List your filesPATCH /api/v1/files/{file_id}/rename?new_name=...— Rename a fileGET /api/v1/files/{file_id}/download— Download original file (streaming, not cached)GET /api/v1/files/{file_id}/download_zip— Download ZIP file (after processing, streaming, not cached)GET /api/v1/files/{file_id}— Get file info
You can also use tools like:
- curl
- httpie
- Postman (import cookies from your browser for session auth)
- If you get “Not authenticated”, make sure you’re logged in via Google and your browser sends the session cookie.
- If you get “File not found”, check the file ID and that you’re logged in as the correct user.
- If you get an error, check your FastAPI logs for details.
- Make sure your Pinata API credentials are correct and active.
celery -A api.services.celery_app inspect ping- Unit tests: test isolated functions/classes (no DB, no network)
- Integration tests: test API endpoints and DB/service integration
- E2E tests: simulate real user flows (require the FastAPI server to be running)
From the project root, run:
PYTHONPATH=. pytestNote:
- For E2E and requests-based tests, you must have the FastAPI server running at
http://localhost:8000. - For integration/unit tests using
TestClient, the server is started automatically by the test client.
PYTHONPATH=. pytest tests/unit/
PYTHONPATH=. pytest tests/integration/
PYTHONPATH=. pytest tests/e2e/PYTHONPATH=. pytest --cov=api --cov-report=term-missing --cov-fail-under=85Check task status:
celery -A api.services.celery_app inspect active
celery -A api.services.celery_app inspect registeredCheck SQLite database:
sqlite3 instashare.db
.tables
SELECT * FROM files;
SELECT * FROM users;- Upload → Pinata → DB → Celery → ZIP → Pinata → DB
- Download original or ZIP file via API
- black: Code formatter
- isort: Import sorter
- flake8: Linting for code style and errors
- mypy: Static type checking
.flake8(for flake8 settings)pyproject.toml(for black and isort settings)
pip install -r requirements.txt# Check code style
flake8 .
# Check type hints
mypy api/ tests/
# Format code
black .
isort .Important: Endpoints returning
StreamingResponseorgenerators(e.g.,/files/{file_id}/downloadand/files/{file_id}/download_zip) are not cached. The@cachedecorator is not supported for streaming responses.