How asheriff-bot/17-647-assignment-a4 works
This repository implements a small bookstore platform as a set of Python microservices with two client-facing BFF layers, an internal routing tier, and Kubernetes deployment assets for AWS EKS.
1. Top-level architecture
The system is split into:
- Web BFF and Mobile BFF at the edge
- Backend services for books, customers, and CRM
- A shared nginx backend-router inside the cluster
- A book data sync job for read-model synchronization
- A shared Python library for common BFF logic
2. Client entry points
web_bff/ and mobile_bff/ are the public HTTP entry points. They authenticate requests with JWT, require an X-Client-Type header, and then proxy downstream calls. The mobile BFF also reshapes some responses differently from the web BFF.
3. BFF responsibilities
The BFFs are not just pass-through proxies:
- they validate JWTs using shared auth helpers
- they enforce client type routing rules (Web vs iOS/Android)
- they apply client-specific response transformations
- they forward requests to the backend router rather than directly to services
4. Internal routing boundary
k8s/backend-router.yaml and the nginx config in scripts/nginx-backend.conf define an internal routing layer. The BFFs talk to this single backend endpoint, which routes book-related paths and customer-related paths to the appropriate service. This creates a clean boundary between edge concerns and backend service topology.
5. Book domain
The book domain is split into book_command_service/, book_query_service/, and book_data_sync/. This strongly suggests a CQRS-style separation:
- the command service handles writes and mutation endpoints
- the query service handles read endpoints
- the sync job keeps the read side aligned with the write side or indexed data
The README also indicates a related-books flow that depends on an external recommendation API and includes timeout/circuit-breaker behavior.
6. Customer domain
customer_service/ owns customer data and CRUD-style customer APIs. It is backed by a relational database and is the source of customer events for downstream processing. The repository includes SQL initialization and truncation scripts for the customer and books databases.
7. CRM/event processing
crm_service/ is an event-driven consumer. It receives customer events via Kafka and sends outbound email using SMTP settings provided through deployment environment variables. This makes CRM a side-effect service rather than a synchronous request handler.
8. Data flow across services
A typical request path is:
client → BFF → backend-router → domain service → database.
For customer creation, the flow extends to:
customer_service → Kafka → crm_service → email delivery.
For book reads, the flow can involve:
client → BFF → backend-router → book query service → read model/index.
9. Shared code and cross-cutting concerns
shared/ contains code reused by both BFFs:
- JWT validation helpers
- client-type and auth checks
- response formatting helpers
- book/customer transformation logic
This avoids duplicating edge behavior across the two frontends.
10. Infrastructure and deployment
The repo is designed for both local and AWS deployment:
- docker-compose.yml runs the full stack locally
- k8s/*.yaml contains Kubernetes manifests for EKS
- scripts/render_k8s_from_env.sh generates concrete manifests from environment values
- CF-A4.yml / CF-A4-cmu.yml provide optional AWS infrastructure provisioning
The Kubernetes manifests include a namespace, services, and a CronJob for data sync.
11. Runtime and operational model
All services are Python/Flask-based and containerized with per-service Dockerfiles. Health checking is standardized with /status, and the manifests are set up for Kubernetes probes and service exposure. Secrets and environment-specific endpoints are injected through deploy-time env files rather than hardcoded values.
12. Local vs production dependencies
In local compose, the stack includes MySQL, Kafka, the services, and a mock recommendation API. In EKS, the services depend on externally provisioned infrastructure such as Aurora writer access and Kafka/MSK connectivity, which are configured through the deployment environment and manifests.
13. How to draw the architecture
A good diagram should show:
- two client apps entering through two BFFs
- both BFFs going to a single backend-router
- backend-router splitting traffic to book and customer services
- customer service emitting Kafka events to CRM
- book command/query separation with a sync process between them
- shared JWT/transformation code used only by the BFFs
- databases and SMTP/Kafka as external dependencies
Main entry points: docker-compose.yml Compose Stack · web_bff/app.py Web BFF · mobile_bff/app.py Mobile BFF · backend-router.yaml Router
Components 19
Edge BFFs
Public client-facing request handlers
- Web BFF · Public HTTP entry point for web clients
web_bff/app.py - Mobile BFF · Public HTTP entry point for mobile clients
mobile_bff/app.py
Domain services
Core bookstore and customer services
- Book Command · Book mutation and write-side endpoints
book_command_service/app.py - Book Query · Book read-side endpoints and query model
book_query_service/app.py - Book Sync · Keeps the read model aligned with source data
book_data_sync/sync.py - Customer Service · Owns customer records and emits customer events
customer_service/app.py - CRM Service · Consumes customer events and sends outbound email
crm_service/app.py
Shared code
Reusable BFF helpers
- JWT Auth · JWT validation and auth checks used by BFFs
shared/bff_auth.py - Client Types · Client-type header validation and routing rules
shared/client_headers.py - Transforms · Response shaping and book/customer mapping helpers
shared/bff_book_transform.py
Infra assets
Deployment and routing configuration
- Router · Internal routing boundary for book and customer traffic
k8s/backend-router.yaml - K8s Assets · Namespace, service, and CronJob manifests for EKS
k8s/namespace.yaml - Render Script · Generates manifests from environment values
scripts/render_k8s_from_env.sh - Compose Stack · Local multi-service runtime definition
docker-compose.yml
External systems
Datastores and outbound integrations
- Books DB · Persistent store for book data and read/write state
scripts/init_db.sql - Customers DB · Persistent store for customer data
scripts/init_db.sql - Kafka · Carries customer events to CRM
- SMTP · Outbound email delivery for CRM
- Reco API · Related-books recommendation dependency
Connections 30
- Web BFF → JWT Auth: validate · Checks JWTs before forwarding requests
- Mobile BFF → JWT Auth: validate · Checks JWTs before forwarding requests
- Web BFF → Client Types: route · Enforces web client type rules
- Mobile BFF → Client Types: route · Enforces mobile client type rules
- Web BFF → Transforms: shape · Applies web-facing response formatting
- Mobile BFF → Transforms: shape · Applies mobile-facing response formatting
- Web BFF → Router: proxy · Forwards API traffic to internal router
- Mobile BFF → Router: proxy · Forwards API traffic to internal router
- Router → Book Command: books write · Routes book mutation paths
- Router → Book Query: books read · Routes book query paths
- Router → Customer Service: customers · Routes customer paths
- Book Command → Books DB: write · Persists book mutations
- Book Query → Books DB: read · Serves book reads from database
- Book Sync → Books DB: sync · Refreshes read-side data from source state
- Customer Service → Customers DB: write · Persists customer records
- Customer Service → Kafka: emit · Publishes customer events
- CRM Service → Kafka: consume · Consumes customer events
- CRM Service → SMTP: send · Delivers outbound email
- Book Command → Reco API: related books · Calls recommendation service with timeout protection
- K8s Assets → Router: deploy · Defines cluster routing boundary
- K8s Assets → Web BFF: deploy · Defines web BFF workload
- K8s Assets → Mobile BFF: deploy · Defines mobile BFF workload
- K8s Assets → Book Sync: deploy · Defines CronJob for sync
- Render Script → K8s Assets: render · Produces environment-specific manifests
- Compose Stack → Web BFF: run · Starts local web stack
- Compose Stack → Mobile BFF: run · Starts local mobile stack
- Compose Stack → Book Command: run · Starts local book write service
- Compose Stack → Book Query: run · Starts local book read service
- Compose Stack → Customer Service: run · Starts local customer service
- Compose Stack → CRM Service: run · Starts local CRM service