TrailTastic Logo

TrailTastic V2 Firestore & Storage Schema

V2 collections, atomic Storage bundles, and security rules flowcharts

Back to Summary

V2 Schema Cutover

Legacy V1 collections (/trailSystems, trails, and /waypoints) have been removed from this V2 reference. They remain active in Firestore during the mobile transition window while all V2 vector geometry & POIs live inside atomic systems_v2/{systemId}/{systemId}.geojson.gz bundles paired with /trailSystems_v2.

V2 Database & Storage Relationships

Active V2 production collections and their links to Cloud Storage bundles.

users Root Coll

Rider profiles, app preferences, favorites, and admin flags.

↳ equipment Subcollection

Registered vehicles, machines, and ride gear.

trailSystems_v2 V2 Root

System metadata, bounds, ownership, visibility, and rating scale.

↳ systems_v2/{id}/*.geojson.gz

Atomic Gzip GeoJSON bundle (tracks + waypoints + topology).

trailIssues / basepngs Linked via systemId
tracks Root Coll

Recorded rider GPX logs linked to ownerId & trailSystem.

feedback Write-only
app_config Runtime flags

Security Rules Flowcharts (firestore.rules & storage.rules)

Decision paths enforced on every V2 Firestore document operation and Cloud Storage bundle/image request.

Super Admin UID: xBKs52...Wq1

1. firestore.rules — /trailSystems_v2/{systemId} & Subcollections

allow list: if true (client UI filters private/shared)
READ: get & /{subcollection}/{docId}
Is isSuperAdmin() or resource == null?
YES → ALLOW
NO ↓
Is user signed in (request.auth != null)?
YES (Signed In)

• accessLevel != 'private' (public/shared) → ALLOW

• 'private' → ALLOW only if ownerId or in adminUIDs

NO ("Skip")

• accessLevel omitted or 'public' AND isPaid != true → ALLOW

• Otherwise → DENY

CREATE: /trailSystems_v2/{systemId}
Is isSuperAdmin()?
YES → ALLOW (Any)
NO (Community) ↓
Must pass ALL checks:
1. Signed in & ownerId == auth.uid
2. accessCategory == 'community'
3. accessLevel in ['public', 'shared', 'private']
4. adminUIDs is exact 2-item list [auth.uid, superAdmin]
5. systemId (if set) == doc ID & sharedUIDs is list
ALL PASS → ALLOW
ANY FAIL → DENY
UPDATE: /trailSystems_v2/{systemId}
Is isSuperAdmin()? → ALLOW, else ↓
1. Caller is ownerId OR in adminUIDs
2. Immutable keys untouched: ownerId, systemId, adminUIDs
3. accessCategory locked (no switching community → official)
4. Changing accessLevel or sharedUIDs → ownerId only
5. Valid types/enums for accessLevel & sharedUIDs
Note: Subcollection create/update/delete allows Super Admin, ownerId, or adminUIDs.
DELETE: /trailSystems_v2/{systemId}
Is isSuperAdmin()?
YES → ALLOW
NO ↓
1. Signed in & ownerId == auth.uid (admins cannot delete)
2. accessCategory != 'official'
3. System is 'community' (or missing category) OR accessLevel == 'private'
Delete Order: Delete Storage .geojson.gz before deleting this Firestore doc, because storage.rules reads this doc to authorize deletion.

2. storage.rules — Cross-Service Checks via Firestore /trailSystems_v2/{systemId}

Applies to systems_v2/ & basepngs/
systems_v2/{systemId}/{allPaths=**}
GET (Download): Super Admin OR Firestore doc exists AND:
• Signed in & (accessLevel != 'private' OR owner/admin)
• Unauthenticated & public + isPaid != true
LIST: Super Admin OR signed-in ownerId / adminUIDs
DELETE: Super Admin OR ownerId when accessCategory != 'official' (must run while Firestore doc still exists)
Bundle Uploads & basepngs/{fileName}
systems_v2/{systemId}/{fileName} (create/update):
• Super Admin → ALLOW (any size)
• Owner/Admin → filename {systemId}.geojson.gz or trails.geojson.gz, gzip contentType, Firestore doc exists, and official OR size <= 3 MB
basepngs/{fileName}: Read = public (true); Write = Super Admin OR signed-in image/* <= 15 MB (non-placeholder); Delete = Super Admin only.

3. Role-Based Access & Sharing Flow — 6 Personas (Current Live vs. Planned)

Visualizing how Super Admin, ownerId, adminUIDs, sharedUIDs, Authenticated, and Non-Authenticated users resolve across V2 systems.
LIVE = Enforced Today PLANNED = Target Sharing Flow
A. Decision Waterfall: Who Is Making the Request?
Incoming Request to /trailSystems_v2/{systemId} or systems_v2/{systemId}/...
1. Non-Authenticated ("Skip") auth == null
• READ: Only public + free (isPaid != true).
• BLOCKED: shared, private, isPaid == true, and all writes.
• LIVE allow list: if true returns directory docs (UI hides private/shared); PLANNED scoped public query lets rules lock list too.
2. Authenticated User (Signed In) auth != null
Evaluated top-down against the system's identity fields ↓
① Super Admin (uid == xBKs52...Wq1) → Full read, edit, share, & delete on every system (official + community, no 3 MB cap).
② Owner (uid == ownerId) → See/edit/upload bundle for own public/shared/private, manage accessLevel & sharedUIDs, delete non-official system.
③ Assigned Admin (uid in adminUIDs) → See & edit trails/metadata/bundles on public/shared/private. Cannot change visibility/sharing or delete system.
④ Shared User (uid in sharedUIDs) → See & download public and shared systems (view-only). Blocked from private and all edits/deletes.
⑤ Other Signed-In Rider (not in owner/admin/shared) → See & download public systems (paywall in UI if isPaid); blocked from private. See shared difference below ↓
B. 6-Role Permission Breakdown (Current Live vs. Planned)
1. Super Admin uid == xBKs52...Wq1
public: Allow
shared: Allow
private: Allow
Edit Trails & Bundle: Allow (no 3 MB cap, official & community)
Share / Visibility / Admins: Allow (all fields editable)
Delete System: Allow (any system + basepngs/)
2. Owner uid == doc.ownerId
public: Allow
shared: Allow
private: Allow
Edit Trails & Bundle: Allow (≤ 3 MB for community)
Share / Visibility / Admins:
LIVE Can change accessLevel & sharedUIDs (adminUIDs locked)
PLANNED Share UI + optional co-admin invite (adminUIDs)
Delete System: Allow (non-official only; Storage first)
3. Assigned Admin uid in doc.adminUIDs
public: Allow
shared: Rules + Web*
private: Rules + Web*
*Visibility on shared & private:
LIVE Rules + Web UI allow; iOS/Android filters omit adminUIDs
PLANNED Web + iOS + Android UIs all check adminUIDs
Edit Trails & Bundle: Allow (≤ 3 MB for community)
Share / Visibility / Delete: Deny (Owner / Super Admin only)
4. Shared User uid in doc.sharedUIDs
public: Allow*
shared: Allow
private: Deny
shared Access:
LIVE View-only in Web & Mobile UIs + Rules allow (*paywall if isPaid)
PLANNED Invite / share-link flow adds UID to sharedUIDs
Edit Trails & Bundle: Deny (View-only)
Share / Visibility / Delete: Deny
5. Authenticated User auth != null (other)
public: Allow*
shared: Slug*
private: Deny
*shared Behavior:
LIVE Hidden in directory UI, but Rules allow get by systemId ("Join via Slug")
PLANNED Rules deny get unless uid in sharedUIDs (or redeemed via invite token)
Edit / Share / Delete: Deny on others' systems (can create 1 own community system; public subject to isPaid)
6. Non-Authenticated ("Skip") request.auth == null
public: Free only
shared: Deny
private: Deny
Read / Download: Allow only if public AND isPaid != true (isPaid == true is blocked at Rules)
Directory Query (list):
LIVE allow list: if true (UI hides shared & private)
PLANNED Scoped public query lets list rules block shared/private too
Create / Edit / Delete: Deny
Current Live Sharing Behavior (Today)
1. Directory Fetch: allow list: if true returns all docs; Web/iOS/Android filter out private & shared in client UI.
2. Shared Enforcement Gap: sharedUIDs is only checked in client UIs. Firestore get & Storage get still let any signed-in user fetch a shared system if they know its systemId.
3. Mobile Admin Gap: Web checks adminUIDs for shared/private, while iOS & Android directory filters currently check only ownerId & sharedUIDs.
4. No Sharing UI Yet: Owners cannot yet invite riders by email/link to populate sharedUIDs or promote co-admins into adminUIDs.
Planned Sharing Architecture (Target Flow)
1. Owner Invites / Share Link: Owner sets accessLevel = 'shared' and invites riders (by email/handle or share link) as Viewer (sharedUIDs) or Co-Admin (adminUIDs via Cloud Function).
2. Strict Rules Gate on shared: Tighten canSignedInReadV2System & Storage canSignedInGetV2System so shared requires ownerId, adminUIDs, or uid in sharedUIDs (blocking uninvited slug guessing).
3. Scoped Queries Everywhere: Replace unfiltered .get() with scoped queries (public + ownerId + adminUIDs + sharedUIDs) on iOS, Android, & Web so allow list can also lock down private/shared.
4. Mobile Parity: Add adminUIDs check to iOS & Android filters so assigned admins see & edit shared/private parks on all platforms.
Path Read Access Write / Delete Access
/users/{uid} (+ equipment) Owner (auth.uid == uid) or Super Admin Owner (auth.uid == uid) only
/tracks/{trackId} & Storage /tracks/{uid} Firestore: isPublic, owner, or Super Admin; Storage: any signed-in user Owner (ownerId == auth.uid) only
/trailIssues/{issueId} Public (true) Create: signed-in (reporterUid == uid, status == 'open'); Update: signed-in status updates (core fields immutable)
/feedback & /testers Denied (false) — write-only Create: public (true); Update/Delete: denied (false)
/app_config/{docId} Public (true) Super Admin only
/tracksVideo/{trackId} Public (true) Any signed-in user

Planned Features & Schema Roadmap

Experimental structures, feature brainstorms, and work-in-progress collections reserved for future releases.

Future Roadmap

tracksVideo In Development

/tracksVideo/{id}

Designed to link video assets, offset markers, and multi-segment playback configs to ride tracks for video map synchronization features.

Fields: trackId, youtubeVideoId, startOffsetSeconds, localVideoName, videoSegments [ ]

subscriptions Future Brainstorm

/users/{uid}/subscriptions/{systemId}

Proposed user subcollection for managing paid trail system subscriptions, start/end validity dates, auto-renew status, and offline trailhead access tokens.

Fields: trailSystemId, status, startDate, endDate, autoRenew, paymentProvider