# alchemistofweb/wishlists_backend architecture

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

- Interactive diagram: https://gitdiagram.com/alchemistofweb/wishlists_backend
- Repository: https://github.com/alchemistofweb/wishlists_backend

## Overview

1. **What this repo is**
   - A FastAPI-style Python 3.12 backend for a social wishlist platform.
   - Core domain: users, wishlists, wishlist items, friendships, events, and notifications.
   - The architecture is layered: HTTP API → service layer → ORM models/database, with Pydantic schemas at the boundary.

2. **Application entrypoint**
   - `app/main.py` is the composition root where the app is created and routers are mounted.
   - This is the place where the API surface is assembled from the feature modules under `app/api/`.

3. **HTTP/API boundary**
   - `app/api/auth.py`, `users.py`, `friends.py`, `wishlist.py`, and `events.py` split the API by resource/domain.
   - These modules are responsible for request/response handling, validation, and delegating to services rather than embedding business rules.
   - The README indicates the main flows: sign up/sign in/sign out, friend add/accept/delete, wishlist CRUD and status/tag updates, and event-related operations.

4. **Business logic layer**
   - `app/services/auth.py` and `app/services/wish.py` hold the main domain logic.
   - Authentication logic is separated from transport and persistence concerns, and wishlist-related rules are similarly centralized.
   - This layer is where cross-entity rules belong, such as access checks, ownership, and state transitions for wish items.

5. **Domain model layer**
   - `app/models/user.py`, `wishlist.py`, `wish_item.py`, `tag.py`, `wish_item_tag.py`, `friendship.py`, `event.py`, and `notification.py` define the persistent domain objects.
   - The model set suggests several important relationships:
     - user ↔ wishlist
     - wishlist ↔ wish items
     - wish item ↔ tags via a many-to-many link table
     - user ↔ user via friendship
     - user ↔ events/notifications for reminders and gifting-related alerts

6. **Schemas as the API contract**
   - `app/schemas/auth.py`, `event.py`, `tag.py`, and `wish_item.py` define request/response shapes.
   - These schemas form the contract between clients and the service layer, keeping API payloads separate from ORM entities.
   - The README explicitly calls out response shaping for wishlist items, including tags in item listings.

7. **Authentication and authorization boundary**
   - `app/core/security.py` and `app/constants/auth.py` contain JWT/security primitives and auth-related constants.
   - `app/dependencies/auth.py` provides the dependency-based access control hook used by protected endpoints.
   - The auth flow is: API request → auth service → security helpers → user model/session → JWT/token response.

8. **Persistence and database access**
   - `app/db/session.py` and `app/db/base.py` define the DB session and ORM base wiring.
   - This is a classic ORM-backed persistence layer, with application code interacting through sessions rather than raw SQL.
   - `alembic.ini` plus `migrations/` show that schema evolution is managed explicitly through Alembic.

9. **Schema migration boundary**
   - `migrations/env.py` and version files under `migrations/versions/` capture database evolution.
   - The existing revisions indicate the project already has multiple model/schema initialization steps, which is important for reproducing and evolving the data model.

10. **Configuration and environment**
   - `app/core/config.py` centralizes runtime configuration, likely loaded from environment variables.
   - `.env.example` and Docker setup indicate the app is expected to run in containerized environments with externalized configuration.
   - This keeps secrets, DB URLs, and service-specific settings out of the codebase.

11. **Constants and domain rules**
   - `app/constants/wishlist.py` and `app/constants/auth.py` hold shared enumerations or fixed values.
   - The README hints at status values like `is_gifted`, `is_delivering`, `is_archieved`, and `is_deleted`, which belong in this layer rather than being scattered through handlers.

12. **Infrastructure and packaging**
   - `Dockerfile`, `docker-compose.yml`, and `pyproject.toml` define the runtime and dependency management story.
   - `poetry` is the dependency manager, and Docker Compose is the primary local orchestration path.
   - This suggests the backend is designed to run as a containerized API service with migrations executed against the same environment.

