# smith8h/spermissions architecture

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

- Interactive diagram: https://gitdiagram.com/smith8h/spermissions
- Repository: https://github.com/smith8h/spermissions

## Overview

##### SPermissions Library Module
- Located under the “SPermissions” directory, this module contains the core implementation.
- It includes an AndroidManifest.xml and classes such as SPermissions.java and SPermissionsCallback.java under the package "smith.lib.tools.perms".
- The library provides an API for initializing a permissions request (via SPermissions.with(activity)), checking if a permission or a set of permissions is granted, and then, if not, issuing a request with configurable request codes.
- It also abstracts handling of special permissions (e.g., external storage access on different Android versions).

##### Sample Application Module
- Located under the “app” directory, this module is structured like a typical Android application.
- It demonstrates how to use the SPermissions library by having a MainActivity (in package "smith.test.spermission") that utilizes the library’s API.
- The app includes appropriate resources (layouts, drawables, values) as well as an AndroidManifest.xml.

- Client/Application Component: Represent the “Sample App” (MainActivity and related UI components) that calls into the library.
- Android System/Framework: Represent the underlying Android APIs (such as runtime permission APIs, manifest system) that the library interacts with.
- Development & Build Environment: Optionally, note Gradle build scripts, JitPack repository integration, and CI configuration (the GitHub workflows) as peripheral components supporting the build and deployment process.

B. Relationships and Interactions:
- The sample application instantiates the SPermissions object by calling SPermissions.with(activity) and then uses methods like hasPermission, askPermission(s), and handles callback results.
- That the library internally makes calls to the Android system (via permission management APIs) and forwards callback results through SPermissionsCallback.

C. Architectural Patterns and Design Principles:
- Modular Design: Clearly separate the library module from the sample application. This shows that SPermissions can be integrated as a dependency by other apps.
- API Abstraction: Highlight how the library simplifies the underlying Android permission framework (e.g., abstracting the onRequestPermissionsResult mechanism).
- Callback Mechanism: Emphasize the use of the callback interface (SPermissionsCallback) for handling responses asynchronously.

D. Relevant Technologies and Frameworks:
- Android SDK – as the platform for the runtime permission model.
- Gradle build system – with directories and scripts (gradle.properties, settings.gradle, etc.) coordinating the build.
- JitPack – used for dependency management and distribution as seen in the README instructions.
- GitHub Actions – for CI/CD, as indicated by the workflow configuration files.

- For this Android library project, focus on the distinct separation between the “client” (sample app) and the “library” (SPermissions module). Illustrate how the client code leverages the library API to interact with Android’s permission systems.
- Library’s public API methods and represent them as part of the library component.

▪ Application layer components (e.g., user interface elements, sample app)
▪ Library components (SPermissions API and callback interfaces)
▪ Underlying platform services (Android system services)
▪ Build/Deployment components (Gradle, GitHub Actions)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% SPermissions Library Module
    subgraph "SPermissions Library Module"
        direction TB
        SPerm["SPermissions.java (API)"]:::library
        SPermCB["SPermissionsCallback.java (Callback)"]:::library
        SPermManifest["AndroidManifest.xml (Library)"]:::manifest
    end

    %% Sample Application Module
    subgraph "Sample Application Module"
        direction TB
        MainAct["MainActivity (Client)"]:::client
        AppManifest["AndroidManifest.xml (App)"]:::manifest
        AppRes["App Resources (layouts, drawables, values)"]:::resource
    end

    %% Android System
    AndroidSys["Android System – Permission API"]:::system

    %% Build & Deployment Component
    BuildSys["Gradle Build System & CI/CD\n(JitPack & GitHub Actions)"]:::build

    %% Interactions
    MainAct -->|"calls SPermissions.with(activity)"| SPerm
    SPerm -->|"checks permissions via Android APIs"| AndroidSys
    SPerm -->|"triggers callback"| SPermCB
    SPermCB -->|"returns result to"| MainAct

    %% Build Dependencies
    SPerm -->|"built via"| BuildSys
    MainAct -->|"built via"| BuildSys

    %% Click Events
    click SPerm "https://github.com/smith8h/spermissions/blob/main/SPermissions/src/main/java/smith/lib/tools/perms/SPermissions.java"
    click SPermCB "https://github.com/smith8h/spermissions/blob/main/SPermissions/src/main/java/smith/lib/tools/perms/SPermissionsCallback.java"
    click SPermManifest "https://github.com/smith8h/spermissions/blob/main/SPermissions/src/main/AndroidManifest.xml"
    click MainAct "https://github.com/smith8h/spermissions/blob/main/app/src/main/java/smith/test/spermission/MainActivity.java"
    click AppManifest "https://github.com/smith8h/spermissions/blob/main/app/src/main/AndroidManifest.xml"
    click AppRes "https://github.com/smith8h/spermissions/tree/main/app/src/main/res"

    %% Styles
    classDef library fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef client fill:#aed6f1,stroke:#1b4f72,stroke-width:2px;
    classDef system fill:#a9dfbf,stroke:#1e8449,stroke-width:2px;
    classDef build fill:#f5cba7,stroke:#b9770e,stroke-width:2px;
    classDef manifest fill:#d2b4de,stroke:#6c3483,stroke-width:2px;
    classDef resource fill:#fad7a0,stroke:#d35400,stroke-width:2px;
```
