# smehtani83/secure-personal-cloud architecture

> Architecture diagram of the GitHub repository smehtani83/secure-personal-cloud, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/smehtani83/secure-personal-cloud
- Repository: https://github.com/smehtani83/secure-personal-cloud

## Overview

##### Project Type and Purpose
- This is a hybrid system:
- A client-side CLI tool (“spc”) written in Python and Bash scripts that lets users observe, encrypt, and sync directories.
- A server-side component implemented as a Django web application (ssl_project/) with two apps (login, signup), using SQLite to store metadata and encrypted blobs.
- Purpose: enable authenticated users to register and manage encryption keys, observe local directories, perform end-to-end encryption (RSA/MD5), and synchronize encrypted files over SSH/SCP to a central server, with support for sharing and receiving files among users.

##### Directory Structure
- Top-level scripts (blob.py, dec.py, rsa.py, rsa_gen.py, sbwa.py, md5get.py, scp_commands.sh, helper.sh, install.sh) implement the CLI interface, encryption routines, and shell wrappers for SSH/SCP.
- ssl_project/ is a standard Django project:
- ssl_project/ssl_project/: settings.py, urls.py, wsgi.py
- ssl_project/login/ and ssl_project/signup/: apps, models.py, views.py, urls.py, templates, tests, migrations.
- ssl_project/db.sqlite3 persists users, keys, file metadata.
- ssl_project/encryption_helper, blob.py, backfromblob.py, dec.py provide server-side encryption/decryption logic.

##### README Insights
- CLI commands (`spc login`, `spc register`, `spc observe`, `spc sync`, `spc send`, `spc rec`, etc.) define the client workflow: authenticate, initialize or load keys, mark local directory for sync, push encrypted files, share or receive files.
- All communications with the server appear to go over SSH/SCP (no REST API references), with the server running a Django app that responds to file drops and key exchanges.

##### Main Components
a. Client Tier
- CLI Wrapper (“spc” command dispatcher)
- Local Encryption Module (rsa.py, md5get.py, blob.py, dec.py)
- Filesystem Observer & Sync Engine (sbwa.py, sync.py)
- SSH/SCP Transport Layer (scp_commands.sh, helper.sh)
b. Network
- Secure Channel (SSH)
c. Server Tier
- Django Web Application
- Auth & Key Management App (signup, login apps)
- File Metadata & Sharing Logic
- Views for file receipts, directory status
- Server-side Encryption Helper (encryption_helper, backfromblob.py, dec.py)
- Database (SQLite)
- Persistent File Storage (encrypted blob directory or DB blobs)

##### Relationships and Data Flows
- User invokes `spc <command>` → CLI Wrapper
- CLI calls Local Encryption Module → produces encrypted blobs and MD5 checksums
- CLI invokes SSH/SCP scripts → transfers blobs and metadata to server
- On server arrival, Django’s file upload endpoints trigger server-side encryption_helper to validate or re-encrypt, then persist records in SQLite and store blob on disk
- For `spc status` or `spc server`, CLI retrieves metadata via SSH/SCP, then presents back to user
- For `spc send`/`spc rec`, CLI coordinates with Django apps to add sharing keys in DB, then pulls or pushes blobs

##### Architectural Patterns and Design Principles
- Client-Server architecture over SSH/SCP
- Modular encryption pipeline (separate RSA keygen, blob encryption, MD5 checksum stages)
- MVC pattern inside Django: models (file metadata & keys), views (file endpoints, status queries), templates (login/register pages)
- Thin CLI that delegates heavy lifting to reusable Python modules and shell scripts

##### Technologies and Frameworks
- Python 3 scripts (CLI logic, encryption modules)
- Bash scripts for orchestration (scp_commands.sh, helper.sh)
- SSH/SCP as transport
- Django 2.x for server, SQLite for persistence
- RSA cryptography and MD5 hashing

