How anyesh/wardrowbe works
1. Overall shape
- This is a self-hosted wardrobe management system split into a Next.js frontend, a FastAPI backend, and an async worker layer.
- The primary state lives in PostgreSQL; Redis is used for job queueing, caching, and distributed locking.
2. User-facing frontend
- The frontend/ app is a Next.js 14 React application with TypeScript, Tailwind, and shadcn/ui components.
- It contains the main user workflows: wardrobe browsing, item details, outfit history, recommendations, analytics, family feed, notifications, settings, onboarding, and login.
- Frontend data access is organized through lib/hooks/* and lib/api.ts, so most screens consume backend APIs through a consistent client layer.
3. Authentication boundary
- Authentication is handled in the frontend using NextAuth.js, with support for both development credentials and OIDC SSO.
- The auth callback route lives under frontend/app/api/auth/[...nextauth].
- The backend has its own auth utilities and token handling, so the frontend session and backend authorization are separate concerns connected by API calls.
4. Backend API surface
- The backend is a FastAPI app with versioned route modules under backend/app/api/.
- The API is split by domain: items, outfits, pairings, users, families, preferences, notifications, learning, weather, images, health, analytics, and auth.
- backend/app/api/router.py composes these routes into the public API under /api/v1.
5. Domain model and persistence
- Core data entities are modeled in backend/app/models/: users, families, items, outfits, pairings, preferences, schedules, notifications, and learning-related records.
- Pydantic schemas in backend/app/schemas/ define request/response boundaries, while SQLAlchemy models define persistence.
- Alembic migrations in backend/migrations/ show the system’s evolution around AI tagging, image metadata, learning tables, wash tracking, body measurements, and schedule timing.
6. Service layer
- Business logic is concentrated in backend/app/services/, which acts as the main boundary between API handlers and the database/external systems.
- Important service groups include:
- item/family/user management
- outfit and pairing generation
- recommendation and scoring logic
- learning and feedback ingestion
- notifications and notification-provider adapters
- weather integration
- studio/image processing
- AI orchestration
- This makes the backend architecture more “service-oriented” than route-heavy.
7. Recommendation and AI pipeline
- AI is a first-class subsystem, but it is provider-agnostic: the backend can talk to any OpenAI-compatible API.
- Prompts live in backend/app/prompts/ for clothing analysis, descriptions, pairings, and recommendations.
- The AI flow is split by capability: image analysis/tagging, outfit recommendation, item pairing, and generated descriptions.
- The README notes internal AI can be fully disabled, so the backend can operate without direct AI access when an external agent handles those tasks.
8. Image processing pipeline
- Wardrobe photos go through a dedicated image path: upload, optional background removal, analysis/tagging, and thumbnail/asset handling.
- background_removal.py, image_service.py, studio_service.py, and utils/signed_urls.py indicate the backend manages image transformation and secure asset access.
- There is support for either a local rembg backend or an HTTP background-removal provider.
9. Async worker subsystem
- Background work runs in backend/app/workers/ and is separated from the API process.
- Worker modules cover notifications, AI tagging, and worker-specific DB/settings plumbing.
- The repository uses arq for queued jobs, with Redis as the queue backend.
- This is where longer-running or delayed tasks likely execute: tagging, notification delivery, and recovery/maintenance tasks.
10. Notification and scheduling flow
- The system supports scheduled outfit suggestions and reminders, likely driven by schedules plus notification jobs.
- Notification delivery is abstracted through provider adapters in notification_providers.py, with README support for ntfy, email/SMTP, and similar push channels.
- The worker layer is the natural execution point for scheduled sends; the API mostly configures and records notification preferences/state.
11. External integrations
- Weather comes from Open-Meteo, used for recommendation context.
- OIDC can integrate with external identity providers such as Keycloak, Authentik, PocketID, Auth0, etc.
- Optional IP geolocation is used only as a fallback for location input on the frontend.
- AI is externalized behind an OpenAI-compatible endpoint, which may be OpenAI, Ollama, LocalAI, or another service.
12. Deployment topology
- The standard deployment is containerized with Docker Compose; production and development compose files are both provided.
- Kubernetes manifests in k8s/ show the full stack: frontend, backend, worker, PostgreSQL, Redis, ingress, network policies, and secrets.
- Nginx/Caddy assets suggest reverse-proxy support for local or production serving, but the application itself is split cleanly by service boundaries.
13. Operational and maintenance boundaries
- Database migrations are a required operational step after deployment.
- Scripts such as check_migration_heads.py and regenerate_thumbnails.py point to explicit maintenance workflows for schema correctness and image assets.
- Health checks exist on the backend, and the test suite covers API behavior, services, workers, auth, AI, and weather, which reinforces the service boundaries above.
14. What to draw in an architecture diagram
- The central diagram should show:
- browser/mobile client → Next.js frontend
- frontend → FastAPI backend API
- backend ↔ PostgreSQL
- backend/worker ↔ Redis
- worker → notifications/AI provider/external services
- backend → AI provider, Open-Meteo, OIDC, SMTP/ntfy, background-removal service
- The most important conceptual boundary is that frontend handles UI/session, backend owns domain logic and persistence, and workers handle asynchronous side effects.
Main entry points: router.py FastAPI API · app Next.js App · services Domain Services · worker.py Workers
Components 19
Frontend
Next.js UI, session layer, and browser-side data access.
- Next.js App · Main React application for wardrobe workflows and dashboard pages.
frontend/app - Auth Layer · NextAuth-based login and session handling, including OIDC and dev credentials.
frontend/app/api/auth/[...nextauth]/route.ts - API Client · Shared frontend API access and feature hooks consumed by pages and components.
frontend/lib/api.ts - Studio UI · Specialized wardrobe studio and image-editing interactions in the frontend.
frontend/lib/studio
Backend
FastAPI domain API, persistence, AI/image services, and workers.
- FastAPI API · Versioned backend API composed from domain route modules.
backend/app/api/router.py - Domain Services · Business logic for items, outfits, pairings, users, preferences, and learning.
backend/app/services - Data Models · SQLAlchemy and Pydantic boundaries for core wardrobe entities.
backend/app/models - PostgreSQL · Persistent state for users, wardrobes, outfits, schedules, notifications, and learning.
backend/migrations - Redis · Job queue backend, caching, and distributed locking.
backend/app/utils/redis_lock.py - AI Pipeline · Prompted clothing analysis, pairing, recommendations, and generated descriptions.
backend/app/prompts - Image Pipeline · Upload, background removal, thumbnails, and secure image access.
backend/app/services/image_service.py - Notifications · Notification creation, scheduling, and provider integrations such as email and push.
backend/app/services/notification_providers.py - Weather · Weather context for outfit suggestions via Open-Meteo.
backend/app/services/weather_service.py - Backend Auth · Backend-side auth utilities, token handling, and OIDC helpers.
backend/app/utils/auth.py - Workers · Background execution for tagging, notifications, and maintenance tasks.
backend/app/workers/worker.py
Infra
Deployment, reverse proxy, and operational manifests.
- Compose · Local and production container composition for the full application stack.
docker-compose.yml - Kubernetes · Cluster manifests for frontend, backend, worker, database, Redis, ingress, and secrets.
k8s/kustomization.yaml - Reverse Proxy · Proxy configuration and templates for serving the stack.
nginx/nginx.conf
Other components
- Browser · User device accessing the wardrobe app.
Connections 29
- Browser → Next.js App: uses · Users interact with the Next.js application.
- Next.js App → Auth Layer: sessions · Frontend pages rely on NextAuth for sign-in and session state.
- Next.js App → API Client: data access · UI screens consume backend APIs through shared client/hooks.
- Next.js App → Studio UI: studio flows · Wardrobe studio screens use specialized editing state and helpers.
- API Client → FastAPI API: calls · Frontend client sends requests to the versioned backend API.
- Auth Layer → Backend Auth: delegates · Frontend session/auth workflows connect to backend authorization concerns through API calls.
- FastAPI API → Domain Services: orchestrates · Route handlers delegate to service-layer business logic.
- Domain Services → Data Models: reads/writes · Services operate over ORM and schema boundaries.
- Data Models → PostgreSQL: persists · Models are stored in PostgreSQL via migrations and ORM mappings.
- FastAPI API → AI Pipeline: uses · API endpoints trigger AI-backed analysis, recommendation, and description flows.
- Domain Services → Image Pipeline: processes · Services manage upload, background removal, thumbnails, and signed asset access.
- Domain Services → Notifications: sends · Notification services prepare delivery jobs and provider-specific payloads.
- Domain Services → Weather: enriches · Recommendation logic incorporates weather context.
- FastAPI API → Redis: locks/cache · API and services use Redis for caching and distributed locks.
- Workers → Redis: queues · Workers consume queued jobs from Redis via arq.
- Workers → Domain Services: runs tasks · Background jobs execute notification, tagging, and recovery workflows.
- Workers → Notifications: delivers · Worker processes execute notification dispatch.
- Workers → AI Pipeline: tagging jobs · Workers can run AI tagging and related asynchronous processing.
- FastAPI API → Backend Auth: auth checks · Backend routes enforce authorization and token handling.
- Compose → Next.js App: deploys · Compose defines the frontend container.
- Compose → FastAPI API: deploys · Compose defines the backend container.
- Compose → Workers: deploys · Compose defines the worker container.
- Compose → PostgreSQL: includes · Compose provisions PostgreSQL for the stack.
- Compose → Redis: includes · Compose provisions Redis for the stack.
- Kubernetes → Next.js App: deploys · Kubernetes manifests include the frontend service.
- Kubernetes → FastAPI API: deploys · Kubernetes manifests include the backend service.
- Kubernetes → Workers: deploys · Kubernetes manifests include the worker deployment.
- Reverse Proxy → Next.js App: fronts · Proxy config serves or routes traffic to the frontend.
- Reverse Proxy → FastAPI API: routes · Proxy config can route API traffic to the backend.