Instruction file imported from fao102/Style-Finder (
.github/instructions/backend-python.instructions.md). Copyright stays with the author.
Backend Python Guidelines
Django / DRF Conventions
- Use
python-decouple'sconfig()for every environment variable read — never useos.environ.getdirectly in settings or views. - All API logic lives in
backend/app/api/views.py. Keepbackend/app/views.pyandbackend/app/urls.pyas legacy stubs; do not add new logic there. - DRF viewsets are registered via
DefaultRouterinbackend/app/api/urls.pyand aggregated inbackend/core/api/urls.py. Follow this pattern for any new endpoints. - After adding or modifying a model field, always generate a migration:
python manage.py makemigrations app. - The
OutfitSearchmodel (backend/app/models.py) stores per-request Gemini analysis results. Add nullable fields (blank=True, null=True) for any new AI-extracted attributes.
Gemini Integration
- Model in use:
gemini-2.5-flash. Do not change the model string without updatingrequirements.txtif the API version changes. - Always request
response_mime_type: "application/json"ingeneration_configto get structured output. - Wrap Gemini and SerpAPI calls in
try/except Exceptionand return a graceful error dict; never let an API failure cause an unhandled 500.
Image Handling
- Use
resize_image()frombackend/app/api/helper.pybefore passing images to Gemini. It caps dimensions at 720 px to control token cost. - Uploaded images are stored at
backend/media/uploads/(controlled byMEDIA_ROOT). In production, consider cloud storage (S3/GCS) — placeholders are commented out insettings.py.
Settings
- Production settings:
backend/core/settings.py— requiresDATABASE_URL,SECRET_KEY,GEMINI_API_KEY,SERP_API_KEY,ALLOWED_HOSTS,CORS_ALLOWED_ORIGINS,CSRF_TRUSTED_ORIGINS. - Dev settings:
backend/core/dev_settings.py— uses SQLite andDEBUG=True. Select withDJANGO_SETTINGS_MODULE=core.dev_settings. CORS_ALLOWED_ORIGIN_REGEXESincludesr"^https://.*\.vercel\.app$"to handle Vercel preview URLs automatically.
Testing
cd backend
python manage.py test # runs Django test suite
There are no frontend-facing tests configured yet. Add tests under backend/app/tests/.