Skip to content

Next-gen Android security: On-device AI malware scanning, real-time threat protection, network traffic analysis, and cloud-powered threat intelligence.

License

Notifications You must be signed in to change notification settings

abbasiandev/codekhoda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

56 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ Hybrid Cloud Sentinel

Version Platform Backend License

Live API

"The smartphone is too weak to fight alone. We brought the brain to the cloud."

A next-generation mobile security solution that offloads complex threat analysis to a centralized "Cloud Brain"

πŸ“– Documentation β€’ πŸ—οΈ Architecture β€’ πŸš€ Setup Guide β€’ πŸ§ͺ Testing


🎯 Overview

Hybrid Cloud Sentinel (HCS) is a mobile security MVP that combines a lightweight on-device Android agent with a powerful Python-based backend analysis engine. The solution provides comprehensive threat detection while maintaining minimal battery impact on the user's device.

Key Value Proposition

Feature Description
⚑ Lightweight Endpoint Minimal battery drain through cloud-offloaded processing
🧠 Deep Analysis Cloud-based heuristics & ML for advanced threat detection
πŸ”΄ Real-time Protection Instantaneous feedback and blocking capabilities
🌐 Hybrid Ensemble On-device TFLite + Heuristic Matrix + Cloud Brain Intelligence
πŸ›‘οΈ Trust-First UX Educational onboarding and security score gamification
πŸ”„ OTA Model Updates Automated ML model retraining and over-the-air updates
πŸ“Š Admin Dashboard Comprehensive analytics and threat management interface
πŸ’³ Flexible Plans Freemium and Featured subscription models with integrated billing

πŸ—οΈ Architecture

We prioritize Clean Architecture with MVVM to ensure scalability and testability.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     HYBRID CLOUD SENTINEL                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Android Agent  │◄──── HTTPS ───────►│   Cloud Brain   β”‚  β”‚
β”‚  β”‚                 β”‚                    β”‚                 β”‚  β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚                    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚  β”‚  β”‚:app       β”‚  β”‚                    β”‚  β”‚ FastAPI   β”‚  β”‚  β”‚
β”‚  β”‚  β”‚:domain    β”‚  β”‚    Threat Data     β”‚  β”‚ Engine    β”‚  β”‚  β”‚
β”‚  β”‚  β”‚:data      β”‚  │◄──────────────────►│  β”‚ ML Models β”‚  β”‚  β”‚
β”‚  β”‚  β”‚:present   β”‚  β”‚                    β”‚  β”‚ Heuristicsβ”‚  β”‚  β”‚
β”‚  β”‚  β”‚:agent     β”‚  β”‚                    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚                    β”‚                 β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Android Client (Kotlin)

Module Purpose
:app Dependency Injection (Hilt), Application class, Navigation host
:domain Pure Kotlin entities, Use Cases, Repository interfaces (NO Android deps)
:data Repository implementations, Room Database, Retrofit API, Mappers
:presentation Jetpack Compose UI, ViewModels, State holders
:agent Foreground Services, Permission Analysis, Package Scanning

Cloud Brain (Python)

Component Purpose
FastAPI High-performance async API with automatic OpenAPI docs
Pydantic Type safety and shared contracts with Android
Heuristic Engine Rule-based detection of semantic threat patterns
ML Classifier Extensible interface for TensorFlow/PyTorch models

🌐 Live Deployment

The Cloud Brain is deployed and accessible at:

Endpoint URL
Landing Page https://codekhoda-sentinel.liara.run/
Admin Dashboard https://codekhoda-sentinel.liara.run/dashboard/
Login Page https://codekhoda-sentinel.liara.run/dashboard/login
Health Check https://codekhoda-sentinel.liara.run/health
API Documentation https://codekhoda-sentinel.liara.run/docs
Scan Endpoint https://codekhoda-sentinel.liara.run/api/v1/scan/analyze
Threat Intel (Web) Package Lists JSON

