How varadha-rajan-volopay/finpay_api works
Finpay API is a multi-tenant expense-tracking and reimbursement service. Its main workflow authenticates a company user, serves tenant-scoped expense CRUD and listing, then applies approval, rejection, reimbursement, or archive actions; responses are serialized for the API. The code also provides refresh-token rotation, receipt OCR processing, audit logging, and overdue reminders. Edges are limited to routes and calls visible in the excerpts; unsampled worker and provisioning links are omitted or marked unverified.
Main entry points: expenses_controller.rb Expense endpoints · routes.rb API routes · refresh_tokens_controller.rb Refresh endpoint · sessions_controller.rb Session endpoints
Components 27
API and access
- API routes
config/routes.rb - Expense endpoints
app/controllers/api/v1/expenses_controller.rb - Session endpoints
app/controllers/api/v1/users/sessions_controller.rb - Refresh endpoint
app/controllers/api/v1/users/refresh_tokens_controller.rb - Registration endpoint
app/controllers/api/v1/users/registrations_controller.rb - Expense authorization
app/policies/expense_policy.rb - Expense serialization
app/serializers/api/v1/expense_serializer.rb
Expense workflows
- Expense CRUD
app/services/expense_crud_service.rb - Expense filters
app/services/expense_filter.rb - Expense pagination
app/services/expense_pagination.rb - Workflow transitions
app/services/expense_workflow_service.rb - Workflow idempotency
app/services/expense_workflow_idempotency_service.rb - Reimbursement idempotency
app/services/reimbursement_idempotency_service.rb - Expense records
app/models/expense.rb
Tenant and identity
- Identity records
app/models/user.rb - Refresh tokens
app/models/refresh_token.rb - Company tenants
app/models/company.rb - Tenant provisioning
app/services/companies/provision.rb
Background processing
- Receipt OCR worker
app/workers/receipt_processor_worker.rb - Audit worker
app/workers/audit_log_worker.rb - Overdue reminders
app/workers/overdue_reminder_worker.rb - Receipt records
app/models/receipt.rb - Activity logs
app/models/activity_log.rb - Reminder records
app/models/overdue_reminder.rb
Other components
- API client
- PostgreSQL
- OCR processing
Connections 30
- API client → API routes: sends requests
config/routes.rb - API routes → Expense endpoints: routes expenses
config/routes.rb - API routes → Session endpoints: routes sessions
config/routes.rb - API routes → Refresh endpoint: routes refresh
config/routes.rb - API routes → Registration endpoint: routes registration
config/routes.rb - Expense endpoints → Expense authorization: authorizes access
app/controllers/api/v1/expenses_controller.rb - Expense endpoints → Expense filters: filters results
app/controllers/api/v1/expenses_controller.rb - Expense endpoints → Expense pagination: paginates results
app/controllers/api/v1/expenses_controller.rb - Expense endpoints → Expense CRUD: runs CRUD
app/controllers/api/v1/expenses_controller.rb - Expense endpoints → Workflow idempotency: runs approval
app/controllers/api/v1/expenses_controller.rb - Expense endpoints → Workflow transitions: runs archive
app/controllers/api/v1/expenses_controller.rb - Expense endpoints → Reimbursement idempotency: runs reimbursement
app/controllers/api/v1/expenses_controller.rb - Expense endpoints → Expense serialization: serializes responses
app/controllers/api/v1/expenses_controller.rb - Workflow idempotency → Workflow transitions: executes transition
app/services/expense_workflow_idempotency_service.rb - Workflow idempotency → Expense serialization: serializes result
app/services/expense_workflow_idempotency_service.rb - Session endpoints → Company tenants: finds tenant
app/controllers/api/v1/users/sessions_controller.rb - Session endpoints → Refresh tokens: issues tokens
app/controllers/api/v1/users/sessions_controller.rb - Refresh endpoint → Company tenants: finds tenant
app/controllers/api/v1/users/refresh_tokens_controller.rb - Refresh endpoint → Refresh tokens: rotates tokens
app/controllers/api/v1/users/refresh_tokens_controller.rb - Refresh endpoint → Identity records: finds user
app/controllers/api/v1/users/refresh_tokens_controller.rb - Receipt OCR worker → Receipt records: loads and updates
app/workers/receipt_processor_worker.rb - Receipt OCR worker → OCR processing: processes receipt
- Audit worker → Activity logs: writes audit events
- Overdue reminders → Reminder records: records reminders
- Expense records → PostgreSQL: persists records
- Identity records → PostgreSQL: persists records
- Refresh tokens → PostgreSQL: persists tokens
- Receipt records → PostgreSQL: persists records
- Activity logs → PostgreSQL: persists records
- Reminder records → PostgreSQL: persists records