How alchemistofweb/wishlists_backend works
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: base.py ORM base · wish.py Wish service · main.py App entry · auth.py Auth service
Components 26
Runtime
Application composition and execution entrypoints
- App entry · Creates the application and mounts feature routers
app/main.py
Interface
HTTP layer and request/response contracts
- Auth API · Sign up, sign in, sign out endpoints
app/api/auth.py - Users API · User-facing endpoints and profile flows
app/api/users.py - Friends API · Friend add, accept, and delete flows
app/api/friends.py - Wishlists API · Wishlist and wish item CRUD plus status updates
app/api/wishlist.py - Events API · Event-related endpoints and notifications surface
app/api/events.py - Auth schemas · Authentication request and response shapes
app/schemas/auth.py - Wish schemas · Wish item and wishlist payload shapes
app/schemas/wish_item.py - Event schemas · Event and notification payload shapes
app/schemas/event.py
Domain
Business logic and persistent domain objects
- Auth service · Authentication and token issuance rules
app/services/auth.py - Wish service · Wishlist, ownership, and item state rules
app/services/wish.py - Users · User accounts and identity records
app/models/user.py - Wishlists · Wishlist aggregates owned by users
app/models/wishlist.py - Wish items · Individual wishlist items and status fields
app/models/wish_item.py - Friendships · User-to-user friendship relationships
app/models/friendship.py - Events · Reminder and gifting-related event records
app/models/event.py - Notifications · Notification records tied to users and events
app/models/notification.py - Tags · Tag records for wish items
app/models/tag.py - Item tags · Many-to-many association between wish items and tags
app/models/wish_item_tag.py
Platform
Security, configuration, and shared infrastructure
Persistence
Database wiring and schema evolution
- DB session · Database session creation and lifecycle
app/db/session.py - ORM base · Shared ORM base and model registration support
app/db/base.py - Migrations · Database schema evolution and revision history
migrations/env.py
Connections 32
- 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