Infrastructure

Component Platform Details
Backend Liara Docker container on free tier
Database SQLite Lightweight embedded database
Intel Source GitHub Dynamic threat signatures (OTA)

πŸ›‘οΈ Hybrid Security Matrix

We utilize a multi-layered approach to threat detection:

  1. L1: Local Whitelist (System): Fast bypass for verified system/OS apps.
  2. L2: Local TFLite Model: On-device AI for instant heuristic flagging.
  3. L3: Cloud Allow/Blocklist: Real-time verification against global threat databases.
  4. L4: External Intelligence: Dynamic fetching of signatures from GitHub and VirusTotal.
  5. L5: Contextual Analysis: Correlating app categories with requested permissions.

πŸš€ Quick Start

Prerequisites

  • Android Development: Android Studio Arctic Fox+, JDK 17
  • Backend Development: Python 3.10+, pip

Option A: Use Live Backend (Recommended)

The Android app is pre-configured to use the live Liara backend at https://codekhoda-sentinel.liara.run. Simply:

  1. Clone the repository
  2. Open android/ in Android Studio
  3. Build & Run on your device

Option B: Local Development

1. Clone the Repository

git clone https://github.com/your-org/hybrid-cloud-sentinel.git
cd hybrid-cloud-sentinel

2. Start the Backend (Cloud Brain)

cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Local Server runs at http://127.0.0.1:8000
Production API available at https://codekhoda-sentinel.liara.run
API Documentation: Local | Production

3. Configure Android for Local Backend

  1. Open the android/ folder in Android Studio
  2. Sync Gradle dependencies
  3. Configure the Cloud Brain URL in your local.properties:
    # android/local.properties
    # For local development (Emulator):
    cloud.brain.url=http://10.0.2.2:8000
    
    # For production (Liara):
    # cloud.brain.url=https://codekhoda-sentinel.liara.run

☁️ Deployment Guide

Deploying to Liara

  1. Install Liara CLI:

    npm install -g @liara/cli
  2. Deploy Backend:

    cd backend
    liara deploy --app codekhoda-sentinel --platform docker --port 8000

    The deployment uses the Docker platform and will automatically build the image from the Dockerfile.

  3. Configure Environment Variables (Optional):

    liara env set --app codekhoda-sentinel JWT_SECRET=your-secure-secret-key-here
    liara env set --app codekhoda-sentinel DEBUG=false
  4. Using GitHub Actions for CI/CD:

    • Add LIARA_API_TOKEN to your GitHub repository secrets
    • Generate the token from Liara Console -> Account -> API Tokens
    • The workflow will automatically deploy on push to main branch

Database Information

The backend uses SQLite as an embedded database, which:

  • Requires no external database service
  • Stores data in a single file (sentinel_brain.db)
  • Is perfect for MVP and small-scale deployments
  • Automatically initializes on first startup

For production with high traffic, consider migrating to PostgreSQL by:

  1. Adding psycopg2-binary to requirements.txt
  2. Setting DATABASE_URL environment variable to PostgreSQL connection string
  3. The code will automatically detect and use PostgreSQL

Environment Variables

Variable Description Example
DATABASE_URL Database connection string sqlite:///./sentinel_brain.db (default)
JWT_SECRET Secret key for JWT tokens your-secret-key-change-in-production
DEBUG Enable debug mode false
SKIP_INIT_DB Skip database seeding on startup 0

πŸ“ Project Structure

