How zakzap16/flyrank-capstone-metering-billing works
Flyrank is a multi-tenant metering and billing API. The principal flow is tenant-authenticated usage submission through middleware and the meter endpoint, followed by idempotency, subscription/quota checks, integer-cost calculation, and event recording. Separate branches provide usage and quota reads, tenant authentication, Stripe checkout/billing, and Stripe webhook synchronization. The README documents these capabilities; source-index references and excerpts support selected call relationships, while some storage and route details remain unsampled.
Main entry points: main.py FastAPI app · repositories Data repositories · usage.py Usage endpoint · meter_service.py Meter service
Components 23
API and access
- FastAPI app
src/main.py - Request middleware
src/api/middleware - Tenant authentication
src/api/middleware/auth.py - Auth endpoints
src/api/v1/auth.py - Meter endpoint
src/api/v1/meter.py - Usage endpoint
src/api/v1/usage.py - API key service
src/services/auth_service.py
Metering and quotas
- Meter service
src/services/meter_service.py - Quota service
src/services/quota_service.py - Cost calculation
src/services/cost_service.py
Billing lifecycle
- Billing and checkout
src/api/v1/checkout.py - Billing routes
src/api/v1/billing.py - Subscription routes
src/api/v1/subscription.py - Stripe webhook handler
src/api/v1/webhook.py - Stripe integration
src/services/stripe_service.py
State and integrations
- Data repositories
src/repositories - Domain records
src/models - PostgreSQL
- Cache and idempotency
src/config/cache.py - Redis
- Runtime settings
src/config/settings.py
Other components
- SaaS client
- Stripe
Connections 36
- SaaS client → FastAPI app: sends requests
- FastAPI app → Request middleware: installs
src/main.py - FastAPI app → Meter endpoint: routes to
src/main.py - FastAPI app → Usage endpoint: routes to
src/main.py - FastAPI app → Auth endpoints: routes to
src/main.py - FastAPI app → Billing and checkout: routes to
src/main.py - FastAPI app → Billing routes: routes to
src/main.py - FastAPI app → Subscription routes: routes to
src/main.py - FastAPI app → Stripe webhook handler: routes to
src/main.py - Meter endpoint → Tenant authentication: authenticates via
src/api/v1/meter.py - Meter endpoint → Meter service: calls
src/api/v1/meter.py - Meter service → Quota service: checks quota
src/services/meter_service.py - Meter service → Cost calculation: calculates cost
src/services/meter_service.py - Meter service → Data repositories: records usage
src/services/meter_service.py - Meter service → Cache and idempotency: uses idempotency
- Quota service → Data repositories: reads usage and plans
src/services/quota_service.py - Usage endpoint → Tenant authentication: authenticates via
src/api/v1/usage.py - Usage endpoint → Quota service: reads quotas
src/api/v1/usage.py - Usage endpoint → Cost calculation: uses cost data
src/api/v1/usage.py - Usage endpoint → Data repositories: queries rollups
src/api/v1/usage.py - Tenant authentication → API key service: verifies keys
src/api/middleware/auth.py - Tenant authentication → Cache and idempotency: caches tenants
src/api/middleware/auth.py - Tenant authentication → Data repositories: loads tenant
- Auth endpoints → API key service: manages keys
src/api/v1/auth.py - Billing and checkout → Stripe integration: creates checkout
src/api/v1/checkout.py - Billing routes → Stripe integration: uses billing
src/api/v1/billing.py - Stripe webhook handler → Stripe integration: verifies signature
src/api/v1/webhook.py - Stripe webhook handler → Data repositories: deduplicates and updates
src/api/v1/webhook.py - Stripe webhook handler → Cache and idempotency: invalidates cache
src/api/v1/webhook.py - Stripe → Stripe webhook handler: sends events
- Stripe integration → Stripe: calls Stripe API
- Data repositories → Domain records: persists records
src/repositories/usage_repo.py - Domain records → PostgreSQL: stored in
- Cache and idempotency → Redis: reads and writes
- Cache and idempotency → Runtime settings: loads Redis config
src/config/cache.py - Stripe integration → Runtime settings: loads credentials
src/services/stripe_service.py