BLACKSTAR

Active

System Design

Detailed system architecture and design decisions

Active·Owner: rafa·2026-04-04

System Design

Request Flow

  • 1. Request enters Rails app
  • 2. Authentication (Devise) validates user
  • 3. Tenant assignment (actsastenant) sets Current.tenant
  • 4. Authorization (Pundit policy) checks permissions
  • 5. Validation ensures data integrity
  • 6. Business logic processes request
  • 7. Audit logging records changes
  • 8. Response returned to client

Journal Entry Posting Flow

  • 1. User submits entry with lines
  • 2. Validation checks debits == credits
  • 3. Authorization verifies posting permission
  • 4. Period check verifies period is open
  • 5. Posting updates account balances
  • 6. Audit log records posting
  • 7. Success notification returned

Period Close Flow

  • 1. User initiates close
  • 2. Validation checks for unposted entries
  • 3. Balance snapshot recorded
  • 4. Period state transitions to soft-closed
  • 5. Reversals generated for next period
  • 6. Audit log records close
  • 7. Confirmation shown to user

Multitenancy Model

  • Tenant is root isolation unit
  • Current.tenant middleware sets active tenant
  • actsastenant scopes all queries
  • RLS policies enforce database-level isolation
  • Integration tests verify boundaries

Performance Optimization

  • Indexing on tenantid, periodid, account_id
  • Caching account balances in Redis
  • Pagination on all list endpoints
  • Async jobs for reports and imports
  • Query optimization checklist in code review

[See [Architecture Overview](./index.mdx) for more details]