hybrid-cloud-sentinel/
β”œβ”€β”€ πŸ“‚ android/                    # Android Application
β”‚   β”œβ”€β”€ πŸ“‚ app/                    # Main application module
β”‚   β”œβ”€β”€ πŸ“‚ domain/                 # Business logic (Pure Kotlin)
β”‚   β”‚   β”œβ”€β”€ model/                 # Entities (AppPackage, RiskAssessment)
β”‚   β”‚   β”œβ”€β”€ repository/            # Repository interfaces
β”‚   β”‚   └── usecase/               # Use cases (ScanAppUseCase)
β”‚   β”œβ”€β”€ πŸ“‚ data/                   # Data layer
β”‚   β”‚   β”œβ”€β”€ local/                 # Room database, DAOs
β”‚   β”‚   β”œβ”€β”€ remote/                # Retrofit API, DTOs
β”‚   β”‚   β”œβ”€β”€ ml/                    # TFLite model, FeatureExtractor
β”‚   β”‚   └── repository/            # Repository implementations
β”‚   β”œβ”€β”€ πŸ“‚ presentation/           # UI Layer (Jetpack Compose)
β”‚   β”‚   β”œβ”€β”€ theme/                 # Cyberpunk design system
β”‚   β”‚   β”œβ”€β”€ components/            # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ scan/                  # Scanning screens
β”‚   β”‚   └── about/                 # About screen
β”‚   └── πŸ“‚ agent/                  # System services
β”‚       β”œβ”€β”€ service/               # Foreground service (SentinelService)
β”‚       └── scanner/               # Package analyzer
β”œβ”€β”€ πŸ“‚ backend/                    # Python Backend (Cloud Brain)
β”‚   β”œβ”€β”€ πŸ“‚ app/
β”‚   β”‚   β”œβ”€β”€ api/v1/endpoints/      # REST endpoints (scan, auth, dashboard)
β”‚   β”‚   β”œβ”€β”€ core/                  # Config, database, security
β”‚   β”‚   β”œβ”€β”€ engine/                # Heuristics & ML
β”‚   β”‚   β”œβ”€β”€ models/                # SQLAlchemy models (User, ScanLog)
β”‚   β”‚   β”œβ”€β”€ schemas/               # Pydantic schemas
β”‚   β”‚   β”œβ”€β”€ services/              # Business logic (auth)
β”‚   β”‚   β”œβ”€β”€ static/                # CSS, JavaScript
β”‚   β”‚   └── templates/             # Jinja2 HTML templates (dashboard)
β”‚   └── πŸ“‚ tests/                  # pytest test suite
β”œβ”€β”€ πŸ“‚ docs/                       # Documentation
β”œβ”€β”€ πŸ“‚ references/                 # Reference ML models & datasets
└── πŸ“‚ samples/                    # Test APK samples

πŸ§ͺ Testing

Android Tests

# Unit Tests (Domain logic, ViewModels)
cd android
./gradlew testDebugUnitTest

# Instrumented Tests (Room DB, UI flows)
./gradlew connectedDebugAndroidTest

Backend Tests

cd backend
pytest --cov=app tests/

Manual Verification

  1. Threat Detection Test: Install a test app with suspicious permissions
  2. Connectivity Test: Verify offline mode shows cached results
  3. UI Fluidity: Test radar animations on real device

πŸ† Features Checklist

  • Core Scanning Loop - Real-time app analysis
  • Cloud Integration - Offloaded threat analysis
  • Offline Support - Local caching with Room
  • ML Classification - Ensemble TFLite model integration
  • Trust-First Onboarding - Educational permission dashboard
  • OTA Model Updates - Background model synchronization
  • Admin Dashboard - Real-time analytics and management
  • Premium Features - Subscription model and sandbox payments
  • Network Monitoring - Packet analysis (implemented)

πŸ“š Documentation

Document Description
Architecture Guide Detailed system architecture and design decisions
Setup Guide Complete installation and configuration instructions
API Reference Cloud Brain REST API documentation
Development Guide Contributing guidelines and coding standards
Testing Guide Testing strategy and test writing guide

🀝 Contributing

We welcome contributions! Please see our Development Guide for:

  • Coding standards and conventions
  • Branch naming and commit messages
  • Pull request process
  • Code review guidelines

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❀️ by AI + Human Collaboration

Protecting your digital life, one scan at a time.