This document maps source code modules to responsibilities and workflows.
- FastAPI bootstrap
- CORS setup
- startup backend verification (PostgreSQL + Redis)
- router registration
- typed runtime configuration from environment
- includes database URL, redis URL, HMAC and rate limits
- async SQLAlchemy engine and session factory
- Base metadata root
- agent.py: agent identity + api key hash + status
- wallet.py: balance and currency (one wallet per agent)
- policy.py: strict policy controls and thresholds
- transaction.py: spend outcomes + idempotency key
- audit_log.py: event payload records for traceability
- request and response validation contracts
- strict typed input for spend/policy/wallet endpoints
- API key authentication
- HMAC signature + timestamp validation
- replay key protection
- rate limiting and velocity checks
- Redis-backed request protection only
Decision order:
- per transaction limit
- vendor allowlist
- blocked category
- daily total
- monthly total
- approval threshold
Return states:
- APPROVED
- REJECTED
- PENDING_APPROVAL
- idempotency check before new transaction create
- wallet and policy row locking
- policy evaluation and reason code propagation
- balance deduction on approved path only
- mock payment adapter call
- audit event generation
- replaceable interface point
- current mock implementation returns SUCCESS
- centralized audit log write helper
- agents.py: create/list agents
- wallet.py: fund/get wallet
- policy.py: set policy
- spend.py: signed spend endpoint
- transactions.py: list transactions
- audit_logs.py: list audit entries
- global shell and route navigation
- agent and wallet display
- transaction metrics and recent activity
- transaction table with status/reason visibility
- policy input form
- backend response JSON view
- audit activity feed for governance visibility
- centralized API fetch wrappers
Spend call security gate order:
- X-API-Key auth
- X-Timestamp freshness
- X-Signature HMAC validation
- replay key check
- rate limit and velocity checks
- strict policy evaluation and transactional spend handling
- Production runtime requires PostgreSQL + Redis.
- Unit and integration tests use isolated SQLite fixtures only.