# buvindus/cs3053-mfa-gallifrey architecture

> Architecture diagram of the GitHub repository buvindus/cs3053-mfa-gallifrey, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/buvindus/cs3053-mfa-gallifrey
- Repository: https://github.com/buvindus/cs3053-mfa-gallifrey

## Overview

Gallifrey combines an accessible Android authenticator, a demonstration relying-party website, and a separate authentication API. The user workflow is: a website login starts a bound MFA request; the enrolled phone retrieves and approves or denies it using haptic-pattern interaction and device signing; the website checks and redeems the one-time result before creating a session. The README also documents enrollment, device management, recovery, request limits, and audit-related behavior. Connections for unsampled Android and route internals are omitted where the excerpts do not establish their wiring.

Main entry points: [`android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt`](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt) (Authenticator app), [`auth_service/main.py`](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/main.py) (Authentication service), [`auth_service/db.py`](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/db.py) (Auth database), [`auth_service/services/transaction_service.py`](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/transaction_service.py) (Request lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_android["Android authenticator"]
  node_android_app["Authenticator app<br/>[MainActivity.kt]"]
  node_device_auth["Device authentication"]
  node_keystore_signer["Keystore signer"]
  node_practice_session["Practice session<br/>[PracticeSession.kt]"]
  node_haptic_engine["Haptic output<br/>[HapticEngine.kt]"]
  node_calibration["Haptic calibration"]
end

subgraph group_website["Relying-party website"]
  node_website["Demo website<br/>[main.py]"]
  node_login_routes["Login routes<br/>[login.py]"]
  node_auth_routes["MFA routes<br/>[auth.py]"]
  node_pending_flow["Pending login state"]
  node_session_flow["Web sessions<br/>[session_service.py]"]
  node_client_contract["Auth client contract"]
  node_http_adapter["HTTP adapter"]
  node_mock_adapter["Mock adapter"]
end

subgraph group_auth_api["Authentication API"]
  node_auth_service["Authentication service<br/>[main.py]"]
  node_enrollment_routes["Enrollment routes<br/>[enrollments.py]"]
  node_request_routes["Device request routes<br/>[auth_requests.py]"]
  node_rp_routes["RP and management routes<br/>[rp_routes.py]"]
end

subgraph group_auth_domain["Authentication domain"]
  node_enrollment["Device enrollment"]
  node_transactions["Request lifecycle"]
  node_signatures["Signature verification"]
  node_results["Result issuance<br/>[result_service.py]"]
  node_audit["Audit writing<br/>[audit_writer.py]"]
end

subgraph group_storage["Persistence"]
  node_auth_db[("Auth database<br/>[db.py]")]
  node_web_db[("Website database<br/>[db.py]")]
  node_auth_models[("Auth records")]
end

node_person(("Phone user"))
node_website_user(("Website user"))

node_person -->|"uses"| node_android_app
node_android_app -->|"invokes"| node_device_auth
node_android_app -->|"invokes"| node_keystore_signer
node_android_app -->|"starts"| node_practice_session
node_android_app -->|"uses"| node_haptic_engine
node_android_app -->|"loads settings"| node_calibration
node_practice_session -->|"plays patterns"| node_haptic_engine
node_website_user -->|"visits"| node_website
node_website -->|"routes to"| node_login_routes
node_website -->|"routes to"| node_auth_routes
node_website -->|"initializes"| node_web_db
node_login_routes -.->|"creates pending login"| node_pending_flow
node_auth_routes -->|"uses"| node_pending_flow
node_auth_routes -->|"requests MFA"| node_client_contract
node_auth_routes -->|"creates session"| node_session_flow
node_session_flow -->|"persists sessions"| node_web_db
node_client_contract -->|"implemented by"| node_http_adapter
node_client_contract -->|"implemented by"| node_mock_adapter
node_http_adapter -->|"calls over HTTP"| node_auth_service
node_mock_adapter -->|"uses"| node_web_db
node_auth_service -->|"initializes"| node_auth_db
node_auth_service -->|"routes to"| node_enrollment_routes
node_auth_service -->|"routes to"| node_request_routes
node_auth_service -->|"routes to"| node_rp_routes
node_enrollment_routes -->|"delegates enrollment"| node_enrollment
node_enrollment -->|"verifies proof"| node_signatures
node_rp_routes -->|"reads and cancels"| node_transactions
node_rp_routes -->|"issues and redeems"| node_results
node_request_routes -->|"handles requests"| node_transactions
node_transactions -->|"issues result"| node_results
node_enrollment -->|"records events"| node_audit
node_transactions -->|"records events"| node_audit
node_results -->|"records events"| node_audit
node_enrollment -->|"reads and writes"| node_auth_db
node_transactions -->|"reads and writes"| node_auth_db
node_results -->|"reads and writes"| node_auth_db
node_audit -->|"writes events"| node_auth_db
node_auth_db -->|"registers models"| node_auth_models
node_android_app -.->|"uses enrollment and MFA API"| node_auth_service

click node_android_app "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt"
click node_device_auth "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/device/DeviceAuthenticator.kt"
click node_keystore_signer "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/device/KeystoreDeviceSigner.kt"
click node_practice_session "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/core/src/main/kotlin/com/gallifrey/authenticator/practice/PracticeSession.kt"
click node_haptic_engine "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/haptics/HapticEngine.kt"
click node_calibration "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/settings/CalibrationScreen.kt"
click node_website "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/main.py"
click node_login_routes "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/routes/login.py"
click node_auth_routes "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/routes/auth.py"
click node_pending_flow "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/pending_login_service.py"
click node_session_flow "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/session_service.py"
click node_client_contract "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/auth_service_client.py"
click node_http_adapter "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/http_auth_service.py"
click node_mock_adapter "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/mock_auth_service.py"
click node_auth_service "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/main.py"
click node_enrollment_routes "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/routes/enrollments.py"
click node_request_routes "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/routes/auth_requests.py"
click node_rp_routes "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/routes/rp_routes.py"
click node_enrollment "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/enrollment_service.py"
click node_transactions "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/transaction_service.py"
click node_signatures "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/signature_service.py"
click node_results "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/result_service.py"
click node_audit "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/audit_writer.py"
click node_auth_db "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/db.py"
click node_web_db "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/db.py"
click node_auth_models "https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/models/auth_transaction.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_android_app,node_device_auth,node_keystore_signer,node_practice_session,node_haptic_engine,node_calibration,node_person,node_website_user toneBlue
class node_website,node_login_routes,node_auth_routes,node_pending_flow,node_session_flow,node_client_contract,node_http_adapter,node_mock_adapter toneAmber
class node_auth_service,node_enrollment_routes,node_request_routes,node_rp_routes toneMint
class node_enrollment,node_transactions,node_signatures,node_results,node_audit toneRose
class node_auth_db,node_web_db,node_auth_models toneIndigo
```

## Components

### Android authenticator

- [Authenticator app](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt): `android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt`
- [Device authentication](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/device/DeviceAuthenticator.kt): `android/app/src/main/kotlin/com/gallifrey/authenticator/device/DeviceAuthenticator.kt`
- [Keystore signer](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/device/KeystoreDeviceSigner.kt): `android/app/src/main/kotlin/com/gallifrey/authenticator/device/KeystoreDeviceSigner.kt`
- [Practice session](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/core/src/main/kotlin/com/gallifrey/authenticator/practice/PracticeSession.kt): `android/core/src/main/kotlin/com/gallifrey/authenticator/practice/PracticeSession.kt`
- [Haptic output](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/haptics/HapticEngine.kt): `android/app/src/main/kotlin/com/gallifrey/authenticator/haptics/HapticEngine.kt`
- [Haptic calibration](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/android/app/src/main/kotlin/com/gallifrey/authenticator/settings/CalibrationScreen.kt): `android/app/src/main/kotlin/com/gallifrey/authenticator/settings/CalibrationScreen.kt`

### Relying-party website

- [Demo website](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/main.py): `app/main.py`
- [Login routes](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/routes/login.py): `app/routes/login.py`
- [MFA routes](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/routes/auth.py): `app/routes/auth.py`
- [Pending login state](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/pending_login_service.py): `app/services/pending_login_service.py`
- [Web sessions](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/session_service.py): `app/services/session_service.py`
- [Auth client contract](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/auth_service_client.py): `app/services/auth_service_client.py`
- [HTTP adapter](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/http_auth_service.py): `app/services/http_auth_service.py`
- [Mock adapter](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/services/mock_auth_service.py): `app/services/mock_auth_service.py`

### Authentication API

- [Authentication service](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/main.py): `auth_service/main.py`
- [Enrollment routes](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/routes/enrollments.py): `auth_service/routes/enrollments.py`
- [Device request routes](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/routes/auth_requests.py): `auth_service/routes/auth_requests.py`
- [RP and management routes](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/routes/rp_routes.py): `auth_service/routes/rp_routes.py`

### Authentication domain

- [Device enrollment](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/enrollment_service.py): `auth_service/services/enrollment_service.py`
- [Request lifecycle](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/transaction_service.py): `auth_service/services/transaction_service.py`
- [Signature verification](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/signature_service.py): `auth_service/services/signature_service.py`
- [Result issuance](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/result_service.py): `auth_service/services/result_service.py`
- [Audit writing](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/services/audit_writer.py): `auth_service/services/audit_writer.py`

### Persistence

- [Auth database](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/db.py): `auth_service/db.py`
- [Website database](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/app/db.py): `app/db.py`
- [Auth records](https://github.com/buvindus/cs3053-mfa-gallifrey/blob/main/auth_service/models/auth_transaction.py): `auth_service/models/auth_transaction.py`

### Other components

- **Phone user**
- **Website user**

## Connections

- Phone user → Authenticator app: uses
- Authenticator app → Device authentication: invokes (evidence: `android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt`)
- Authenticator app → Keystore signer: invokes (evidence: `android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt`)
- Authenticator app → Practice session: starts (evidence: `android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt`)
- Authenticator app → Haptic output: uses (evidence: `android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt`)
- Authenticator app → Haptic calibration: loads settings (evidence: `android/app/src/main/kotlin/com/gallifrey/authenticator/MainActivity.kt`)
- Practice session → Haptic output: plays patterns (evidence: `android/app/src/main/kotlin/com/gallifrey/authenticator/haptics/HapticEngine.kt`)
- Website user → Demo website: visits
- Demo website → Login routes: routes to (evidence: `app/main.py`)
- Demo website → MFA routes: routes to (evidence: `app/main.py`)
- Demo website → Website database: initializes (evidence: `app/main.py`)
- Login routes → Pending login state: creates pending login
- MFA routes → Pending login state: uses (evidence: `app/routes/auth.py`)
- MFA routes → Auth client contract: requests MFA (evidence: `app/routes/auth.py`)
- MFA routes → Web sessions: creates session (evidence: `app/routes/auth.py`)
- Web sessions → Website database: persists sessions (evidence: `app/services/session_service.py`)
- Auth client contract → HTTP adapter: implemented by (evidence: `app/services/http_auth_service.py`)
- Auth client contract → Mock adapter: implemented by (evidence: `app/services/mock_auth_service.py`)
- HTTP adapter → Authentication service: calls over HTTP
- Mock adapter → Website database: uses (evidence: `app/services/mock_auth_service.py`)
- Authentication service → Auth database: initializes (evidence: `auth_service/main.py`)
- Authentication service → Enrollment routes: routes to (evidence: `auth_service/main.py`)
- Authentication service → Device request routes: routes to (evidence: `auth_service/main.py`)
- Authentication service → RP and management routes: routes to (evidence: `auth_service/main.py`)
- Enrollment routes → Device enrollment: delegates enrollment (evidence: `auth_service/routes/enrollments.py`)
- Device enrollment → Signature verification: verifies proof (evidence: `auth_service/services/enrollment_service.py`)
- RP and management routes → Request lifecycle: reads and cancels (evidence: `auth_service/routes/rp_routes.py`)
- RP and management routes → Result issuance: issues and redeems (evidence: `auth_service/routes/rp_routes.py`)
- Device request routes → Request lifecycle: handles requests (evidence: `auth_service/routes/auth_requests.py`)
- Request lifecycle → Result issuance: issues result (evidence: `auth_service/services/transaction_service.py`)
- Device enrollment → Audit writing: records events (evidence: `auth_service/services/enrollment_service.py`)
- Request lifecycle → Audit writing: records events (evidence: `auth_service/services/transaction_service.py`)
- Result issuance → Audit writing: records events (evidence: `auth_service/services/result_service.py`)
- Device enrollment → Auth database: reads and writes (evidence: `auth_service/services/enrollment_service.py`)
- Request lifecycle → Auth database: reads and writes (evidence: `auth_service/services/transaction_service.py`)
- Result issuance → Auth database: reads and writes (evidence: `auth_service/services/result_service.py`)
- Audit writing → Auth database: writes events (evidence: `auth_service/services/audit_writer.py`)
- Auth database → Auth records: registers models (evidence: `auth_service/db.py`)
- Authenticator app → Authentication service: uses enrollment and MFA API
