|
| 1 | +# DroidOps - Modular Architecture Guide |
| 2 | + |
| 3 | +## 📁 Project Structure |
| 4 | + |
| 5 | +``` |
| 6 | +src/ |
| 7 | +├── components/ # Reusable UI components |
| 8 | +│ ├── DeviceSelector.jsx |
| 9 | +│ ├── FileExplorer.jsx |
| 10 | +│ ├── Gallery.jsx |
| 11 | +│ └── Sidebar.jsx |
| 12 | +├── pages/ # Page-level components |
| 13 | +│ ├── Dashboard.jsx |
| 14 | +│ ├── AppManager.jsx |
| 15 | +│ ├── ShellPage.jsx |
| 16 | +│ ├── FastbootPage.jsx |
| 17 | +│ └── SideloadPage.jsx |
| 18 | +├── lib/ # Core functionality |
| 19 | +│ ├── adb.js # ADB command wrappers |
| 20 | +│ └── cache.js # File caching utilities |
| 21 | +├── data/ # Configuration & strings |
| 22 | +│ ├── strings.js # All UI text/labels |
| 23 | +│ └── config.js # App configuration |
| 24 | +├── hooks/ # Custom React hooks |
| 25 | +│ └── useStrings.js # String management hook |
| 26 | +├── utils/ # Utility functions |
| 27 | +│ └── dialog.js # Dialog helpers |
| 28 | +└── App.jsx # Main application |
| 29 | +
|
| 30 | +``` |
| 31 | + |
| 32 | +## 🔧 Data-Driven Design |
| 33 | + |
| 34 | +### Strings Management (`src/data/strings.js`) |
| 35 | + |
| 36 | +All UI text, labels, and messages are centralized in the `STRINGS` object: |
| 37 | + |
| 38 | +```javascript |
| 39 | +import { STRINGS, formatString } from '../data/strings'; |
| 40 | + |
| 41 | +// Direct access |
| 42 | +const title = STRINGS.dashboard.title; |
| 43 | + |
| 44 | +// With placeholders |
| 45 | +const message = formatString(STRINGS.apps.confirmUninstall, { app: 'MyApp' }); |
| 46 | +``` |
| 47 | + |
| 48 | +**Categories:** |
| 49 | +- `app` - Application metadata |
| 50 | +- `navigation` - Menu labels |
| 51 | +- `device` - Device-related strings |
| 52 | +- `dashboard`, `apps`, `files`, `gallery`, etc. - Page-specific strings |
| 53 | +- `errors` - Error messages |
| 54 | +- `common` - Common UI strings |
| 55 | + |
| 56 | +### Configuration (`src/data/config.js`) |
| 57 | + |
| 58 | +App-wide settings and constants: |
| 59 | + |
| 60 | +```javascript |
| 61 | +import { APP_CONFIG, ROUTES, DEVICE_STATES } from '../data/config'; |
| 62 | + |
| 63 | +// Configuration |
| 64 | +const theme = APP_CONFIG.ui.defaultTheme; |
| 65 | + |
| 66 | +// Routes |
| 67 | +navigate(ROUTES.DASHBOARD); |
| 68 | + |
| 69 | +// Constants |
| 70 | +if (device.state === DEVICE_STATES.OFFLINE) { ... } |
| 71 | +``` |
| 72 | + |
| 73 | +## 🎣 Custom Hooks |
| 74 | + |
| 75 | +### useStrings Hook |
| 76 | + |
| 77 | +```javascript |
| 78 | +import { useStrings } from '../hooks/useStrings'; |
| 79 | + |
| 80 | +const MyComponent = () => { |
| 81 | + const { strings, format } = useStrings(); |
| 82 | + |
| 83 | + return <h1>{strings.app.title}</h1>; |
| 84 | +}; |
| 85 | +``` |
| 86 | + |
| 87 | +## 🔔 Dialog System |
| 88 | + |
| 89 | +Centralized dialog handling with i18n support: |
| 90 | + |
| 91 | +```javascript |
| 92 | +import { confirmDelete, confirmUninstall, alertDialog } from '../utils/dialog'; |
| 93 | + |
| 94 | +// Confirm deletion |
| 95 | +if (confirmDel ete(fileName)) { |
| 96 | + deleteFile(); |
| 97 | +} |
| 98 | + |
| 99 | +// Custom alerts |
| 100 | +alertDialog(STRINGS.files.uploadSuccess); |
| 101 | +``` |
| 102 | + |
| 103 | +## 📦 Component Guidelines |
| 104 | + |
| 105 | +### 1. Import Order |
| 106 | +```javascript |
| 107 | +// 1. React & third-party |
| 108 | +import React, { useState } from 'react'; |
| 109 | +import { Icon } from 'lucide-react'; |
| 110 | + |
| 111 | +// 2. Data & config |
| 112 | +import { STRINGS } from '../data/strings'; |
| 113 | +import { APP_CONFIG } from '../data/config'; |
| 114 | + |
| 115 | +// 3. Utilities & hooks |
| 116 | +import { useStrings } from '../hooks/useStrings'; |
| 117 | +import { confirmDialog } from '../utils/dialog'; |
| 118 | + |
| 119 | +// 4. Local imports |
| 120 | +import { myFunction } from '../lib/myLib'; |
| 121 | +``` |
| 122 | + |
| 123 | +### 2. Use Constants |
| 124 | +```javascript |
| 125 | +// ❌ Bad |
| 126 | +if (activeTab === "dashboard") { ... } |
| 127 | + |
| 128 | +// ✅ Good |
| 129 | +import { ROUTES } from '../data/config'; |
| 130 | +if (activeTab === ROUTES.DASHBOARD) { ... } |
| 131 | +``` |
| 132 | + |
| 133 | +### 3. Use Centralized Strings |
| 134 | +```javascript |
| 135 | +// ❌ Bad |
| 136 | +<button>Delete</button> |
| 137 | + |
| 138 | +// ✅ Good |
| 139 | +<button>{STRINGS.files.delete}</button> |
| 140 | +``` |
| 141 | + |
| 142 | +## 🌐 Adding New Features |
| 143 | + |
| 144 | +### Adding a New Page |
| 145 | + |
| 146 | +1. **Create page component** in `src/pages/` |
| 147 | +2. **Add route** to `ROUTES` in `config.js` |
| 148 | +3. **Add strings** to appropriate section in `strings.js` |
| 149 | +4. **Register route** in `App.jsx` |
| 150 | +5. **Add navigation** item to `Sidebar.jsx` |
| 151 | + |
| 152 | +### Adding New Strings |
| 153 | + |
| 154 | +1. Add to appropriate category in `src/data/strings.js`: |
| 155 | +```javascript |
| 156 | +export const STRINGS = { |
| 157 | + myFeature: { |
| 158 | + title: "My Feature", |
| 159 | + description: "Description here", |
| 160 | + action: "Action button label" |
| 161 | + } |
| 162 | +}; |
| 163 | +``` |
| 164 | + |
| 165 | +2. Use in component: |
| 166 | +```javascript |
| 167 | +import { STRINGS } from '../data/strings'; |
| 168 | +<h1>{STRINGS.myFeature.title}</h1> |
| 169 | +``` |
| 170 | + |
| 171 | +### Adding Configuration |
| 172 | + |
| 173 | +1. Add to `src/data/config.js`: |
| 174 | +```javascript |
| 175 | +export const APP_CONFIG = { |
| 176 | + myFeature: { |
| 177 | + setting1: true, |
| 178 | + setting2: "value" |
| 179 | + } |
| 180 | +}; |
| 181 | +``` |
| 182 | + |
| 183 | +2. Use in code: |
| 184 | +```javascript |
| 185 | +import { APP_CONFIG } from '../data/config'; |
| 186 | +if (APP_CONFIG.myFeature.setting1) { ... } |
| 187 | +``` |
| 188 | + |
| 189 | +## 🎨 Styling Conventions |
| 190 | + |
| 191 | +- Use Tailwind CSS classes |
| 192 | +- Dark theme by default |
| 193 | +- Color palette: |
| 194 | + - Primary: `#2ca9bc` |
| 195 | + - Background: `#0f0f12` |
| 196 | + - Surface: `#1a1a1f` |
| 197 | + - Border: `#27272a` |
| 198 | + |
| 199 | +## 📝 Best Practices |
| 200 | + |
| 201 | +1. **Keep components focused** - Single responsibility |
| 202 | +2. **Use data files** - No hardcoded strings/config |
| 203 | +3. **Leverage hooks** - Extract reusable logic |
| 204 | +4. **Handle errors gracefully** - Use standardized dialogs |
| 205 | +5. **Document new features** - Update this README |
| 206 | + |
| 207 | +## 🔄 Migration Checklist |
| 208 | + |
| 209 | +When updating existing code: |
| 210 | +- [ ] Replace hardcoded strings with `STRINGS` references |
| 211 | +- [ ] Replace magic values with `APP_CONFIG` constants |
| 212 | +- [ ] Use `ROUTES` for navigation logic |
| 213 | +- [ ] Use dialog utilities instead of raw `window.confirm/alert` |
| 214 | +- [ ] Extract reusable logic into hooks |
| 215 | + |
| 216 | +## 🚀 Development Workflow |
| 217 | + |
| 218 | +```bash |
| 219 | +# Start development server |
| 220 | +npm run tauri dev |
| 221 | + |
| 222 | +# Build for production |
| 223 | +npm run tauri build |
| 224 | +``` |
| 225 | + |
| 226 | +## 📚 Additional Resources |
| 227 | + |
| 228 | +- [Tauri Documentation](https://tauri.app/) |
| 229 | +- [React Hooks](https://react.dev/reference/react) |
| 230 | +- [Tailwind CSS](https://tailwindcss.com/) |
0 commit comments