# anyesh/wardrowbe architecture

> Architecture diagram of the GitHub repository anyesh/wardrowbe, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anyesh/wardrowbe
- Repository: https://github.com/anyesh/wardrowbe

## Overview

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: [`backend/app/api/router.py`](https://github.com/anyesh/wardrowbe/blob/main/backend/app/api/router.py) (FastAPI API), [`frontend/app`](https://github.com/anyesh/wardrowbe/tree/main/frontend/app) (Next.js App), [`backend/app/services`](https://github.com/anyesh/wardrowbe/tree/main/backend/app/services) (Domain Services), [`backend/app/workers/worker.py`](https://github.com/anyesh/wardrowbe/blob/main/backend/app/workers/worker.py) (Workers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["Next.js App<br/>nextjs ui"]
  node_frontend_auth["Auth Layer<br/>nextauth session<br/>[route.ts]"]
  node_frontend_client["API Client<br/>hooks client<br/>[api.ts]"]
  node_frontend_studio["Studio UI<br/>editor module"]
end

subgraph group_backend["Backend"]
  node_backend_api["FastAPI API<br/>http api<br/>[router.py]"]
  node_backend_domain["Domain Services<br/>service layer"]
  node_backend_models[("Data Models<br/>orm schemas")]
  node_backend_db[("PostgreSQL<br/>primary db")]
  node_backend_cache[("Redis<br/>queue cache<br/>[redis_lock.py]")]
  node_backend_ai["AI Pipeline<br/>provider-agnostic ai"]
  node_backend_images["Image Pipeline<br/>asset processing<br/>[image_service.py]"]
  node_backend_notify["Notifications<br/>delivery adapters"]
  node_backend_weather["Weather<br/>external integration<br/>[weather_service.py]"]
  node_backend_auth["Backend Auth<br/>token oidc<br/>[auth.py]"]
  node_backend_workers["Workers<br/>arq async jobs<br/>[worker.py]"]
end

subgraph group_infra["Infra"]
  node_infra_compose["Compose<br/>container stack<br/>[docker-compose.yml]"]
  node_infra_k8s["Kubernetes<br/>deployment manifests<br/>[kustomization.yaml]"]
  node_infra_proxy["Reverse Proxy<br/>nginx caddy<br/>[nginx.conf]"]
end

node_browser(("Browser<br/>client"))

node_browser -->|"uses"| node_frontend_app
node_frontend_app -->|"sessions"| node_frontend_auth
node_frontend_app -->|"data access"| node_frontend_client
node_frontend_app -->|"studio flows"| node_frontend_studio
node_frontend_client -->|"calls"| node_backend_api
node_frontend_auth -->|"delegates"| node_backend_auth
node_backend_api -->|"orchestrates"| node_backend_domain
node_backend_domain -->|"reads/writes"| node_backend_models
node_backend_models -->|"persists"| node_backend_db
node_backend_api -->|"uses"| node_backend_ai
node_backend_domain -->|"processes"| node_backend_images
node_backend_domain -->|"sends"| node_backend_notify
node_backend_domain -->|"enriches"| node_backend_weather
node_backend_api -->|"locks/cache"| node_backend_cache
node_backend_workers -->|"queues"| node_backend_cache
node_backend_workers -->|"runs tasks"| node_backend_domain
node_backend_workers -->|"delivers"| node_backend_notify
node_backend_workers -->|"tagging jobs"| node_backend_ai
node_backend_api -->|"auth checks"| node_backend_auth
node_infra_compose -->|"deploys"| node_frontend_app
node_infra_compose -->|"deploys"| node_backend_api
node_infra_compose -->|"deploys"| node_backend_workers
node_infra_compose -->|"includes"| node_backend_db
node_infra_compose -->|"includes"| node_backend_cache
node_infra_k8s -->|"deploys"| node_frontend_app
node_infra_k8s -->|"deploys"| node_backend_api
node_infra_k8s -->|"deploys"| node_backend_workers
node_infra_proxy -->|"fronts"| node_frontend_app
node_infra_proxy -->|"routes"| node_backend_api

click node_frontend_app "https://github.com/anyesh/wardrowbe/tree/main/frontend/app"
click node_frontend_auth "https://github.com/anyesh/wardrowbe/blob/main/frontend/app/api/auth/[...nextauth]/route.ts"
click node_frontend_client "https://github.com/anyesh/wardrowbe/blob/main/frontend/lib/api.ts"
click node_frontend_studio "https://github.com/anyesh/wardrowbe/tree/main/frontend/lib/studio"
click node_backend_api "https://github.com/anyesh/wardrowbe/blob/main/backend/app/api/router.py"
click node_backend_domain "https://github.com/anyesh/wardrowbe/tree/main/backend/app/services"
click node_backend_models "https://github.com/anyesh/wardrowbe/tree/main/backend/app/models"
click node_backend_db "https://github.com/anyesh/wardrowbe/tree/main/backend/migrations"
click node_backend_cache "https://github.com/anyesh/wardrowbe/blob/main/backend/app/utils/redis_lock.py"
click node_backend_ai "https://github.com/anyesh/wardrowbe/tree/main/backend/app/prompts"
click node_backend_images "https://github.com/anyesh/wardrowbe/blob/main/backend/app/services/image_service.py"
click node_backend_notify "https://github.com/anyesh/wardrowbe/blob/main/backend/app/services/notification_providers.py"
click node_backend_weather "https://github.com/anyesh/wardrowbe/blob/main/backend/app/services/weather_service.py"
click node_backend_auth "https://github.com/anyesh/wardrowbe/blob/main/backend/app/utils/auth.py"
click node_backend_workers "https://github.com/anyesh/wardrowbe/blob/main/backend/app/workers/worker.py"
click node_infra_compose "https://github.com/anyesh/wardrowbe/blob/main/docker-compose.yml"
click node_infra_k8s "https://github.com/anyesh/wardrowbe/blob/main/k8s/kustomization.yaml"
click node_infra_proxy "https://github.com/anyesh/wardrowbe/blob/main/nginx/nginx.conf"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_auth,node_frontend_client,node_frontend_studio toneBlue
class node_backend_api,node_backend_domain,node_backend_models,node_backend_db,node_backend_cache,node_backend_ai,node_backend_images,node_backend_notify,node_backend_weather,node_backend_auth,node_backend_workers toneAmber
class node_infra_compose,node_infra_k8s,node_infra_proxy toneMint
class node_browser toneNeutral
```

## Components

### Frontend

Next.js UI, session layer, and browser-side data access.

- [Next.js App](https://github.com/anyesh/wardrowbe/tree/main/frontend/app): nextjs ui · Main React application for wardrobe workflows and dashboard pages. · `frontend/app`
- [Auth Layer](https://github.com/anyesh/wardrowbe/blob/main/frontend/app/api/auth/[...nextauth]/route.ts): nextauth session · NextAuth-based login and session handling, including OIDC and dev credentials. · `frontend/app/api/auth/[...nextauth]/route.ts`
- [API Client](https://github.com/anyesh/wardrowbe/blob/main/frontend/lib/api.ts): hooks client · Shared frontend API access and feature hooks consumed by pages and components. · `frontend/lib/api.ts`
- [Studio UI](https://github.com/anyesh/wardrowbe/tree/main/frontend/lib/studio): editor module · 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](https://github.com/anyesh/wardrowbe/blob/main/backend/app/api/router.py): http api · Versioned backend API composed from domain route modules. · `backend/app/api/router.py`
- [Domain Services](https://github.com/anyesh/wardrowbe/tree/main/backend/app/services): service layer · Business logic for items, outfits, pairings, users, preferences, and learning. · `backend/app/services`
- [Data Models](https://github.com/anyesh/wardrowbe/tree/main/backend/app/models): orm schemas · SQLAlchemy and Pydantic boundaries for core wardrobe entities. · `backend/app/models`
- [PostgreSQL](https://github.com/anyesh/wardrowbe/tree/main/backend/migrations): primary db · Persistent state for users, wardrobes, outfits, schedules, notifications, and learning. · `backend/migrations`
- [Redis](https://github.com/anyesh/wardrowbe/blob/main/backend/app/utils/redis_lock.py): queue cache · Job queue backend, caching, and distributed locking. · `backend/app/utils/redis_lock.py`
- [AI Pipeline](https://github.com/anyesh/wardrowbe/tree/main/backend/app/prompts): provider-agnostic ai · Prompted clothing analysis, pairing, recommendations, and generated descriptions. · `backend/app/prompts`
- [Image Pipeline](https://github.com/anyesh/wardrowbe/blob/main/backend/app/services/image_service.py): asset processing · Upload, background removal, thumbnails, and secure image access. · `backend/app/services/image_service.py`
- [Notifications](https://github.com/anyesh/wardrowbe/blob/main/backend/app/services/notification_providers.py): delivery adapters · Notification creation, scheduling, and provider integrations such as email and push. · `backend/app/services/notification_providers.py`
- [Weather](https://github.com/anyesh/wardrowbe/blob/main/backend/app/services/weather_service.py): external integration · Weather context for outfit suggestions via Open-Meteo. · `backend/app/services/weather_service.py`
- [Backend Auth](https://github.com/anyesh/wardrowbe/blob/main/backend/app/utils/auth.py): token oidc · Backend-side auth utilities, token handling, and OIDC helpers. · `backend/app/utils/auth.py`
- [Workers](https://github.com/anyesh/wardrowbe/blob/main/backend/app/workers/worker.py): arq async jobs · Background execution for tagging, notifications, and maintenance tasks. · `backend/app/workers/worker.py`

### Infra

Deployment, reverse proxy, and operational manifests.

- [Compose](https://github.com/anyesh/wardrowbe/blob/main/docker-compose.yml): container stack · Local and production container composition for the full application stack. · `docker-compose.yml`
- [Kubernetes](https://github.com/anyesh/wardrowbe/blob/main/k8s/kustomization.yaml): deployment manifests · Cluster manifests for frontend, backend, worker, database, Redis, ingress, and secrets. · `k8s/kustomization.yaml`
- [Reverse Proxy](https://github.com/anyesh/wardrowbe/blob/main/nginx/nginx.conf): nginx caddy · Proxy configuration and templates for serving the stack. · `nginx/nginx.conf`

### Other components

- **Browser**: client · User device accessing the wardrobe app.

## Connections

- 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.
