How jbocciadev/pp5-crafty works
1. Overall shape
Crafty is a Django 3.2 monolith built around server-rendered pages, not a separate frontend/backend split. The project is divided into feature apps, each owning its own models, views, forms, URLs, templates, and tests.
2. Request routing
The crafty/urls.py project router delegates to six main domains: home, products, bag, checkout, profiles, and contact. This is the primary architectural boundary for user-facing functionality.
3. Core domain: product catalog
The products app is the catalog subsystem. It models categories, age groups, topics, products, and reviews. It also contains product management flows such as add/edit product pages, product detail pages, and review submission/editing. A custom widget and template tags support richer form rendering and rating display.
4. Cart subsystem
The bag app is a session-backed shopping cart. It is responsible for add/update/remove item actions, bag totals, and the checkout entry point. Its template tags and partial templates are used to render item summaries consistently across product and bag pages.
5. Checkout and payment boundary
The checkout app owns purchase finalization. It contains the Order and order line item models, checkout form, checkout page, success page, and Stripe integration. The JavaScript in checkout/static/checkout/js/stripe_elements.js drives card collection, while webhooks.py and webhook_handler.py handle payment event reconciliation on the server side. This app is the boundary between the site and the external payment processor.
6. User accounts and profiles
Authentication is handled through Django allauth, with custom templates overriding the default auth UI. The profiles app extends the built-in user with a UserProfile model for delivery/contact details and exposes a profile page with order history and profile management forms. This app is the user account boundary for personal data and post-purchase history.
7. Contact and newsletter
The contact app manages customer contact submissions and newsletter subscribers. It includes an unsubscribe flow and likely sends notification emails to the support mailbox and confirmation emails to the user. This is separate from checkout communications and acts as the site’s general inbound communication channel.
8. Public pages and shared site shell
The home app provides the landing page, while the global templates/ directory supplies shared layout and reusable UI fragments: main navigation, desktop/mobile footers, modal dialogs, and toast notifications. These shared templates are the presentation layer used across all apps.
9. Data model relationships
The system centers on a few key relational flows: users own profiles; products belong to catalog taxonomies; reviews attach users to products; orders own line items; order history is surfaced back into profiles. This creates a clean separation between browse, cart, and fulfillment data.
10. Static and media handling
Static CSS/JS lives under each app or in the global static/ directory. Media assets, including product images and site imagery, are stored separately and the repo includes custom_storages.py, indicating custom storage configuration for production media/static hosting.
11. Infrastructure and deployment
The app is deployed on Heroku with Gunicorn as the WSGI server. Production data is stored in PostgreSQL via ElephantSQL, and the app uses environment variables for secrets and service credentials. The README and config files indicate AWS S3 integration for static/media storage.
12. External service integrations
The two main external integrations are Stripe for payments and email delivery for confirmations/notifications. Django allauth provides account management, while Stripe webhooks provide a trusted asynchronous payment confirmation path after checkout submission.
13. Operational and cross-cutting concerns
The repo includes custom error pages, sitemap and robots files for SEO, and Django admin customizations for staff operations. Migrations are present for each app, and the included tests show that each subsystem is meant to be validated independently.
14. In practical diagram terms
A useful architecture diagram would show: browser requests into Django; Django dispatching into feature apps; shared templates/static supporting all apps; checkout branching out to Stripe and email; and persistence flowing into PostgreSQL and AWS-backed media/static storage. The main trust boundary is the checkout/payment path, followed by auth/profile data and contact/newsletter messaging.
Main entry points: urls.py Project router · checkout/views.py Checkout · products/views.py Catalog · profiles/views.py Profiles
Components 24
Core apps
Feature apps behind the main site routes
- Project router · Delegates site traffic to feature apps
crafty/urls.py - Home · Public landing page and home route
home/views.py - Catalog · Products, categories, reviews, and product management flows
products/views.py - Bag · Session-backed shopping cart and bag actions
bag/views.py - Checkout · Order finalization and payment processing boundary
checkout/views.py - Profiles · User profile, delivery details, and order history
profiles/views.py - Contact · Contact submissions and newsletter unsubscribe flow
contact/views.py - Catalog data · Categories, age groups, topics, products, and reviews
products/models.py - Product forms · Admin/product edit forms and custom file input widget
products/forms.py - Bag context · Cart summary data injected into templates
bag/contexts.py - Orders · Order and order line items persisted at checkout
checkout/models.py - Checkout form · Checkout page form used to collect order details
checkout/forms.py - Webhooks · Stripe event reconciliation and fulfillment updates
checkout/webhooks.py - User profile · Extended user record for delivery and contact data
profiles/models.py - Subscribers · Contact submissions and newsletter subscriber records
contact/models.py
Shared UI
Global templates and static assets used across apps
- Site shell · Global layout, nav, footers, modals, toasts, and error pages
templates/base.html - Auth UI · Custom allauth login, signup, reset, and email templates
templates/allauth/account/login.html - Shared static · Global CSS, favicon, and site-wide styling assets
static/css/base.css
Integrations
External services and boundaries
- Stripe · External card payment processor
- Email · Outbound notification and confirmation delivery
- PostgreSQL · Primary relational persistence for site data
- S3 storage · External media and static asset storage
custom_storages.py
Ops
Deployment and environment configuration
- Heroku · Runtime and deployment environment
Procfile - Runtime config · Environment-driven secrets and service configuration
crafty/settings.py
Connections 33
- Project router → Home: routes · Dispatches the home route
- Project router → Catalog: routes · Dispatches catalog URLs
- Project router → Bag: routes · Dispatches bag URLs
- Project router → Checkout: routes · Dispatches checkout URLs
- Project router → Profiles: routes · Dispatches profile URLs
- Project router → Contact: routes · Dispatches contact URLs
- Home → Site shell: renders · Uses shared site chrome and layout
- Catalog → Catalog data: reads/writes · Catalog and review data access
- Catalog → Product forms: uses · Product creation and edit flows
- Catalog → Site shell: renders · Uses global templates and includes
- Bag → Bag context: computes · Builds cart summary context for pages
- Bag → Site shell: renders · Uses shared page chrome and partials
- Checkout → Orders: persists · Creates orders and line items
- Checkout → Checkout form: uses · Collects checkout details
- Checkout → Stripe: charges · Starts payment flow with Stripe
- Webhooks → Stripe: receives events · Handles asynchronous payment confirmation
- Webhooks → Orders: updates · Reconciles order state after payment events
- Checkout → Email: sends · Sends confirmation emails
- Profiles → User profile: reads/writes · Stores delivery and contact details
- Profiles → Orders: reads · Displays user order history
- Contact → Subscribers: persists · Stores contact submissions and subscribers
- Contact → Email: sends · Notifies support and confirms subscriptions
- Auth UI → Profiles: supports auth · Customizes account and signup experience
- Site shell → Shared static: loads · Shared styles and site assets
- Runtime config → Stripe: configures · Supplies API keys and service settings
- Runtime config → PostgreSQL: configures · Database connection settings
- Runtime config → S3 storage: configures · Media and static storage configuration
- Heroku → Runtime config: uses · Production runtime configuration
- Checkout → PostgreSQL: stores · Order and checkout data
- Catalog → PostgreSQL: stores · Catalog and review data
- Profiles → PostgreSQL: stores · Profile data
- Contact → PostgreSQL: stores · Contact and subscriber data
- S3 storage → Shared static: serves · Hosts media and static assets