fplaces Frontend Integration Guide

Backend Engineer: Sunday Ajayi

This guide breaks down the division of responsibilities between the stateless REST API (used for fetching static data and initiating actions) and the WebSocket layer (used exclusively for receiving real-time live updates).

All REST endpoints require the Authorization: Bearer <access_token> header, and all WebSockets require the token to be passed as a query parameter ?token=<access_token>.


PART 1: Fan / User Application

This section covers the standard mobile or web application used by venue visitors.

1. Setup, Authentication, & Onboarding (REST)

The authentication flow uses SimpleJWT. The backend is stateless, so your client must store the access and refresh tokens securely.

2. Venue Selection & Initial Feed Load (REST)

When a user opens the app and selects a venue, fetch the historical state of that venue.

3. The Live Feed & Heatmap (WebSocket)

Immediately after fetching the initial feed, establish a WebSocket connection to the venue's room:
ws://<domain>/ws/venues/<venue_id>/?token=<access_token>

You never send data up this socket. It is purely for receiving live JSON broadcasts:

  1. new_post:
    • Payload: The full JSON object of the newly created post.
    • Action: Unshift/prepend it to your feed state.
  2. upvote_update:
    • Payload: {"post_id": 123, "upvotes_count": 5, "upvoted": true}
    • Action: Find post 123 in your state and update its count.
  3. post_hidden:
    • Payload: {"post_id": 123}
    • Action: Immediately remove post 123 from the UI.
  4. section_heat_update:
    • Payload: {"heatmap": [{"section_id": 4, "post_count": 8, "priority": "high"}, ...]}
    • Action: Overwrite your entire UI venue map state with this array. Map the priority string ("high", "medium", "low") directly to your CSS glowing colors. Any missing section ID has 0 posts and is neutral.
  5. presence_update:
    • Payload: {"online_count": 42}
    • Action: Dynamically update the "live users" counter shown on the venue map screen. This tracks unique users actively connected to the venue room.

4. Comments (WebSocket & REST)

Each post has its own flat (1-level) comment thread. Unlike section conversations, comments are broadcast over the same venue room used for the live feed (Part 1, Section 3) rather than a socket of their own.

5. User Interactions (REST)

When the user does something, fire a REST request. If successful, the backend automatically broadcasts the result over the WebSocket.

6. Personal Notifications (WebSocket & REST)

Users have a personal WebSocket for cross-venue, account-level alerts.

7. Location (Map Pin) Conversations (WebSocket & REST)

Map-area chat is keyed by (venue, location_id), where location_id is the Mappedin location/place id the fan tapped on the map — not an admin Section PK (see Part 1, Section 2 for those). The client never creates a conversation id and never needs an admin to pre-seed anything for a location: the first message for a never-seen location_id auto-creates its channel.

Admin Sections (North Stand / South Stand / VIP) are unaffected and still used for onboarding, the venue post feed's optional section, and the heatmap — they are a separate, much smaller catalog and are never auto-created from map pins.


PART 2: Admin / Moderator Dashboard

This section covers the web-based administrative panel used by staff. Accessing these endpoints requires an account with is_staff=True or user_type=admin.

1. Dashboard Authentication (REST)

Admins log in using the exact same login endpoints as users (POST /api/users/login/). Ensure your dashboard checks if the decoded JWT belongs to an admin before allowing entry.

2. Platform Statistics Overview (REST)

Used to render the charts and metric cards on the admin homepage.

3. Content Moderation (REST)

Admins have elevated visibility into all content, including posts hidden from the public.

4. User Management (REST)

Complete control over user accounts.

5. Broadcast Notifications (REST)

Send a targeted push and/or email blast to users matched by venue, section, category, or explicit user ids (a union of whichever filters are provided — at least one is required).