feat: reorganize admin settings with tabbed interface and documentation

- Reorganized admin settings into tabbed interface (General, Security, Payment Methods)
- Vertical tabs on desktop, horizontal scrollable on mobile
- Moved Payment Methods from separate menu to Settings tab
- Fixed admin profile reuse and dashboard blocking
- Fixed maintenance mode guard to use AppConfig model
- Added admin auto-redirect after login (admins → /admin, users → /)
- Reorganized documentation into docs/ folder structure
- Created comprehensive README and documentation index
- Added PWA and Web Push notifications to to-do list
This commit is contained in:
dwindown
2025-10-13 09:28:12 +07:00
parent 49d60676d0
commit 89f881e7cf
99 changed files with 4884 additions and 392 deletions

394
docs/planning/tech-qa.md Normal file
View File

@@ -0,0 +1,394 @@
# Technical Questions & Answers
## 📱 **Q1: Mobile App - Native vs PWA?**
### **Recommendation: PWA (Progressive Web App)**
#### **Why PWA is Better for Tabungin:**
**✅ Advantages:**
1. **Single Codebase**
- Same React/TypeScript code for web, mobile, and desktop
- No need to learn Swift (iOS) or Kotlin (Android)
- Faster development and easier maintenance
2. **Instant Updates**
- No app store approval delays
- Users always get the latest version
- Fix bugs immediately
3. **Lower Cost**
- No Apple Developer ($99/year) or Google Play ($25 one-time) fees
- No separate mobile development team needed
- Shared backend API
4. **Easy Distribution**
- Users just visit the URL
- "Add to Home Screen" prompt
- No app store submission process
5. **Cross-Platform**
- Works on iOS, Android, Windows, Mac, Linux
- Same experience everywhere
- Responsive design handles all screen sizes
**❌ Native App Disadvantages:**
- Need to build 2 separate apps (iOS + Android)
- Different programming languages (Swift + Kotlin)
- App store approval process (can take days/weeks)
- Higher development cost (2-3x more expensive)
- Slower iteration cycle
#### **When to Consider Native:**
- Need advanced device features (Bluetooth, NFC, advanced camera)
- Performance-critical 3D graphics or games
- Offline-first with complex local database
- Very large user base willing to download apps
#### **For Tabungin Specifically:**
PWA is perfect because:
- ✅ Financial tracking doesn't need native features
- ✅ Web APIs cover all needs (storage, notifications, camera)
- ✅ Users prefer quick access without app download
- ✅ Easier to maintain with small team
- ✅ Can always add native wrapper later (Capacitor/Cordova)
---
## 🔔 **Q2: Push Notifications in PWA?**
### **Yes! PWA supports push notifications via Web Push API**
#### **How It Works:**
**1. Browser Support:**
- ✅ Chrome (Android & Desktop)
- ✅ Firefox (Android & Desktop)
- ✅ Edge (Android & Desktop)
- ✅ Safari (iOS 16.4+, macOS)
- ✅ Opera (Android & Desktop)
**2. Implementation:**
```typescript
// Frontend: Request permission
async function requestNotificationPermission() {
const permission = await Notification.requestPermission()
if (permission === 'granted') {
// Subscribe to push notifications
const registration = await navigator.serviceWorker.ready
const subscription = await registration.pushManager.subscribe({
userVisibleOnly: true,
applicationServerKey: 'YOUR_VAPID_PUBLIC_KEY'
})
// Send subscription to backend
await fetch('/api/notifications/subscribe', {
method: 'POST',
body: JSON.stringify(subscription),
headers: { 'Content-Type': 'application/json' }
})
}
}
// Service Worker: Receive push
self.addEventListener('push', (event) => {
const data = event.data.json()
event.waitUntil(
self.registration.showNotification(data.title, {
body: data.body,
icon: '/icon-192.png',
badge: '/badge-72.png',
data: data.url
})
)
})
// Handle notification click
self.addEventListener('notificationclick', (event) => {
event.notification.close()
event.waitUntil(
clients.openWindow(event.notification.data)
)
})
```
**3. Backend (NestJS):**
```typescript
// Install: npm install web-push
import * as webpush from 'web-push'
// Setup VAPID keys (one-time)
const vapidKeys = webpush.generateVAPIDKeys()
// Store these in .env:
// VAPID_PUBLIC_KEY=...
// VAPID_PRIVATE_KEY=...
webpush.setVapidDetails(
'mailto:support@tabungin.app',
process.env.VAPID_PUBLIC_KEY,
process.env.VAPID_PRIVATE_KEY
)
// Send notification
async sendPushNotification(subscription: any, payload: any) {
try {
await webpush.sendNotification(subscription, JSON.stringify(payload))
} catch (error) {
console.error('Push notification failed:', error)
}
}
```
**4. Database Schema (Prisma):**
```prisma
model PushSubscription {
id String @id @default(uuid())
userId String
user User @relation(fields: [userId], references: [id])
endpoint String @unique
keys Json // { p256dh, auth }
createdAt DateTime @default(now())
@@index([userId])
}
```
#### **Use Cases for Tabungin:**
1. **Transaction Reminders**
- "Don't forget to log today's expenses!"
- Scheduled daily/weekly
2. **Budget Alerts**
- "You've spent 80% of your monthly budget"
- Real-time when threshold reached
3. **Payment Reminders**
- "Subscription payment due in 3 days"
- Scheduled based on payment dates
4. **Goal Progress**
- "You're 50% towards your savings goal! 🎉"
- Milestone notifications
5. **Admin Notifications**
- "New payment verification request"
- "New user registered"
#### **Notification Channels Summary:**
| Channel | Use Case | Delivery Speed | Cost |
|---------|----------|----------------|------|
| **Web Push** | App updates, reminders | Instant | Free |
| **Email** | Receipts, reports, OTP | 1-5 seconds | Free (SendGrid free tier) |
| **WhatsApp** | OTP, urgent alerts | 1-3 seconds | ~$0.005/message |
| **SMS** | OTP (fallback) | 1-5 seconds | ~$0.01/message |
**Recommendation:**
- ✅ Use Web Push for in-app notifications (free, instant)
- ✅ Use Email for important communications (free, reliable)
- ✅ Use WhatsApp for OTP (cheap, high delivery rate)
- ❌ Avoid SMS unless required (expensive)
---
## 📄 **Q3: Why So Many .md Documentation Files?**
### **Great Question! Let me explain the documentation strategy:**
#### **Current Documentation Files:**
1. `MAINTENANCE_MODE_FLOW.md` - Visual flow diagrams
2. `MAINTENANCE_MODE_TESTING_GUIDE.md` - Testing instructions
3. `ADMIN_AUTO_REDIRECT.md` - Login redirect implementation
4. `ADMIN_PROFILE_REUSE.md` - Profile page reuse
5. `TECH_QUESTIONS_ANSWERED.md` - This file
#### **Why Separate Files?**
**❌ Problem with Single Large Document:**
```
MASTER_DOCUMENTATION.md (5000+ lines)
├── Done Tasks (500 lines)
├── To-Do List (200 lines)
├── Requirements (800 lines)
├── UI/UX Guidelines (600 lines)
├── Feature 1 (300 lines)
├── Feature 2 (400 lines)
├── Feature 3 (350 lines)
└── ... (becomes unmanageable)
```
**Issues:**
- Hard to find specific information
- Merge conflicts when updating
- Overwhelming to read
- Difficult to share specific sections
- No clear separation of concerns
**✅ Benefits of Separate Files:**
1. **Focused Context**
- Each file covers ONE topic
- Easy to find what you need
- Clear purpose and scope
2. **Better Organization**
```
docs/
├── features/
│ ├── maintenance-mode.md
│ ├── admin-redirect.md
│ └── profile-reuse.md
├── guides/
│ ├── testing-guide.md
│ └── deployment-guide.md
└── architecture/
├── tech-stack.md
└── api-design.md
```
3. **Easier Collaboration**
- Multiple people can edit different files
- No merge conflicts
- Clear ownership
4. **Version Control**
- See what changed per feature
- Easier to review changes
- Better git history
#### **Recommended Structure:**
```
/docs
├── README.md # Main index
├── /features # Feature documentation
│ ├── maintenance-mode.md
│ ├── admin-redirect.md
│ └── profile-reuse.md
├── /guides # How-to guides
│ ├── testing.md
│ ├── deployment.md
│ └── development.md
├── /architecture # Technical decisions
│ ├── tech-stack.md
│ ├── database-schema.md
│ └── api-design.md
├── /planning # Project management
│ ├── roadmap.md
│ ├── requirements.md
│ └── changelog.md
└── /ui-ux # Design system
├── design-principles.md
├── components.md
└── style-guide.md
```
#### **What I Can Do:**
**Option 1: Keep Current Structure** (Recommended)
- Separate files for each feature/topic
- Easy to navigate and maintain
- Better for version control
**Option 2: Create Index File**
```markdown
# Tabungin Documentation Index
## Features
- [Maintenance Mode](./features/maintenance-mode.md)
- [Admin Auto-Redirect](./features/admin-redirect.md)
- [Profile Page Reuse](./features/profile-reuse.md)
## Guides
- [Testing Guide](./guides/testing.md)
- [Deployment Guide](./guides/deployment.md)
## Planning
- [Roadmap](./planning/roadmap.md)
- [Requirements](./planning/requirements.md)
```
**Option 3: Consolidate by Category**
- `FEATURES.md` - All feature documentation
- `GUIDES.md` - All how-to guides
- `PLANNING.md` - Roadmap, requirements, to-dos
- `ARCHITECTURE.md` - Technical decisions
#### **My Recommendation:**
**Keep separate files BUT organize them better:**
1. **Move to `/docs` folder:**
```bash
mkdir -p docs/{features,guides,planning,architecture}
mv MAINTENANCE_MODE_*.md docs/features/
mv ADMIN_*.md docs/features/
```
2. **Create `docs/README.md` as index:**
- Links to all documentation
- Quick navigation
- Overview of project
3. **Add to root `README.md`:**
- Link to documentation folder
- Quick start guide
- Project overview
#### **Why I Create These Docs:**
1. **Knowledge Transfer**
- You can understand what was done
- Future developers can onboard faster
- Clear implementation details
2. **Testing Reference**
- Step-by-step testing instructions
- Expected behavior documented
- Edge cases covered
3. **Decision Record**
- Why certain approaches were chosen
- Trade-offs considered
- Future reference
4. **Maintenance**
- Easy to modify features later
- Understand dependencies
- Avoid breaking changes
**Note:** I don't actually "read" these files later in the traditional sense. Each conversation is independent. However, these docs are valuable for:
- **You** (the developer) - Reference and knowledge base
- **Team members** - Onboarding and collaboration
- **Future maintenance** - Understanding the system
- **AI assistants** - Can be provided as context in future sessions
---
## 🎯 **Summary & Recommendations**
### **Mobile App:**
✅ **Use PWA** - Perfect for Tabungin's needs, lower cost, faster development
### **Push Notifications:**
✅ **Use Web Push API** - Free, instant, works on all platforms
- Combine with Email for important messages
- WhatsApp for OTP/urgent alerts
### **Documentation:**
✅ **Keep separate files** but organize better
- Create `/docs` folder structure
- Add index/README for navigation
- Group by category (features, guides, planning)
**Would you like me to:**
1. Reorganize the documentation into proper folder structure?
2. Implement Web Push notifications?
3. Add PWA manifest and service worker for mobile installation?

