Skip to content

Firestore Schema

Collections

users

Stores user profile and points data.

users/{userId}
├── name: string
├── email: string
├── phone: string | null
├── avatarUrl: string | null
├── currentPoints: number          # Redeemable points
├── totalPoints: number            # All-time earnings
├── recycledCount: number          # Total items recycled
├── rank: string                   # Bronze, Silver, Gold, Platinum
├── badges: array<string>          # Achievement badges
├── isAdmin: boolean               # Admin access
├── fcmToken: string | null        # Push notification token
├── fcmTokenUpdatedAt: timestamp
├── createdAt: timestamp
│
└── notifications/{notificationId}  # Subcollection
    ├── type: string               # points_earned, offer_redeemed, etc.
    ├── title: string
    ├── message: string
    ├── isRead: boolean
    └── timestamp: timestamp

offers

Partner offers available for redemption.

offers/{offerId}
├── title: string
├── description: string
├── imageUrl: string
├── partnerName: string
├── partnerLogo: string
├── pointsRequired: number
├── isActive: boolean
├── expiresAt: timestamp | null
├── createdAt: timestamp
└── terms: string                  # Terms and conditions

kiosks

Recycling kiosk locations and status.

kiosks/{kioskId}
├── name: string
├── address: string
├── latitude: number
├── longitude: number
├── status: string                 # available, maintenance, offline
├── plasticCount: number           # Total plastic recycled
├── metalCount: number             # Total metal recycled
├── lastUpdated: timestamp
└── createdAt: timestamp

transactions

Recycling transaction history.

transactions/{transactionId}
├── userId: string
├── kioskId: string
├── plasticCount: number
├── metalCount: number
├── points: number
└── timestamp: timestamp

announcements

Admin announcements shown to all users.

announcements/{announcementId}
├── title: string
├── message: string
├── isActive: boolean
├── createdAt: timestamp
└── createdBy: string              # Admin userId

Indexes

Required Firestore composite indexes:

offers

  • isActive (Ascending) + pointsRequired (Ascending)

users (for leaderboard)

  • totalPoints (Descending)

transactions

  • userId (Ascending) + timestamp (Descending)

User Ranks

Rank Points Required
Bronze 0
Silver 500
Gold 1500
Platinum 5000

Points System

Item Type Points
Plastic 10
Metal 10