How maheshgummul9/pythoncoffeeapp works
Purpose and Entry Point
SecureCart is a FastAPI-rendered coffee/snacks storefront used to demonstrate a resilient AWS deployment. The application handles catalog browsing, session cart operations, checkout, JSON product APIs, and an ALB-facing health check. Its executable entry point is app/main.py; local startup uses Uvicorn against the exported FastAPI application.
HTTP Application Layer
app/main.py is the central application boundary: it defines page routes (/, products, cart, checkout), mutation routes for cart changes and order completion, JSON product endpoints, and /health. It coordinates request handling, persistence access, cart/session behavior, and Jinja rendering.
• app/main.py
• templates/home.html
• templates/checkout.html
Server-Rendered Storefront
The browser-facing UI is server-rendered with Jinja templates. Shared page layout and styling are separated from route logic, while catalog, product detail, cart, checkout, and successful-order views represent the main customer flow.
• templates/base.html
• templates/product.html
• templates/cart.html
• static/style.css
Commerce Data Boundaries
The intended persistence split is relational product/order data versus high-frequency cart and session state. Locally, the application begins with SQLite and seeds an initial eight-product catalog; production switches relational storage through DATABASE_URL to RDS PostgreSQL. DynamoDB is the planned/production boundary for cart and session reads/writes.
• app/main.py
• requirements.txt
Request and Checkout Flow
A customer request enters the FastAPI app, which retrieves product data and renders templates or returns JSON. Cart add/update/remove operations mutate session/cart state; checkout reads that state, persists the resulting order in the relational store, then renders a success page. /health is intentionally isolated as a lightweight liveness target for the load balancer.
• app/main.py
• templates/cart.html
• templates/success.html
AWS Edge, Compute, and Network
Production traffic is designed to flow Route 53 → AWS WAF → Application Load Balancer → EC2 Auto Scaling Group. Instances run the FastAPI/Uvicorn service across two Availability Zones. Application and database tiers reside in private VPC subnets, preventing direct internet access; the ALB is the public application ingress.
• architecture/securecart_architecture.png
• app/main.py
Reliability, Security, and Operations
RDS PostgreSQL uses Multi-AZ deployment for relational-data availability; EC2 Auto Scaling removes a single compute-instance dependency. IAM roles enforce workload access, Secrets Manager supplies sensitive values such as database credentials, and CloudWatch provides logs and alarms. Static assets are intended for S3 delivery, while Route 53 provides DNS and WAF filters malicious edge traffic.
• architecture/securecart_architecture.png
• static/style.css
Main entry points: main.py FastAPI / Uvicorn · product.html Jinja Storefront Views · style.css Storefront Styling
Components 17
Public Edge
- Route 53
- AWS WAF
- Application Load Balancer · Routes traffic and checks /health.
Private Application Tier
EC2 instances run across two Availability Zones.
- EC2 Auto Scaling Group
- FastAPI / Uvicorn · Routes pages, mutations, JSON APIs, checkout, and health checks.
app/main.py - Jinja Storefront Views · Catalog, product, cart, checkout, and order-success pages.
templates/product.html - Storefront Styling
static/style.css - Product JSON API
app/main.py - Checkout and Order Completion · Converts cart state into a persisted order.
app/main.py
State and Data
- Product and Order Store · SQLite locally; RDS PostgreSQL through DATABASE_URL in production.
app/main.py - RDS PostgreSQL Multi-AZ · Highly available relational persistence.
- DynamoDB Cart and Sessions · Production boundary for high-frequency cart and session reads/writes.
app/main.py - S3 Static Assets
Security and Operations
- Secrets Manager · Supplies database credentials and other sensitive values.
- IAM Roles · Grants workload access to AWS resources.
- CloudWatch · Collects logs and drives alarms.
Other components
- Customer Browser
Connections 18
- Customer Browser → Route 53: store request
- Route 53 → AWS WAF: DNS traffic
- AWS WAF → Application Load Balancer: filtered HTTPS
- Application Load Balancer → EC2 Auto Scaling Group: forwards requests
- Application Load Balancer → FastAPI / Uvicorn: /health
- EC2 Auto Scaling Group → FastAPI / Uvicorn: runs
- FastAPI / Uvicorn → Jinja Storefront Views: renders pages
- FastAPI / Uvicorn → Product JSON API: serves JSON
- FastAPI / Uvicorn → Checkout and Order Completion: handles checkout
- FastAPI / Uvicorn → Product and Order Store: reads products and orders
- FastAPI / Uvicorn → DynamoDB Cart and Sessions: mutates cart state
- Checkout and Order Completion → Product and Order Store: persists order
- Product and Order Store → RDS PostgreSQL Multi-AZ: production backend
- Customer Browser → S3 Static Assets: loads static assets
- S3 Static Assets → Storefront Styling: delivers
- Secrets Manager → FastAPI / Uvicorn: provides credentials
- IAM Roles → FastAPI / Uvicorn: workload permissions
- FastAPI / Uvicorn → CloudWatch: logs and metrics