================================================================================
                    SLEEKDEPLOY - PHP WEB HOSTING SYSTEM SUMMARY
================================================================================

Yeh summary.txt file SleekDeploy (PHP File Hosting & Deployment System) ke backend
working, logic, architecture aur working steps ko easy Hinglish me samjhane ke liye banayi gayi hai.

--------------------------------------------------------------------------------
1. FTP vs NON-FTP (Yeh kaise kaam karta hai?)
--------------------------------------------------------------------------------
* **NON-FTP (HTTP Upload Mechanism):** Yeh system poori tarah se NON-FTP hai.
* **Kaise kaam karta hai?:** Isme file transfer karne ke liye kisi bhi FTP Protocol ya FTP
  Credentials (Host, Username, Password) ki zaroorat nahi hoti. Iski jagah, yeh normal
  HTTP POST Request (Multipart Form-Data aur JSON Payload) ka use karta hai.
* **Fayda (Advantage):** FTP ke mukable yeh bohot fast hai, firewall-friendly hai, aur
  user ko apna koi bhi sensitive FTP password share nahi karna padta. Yeh poori tarah se
  API-driven hai.

--------------------------------------------------------------------------------
2. Architecture aur Tech Stack (Technology Stack)
--------------------------------------------------------------------------------
* **Frontend:** HTML5, Modern CSS (Glassmorphism UI), aur Vanilla JavaScript (AJAX Fetch API).
* **Backend:** Core PHP (config.php, functions.php, api.php).
* **Database:** Lightweight flat-file JSON Database (database.json). Isme kisi bhi SQL database
  (jaise MySQL) ki zaroorat nahi hai. Is wajah se yeh project 100% portable hai (matlab direct folder copy-paste karke chal jayega).

--------------------------------------------------------------------------------
3. Ideology aur Core Logic (Siddhant aur Logic)
--------------------------------------------------------------------------------
* **Security First (Suraksha):**
  - **Deployment Keys Setup:** Jab tak authorized deployment key nahi bhejenge, upload start nahi hoga (yeh api.php aur index.php dono me kaam karta hai). Yeh keys `config.php` file ke andar line number 7 par `DEPLOYMENT_KEYS` constant array me define hoti hain:
    ```php
    define('DEPLOYMENT_KEYS', [
        'deploy123',
        'secret-key-99'
    ]);
    ```
    Aap is list me naye keys add kar sakte hain ya purane change kar sakte hain.
  - **Spam & Brute Force Protection (IP Blocking):** Agar koi unauthorized person ya spam bot lagatar 5 baar galat key send karta hai, toh uska IP address automatically **24 hours ke liye block** ho jata hai.
    - Block ka status checking `deploy/failed_attempts.json` file ke zariye track kiya jata hai.
    - Har request se pehle backend client ka IP check karta hai aur block status trigger hone par 403 Forbidden return kar deta hai.
  - Direct directory browsing ko block karne ke liye, jab bhi koi extension folder banta hai, toh uske andar automatic ek 'index.html' (403 Forbidden page) file create ho jati hai.
* **Automatic Categorization (Automatic Folder Organization):**
  - File extension ke hisab se file sahi folder me chali jati hai (jaise: .png -> deploy/png/, .php -> deploy/php/).
* **Unique Links (Koi overwriting nahi):**
  - Har file ko ek 12-character ki random unique ID (jaise: a1b2c3d4e5f6) milti hai. Iska fayda yeh hai ki agar do files ka naam same bhi ho, toh bhi woh ek dusre ko overwrite nahi karengi.

--------------------------------------------------------------------------------
4. Core PHP Functions (Kaunsa function kya karta hai?)
--------------------------------------------------------------------------------

1. validate_deployment_key($key)
   - Kaam: Client se aayi hui deployment key ko check karta hai ki woh config.php ki authorized keys me hai ya nahi.
   - File: functions.php

2. sanitize_filename($filename)
   - Kaam: File name me se dangerous characters aur directory traversal (../) ke threats ko saaf karta hai.
   - File: functions.php

3. get_file_category($extension)
   - Kaam: File ka extension dekh kar folder category decide karta hai (jaise html, php, image, video, etc.).
   - File: functions.php

4. deploy_raw_code($code, $extension, $key)
   - Kaam: Agar user ne seedhe textarea me code paste kiya hai, toh yeh function use dynamic file me badal kar target category folder me save karta hai aur metadata entry generate karta hai.
   - File: functions.php

5. deploy_uploaded_file($file_info, $key)
   - Kaam: Client se aayi physical file ko validation rules check karne ke baad destination directory me move (save) karta hai.
   - File: functions.php

6. save_metadata($file_record)
   - Kaam: Uploaded file ki saari details (Unique ID, dynamic URL, size, category, upload time) ko database.json file me save karta hai.
   - File: functions.php

7. delete_file($unique_id)
   - Kaam: Admin panel se jab delete press hota hai, toh yeh us unique ID ke folder aur physical file ko delete karta hai aur database.json se record saaf karta hai.
   - File: functions.php

--------------------------------------------------------------------------------
5. Step-by-Step Request Flow (Upload Kaise Process Hota Hai?)
--------------------------------------------------------------------------------

Step 1: User Input
User page par aata hai, Authorization Key dalta hai, aur file select karta hai (ya fir code paste karta hai).

Step 2: Frontend Sending (AJAX)
Submit click karne par frontend ka JS input data read karta hai aur 'api.php' par ek HTTP POST request bhejta hai.

Step 3: API Routing (api.php)
'api.php' request receive karke Content-Type check karta hai:
- Agar JSON hai, toh Code Deployment trigger karta hai.
- Agar Multipart Form-Data hai, toh File Upload trigger karta hai.

Step 4: Verification
Backend key ko check karta hai. Agar key invalid hai, toh turant "Invalid deployment key" ka 401 error response de deta hai.

Step 5: Folder & File Creation
System unique 12-character ID banata hai.
'deploy/<extension>/<unique_id>/' directory create karta hai aur file wahan write/move karta hai.

Step 6: Update Database
'save_metadata()' database.json file ko load karke usme is file ka record entry add karke save kar deta hai.

Step 7: Success Response
Backend success true aur hosted file ka dynamic link return karta hai.
Frontend ko link milte hi screen par link show hota hai aur live preview iframe me load ho jata hai.

================================================================================
Designed with high standards to run securely on any standard Apache/Nginx PHP Server.
================================================================================