221
docs/planning/todo.md Normal file
View File

@@ -0,0 +1,221 @@
# To-Do List
## 🚀 High Priority
### 3. PWA Implementation
**Status:** Pending
**Priority:** High
**Estimated Time:** 4-6 hours
**Tasks:**
- [ ] Create `manifest.json` for PWA
- App name, icons, theme colors
- Display mode (standalone)
- Start URL and scope
- [ ] Add app icons
- 192x192 icon
- 512x512 icon
- Maskable icons for Android
- Apple touch icons for iOS
- [ ] Create Service Worker
- Cache strategy (network-first for API, cache-first for assets)
- Offline fallback page
- Background sync for transactions
- [ ] Add "Add to Home Screen" prompt
- Detect installation capability
- Show custom install prompt
- Handle installation events
- [ ] Test PWA features
- Install on Android
- Install on iOS (Safari)
- Test offline functionality
- Verify caching works
**Benefits:**
- Users can install app on home screen
- Works offline
- Faster load times
- Native app-like experience
**Resources:**
- [PWA Documentation](https://web.dev/progressive-web-apps/)
- [Workbox (Service Worker library)](https://developers.google.com/web/tools/workbox)
---
### 4. Web Push Notifications
**Status:** Pending
**Priority:** High
**Estimated Time:** 6-8 hours
**Backend Tasks:**
- [ ] Install `web-push` library
```bash
cd apps/api
npm install web-push
```
- [ ] Generate VAPID keys
```typescript
const vapidKeys = webpush.generateVAPIDKeys()
// Add to .env:
// VAPID_PUBLIC_KEY=...
// VAPID_PRIVATE_KEY=...
```
- [ ] Create PushSubscription model (Prisma)
```prisma
model PushSubscription {
id String @id @default(uuid())
userId String
user User @relation(fields: [userId], references: [id])
endpoint String @unique
keys Json
createdAt DateTime @default(now())
@@index([userId])
}
```
- [ ] Create NotificationService
- Subscribe endpoint
- Unsubscribe endpoint
- Send notification method
- Batch send for multiple users
- [ ] Add notification triggers
- Transaction reminders (scheduled)
- Budget alerts (real-time)
- Payment reminders (scheduled)
- Admin alerts (real-time)
**Frontend Tasks:**
- [ ] Request notification permission
- Show permission prompt
- Handle user response
- Store permission status
- [ ] Subscribe to push notifications
- Get service worker registration
- Subscribe with VAPID public key
- Send subscription to backend
- [ ] Handle push events in Service Worker
- Show notification
- Handle notification click
- Open relevant page
- [ ] Add notification preferences UI
- Enable/disable notifications
- Choose notification types
- Set quiet hours
- [ ] Test notifications
- Test on Chrome (Android & Desktop)
- Test on Firefox
- Test on Safari (iOS 16.4+)
- Test notification click actions
**Use Cases:**
1. **Transaction Reminders**
- "Don't forget to log today's expenses!"
- Daily/weekly schedule
2. **Budget Alerts**
- "You've spent 80% of your monthly budget"
- Real-time threshold alerts
3. **Payment Reminders**
- "Subscription payment due in 3 days"
- Scheduled based on payment dates
4. **Goal Progress**
- "You're 50% towards your savings goal! 🎉"
- Milestone notifications
5. **Admin Notifications**
- "New payment verification request"
- "New user registered"
**Resources:**
- [Web Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API)
- [web-push library](https://github.com/web-push-libs/web-push)
- [Notification API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API)
---
## 📋 Medium Priority
### Code Quality
- [ ] Fix ESLint warnings (87 issues)
- Review and fix auth-related warnings
- Fix OTP component warnings
- Fix transaction/wallet warnings
### Testing
- [ ] Add unit tests for critical functions
- [ ] Add integration tests for API endpoints
- [ ] Add E2E tests for main user flows
### Documentation
- [ ] API endpoint documentation (Swagger/OpenAPI)
- [ ] Component documentation (Storybook)
- [ ] Database schema documentation
---
## 🔮 Future Enhancements
### Features
- [ ] Export transactions (CSV, PDF)
- [ ] Recurring transactions
- [ ] Budget categories
- [ ] Multi-currency support
- [ ] Team/family sharing
- [ ] Financial reports and charts
### Admin Features
- [ ] Analytics dashboard
- [ ] User activity logs
- [ ] System health monitoring
- [ ] Backup and restore
### Integrations
- [ ] Bank account sync
- [ ] Receipt scanning (OCR)
- [ ] Cryptocurrency tracking
- [ ] Investment portfolio
---
## ✅ Completed
- [x] Maintenance mode implementation
- [x] Admin auto-redirect after login
- [x] Profile page reuse for admin
- [x] Admin dashboard blocking for regular users
- [x] Admin settings tabbed interface
- [x] Documentation reorganization
---
## 📝 Notes
**Priority Levels:**
- **High:** Should be done soon (within 1-2 weeks)
- **Medium:** Important but not urgent (within 1 month)
- **Low:** Nice to have (when time permits)
**Time Estimates:**
- Based on single developer working full-time
- May vary based on experience and complexity
- Include testing and documentation time
**Update Frequency:**
- Review weekly
- Mark completed items
- Add new items as needed
- Reprioritize based on user feedback