13. **Current feature coverage vs. planned work**
   - Implemented modules cover auth, users, friends, wishlists, and event/notification data structures.
   - The README also lists planned subsystems not yet present in code: hourly notification jobs, AI/gift recommendations, and a goods/catalog browsing flow.
   - For an architecture diagram, treat those as future external workers/integrations rather than current in-process components.

14. **Main end-to-end data flows**
   - Auth flow: client → `app/api/auth.py` → `app/services/auth.py` → `app/models/user.py` / DB → JWT back to client.
   - Wishlist flow: client → `app/api/wishlist.py` → `app/services/wish.py` → wish item/tag/wishlist models → DB.
   - Friendship flow: client → `app/api/friends.py` → friendship model updates → downstream visibility rules for friend wishlists.
   - Event/notification flow is modeled in the domain, but the scheduled delivery worker is still a planned subsystem.

Main entry points: [`app/db/base.py`](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/db/base.py) (ORM base), [`app/services/wish.py`](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/services/wish.py) (Wish service), [`app/main.py`](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/main.py) (App entry), [`app/services/auth.py`](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/services/auth.py) (Auth service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_app_main["App entry<br/>FastAPI composition<br/>[main.py]"]
end

subgraph group_interface["Interface"]
  node_api_auth["Auth API<br/>HTTP router<br/>[auth.py]"]
  node_api_users["Users API<br/>HTTP router<br/>[users.py]"]
  node_api_friends["Friends API<br/>HTTP router<br/>[friends.py]"]
  node_api_wishlist["Wishlists API<br/>HTTP router<br/>[wishlist.py]"]
  node_api_events["Events API<br/>HTTP router<br/>[events.py]"]
  node_schemas_auth["Auth schemas<br/>Pydantic contract<br/>[auth.py]"]
  node_schemas_wish["Wish schemas<br/>Pydantic contract<br/>[wish_item.py]"]
  node_schemas_event["Event schemas<br/>Pydantic contract<br/>[event.py]"]
end

subgraph group_domain["Domain"]
  node_services_auth["Auth service<br/>Service layer<br/>[auth.py]"]
  node_services_wish["Wish service<br/>Service layer<br/>[wish.py]"]
  node_models_user[("Users<br/>ORM model<br/>[user.py]")]
  node_models_wishlist[("Wishlists<br/>ORM model<br/>[wishlist.py]")]
  node_models_wish_item[("Wish items<br/>ORM model<br/>[wish_item.py]")]
  node_models_friendship[("Friendships<br/>ORM model<br/>[friendship.py]")]
  node_models_event[("Events<br/>ORM model<br/>[event.py]")]
  node_models_notification[("Notifications<br/>ORM model<br/>[notification.py]")]
  node_models_tag[("Tags<br/>ORM model<br/>[tag.py]")]
  node_models_link[("Item tags<br/>Link model<br/>[wish_item_tag.py]")]
end

subgraph group_platform["Platform"]
  node_core_security{{"Security<br/>[security.py]"}}
  node_core_config["Config<br/>[config.py]"]
  node_auth_dep["Auth deps<br/>Access control<br/>[auth.py]"]
  node_constants["Constants<br/>[auth.py]"]
end

subgraph group_persistence["Persistence"]
  node_db_session[("DB session<br/>Session wiring<br/>[session.py]")]
  node_db_base[("ORM base<br/>Declarative base<br/>[base.py]")]
  node_migrations["Migrations<br/>Alembic schema<br/>[env.py]"]
end

node_app_main -->|"mounts"| node_api_auth
node_app_main -->|"mounts"| node_api_users
node_app_main -->|"mounts"| node_api_friends
node_app_main -->|"mounts"| node_api_wishlist
node_app_main -->|"mounts"| node_api_events
node_api_auth -->|"delegates"| node_services_auth
node_api_wishlist -->|"delegates"| node_services_wish
node_api_friends -->|"updates"| node_models_friendship
node_api_events -->|"reads/writes"| node_models_event
node_api_auth -->|"shapes"| node_schemas_auth
node_api_wishlist -->|"shapes"| node_schemas_wish
node_api_events -->|"shapes"| node_schemas_event
node_services_auth -->|"uses"| node_core_security
node_services_auth -->|"queries"| node_models_user
node_services_wish -->|"uses"| node_models_wishlist
node_services_wish -->|"uses"| node_models_wish_item
node_services_wish -->|"uses"| node_models_tag
node_services_wish -->|"joins"| node_models_link
node_auth_dep -->|"verifies"| node_core_security
node_auth_dep -->|"loads"| node_models_user
node_core_config -->|"configures"| node_db_session
node_db_base -->|"registers"| node_models_user
node_db_base -->|"registers"| node_models_wishlist
node_db_base -->|"registers"| node_models_wish_item
node_db_base -->|"registers"| node_models_friendship
node_db_base -->|"registers"| node_models_event
node_db_base -->|"registers"| node_models_notification
node_db_base -->|"registers"| node_models_tag
node_db_base -->|"registers"| node_models_link
node_migrations -->|"tracks"| node_db_base
node_services_auth -->|"reads"| node_constants
node_services_wish -->|"reads"| node_constants

click node_app_main "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/main.py"
click node_api_auth "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/auth.py"
click node_api_users "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/users.py"
click node_api_friends "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/friends.py"
click node_api_wishlist "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/wishlist.py"
click node_api_events "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/events.py"
click node_schemas_auth "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/schemas/auth.py"
click node_schemas_wish "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/schemas/wish_item.py"
click node_schemas_event "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/schemas/event.py"
click node_services_auth "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/services/auth.py"
click node_services_wish "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/services/wish.py"
click node_models_user "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/user.py"
click node_models_wishlist "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/wishlist.py"
click node_models_wish_item "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/wish_item.py"
click node_models_friendship "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/friendship.py"
click node_models_event "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/event.py"
click node_models_notification "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/notification.py"
click node_models_tag "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/tag.py"
click node_models_link "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/wish_item_tag.py"
click node_core_security "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/core/security.py"
click node_core_config "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/core/config.py"
click node_auth_dep "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/dependencies/auth.py"
click node_constants "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/constants/auth.py"
click node_db_session "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/db/session.py"
click node_db_base "https://github.com/alchemistofweb/wishlists_backend/blob/main/app/db/base.py"
click node_migrations "https://github.com/alchemistofweb/wishlists_backend/blob/main/migrations/env.py"

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_app_main toneBlue
class node_api_auth,node_api_users,node_api_friends,node_api_wishlist,node_api_events,node_schemas_auth,node_schemas_wish,node_schemas_event toneAmber
class node_services_auth,node_services_wish,node_models_user,node_models_wishlist,node_models_wish_item,node_models_friendship,node_models_event,node_models_notification,node_models_tag,node_models_link toneMint
class node_core_security,node_core_config,node_auth_dep,node_constants toneRose
class node_db_session,node_db_base,node_migrations toneIndigo
```

## Components

### Runtime

Application composition and execution entrypoints

- [App entry](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/main.py): FastAPI composition · Creates the application and mounts feature routers · `app/main.py`

### Interface

HTTP layer and request/response contracts

- [Auth API](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/auth.py): HTTP router · Sign up, sign in, sign out endpoints · `app/api/auth.py`
- [Users API](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/users.py): HTTP router · User-facing endpoints and profile flows · `app/api/users.py`
- [Friends API](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/friends.py): HTTP router · Friend add, accept, and delete flows · `app/api/friends.py`
- [Wishlists API](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/wishlist.py): HTTP router · Wishlist and wish item CRUD plus status updates · `app/api/wishlist.py`
- [Events API](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/api/events.py): HTTP router · Event-related endpoints and notifications surface · `app/api/events.py`
- [Auth schemas](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/schemas/auth.py): Pydantic contract · Authentication request and response shapes · `app/schemas/auth.py`
- [Wish schemas](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/schemas/wish_item.py): Pydantic contract · Wish item and wishlist payload shapes · `app/schemas/wish_item.py`
- [Event schemas](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/schemas/event.py): Pydantic contract · Event and notification payload shapes · `app/schemas/event.py`

### Domain

Business logic and persistent domain objects

- [Auth service](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/services/auth.py): Service layer · Authentication and token issuance rules · `app/services/auth.py`
- [Wish service](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/services/wish.py): Service layer · Wishlist, ownership, and item state rules · `app/services/wish.py`
- [Users](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/user.py): ORM model · User accounts and identity records · `app/models/user.py`
- [Wishlists](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/wishlist.py): ORM model · Wishlist aggregates owned by users · `app/models/wishlist.py`
- [Wish items](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/wish_item.py): ORM model · Individual wishlist items and status fields · `app/models/wish_item.py`
- [Friendships](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/friendship.py): ORM model · User-to-user friendship relationships · `app/models/friendship.py`
- [Events](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/event.py): ORM model · Reminder and gifting-related event records · `app/models/event.py`
- [Notifications](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/notification.py): ORM model · Notification records tied to users and events · `app/models/notification.py`
- [Tags](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/tag.py): ORM model · Tag records for wish items · `app/models/tag.py`
- [Item tags](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/models/wish_item_tag.py): Link model · Many-to-many association between wish items and tags · `app/models/wish_item_tag.py`

### Platform

Security, configuration, and shared infrastructure

- [Security](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/core/security.py): JWT/security · Token and auth helper primitives · `app/core/security.py`
- [Config](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/core/config.py): App config · Environment-driven runtime configuration · `app/core/config.py`
- [Auth deps](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/dependencies/auth.py): Access control · Dependency hook for protected endpoints · `app/dependencies/auth.py`
- [Constants](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/constants/auth.py): Domain constants · Shared auth and wishlist fixed values · `app/constants/auth.py`

### Persistence

Database wiring and schema evolution

- [DB session](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/db/session.py): Session wiring · Database session creation and lifecycle · `app/db/session.py`
- [ORM base](https://github.com/alchemistofweb/wishlists_backend/blob/main/app/db/base.py): Declarative base · Shared ORM base and model registration support · `app/db/base.py`
- [Migrations](https://github.com/alchemistofweb/wishlists_backend/blob/main/migrations/env.py): Alembic schema · Database schema evolution and revision history · `migrations/env.py`

## Connections

- App entry → Auth API: mounts · Registers auth routes
- App entry → Users API: mounts · Registers user routes
- App entry → Friends API: mounts · Registers friendship routes
- App entry → Wishlists API: mounts · Registers wishlist routes
- App entry → Events API: mounts · Registers event routes
- Auth API → Auth service: delegates · Hands off auth logic
- Wishlists API → Wish service: delegates · Hands off wishlist logic
- Friends API → Friendships: updates · Creates and mutates friendships
- Events API → Events: reads/writes · Works with event records
- Auth API → Auth schemas: shapes · Uses auth request/response schemas
- Wishlists API → Wish schemas: shapes · Uses wishlist payload schemas
- Events API → Event schemas: shapes · Uses event payload schemas
- Auth service → Security: uses · Creates and validates tokens
- Auth service → Users: queries · Looks up and persists users
- Wish service → Wishlists: uses · Operates on wishlists
- Wish service → Wish items: uses · Operates on wish items
- Wish service → Tags: uses · Applies and resolves tags
- Wish service → Item tags: joins · Manages item-tag associations
- Auth deps → Security: verifies · Checks incoming credentials
- Auth deps → Users: loads · Resolves current user context
- Config → DB session: configures · Supplies DB connection settings
- ORM base → Users: registers · ORM model metadata
- ORM base → Wishlists: registers · ORM model metadata
- ORM base → Wish items: registers · ORM model metadata
- ORM base → Friendships: registers · ORM model metadata
- ORM base → Events: registers · ORM model metadata
- ORM base → Notifications: registers · ORM model metadata
- ORM base → Tags: registers · ORM model metadata
- ORM base → Item tags: registers · ORM model metadata
- Migrations → ORM base: tracks · Evolves the ORM schema
- Auth service → Constants: reads · Uses auth constants
- Wish service → Constants: reads · Uses wishlist constants
