# rez3x/jw_web architecture

> Architecture diagram of the GitHub repository rez3x/jw_web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rez3x/jw_web
- Repository: https://github.com/rez3x/jw_web

## Overview

1. **Overall shape**
   - This repo is a **Next.js App Router frontend** for the JogjaWaskita civic platform.
   - It is not just a UI shell: it functions as a **BFF (Backend-For-Frontend)** that mediates all browser access to the Rust backend.

2. **Primary boundary**
   - The key architectural boundary is between:
     - **Browser/UI** in `src/app` and `src/components`
     - **Backend access** through `src/app/api/...` route handlers
   - The browser should not talk directly to the Rust API. Instead, client-side requests go through Next.js API routes, while server-rendered parts can call backend services during SSR.

3. **Application routing layer**
   - `src/app` contains the user-facing routes:
     - public/community feed
     - auth pages
     - chat
     - post detail
     - profile pages and settings
     - explore/search
     - government dashboard
     - admin panel
     - CCTV view
   - This is the main presentation layer and defines the app’s navigable surfaces.

4. **BFF/API proxy layer**
   - `src/app/api` contains route handlers that proxy or orchestrate backend calls.
   - Major API domains are visible in the tree:
     - `auth`
     - `posts`
     - `comments`
     - `chats`
     - `users`
     - `departments`
     - `analytics`
     - `logs`
     - `votes`
     - `cctv`
     - `dev`
   - The catch-all patterns like `[...slug]` suggest these handlers forward or normalize backend endpoints rather than implementing business logic locally.

5. **Authentication and session model**
   - Auth is centered on **Google OAuth**, **email verification**, and **logout/me** flows.
   - The README says auth uses **HttpOnly cookies**, so token state is kept server-side from the browser’s perspective.
   - `src/components/auth/AuthProvider.js` and `src/lib/auth.js` likely provide client-side auth state and guards, but the authoritative session lives in the backend/cookies, not local storage.

6. **Content and engagement subsystem**
   - The social/reporting core revolves around:
     - posts
     - votes
     - nested comments and subcomments
     - pinned comments
     - post classification
   - The feed (`src/app/HomeFeed.js`) and post components (`src/components/post/*`) imply an infinite-scroll community timeline with detail views, creation flows, media upload, and voting interactions.

7. **Conversation / AI assistant subsystem**
   - `src/app/chat` and `src/app/api/chats` implement a unified chat interface.
   - The README describes it as a **ChatGPT-style civic assistant** with agentic tools, so the UI likely drives backend-assisted conversational workflows rather than a purely local chat experience.
   - `src/components/ui/Markdown` support in the README suggests assistant responses are rendered as formatted content, not plain text.

8. **Government operations subsystem**
   - `src/app/dashboard` is the operational workspace for departments to manage issue queues.
   - The post lifecycle likely maps to states such as **Pending**, **In Progress**, and **Resolved**, with department assignment and classification supporting that workflow.
   - `src/app/api/departments` and post classification endpoints indicate the dashboard depends on structured department metadata.

9. **Admin and observability subsystem**
   - `src/app/admin` plus `src/app/api/logs` and `src/app/api/dev` form a higher-privilege administrative area.
   - This includes user management, role assignment, and log viewing for auditing.
   - The presence of analytics and logs routes suggests the admin UI is backed by operational telemetry, not just user data.

10. **Search/discovery and profiles**
   - `src/app/explore` provides search across posts and a people directory view.
   - `src/app/profile/[username]` and `src/app/profile/settings` expose public profiles and account preferences.
   - These views likely consume shared user/search endpoints and are separate from the feed because they focus on retrieval and identity rather than creation.

11. **CCTV / media-specific subsystem**
   - `src/app/cctv` and `src/components/cctv/*` indicate a dedicated surveillance/media viewing experience.
   - The presence of `HLSPlayer` suggests live/streamed media playback, while `CCTVMap` and `CCTVPanel` suggest a spatial browsing and selection flow.
   - `src/lib/cctv-data.js` likely supplies local metadata or configuration for camera locations.

12. **Shared component and utility layer**
   - `src/components` is organized by domain and reusable UI:
     - layout chrome: navbar, sidebars, trending panel
     - post UI: cards, forms, modals, vote controls
     - comment UI: threads, replies, forms
     - generic UI primitives: buttons, badges, modals, search, skeletons, avatars
   - `src/lib` holds cross-cutting concerns such as API helpers, constants, store/state, and utilities.

