================================================================================ SUI API - PROJECT STRUCTURE & FILES ================================================================================ Project Name: SUI API (Simple User Interaction API) Created: 27 Mei 2026 Purpose: Connect mobile app to MySQL Remote Database ================================================================================ DIRECTORY STRUCTURE ================================================================================ sui_api/ ├── api.php ⭐ Main application file ├── test_connection.php 🔧 Database connection tester │ ├── config/ │ └── database.php 🔐 Database configuration │ ├── models/ │ ├── User.php 👤 User model │ ├── Product.php 📦 Product model │ ├── Notification.php 🔔 Notification model │ └── Log.php 📝 Log model │ ├── helpers/ │ └── Response.php ✅ Response helper class │ ├── Documentation Files: │ ├── README.md 📖 Project overview & setup │ ├── tutorial.txt 📚 Client integration guide and request examples │ ├── QUICKSTART.txt ⚡ Quick start guide │ ├── API_EXAMPLES.txt 📋 Request/response examples │ ├── DATABASE_SCHEMA.sql 🗄️ Database schema reference │ └── PROJECT_STRUCTURE.txt 📂 This file │ ├── Configuration Files: │ ├── .htaccess 🔄 URL rewriting for API routing │ ├── .env.example ⚙️ Environment variables template ================================================================================ FILES EXPLANATION ================================================================================ 1. ⭐ api.php (Main Application - THE CORE) ──────────────────────────────────────────── Purpose : Main router dan request dispatcher Language : PHP 7.4+ Size : ~280+ lines Features: - Handle HTTP methods (GET, POST, PUT, DELETE) - Request routing berdasarkan endpoint - CORS headers untuk cross-origin requests - JSON request/response handling - Error handling dengan status codes Endpoints yang di-handle: - /api/users (GET, POST, PUT, DELETE) - /api/products (GET, POST, PUT, DELETE) - /api/notifications (GET, POST, PUT, DELETE) ← MAIN FOCUS - /api/logs (GET, POST, PUT, DELETE) ← MAIN FOCUS - /api/health (health check) How it works: 1. Receive HTTP request 2. Parse URI dan extract endpoint 3. Call appropriate handler function 4. Return JSON response 2. 🔧 test_connection.php (Database Connection Tester) ──────────────────────────────────────────────────── Purpose : Verify database connection successful Usage : php test_connection.php What it does: - Test connection to MySQL remote - Display database info (host, db, user) - List all tables di database - Show structure dari sui_notifications tabel - Show structure dari sui_logs tabel - Count total records di setiap tabel Output: ``` Database Connected Successfully! Available tables: access, products, sui_logs, sui_notifications, users sui_notifications: 8 records - sui_id (INT) NOT NULL - title (TEXT) NULLABLE - text (TEXT) NULLABLE - package (TEXT) NULLABLE - post_time (BIGINT) NULLABLE - notification_key (TEXT) NULLABLE ``` 3. 🔐 config/database.php ────────────────────── Purpose : Database configuration dan connection setup Contains: - Database class dengan singleton pattern - Credentials (host, port, user, pass, db) - Connection method dengan error handling - Table creation queries (auto-run pada first execution) Tables yang di-create: - users (jika belum ada) - products (jika belum ada) Credentials: - Host: ftp.akfo.cc - Port: 3306 - User: akfomyid_sui - Pass: sui029060 - DB: akfomyid_sui 4. 👤 models/User.php ─────────────────── Purpose : User data management (CRUD operations) Methods: - getAll() → Get semua users - getById($id) → Get specific user - create($data) → Insert user baru - update($id, $data) → Update user - delete($id) → Delete user Database fields: - id, name, email, phone, address - created_at, updated_at 5. 📦 models/Product.php ────────────────────── Purpose : Product data management (CRUD operations) Methods: - getAll() → Get semua products - getById($id) → Get specific product - create($data) → Insert product baru - update($id, $data) → Update product - delete($id) → Delete product Database fields: - id, name, description, price, stock, category - created_at, updated_at 6. 🔔 models/Notification.php ⭐ PENTING ──────────────────────────────────── Purpose : Manage push notifications from mobile client Methods: - getAll($limit, $offset) → Get all notifications with pagination - getById($id) → Get specific notification - getBySuiId($sui_id) → Get notifications untuk specific user - create($data) → Create notification baru - update($id, $data) → Update notification - delete($id) → Delete notification - getTotal() → Count total notifications Database fields: - sui_id (INT) - User ID - title (TEXT) - Notification title - text (TEXT) - Notification content - package (TEXT) - App package name - post_time (BIGINT) - Timestamp in milliseconds - notification_key (TEXT) - Unique identifier 7. 📝 models/Log.php ⭐ PENTING ─────────────────────────── Purpose : Manage activity logs from mobile client Methods: - getAll($limit, $offset) → Get all logs with pagination - getById($id) → Get specific log - getBySuiId($sui_id) → Get logs untuk specific user - create($data) → Create log baru - update($id, $data) → Update log - delete($id) → Delete log - deleteOlderThan($days) → Auto-cleanup old logs - getTotal() → Count total logs - getTotalBySuiId($sui_id) → Count logs untuk user specific Database fields: - sui_id (INT) - User ID - message (TEXT) - Log message - timestamp (BIGINT) - Timestamp in milliseconds 8. ✅ helpers/Response.php ─────────────────────── Purpose : Standardized JSON response formatting Methods: - static send($data, $statusCode) → Send success response - static error($message, $statusCode) → Send error response Response format: Success: { "status": "success", "code": 200, "data": { ... } } Error: { "status": "error", "code": 400, "message": "Error message" } 9. 🔄 .htaccess ─────────── Purpose : URL rewriting untuk API routing What it does: - Enable mod_rewrite - Route semua requests ke api.php - Preserve query strings Requirements: - Apache server - mod_rewrite enabled (a2enmod rewrite) - AllowOverride All in Apache config 10. ⚙️ .env.example ────────────── Purpose : Environment variables template Contains: - Database credentials - Server configuration - Security settings - Logging settings Usage: - Copy to .env - Update dengan credentials actual - Load di config/database.php ================================================================================ DOCUMENTATION FILES ================================================================================ 12. 📖 README.md ─────────── Purpose : Project overview dan setup guide Contains: - Project description - Directory structure - Database info - Endpoints summary (table format) - Setup instructions - Testing guide - Development requirements - Troubleshooting Audience: Developers / Project Leads 13. 📚 tutorial.txt ⭐ MOST IMPORTANT FOR CLIENT INTEGRATION ────────────────────────────────────────────────── Purpose : Complete client integration guide Length : 500+ lines Contains: Section I: Database Structure - Explanation dari tabel sui_notifications - Explanation dari tabel sui_logs - Field descriptions Section II: API Endpoints - Detailed endpoint documentation - Request body examples - Response examples - curl command examples Section III: Client Implementation (THE MAIN PART) A. Dependencies - Add required packages ke project config - Setup client dependency manager B. API Service Class ⭐ - Complete HTTP client implementation - Methods untuk semua endpoints - Error handling - Connection timeout - Header management ```dart ApiService.createNotification(...) ApiService.getNotifications(...) ApiService.getLogsBySuiId(...) ApiService.createLog(...) // ... dan lainnya ``` C. User Service Class - Manage sui_id dengan SharedPreferences - Login/logout functionality - Check if user logged in D. Example Screens - NotificationsScreen dengan FutureBuilder - LogsScreen dengan list view - Complete implementation E. Main Widget - Bottom navigation - Login/logout button - Navigation between screens Section IV: Testing - Unit testing guide - Manual testing dengan curl Section V: Best Practices - Authentication notes - Error handling - Data storage - Performance optimization - Security tips Section VI: Troubleshooting - Common errors - Solutions - Debug tips 14. ⚡ QUICKSTART.txt ──────────────── Purpose : Quick reference guide Length : 300+ lines Contains: - File checklist - Database info quick reference - Endpoints summary - Setup step-by-step - Testing instructions - Deployment checklist - Next steps User: Developers yang butuh quick reference 15. 📋 API_EXAMPLES.txt ───────────────── Purpose : Complete request/response examples Contains: - GET /notifications - multiple examples - GET /notifications by sui_id - GET /notifications/:id - POST /notifications (success & error) - PUT /notifications/:id - DELETE /notifications/:id - GET /logs - multiple examples - POST /logs (success & error) - PUT /logs/:id - DELETE /logs/:id - Error responses (404, 405, 500, connection errors) - curl command examples untuk setiap endpoint Purpose: Copy-paste references untuk testing 16. 🗄️ DATABASE_SCHEMA.sql ────────────────────── Purpose : Database schema reference Contains: - CREATE TABLE statements untuk semua tabel - Field explanations - Useful SQL queries - Index optimization - Sample data inserts - Data types explanation - Backup/restore commands Usage: - Reference untuk database structure - Create tables di database baru - Optimize dengan indexes 17. 📂 PROJECT_STRUCTURE.txt ─────────────────────── Purpose : This file Contains : Complete project documentation ================================================================================ FILE RELATIONSHIPS ================================================================================ ┌─────────────────┐ │ api.php │ ← Main router └────────┬────────┘ │ loads ├─────────────────────────────────────┐ │ │ ┌────▼────────┐ ┌───────────▼────────────┐ │ DATABASE │ │ REQUEST HANDLERS │ ├─────────────┤ ├────────────────────────┤ │ - connect() │ │ - handleUsers() │ │ - getInstance║ │ - handleProducts() │ └─────────────┘ │ - handleNotifications()│ △ │ - handleLogs() │ │ uses └────────┬───────────────┘ │ │ instantiate ┌────┴────────────────────────────────┴────────────┐ │ MODEL CLASSES │ ├───────────────────────────────────────────────────┤ │ - User.php (CRUD operations) │ │ - Product.php (CRUD operations) │ │ - Notification.php (CRUD + getBySuiId) ⭐ │ │ - Log.php (CRUD + getBySuiId) ⭐ │ └─────────┬──────────────────────────────┬──────────┘ │ execute queries │ get results │ │ ┌─────────▼──────────────────────────────▼─────────┐ │ MYSQL DATABASE (ftp.akfo.cc) │ ├──────────────────────────────────────────────────┤ │ - users │ │ - products │ │ - sui_notifications ⭐ │ │ - sui_logs ⭐ │ │ - access │ └──────────────────────────────────────────────────┘ └─ returns JSON responses │ ┌───────────────────▼──────────────────┐ │ RESPONSE HELPER (Response.php) │ ├────────────────────────────────────┤ │ - send() → success JSON │ │ - error() → error JSON │ └───────────────────┬──────────────────┘ │ JSON output ┌─────────▼──────────┐ │ HTTP RESPONSE │ │ to Client/App │ └────────────────────┘ ================================================================================ TECHNOLOGY STACK ================================================================================ Backend: - PHP 7.4+ - MySQLi (MySQL Improved Extension) - Apache (with mod_rewrite) Database: - MySQL 5.7+ - Remote host: ftp.akfo.cc Client Integration: - Android/Kotlin: OkHttp, Retrofit, Volley - iOS/Swift: URLSession, Alamofire - Web: fetch, Axios - JSON + HTTP request/response Documentation: - Markdown (README.md) - Plain text (.txt files) - SQL (.sql file) ================================================================================ DEVELOPMENT WORKFLOW ================================================================================ 1. Local Testing: - Setup local MySQL database dengan akfomyid_sui - Update config/database.php untuk local connection - Test dengan test_connection.php - Test endpoints dengan curl 2. Deployment: - Upload semua files ke sui.akfo.cc/public_html/ - Maintain folder structure - Enable Apache mod_rewrite - Verify .htaccess permissions 3. Client Implementation: - Copy code dari tutorial.txt ke client project - Setup API base URL di client app - Test dengan emulator/device - Deploy ke environment 4. Monitoring: - Monitor logs di sui_logs table - Check notifications di sui_notifications - Performance monitoring dengan indexes - Regular backups ================================================================================ KEY POINTS TO REMEMBER ================================================================================ ✓ sui_id adalah USER ID dari aplikasi client ✓ Timestamps selalu dalam MILLISECONDS (bukan seconds) ✓ Notifications store push notifications dari app ✓ Logs store activity logs dari user ✓ API URLs: https://sui.akfo.cc/api/[endpoint] ✓ Database: akfomyid_sui @ ftp.akfo.cc:3306 ✓ All responses dalam format JSON ✓ CORS enabled untuk mobile apps ✓ Pagination dengan limit & offset ================================================================================ Last Updated: 27 Mei 2026 Version: 1.0