Spaces:
Sleeping
Download README.md from tech-ties/filezkit-backend: direct link, hf CLI and curl.
- Browser
- Download file 17.3 kB
-
https://huggingface.co/spaces/tech-ties/filezkit-backend/resolve/main/README.md
- Command line
-
hf download hf://spaces/tech-ties/filezkit-backend/README.md
-
curl -L -o README.md https://huggingface.co/spaces/tech-ties/filezkit-backend/resolve/main/README.md
title: FilezKit Backend
emoji: ποΈ
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 7860
pinned: false
ποΈ PDFKit Pro β Full-Stack PDF & File Toolkit
A full-featured PDF and file-processing web app with a Next.js 16 frontend and a FastAPI (Python) backend. It covers everything from merging PDFs to AI summarisation, OCR, image processing, and 70+ file conversion tools.
πΈ Preview
π§° Tech Stack
| Layer | Technology |
|---|---|
| Frontend | Next.js 16 (App Router), TypeScript, Plain CSS |
| Backend | FastAPI (Python 3.10+), SQLAlchemy, Alembic |
| Database | PostgreSQL |
| Task Queue | Redis + Celery workers |
| Auth | JWT + Google OAuth 2.0 |
| AI features | Groq API (summarise, translate, rewrite) |
| Image tools | Cloudinary, Real-ESRGAN, MediaPipe |
| Document tools | Poppler, Ghostscript, Calibre, LibreOffice |
| Fonts | Syne (display) + DM Sans (body) via Google Fonts |
π Project Structure
PDFkit_backend/
βββ backend/ β FastAPI Python backend
β βββ app/
β β βββ main.py β App entry point (FastAPI + CORS)
β β βββ api/v1/
β β β βββ router.py β Registers all API routes
β β β βββ endpoints/ β One file per tool (merge, split, ocr β¦)
β β βββ core/ β Config, security, JWT helpers
β β βββ db/ β SQLAlchemy session + engine
β β βββ models/ β DB models (User, File, Job β¦)
β β βββ schemas/ β Pydantic request/response schemas
β β βββ services/ β Business logic (pdf processing, AI β¦)
β β βββ workers/ β Celery background workers
β βββ alembic/ β Database migrations
β βββ uploads/ β Uploaded files (auto-created)
β βββ outputs/ β Processed output files (auto-created)
β βββ temp/ β Temp working directory
β βββ .env β Backend environment variables β EDIT THIS
β
βββ frontend/ β Next.js frontend
β βββ src/
β β βββ app/
β β β βββ layout.tsx β Root layout (Navbar + Footer + Providers)
β β β βββ page.tsx β Homepage (hero, tools grid, upload)
β β β βββ tools/[toolId] β Dynamic tool pages (70+ tools)
β β β βββ signin/ β Sign-in page
β β β βββ signup/ β Sign-up page
β β β βββ admin/ β Admin dashboard
β β β βββ about/ β About page
β β βββ components/ β Navbar, Footer, ToolCard, etc.
β β βββ lib/
β β βββ api.ts β Axios instance + JWT interceptors
β β βββ authApi.ts β Login / register / Google OAuth calls
β β βββ pdfApi.ts β All 70+ tool API call functions
β β βββ data.ts β Tool definitions, icons, categories
β β βββ fileDetect.ts β Smart file-type detection
β β βββ types.ts β Shared TypeScript types
β β βββ AuthContext.tsx β Global auth state (React context)
β βββ .env.local β Frontend environment variables β EDIT THIS
β βββ next.config.ts β Next.js configuration
β
βββ requirements.txt β Python dependencies
β Prerequisites
Before you start, make sure you have the following installed on your machine:
| Tool | Version | How to check |
|---|---|---|
| Node.js | 18 or higher | node -v |
| npm | 9 or higher | npm -v |
| Python | 3.10 or higher | python --version |
| PostgreSQL | 14 or higher | psql --version |
| Redis | 6 or higher | redis-cli ping (should reply PONG) |
| Git | any | git --version |
π‘ On Windows, you can install Redis via WSL or download the Windows port.
Optional (needed for specific tools)
| Tool | Used for | Download |
|---|---|---|
| Poppler | PDF β image conversion | poppler for Windows |
| Ghostscript | PDF compression | ghostscript.com |
| Calibre | eBook conversions | calibre-ebook.com |
| LibreOffice | Word/Excel/PPT β PDF | libreoffice.org |
| Tesseract OCR | OCR (image β text) | github.com/tesseract-ocr |
βοΈ Step 1 β Set Up the Backend
1a. Create a PostgreSQL database
Open your PostgreSQL client (pgAdmin or psql) and create a database:
CREATE DATABASE pdfflow;
1b. Edit the backend .env file
Open backend/.env and fill in your values:
# PostgreSQL connection string
DATABASE_URL=postgresql://YOUR_POSTGRES_USER:YOUR_POSTGRES_PASSWORD@localhost/pdfflow
# Redis (leave as-is if running locally with default settings)
REDIS_URL=redis://localhost:6379
# JWT secret β generate a strong random string (e.g. run: python -c "import secrets; print(secrets.token_urlsafe(32))")
SECRET_KEY=your-super-secret-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Groq API key β free at https://console.groq.com
GROQ_API_KEY=gsk_your_groq_api_key_here
# Your backend's public URL (use localhost for local dev)
BASE_URL=http://localhost:8000
# Cloudinary β free at https://cloudinary.com
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# Google OAuth Client ID β from https://console.cloud.google.com
GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com
# Paths to installed tools (Windows example β adjust for your system)
POPPLER_PATH=C:\path\to\poppler\bin
GHOSTSCRIPT_PATH=C:\Program Files\gs\gs10.xx.x\bin\gswin64c.exe
CALIBRE_PATH=C:\Program Files\Calibre2\ebook-convert.exe
# AI image models (optional β leave blank if not using)
MEDIAPIPE_FACE_STYLIZER_MODEL_PATH=models/face_stylizer_color_ink.task
REAL_ESRGAN_EXE_PATH=bin/realesrgan-ncnn-vulkan/realesrgan-ncnn-vulkan.exe
1c. Create a Python virtual environment and install dependencies
Open a terminal, navigate to the project root, and run:
# From the project root (PDFkit_backend/)
python -m venv backend/venv
# Activate the venv
# On Windows:
backend\venv\Scripts\activate
# On Mac/Linux:
source backend/venv/bin/activate
# Install all Python packages
pip install -r requirements.txt
1d. Run database migrations
With your venv activated:
cd backend
alembic upgrade head
This creates all the required tables in your PostgreSQL database.
1e. Start the backend server
# Still inside backend/ with venv activated
uvicorn app.main:app --reload --port 8000
You should see:
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Application startup complete.
Test it: Open http://localhost:8000 β you should see
{"message": "Database connected"}.Interactive API docs: Open http://localhost:8000/docs for the full Swagger UI.
1f. (Optional) Start the Celery worker
In a new terminal window (with venv activated):
cd backend
celery -A app.core.celery_app worker --loglevel=info
This is required for background processing jobs (compression, heavy conversions, etc.)
π Step 2 β Set Up the Frontend
2a. Edit the frontend .env.local file
Open frontend/.env.local:
# URL of your running backend β keep as localhost for local development
NEXT_PUBLIC_API_URL=http://localhost:8000
# Google OAuth Client ID β must match the one in your backend .env
NEXT_PUBLIC_GOOGLE_CLIENT_ID=your-google-client-id.apps.googleusercontent.com
2b. Install Node.js dependencies
cd frontend
npm install
2c. Start the frontend dev server
npm run dev
You should see:
β² Next.js 16.2.6 (Turbopack)
- Local: http://localhost:3000
β Ready in 2.0s
2d. Open the app
Visit http://localhost:3000 in your browser. π
π Running Both Servers Together
You need 3 terminal windows running simultaneously:
| Terminal | Command | Where |
|---|---|---|
| 1 β Backend API | uvicorn app.main:app --reload --port 8000 |
backend/ (venv active) |
| 2 β Celery Worker | celery -A app.core.celery_app worker --loglevel=info |
backend/ (venv active) |
| 3 β Frontend | npm run dev |
frontend/ |
π Pages & Routes
Frontend pages
| URL | Description |
|---|---|
/ |
Homepage β hero, tool search, drag-and-drop upload zone |
/signin |
Sign-in with email/password or Google |
/signup |
Create a new account |
/about |
About page |
/admin |
Admin dashboard (admin users only) |
/tools/[toolId] |
Any tool page β see full list below |
Backend API
| URL | Description |
|---|---|
http://localhost:8000/ |
Health check |
http://localhost:8000/docs |
Swagger UI β interactive API explorer |
http://localhost:8000/redoc |
ReDoc API documentation |
http://localhost:8000/api/v1/ |
All API endpoints |
π οΈ All 70+ Tools
PDF Tools
| Tool ID | URL | Description |
|---|---|---|
merge |
/tools/merge |
Merge multiple PDFs into one |
split |
/tools/split |
Split PDF into pages |
compress |
/tools/compress |
Reduce PDF file size |
rotate |
/tools/rotate |
Rotate PDF pages |
watermark |
/tools/watermark |
Add text watermark |
protect |
/tools/protect |
Password-protect a PDF |
unlock |
/tools/unlock |
Remove PDF password |
organize |
/tools/organize |
Reorder or delete pages |
ocr |
/tools/ocr |
Make scanned PDFs searchable |
addPageNumbers |
/tools/addPageNumbers |
Stamp page numbers |
sign |
/tools/sign |
Digital / typed / stamp signature |
qr2pdf |
/tools/qr2pdf |
Embed QR code into PDF |
Convert β PDF β Docs
| Tool ID | URL | Description |
|---|---|---|
pdf2word |
/tools/pdf2word |
PDF β editable Word (.docx) |
word2pdf |
/tools/word2pdf |
Word (.docx) β PDF |
pdf2excel |
/tools/pdf2excel |
PDF tables β Excel |
excel2pdf |
/tools/excel2pdf |
Excel (.xlsx) β PDF |
ppt2pdf |
/tools/ppt2pdf |
PowerPoint β PDF |
pdf2ppt |
/tools/pdf2ppt |
PDF β PowerPoint |
pdf2text |
/tools/pdf2text |
PDF β plain text |
pdf2html |
/tools/pdf2html |
PDF β HTML |
pdf2epub |
/tools/pdf2epub |
PDF β EPUB |
epub2pdf |
/tools/epub2pdf |
EPUB β PDF |
mobi2epub |
/tools/mobi2epub |
MOBI β EPUB |
azw32pdf |
/tools/azw32pdf |
AZW3 β PDF |
Convert β Images
| Tool ID | URL | Description |
|---|---|---|
pdf2jpg |
/tools/pdf2jpg |
PDF pages β JPG images |
pdf2png |
/tools/pdf2png |
PDF pages β PNG images |
jpg2pdf |
/tools/jpg2pdf |
Images β PDF |
jpg2png |
/tools/jpg2png |
JPG β PNG |
png2jpg |
/tools/png2jpg |
PNG β JPG |
png2webp |
/tools/png2webp |
PNG β WebP |
webp2jpg |
/tools/webp2jpg |
WebP β JPG |
ppt2images |
/tools/ppt2images |
PPT slides β images |
Convert β Data Files
| Tool ID | URL | Description |
|---|---|---|
excel2csv |
/tools/excel2csv |
Excel β CSV |
excel2json |
/tools/excel2json |
Excel β JSON |
word2txt |
/tools/word2txt |
Word β plain text |
word2html |
/tools/word2html |
Word β HTML |
word2markdown |
/tools/word2markdown |
Word β Markdown |
json2csv |
/tools/json2csv |
JSON β CSV |
csv2json |
/tools/csv2json |
CSV β JSON |
json2xml |
/tools/json2xml |
JSON β XML |
xml2json |
/tools/xml2json |
XML β JSON |
yaml2json |
/tools/yaml2json |
YAML β JSON |
Compress
| Tool ID | URL | Description |
|---|---|---|
compress |
/tools/compress |
Compress PDF |
compressjpg |
/tools/compressjpg |
Compress JPG |
compresspng |
/tools/compresspng |
Compress PNG |
compresswebp |
/tools/compresswebp |
Compress WebP |
AI Tools
| Tool ID | URL | Description |
|---|---|---|
ai |
/tools/ai |
AI summarise PDF (Groq) |
ai-translate |
/tools/ai-translate |
Translate PDF content |
ai-rewrite |
/tools/ai-rewrite |
Rewrite in a new tone |
upscaleimage |
/tools/upscaleimage |
Upscale image with Real-ESRGAN |
image2cartoon |
/tools/image2cartoon |
Cartoon-style effect |
image2sketch |
/tools/image2sketch |
Sketch-style effect |
image2anime |
/tools/image2anime |
Anime-style effect |
image2avatar |
/tools/image2avatar |
Avatar-style effect |
OCR & Text Extraction
| Tool ID | URL | Description |
|---|---|---|
ocr |
/tools/ocr |
OCR on PDF |
image2text |
/tools/image2text |
Extract text from image |
screenshot2text |
/tools/screenshot2text |
Extract text from screenshot |
handwriting2text |
/tools/handwriting2text |
Handwriting β text |
Image Utilities
| Tool ID | URL | Description |
|---|---|---|
resizeimage |
/tools/resizeimage |
Resize image |
downscaleimage |
/tools/downscaleimage |
Downscale within max dimensions |
cropimage |
/tools/cropimage |
Crop by position/size |
circlecrop |
/tools/circlecrop |
Circular crop |
removebackground |
/tools/removebackground |
Remove background |
transparentbackground |
/tools/transparentbackground |
Make background transparent |
replacebackground |
/tools/replacebackground |
Replace with solid color |
smartcrop |
/tools/smartcrop |
Smart content-aware crop |
Text Utilities
| Tool ID | URL | Description |
|---|---|---|
qr |
/tools/qr |
QR code generator |
upper2lower |
/tools/upper2lower |
Uppercase β lowercase |
lower2upper |
/tools/lower2upper |
Lowercase β UPPERCASE |
titlecase |
/tools/titlecase |
Convert to Title Case |
text2base64 |
/tools/text2base64 |
Text β Base64 |
base642text |
/tools/base642text |
Base64 β text |
urlencode |
/tools/urlencode |
URL encode text |
urldecode |
/tools/urldecode |
URL decode text |
π Google OAuth Setup (Optional)
If you want Google sign-in to work:
- Go to Google Cloud Console
- Create a new project (or use an existing one)
- Go to APIs & Services β Credentials β Create Credentials β OAuth 2.0 Client IDs
- Set Application type to Web application
- Add
http://localhost:3000to Authorized JavaScript origins - Add
http://localhost:3000to Authorized redirect URIs - Copy the Client ID and paste it into:
backend/.envβGOOGLE_CLIENT_IDfrontend/.env.localβNEXT_PUBLIC_GOOGLE_CLIENT_ID
π Troubleshooting
npm install fails
- Make sure you're running Node.js 18+:
node -v - Try deleting
node_modules/andpackage-lock.json, then runnpm installagain
Backend returns Connection refused
- Make sure the backend is running:
uvicorn app.main:app --reload --port 8000 - Make sure
NEXT_PUBLIC_API_URL=http://localhost:8000is set infrontend/.env.local
alembic upgrade head fails
- Check your
DATABASE_URLinbackend/.envβ make sure the PostgreSQL password and database name are correct - Make sure PostgreSQL is running:
pg_isready
Tools fail with 500 Internal Server Error
- Check the backend terminal for the error traceback
- Make sure required tools are installed (Poppler, Ghostscript, etc.) and paths in
.envare correct
OCR doesn't work
- Install Tesseract OCR and make sure it's on your system
PATH
Google sign-in doesn't work
- Make sure
NEXT_PUBLIC_GOOGLE_CLIENT_IDis set correctly infrontend/.env.local - Make sure
http://localhost:3000is listed in your Google OAuth Authorized origins
CORS errors in the browser console
- The backend has
allow_origins=["*"]set, so this should not happen in local dev - If it does, check that the backend is actually running on port 8000
ποΈ Production Build
To build the frontend for production:
cd frontend
npm run build
npm start
For the backend, use a production ASGI server:
cd backend
gunicorn app.main:app -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
π License
MIT β feel free to use, modify and distribute.