13. **Runtime and styling**
   - The stack is **Next.js + React** with **Tailwind CSS v4**.
   - `next.config.mjs`, `postcss.config.mjs`, `biome.json`, and `jsconfig.json` show a standard modern frontend toolchain with lint/format and path alias support.
   - Static assets live under `public/`, which likely holds logos, icons, and media used across the app.

14. **How to diagram the system**
   - The most accurate diagram should show:
     - **Browser → Next.js pages/components**
     - **Client interactions → Next.js API route handlers**
     - **Server-side rendering / route handlers → Rust backend**
     - **Auth state via HttpOnly cookies**
     - **Shared domain models feeding feed, chat, dashboard, admin, explore, and CCTV**
   - In other words, this is a **single frontend repo with multiple domain-specific surfaces, all mediated through a Next.js BFF layer**.

Main entry points: [`src/app`](https://github.com/rez3x/jw_web/tree/main/src/app) (App Router), [`src/components`](https://github.com/rez3x/jw_web/tree/main/src/components) (Components), [`src/app/api/users`](https://github.com/rez3x/jw_web/tree/main/src/app/api/users) (Users API), [`src/app/api/posts`](https://github.com/rez3x/jw_web/tree/main/src/app/api/posts) (Content API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_app_router["App Router<br/>nextjs root"]
  node_home_feed["Home feed<br/>feed page<br/>[HomeFeed.js]"]
  node_auth_pages["Auth pages<br/>route group"]
  node_chat_pages["Chat<br/>route group"]
  node_post_pages["Posts<br/>route group"]
  node_profile_pages["Profiles<br/>route group"]
  node_explore_pages["Explore<br/>discovery page"]
  node_dashboard_page["Dashboard<br/>ops page"]
  node_admin_pages["Admin"]
  node_cctv_pages["CCTV<br/>media page"]
end

subgraph group_bff["BFF API"]
  node_api_root["API routes<br/>bff root"]
  node_api_auth["Auth API<br/>proxy domain"]
  node_api_content["Content API<br/>proxy domain"]
  node_api_chat["Chat API<br/>proxy domain"]
  node_api_ops["Ops API<br/>proxy domain"]
  node_api_telemetry["Telemetry API<br/>proxy domain"]
  node_api_users["Users API<br/>proxy domain"]
  node_api_media["CCTV API<br/>proxy domain"]
end

subgraph group_shared["Shared"]
  node_shared_components["Components<br/>ui library"]
  node_shared_lib["Lib<br/>shared runtime"]
  node_lib_api["API client<br/>helper<br/>[api.js]"]
  node_lib_auth["Auth state<br/>helper<br/>[auth.js]"]
  node_lib_store["Store<br/>state<br/>[store.js]"]
  node_lib_cctv["CCTV data<br/>config<br/>[cctv-data.js]"]
end

subgraph group_external["External"]
  node_browser(("Browser<br/>client"))
  node_rust_backend[("Rust backend")]
end

node_browser -->|"uses"| node_app_router
node_app_router -->|"renders with"| node_shared_components
node_app_router -->|"uses"| node_shared_lib
node_auth_pages -->|"calls"| node_api_auth
node_chat_pages -->|"calls"| node_api_chat
node_post_pages -->|"calls"| node_api_content
node_home_feed -->|"calls"| node_api_content
node_profile_pages -->|"calls"| node_api_users
node_explore_pages -->|"calls"| node_api_users
node_dashboard_page -->|"calls"| node_api_ops
node_admin_pages -->|"calls"| node_api_telemetry
node_admin_pages -->|"calls"| node_api_users
node_cctv_pages -->|"calls"| node_api_media
node_cctv_pages -->|"uses"| node_lib_cctv
node_api_root -->|"proxies"| node_rust_backend
node_api_auth -->|"proxies"| node_rust_backend
node_api_content -->|"proxies"| node_rust_backend
node_api_chat -->|"proxies"| node_rust_backend
node_api_ops -->|"proxies"| node_rust_backend
node_api_telemetry -->|"proxies"| node_rust_backend
node_api_users -->|"proxies"| node_rust_backend
node_api_media -->|"proxies"| node_rust_backend
node_shared_components -->|"uses"| node_lib_api
node_shared_components -->|"uses"| node_lib_auth
node_shared_components -->|"uses"| node_lib_store
node_app_router -->|"hosts"| node_api_root

click node_app_router "https://github.com/rez3x/jw_web/tree/main/src/app"
click node_home_feed "https://github.com/rez3x/jw_web/blob/main/src/app/HomeFeed.js"
click node_auth_pages "https://github.com/rez3x/jw_web/tree/main/src/app/auth"
click node_chat_pages "https://github.com/rez3x/jw_web/tree/main/src/app/chat"
click node_post_pages "https://github.com/rez3x/jw_web/tree/main/src/app/post"
click node_profile_pages "https://github.com/rez3x/jw_web/tree/main/src/app/profile"
click node_explore_pages "https://github.com/rez3x/jw_web/tree/main/src/app/explore"
click node_dashboard_page "https://github.com/rez3x/jw_web/tree/main/src/app/dashboard"
click node_admin_pages "https://github.com/rez3x/jw_web/tree/main/src/app/admin"
click node_cctv_pages "https://github.com/rez3x/jw_web/tree/main/src/app/cctv"
click node_api_root "https://github.com/rez3x/jw_web/tree/main/src/app/api"
click node_api_auth "https://github.com/rez3x/jw_web/tree/main/src/app/api/auth"
click node_api_content "https://github.com/rez3x/jw_web/tree/main/src/app/api/posts"
click node_api_chat "https://github.com/rez3x/jw_web/tree/main/src/app/api/chats"
click node_api_ops "https://github.com/rez3x/jw_web/tree/main/src/app/api/departments"
click node_api_telemetry "https://github.com/rez3x/jw_web/tree/main/src/app/api/analytics"
click node_api_users "https://github.com/rez3x/jw_web/tree/main/src/app/api/users"
click node_api_media "https://github.com/rez3x/jw_web/tree/main/src/app/api/cctv"
click node_shared_components "https://github.com/rez3x/jw_web/tree/main/src/components"
click node_shared_lib "https://github.com/rez3x/jw_web/tree/main/src/lib"
click node_lib_api "https://github.com/rez3x/jw_web/blob/main/src/lib/api.js"
click node_lib_auth "https://github.com/rez3x/jw_web/blob/main/src/lib/auth.js"
click node_lib_store "https://github.com/rez3x/jw_web/blob/main/src/lib/store.js"
click node_lib_cctv "https://github.com/rez3x/jw_web/blob/main/src/lib/cctv-data.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_router,node_home_feed,node_auth_pages,node_chat_pages,node_post_pages,node_profile_pages,node_explore_pages,node_dashboard_page,node_admin_pages,node_cctv_pages toneBlue
class node_api_root,node_api_auth,node_api_content,node_api_chat,node_api_ops,node_api_telemetry,node_api_users,node_api_media toneAmber
class node_shared_components,node_shared_lib,node_lib_api,node_lib_auth,node_lib_store,node_lib_cctv toneMint
class node_browser,node_rust_backend toneRose
```

## Components

### Presentation

App Router surfaces and UI composition

- [App Router](https://github.com/rez3x/jw_web/tree/main/src/app): nextjs root · Top-level Next.js application shell and route tree · `src/app`
- [Home feed](https://github.com/rez3x/jw_web/blob/main/src/app/HomeFeed.js): feed page · Community timeline and entry surface · `src/app/HomeFeed.js`
- [Auth pages](https://github.com/rez3x/jw_web/tree/main/src/app/auth): route group · Login and email verification surfaces · `src/app/auth`
- [Chat](https://github.com/rez3x/jw_web/tree/main/src/app/chat): route group · User conversation surfaces · `src/app/chat`
- [Posts](https://github.com/rez3x/jw_web/tree/main/src/app/post): route group · Post detail and post-related browsing surfaces · `src/app/post`
- [Profiles](https://github.com/rez3x/jw_web/tree/main/src/app/profile): route group · Public profile and settings surfaces · `src/app/profile`
- [Explore](https://github.com/rez3x/jw_web/tree/main/src/app/explore): discovery page · Search and people discovery surface · `src/app/explore`
- [Dashboard](https://github.com/rez3x/jw_web/tree/main/src/app/dashboard): ops page · Department workflow workspace · `src/app/dashboard`
- [Admin](https://github.com/rez3x/jw_web/tree/main/src/app/admin): admin page · Privileged management and audit surfaces · `src/app/admin`
- [CCTV](https://github.com/rez3x/jw_web/tree/main/src/app/cctv): media page · Camera browsing and live stream surface · `src/app/cctv`

### BFF API

Next.js route handlers that proxy and orchestrate backend access

- [API routes](https://github.com/rez3x/jw_web/tree/main/src/app/api): bff root · Next.js route handler layer mediating backend access · `src/app/api`
- [Auth API](https://github.com/rez3x/jw_web/tree/main/src/app/api/auth): proxy domain · Google OAuth, session, and verification flows · `src/app/api/auth`
- [Content API](https://github.com/rez3x/jw_web/tree/main/src/app/api/posts): proxy domain · Posts, comments, and votes endpoints · `src/app/api/posts`
- [Chat API](https://github.com/rez3x/jw_web/tree/main/src/app/api/chats): proxy domain · Chat session and message endpoints · `src/app/api/chats`
- [Ops API](https://github.com/rez3x/jw_web/tree/main/src/app/api/departments): proxy domain · Departments and admin-operational data endpoints · `src/app/api/departments`
- [Telemetry API](https://github.com/rez3x/jw_web/tree/main/src/app/api/analytics): proxy domain · Analytics, logs, and dev/admin observability endpoints · `src/app/api/analytics`
- [Users API](https://github.com/rez3x/jw_web/tree/main/src/app/api/users): proxy domain · User search and profile lookup endpoints · `src/app/api/users`
- [CCTV API](https://github.com/rez3x/jw_web/tree/main/src/app/api/cctv): proxy domain · Camera and media streaming access · `src/app/api/cctv`

### Shared

Reusable components and client-side shared logic

- [Components](https://github.com/rez3x/jw_web/tree/main/src/components): ui library · Reusable layout, post, comment, CCTV, auth, and primitive UI components · `src/components`
- [Lib](https://github.com/rez3x/jw_web/tree/main/src/lib): shared runtime · Cross-cutting client helpers, state, auth, and configuration · `src/lib`
- [API client](https://github.com/rez3x/jw_web/blob/main/src/lib/api.js): helper · Client-side API helper and request plumbing · `src/lib/api.js`
- [Auth state](https://github.com/rez3x/jw_web/blob/main/src/lib/auth.js): helper · Client auth/session helpers and guards · `src/lib/auth.js`
- [Store](https://github.com/rez3x/jw_web/blob/main/src/lib/store.js): state · Shared client-side state management · `src/lib/store.js`
- [CCTV data](https://github.com/rez3x/jw_web/blob/main/src/lib/cctv-data.js): config · Local camera metadata and map data · `src/lib/cctv-data.js`

### External

Runtime boundary outside this repository

- **Browser**: client · End-user runtime that uses the app through pages and API calls
- **Rust backend**: service · Authoritative application backend behind the Next.js BFF

## Connections

- Browser → App Router: uses · Users navigate the App Router surfaces
- App Router → Components: renders with · Pages are composed from shared UI modules
- App Router → Lib: uses · Route-level code relies on shared helpers and state
- Auth pages → Auth API: calls · Login, callback, verify, me, and logout flows go through the auth BFF
- Chat → Chat API: calls · Chat UI reads sessions and sends messages through the chat BFF
- Posts → Content API: calls · Post detail surfaces fetch posts, comments, and votes via the BFF
- Home feed → Content API: calls · Feed loading and engagement actions go through content endpoints
- Profiles → Users API: calls · Profiles and settings use user lookup and account data
- Explore → Users API: calls · Discovery and people search depend on user search endpoints
- Dashboard → Ops API: calls · Department workflow views use structured ops data
- Admin → Telemetry API: calls · Admin views consume logs, analytics, and dev endpoints
- Admin → Users API: calls · User management and role assignment depend on user data
- CCTV → CCTV API: calls · CCTV browsing and stream access go through the media BFF
- CCTV → CCTV data: uses · Camera map and metadata come from local CCTV data
- API routes → Rust backend: proxies · Route handlers forward or orchestrate calls to the Rust backend
- Auth API → Rust backend: proxies · Auth state is backed by backend-managed HttpOnly cookies
- Content API → Rust backend: proxies · Content, comments, and votes are delegated to backend services
- Chat API → Rust backend: proxies · Chat sessions and messages are backend-driven
- Ops API → Rust backend: proxies · Department and dashboard data comes from backend services
- Telemetry API → Rust backend: proxies · Logs and analytics are surfaced from backend telemetry
- Users API → Rust backend: proxies · User identity and directory lookups are delegated upstream
- CCTV API → Rust backend: proxies · Camera and stream access is mediated by the BFF
- Components → API client: uses · Interactive UI components call the shared API client
- Components → Auth state: uses · Auth-aware components consume shared auth state
- Components → Store: uses · Some components coordinate through shared client state
- App Router → API routes: hosts · The application exposes the BFF under the same Next.js runtime