##### Essential Elements Without Over-Segmentation
- You cover all major scripts and Django apps, but group related modules into logical containers (e.g., “Encryption Modules” rather than each `.py` file).
- Interactions (authentication & key exchange, file upload/download, status queries).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Host
    subgraph "Client Host"
        direction TB
        CLI["spc CLI Dispatcher"]:::client
        INSTALL["install.sh"]:::client
        subgraph "Local Encryption Module"
            direction TB
            RSA_GEN["rsa_gen.py"]:::client
            RSA["rsa.py"]:::client
            BLOB_C["blob.py"]:::client
            MD5["md5get.py"]:::client
            DEC_C["dec.py"]:::client
        end
        subgraph "Filesystem Observer & Sync Engine"
            direction TB
            OBS["sbwa.py"]:::client
            SYNC["sync.py"]:::client
        end
        subgraph "SSH/SCP Transport Layer"
            direction TB
            SCP["scp_commands.sh"]:::network
            HELPER["helper.sh"]:::network
        end
    end

    %% Network
    subgraph "Network"
        direction TB
        SSH["Secure Channel (SSH)"]:::network
    end

    %% Server Host
    subgraph "Server Host"
        direction TB
        subgraph "Django Web Application"
            direction TB
            subgraph "Project Configuration"
                SETTINGS["ssl_project/ssl_project/settings.py"]:::server
                URLS["ssl_project/ssl_project/urls.py"]:::server
                WSGI["ssl_project/ssl_project/wsgi.py"]:::server
                MANAGE["ssl_project/manage.py"]:::server
            end
            subgraph "Auth & Key Management Apps"
                direction TB
                SIGNUP_MODELS["ssl_project/signup/models.py"]:::server
                SIGNUP_VIEWS["ssl_project/signup/views.py"]:::server
                SIGNUP_URLS["ssl_project/signup/urls.py"]:::server
                SIGNUP_TPL["ssl_project/signup/templates/signup.html"]:::server
                LOGIN_MODELS["ssl_project/login/models.py"]:::server
                LOGIN_VIEWS["ssl_project/login/views.py"]:::server
                LOGIN_URLS["ssl_project/login/urls.py"]:::server
                LOGIN_TPL["ssl_project/login/templates/login/"]:::server
            end
            subgraph "File Metadata & Sharing Logic"
                FMODEL["ssl_project/login/models.py"]:::server
                FVIEW["ssl_project/login/views.py"]:::server
                SHARE_FORM["ssl_project/login/templates/login/sharefile_form.html"]:::server
                DATA_JSON["ssl_project/login/templates/login/data.json"]:::server
            end
            subgraph "Server-Side Encryption Helpers"
                BACK["ssl_project/backfromblob.py"]:::server
                BLOB_S["ssl_project/blob.py"]:::server
                DEC_S["ssl_project/dec.py"]:::server
                ENC_HELP["ssl_project/encryption_helper/"]:::server
            end
        end
        DB["ssl_project/db.sqlite3"]:::persistence
        STORAGE["ssl_project/links/"]:::persistence
    end

    %% Connections: Client Flow
    CLI -->|"invokes"| RSA_GEN
    CLI -->|"invokes"| RSA
    CLI -->|"invokes"| BLOB_C
    CLI -->|"invokes"| MD5
    CLI -->|"invokes"| DEC_C
    RSA_GEN --> RSA
    RSA --> BLOB_C
    BLOB_C --> MD5
    MD5 --> OBS
    OBS --> SYNC
    SYNC --> SCP
    SCP --> HELPER
    HELPER --> SSH

    %% Transport to Server
    SSH -->|"file upload/download"| SETTINGS

    %% Server Processing Flow
    SETTINGS --> ENC_HELP
    ENC_HELP --> DB
    ENC_HELP --> STORAGE
    SETTINGS --> SIGNUP_VIEWS
    SETTINGS --> LOGIN_VIEWS
    SIGNUP_VIEWS --> DB
    LOGIN_VIEWS --> DB
    SHARE_FORM --> FVIEW
    DATA_JSON --> FVIEW

    %% Status and Metadata Retrieval
    DB -->|"metadata query"| LOGIN_VIEWS
    LOGIN_VIEWS --> SSH
    SSH --> CLI

    %% Click Events
    click RSA_GEN "https://github.com/smehtani83/secure-personal-cloud/blob/master/rsa_gen.py"
    click RSA "https://github.com/smehtani83/secure-personal-cloud/blob/master/rsa.py"
    click BLOB_C "https://github.com/smehtani83/secure-personal-cloud/blob/master/blob.py"
    click DEC_C "https://github.com/smehtani83/secure-personal-cloud/blob/master/dec.py"
    click MD5 "https://github.com/smehtani83/secure-personal-cloud/blob/master/md5get.py"
    click OBS "https://github.com/smehtani83/secure-personal-cloud/blob/master/sbwa.py"
    click SYNC "https://github.com/smehtani83/secure-personal-cloud/blob/master/sync.py"
    click SCP "https://github.com/smehtani83/secure-personal-cloud/blob/master/scp_commands.sh"
    click HELPER "https://github.com/smehtani83/secure-personal-cloud/blob/master/helper.sh"
    click SETTINGS "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/ssl_project/settings.py"
    click URLS "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/ssl_project/urls.py"
    click WSGI "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/ssl_project/wsgi.py"
    click MANAGE "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/manage.py"
    click SIGNUP_MODELS "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/signup/models.py"
    click SIGNUP_VIEWS "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/signup/views.py"
    click SIGNUP_URLS "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/signup/urls.py"
    click SIGNUP_TPL "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/signup/templates/signup.html"
    click LOGIN_MODELS "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/login/models.py"
    click LOGIN_VIEWS "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/login/views.py"
    click LOGIN_URLS "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/login/urls.py"
    click LOGIN_TPL "https://github.com/smehtani83/secure-personal-cloud/tree/master/ssl_project/login/templates/login/"
    click FMODEL "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/login/models.py"
    click FVIEW "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/login/views.py"
    click SHARE_FORM "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/login/templates/login/sharefile_form.html"
    click DATA_JSON "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/login/templates/login/data.json"
    click BACK "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/backfromblob.py"
    click BLOB_S "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/blob.py"
    click DEC_S "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/dec.py"
    click ENC_HELP "https://github.com/smehtani83/secure-personal-cloud/tree/master/ssl_project/encryption_helper/"
    click DB "https://github.com/smehtani83/secure-personal-cloud/blob/master/ssl_project/db.sqlite3"
    click STORAGE "https://github.com/smehtani83/secure-personal-cloud/tree/master/ssl_project/links/"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#000;
    classDef network fill:#98FB98,stroke:#000;
    classDef server fill:#FFA500,stroke:#000;
    classDef persistence fill:#D3D3D3,stroke:#000;
```
