# adityaornet/callrecorder architecture

> Architecture diagram of the GitHub repository adityaornet/callrecorder, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adityaornet/callrecorder
- Repository: https://github.com/adityaornet/callrecorder

## Overview

##### Project type and purpose
- This is a native Android application (written in Kotlin) whose single responsibility is to record incoming and outgoing phone calls on Android 9+ devices.
- It uses an AccessibilityService for call-state events, a ForegroundService+MediaRecorder for audio capture, and saves resulting `.m4a` files into the Music directory via MediaStore or direct file I/O.

##### File structure
- Top level: Gradle wrapper/config, project-wide docs (README, LICENSE, etc.), one Android Studio module named `app`.
- `app/src/main/java/com/brainpulse/callrecorder`:
- MainActivity.kt and ShareReceiverActivity.kt (UI entry points)
- Service implementations (AccessibilityService subclass, ForegroundService)
- PhoneStateListener or TelephonyManager integration
- Utility classes to manage MediaRecorder, WakeLock, file naming
- `app/src/main/res`: layouts for activities, XML configs (accessibility service, backup, data-extraction, file_paths).
- Test folders for unit and instrumented tests.
- Gradle scripts define Android SDK versions, dependencies, ProGuard rules, scoped storage handling.

##### Insights from the README
- Architecture is centered on:
- A background service that listens to phone state changes
- A MediaRecorder pipeline invoked on CALL_STATE_OFFHOOK → RECORD_AUDIO → STORE FILE → on CALL_STATE_IDLE → STOP & VALIDATE
- Permissions required: RECORD_AUDIO, FOREGROUND_SERVICE, WAKE_LOCK, READ_PHONE_STATE, READ_CALL_LOG, WRITE_EXTERNAL_STORAGE (legacy).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        UI_Main["MainActivity"]:::frontend
        UI_Share["ShareReceiverActivity"]:::frontend
    end

    %% Service Layer
    subgraph "Service Layer"
        CallRecordService["CallRecorderAccessibilityService"]:::service
        ForegroundService["RecorderForegroundService"]:::service
    end

    %% Android Framework / OS
    subgraph "Android Framework / OS"
        TelephonyManager["TelephonyManager & PhoneStateListener"]:::system
        AccessibilityAPI["AccessibilityService API"]:::system
        MediaRecorderAPI["MediaRecorder API"]:::system
    end

    %% Storage Layer
    subgraph "Storage Layer"
        Storage[(MediaStore / File I/O)]:::storage
        FilePaths["file_paths.xml"]:::storage
        DataExtract["data_extraction_rules.xml"]:::storage
        BackupRules["backup_rules.xml"]:::storage
    end

    %% Configuration & Tests
    subgraph "Configuration & Tests"
        Manifest["AndroidManifest.xml"]:::config
        AS_Config["accessibility_service_config.xml"]:::config
        BuildGradle["build.gradle"]:::config
        Proguard["proguard-rules.pro"]:::config
        UnitTest["ExampleUnitTest.kt"]:::config
        InstrTest["ExampleInstrumentedTest.kt"]:::config
    end

    %% Interactions
    UI_Main -->|"requestPermissions()"| Manifest
    Manifest -->|"registerService"| AS_Config
    AS_Config --> CallRecordService
    UI_Share -->|"shareIntent()"| CallRecordService

    CallRecordService -->|"CALL_STATE_OFFHOOK event"| ForegroundService
    TelephonyManager -->|"callState events"| CallRecordService
    AccessibilityAPI -->|"accessibility events"| CallRecordService

    ForegroundService -->|"startRecording()"| MediaRecorderAPI
    ForegroundService -->|"acquireWakeLock()"| ForegroundService
    MediaRecorderAPI -->|"write .m4a"| Storage

    Storage --> FilePaths
    Storage --> DataExtract
    Storage --> BackupRules

    Manifest --> BuildGradle
    BuildGradle --> Proguard
    BuildGradle --> UnitTest
    BuildGradle --> InstrTest

    %% Click Events
    click UI_Main "https://github.com/adityaornet/callrecorder/blob/master/app/src/main/java/com/brainpulse/callrecorder/MainActivity.kt"
    click UI_Share "https://github.com/adityaornet/callrecorder/blob/master/app/src/main/java/com/brainpulse/callrecorder/ShareReceiverActivity.kt"
    click AS_Config "https://github.com/adityaornet/callrecorder/blob/master/app/src/main/res/xml/accessibility_service_config.xml"
    click ForegroundService "https://github.com/adityaornet/callrecorder/blob/master/app/src/main/java/com/brainpulse/callrecorder/RecorderForegroundService.kt"
    click CallRecordService "https://github.com/adityaornet/callrecorder/blob/master/app/src/main/java/com/brainpulse/callrecorder/CallRecorderAccessibilityService.kt"
    click Manifest "https://github.com/adityaornet/callrecorder/blob/master/app/src/main/AndroidManifest.xml"
    click FilePaths "https://github.com/adityaornet/callrecorder/blob/master/app/src/main/res/xml/file_paths.xml"
    click DataExtract "https://github.com/adityaornet/callrecorder/blob/master/app/src/main/res/xml/data_extraction_rules.xml"
    click BackupRules "https://github.com/adityaornet/callrecorder/blob/master/app/src/main/res/xml/backup_rules.xml"
    click BuildGradle "https://github.com/adityaornet/callrecorder/blob/master/app/build.gradle"
    click Proguard "https://github.com/adityaornet/callrecorder/blob/master/app/proguard-rules.pro"
    click UnitTest "https://github.com/adityaornet/callrecorder/blob/master/app/src/test/java/com/brainpulse/callrecorder/ExampleUnitTest.kt"
    click InstrTest "https://github.com/adityaornet/callrecorder/blob/master/app/src/androidTest/java/com/brainpulse/callrecorder/ExampleInstrumentedTest.kt"

    %% Style Definitions
    classDef frontend fill:#cce5ff,stroke:#2a7ab8,color:#2a7ab8;
    classDef service fill:#d4edda,stroke:#2e7d32,color:#2e7d32;
    classDef system fill:#fff3cd,stroke:#ffb300,color:#ffb300;
    classDef storage fill:#e2d5f5,stroke:#7e57c2,color:#7e57c2;
    classDef config fill:#f0f0f0,stroke:#999999,color:#555555;
```
