Architecture
System Overview
iOS app / agent client -> api.<domain> -> API Gateway -> Lambda backend -> Postgres
Web app -> app.<domain> -> CloudFront -> SPA
Browser and agent auth -> auth.<domain> -> API Gateway -> Auth Lambda -> Cognito
Apex fallback -> <domain> -> CloudFront redirect -> app.<domain>
Principles
- Separate public domains for
app,api, andauth - Postgres is the source of truth
- The iOS client is offline-first with local SQLite plus sync
- The web app, iOS app, and external agent surface share the same workspace model
- External agents start from
GET https://api.flashcards-open-source-app.com/v1/
Supported Clients
- Web app on
app.flashcards-open-source-app.com - iOS app in the main repository with local SQLite storage
- Android app on Google Play
- External agent clients through discovery, OTP bootstrap, and
Authorization: ApiKey
Data Model
workspacesworkspace_membersuser_settingsdevicescardsdecksreview_eventsapplied_operationssync_state
Data Flow
Web
- The browser signs in through
auth.<domain>. - The web app loads workspace data from
api.<domain>. - AI chat requests go through
/chat/local-turn. - Review submissions update scheduler state on write.
iOS
- The iOS app writes locally to SQLite first.
- Local changes are queued in an outbox.
- Sync uploads changes through
/v1/workspaces/{workspaceId}/sync/push. - Sync downloads remote updates through
/v1/workspaces/{workspaceId}/sync/pull. - The local database applies changes and advances the sync cursor.
External Agents
- Agents start with
GET /v1/. - OTP bootstrap runs on
auth.<domain>. - The agent receives a long-lived API key.
- The agent loads
/v1/agent/me, lists workspaces, selects one if needed, and then uses/v1/agent/sql.
Scheduling
Flashcards uses FSRS as the review scheduler.
Implementation notes:
- backend and iOS keep mirrored FSRS implementations
- the web app mirrors the scheduling data contract, but does not ship a third scheduler copy
- workspace-level scheduler settings include desired retention, learning steps, relearning steps, maximum interval, and fuzz
- the real review timestamp comes from
reviewedAtClient
For the detailed contract, see FSRS scheduling logic in the main repository.
Auth
- Email OTP via Cognito
- Shared-domain browser session cookies for the hosted web app
- Agent OTP bootstrap on
auth.<domain>with long-lived ApiKey output AUTH_MODE=nonefor local developmentAUTH_MODE=cognitofor production-like auth
Deployment Shape
app.<domain>-> CloudFront + S3api.<domain>-> API Gateway + Lambda backendauth.<domain>-> API Gateway + Lambda auth service- Postgres in AWS RDS
The apex domain can stay on a separate marketing site. If it is free during bootstrap, the infrastructure can temporarily redirect it to app.<domain>.