Compact FastAPI backend for file conversions, PDF processing, QR generation, image editing, summarization, and data analysis.
Repository layout
app/— main application package (routers, services, models, schemas)app/api/v1/endpoints/— REST endpoints (see Endpoints section)app/core/— configuration, database, security helpersapp/models/— SQLAlchemy modelsapp/services/— business logic and external integrations (MinIO, PDF, QR, etc.)alembic/— DB migrations (scaffolded)Dockerfile— container imagerequirements.txt— Python dependencies
Prerequisites: Python 3.14, PostgreSQL, MinIO (or adjust storage), Redis for Celery if used.
- Create and activate virtualenv:
python -m venv env
source env/bin/activate- Install dependencies:
pip install -r requirements.txt- Configure environment variables (create a
.envfile) — seeapp/core/config.pyfor names. At minimum set:
DATABASE_URL(e.g.postgresql+asyncpg://user:pass@host:5432/db)MINIO_ENDPOINT,MINIO_ACCESS_KEY,MINIO_SECRET_KEY,MINIO_BUCKETSECRET_KEY
- Run Alembic migrations (after installing alembic in env):
alembic revision --autogenerate -m "initial"
alembic upgrade head- Run the app:
uvicorn app.main:app --host 0.0.0.0 --port 8000Or build and run the Docker image:
docker build -t proj7-api:local .
docker run --env-file .env -p 8000:8000 proj7-api:localThe API uses JWT bearer tokens. Authenticate via /auth/login to receive an access_token and refresh_token. Include Authorization: Bearer <access_token> header on protected endpoints.
Base API root: /api/v1 (see app.main for exact mounting). Below are the primary routes and short descriptions.
-
Authentication (
/auth)POST /auth/register— register a user. Body:UserCreate(email, password, role).POST /auth/login— obtain tokens. Form:username,password(OAuth2PasswordRequestForm).POST /auth/refresh— refresh access token. Body:{ "refresh_token": "..." }
-
Files (
/files)POST /files/— upload a file (multipart). Auth required. Returns file metadata.GET /files/{file_id}— download file. Auth required.DELETE /files/{file_id}— delete file. Auth required.PUT /files/{file_id}/rename— rename file. Body:FileRename.GET /files/{file_id}/versions— list versions for a file.
-
PDF (
/pdf)POST /pdf/merge— merge multiple PDFs (multipart files). Auth required.POST /pdf/convert— convert uploaded file to PDF.
-
QR Codes (
/qrcode)POST /qrcode/generate— generate QR image from payload. Body:QRGenerate.
-
Photo Editing (
/photo)POST /photo/edit— multipart form:operations(JSON string) +file(image). Returns edited image metadata and URL.- Note:
operationsshould be JSON matchingPhotoEditschema.
- Note:
-
File Conversion (
/convert)POST /convert/— multipart form:conversion(JSON string) +file(file). Returns converted file metadata and URL.
-
Summarization (
/summarize)POST /summarize/— upload text file to queue summarization job. Returnsjob_id.GET /summarize/jobs/{job_id}— check job status and result URL.
-
AR Menu (
/ar/menu)POST /ar/menu/create— upload CSV/JSON menu file; returns AR menu JSON preview URL and metadata.
-
Data Analysis (
/analysis)POST /analysis/upload— upload CSV/XLSX dataset; returns analysis JSON and charts.
-
WebSocket (
/ws)WebSocket /ws/notifications— WebSocket endpoint for notifications (authenticated via dependency).
For exact request/response schemas, see app/schemas/*.py.
- Multipart endpoints that accept JSON models require the client to send the JSON as a form field, e.g. using
FormData.append('conversion', JSON.stringify({...}))in browser clients. - Ensure the
alembicCLI uses the sameDATABASE_URLas the app (we load settings inalembic/env.py). - Consider adding tests and CI that run
python -m compileall,ruff/mypy, andpytest.
- Linting / formatting:
black,ruff(add torequirements-devas desired). - Run background workers (Celery) if using tasks: configure
CELERY_BROKER_URLand runcelery -A app.celery_app worker --loglevel=info.
- Fork and create a branch for your feature.
- Run tests and linters locally.
- Open a PR with clear description and changelog.
MUST RUN docker compose exec backend alembic upgrade head after running container for first time