# chandan9335/campusboard architecture

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

- Interactive diagram: https://gitdiagram.com/chandan9335/campusboard
- Repository: https://github.com/chandan9335/campusboard

## Overview

1. **This is a browser-only React SPA**
   The repository is a Vite + React front end with no custom backend service. `src/main.jsx` bootstraps the app, `src/App.jsx` wires the top-level layout/routes, and all persistent state lives in Supabase.

2. **Supabase is the system boundary**
   `src/supabaseClient.js` is the single integration point to Supabase. The app uses Supabase for four distinct concerns: authentication, PostgreSQL data, Storage for avatars, and Realtime subscriptions.

3. **Authentication is centralized in context**
   `src/context/AuthContext.jsx` owns the current session/user state and exposes auth actions to the rest of the app. The login/signup pages (`src/pages/Login.jsx`, `src/pages/Signup.jsx`) feed into this context, which is what the rest of the UI uses to know whether a user is signed in.

4. **Route access is protected at the page boundary**
   `src/routes/ProtectedRoute.jsx` gates authenticated screens such as the dashboard/profile area. Public routes are the auth screens; protected routes depend on the session from `AuthContext`.

5. **The app is organized by route-level pages and reusable components**
   `src/pages/` contains the main screens: `Dashboard`, `Profile`, `Login`, and `Signup`. `src/components/` contains the reusable UI pieces that those pages assemble: navigation, notice cards/forms, notification bell, and avatar upload.

6. **Notices are the main CRUD entity**
   The `notices` table in Supabase is the app’s primary shared feed. `src/hooks/useNotices.js` encapsulates fetching and mutating notices, while `NoticeForm.jsx` creates new rows and `NoticeCard.jsx` renders individual entries. The database row-level policies allow public reads but restrict writes to the owner.

7. **Realtime updates drive the live feed**
   `src/hooks/useRealtimeNotices.js` subscribes to notice changes so the dashboard updates without a manual refresh. This is the live “feed” path: database insert/update/delete events in Supabase Realtime flow back into the React UI.

8. **Notifications are a separate user-scoped channel**
   The `notifications` table is private to each user, and `src/hooks/useNotifications.js` plus `src/components/NotificationBell.jsx` present the unread/read state in the UI. Unlike notices, notifications are not public; each user only sees their own rows.

9. **Notice creation also triggers a notification pipeline**
   The README describes a Supabase trigger that inserts notification rows after a notice is created. That means a notice insert fan-outs into a second table write, and the bell component can reflect that change through the Realtime subscription path.

10. **Profile data and avatar storage are separate from auth**
    `src/pages/Profile.jsx` handles profile metadata backed by the `profiles` table, while `src/components/AvatarUpload.jsx` uploads files into the public `avatars` Storage bucket. The storage path is user-scoped so the logged-in user owns the upload location.

11. **Data access is split by visibility rules in Supabase**
    Profiles and notices are readable broadly, but notifications are private and avatar uploads are constrained by storage policies. This means the architecture relies heavily on Supabase RLS policies to enforce ownership and visibility, not on client-side checks alone.

12. **Utility and presentation layers stay thin**
    `src/utils/formatDate.js` is a small shared formatting helper, and `src/index.css` provides lightweight global styling. The important architectural work happens in the auth context, data hooks, and Supabase-backed tables, not in custom UI state management.

Main entry points: [`src/App.jsx`](https://github.com/chandan9335/campusboard/blob/main/src/App.jsx) (App), [`src/pages/Dashboard.jsx`](https://github.com/chandan9335/campusboard/blob/main/src/pages/Dashboard.jsx) (Dashboard), [`src/supabaseClient.js`](https://github.com/chandan9335/campusboard/blob/main/src/supabaseClient.js) (Supabase Client), [`src/context/AuthContext.jsx`](https://github.com/chandan9335/campusboard/blob/main/src/context/AuthContext.jsx) (Auth Context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app["App Shell"]
  node_node_main["Entry<br/>bootstrap<br/>[main.jsx]"]
  node_node_app["App<br/>shell<br/>[App.jsx]"]
  node_node_protected_route["Protected Route<br/>route guard<br/>[ProtectedRoute.jsx]"]
  node_node_auth_context["Auth Context<br/>session state<br/>[AuthContext.jsx]"]
end

subgraph group_group_ui["UI Surface"]
  node_node_login["Login<br/>page<br/>[Login.jsx]"]
  node_node_signup["Signup<br/>page<br/>[Signup.jsx]"]
  node_node_dashboard["Dashboard<br/>page<br/>[Dashboard.jsx]"]
  node_node_profile["Profile<br/>page<br/>[Profile.jsx]"]
  node_node_navbar["Navbar<br/>[Navbar.jsx]"]
  node_node_notice_form["Notice Form<br/>[NoticeForm.jsx]"]
  node_node_notice_card["Notice Card<br/>[NoticeCard.jsx]"]
  node_node_notification_bell(("Bell"))
  node_node_avatar_upload["Avatar Upload<br/>[AvatarUpload.jsx]"]
end

subgraph group_group_data["Data Layer"]
  node_node_use_notices["useNotices<br/>hook<br/>[useNotices.js]"]
  node_node_use_realtime["useRealtimeNotices<br/>hook"]
  node_node_use_notifications["useNotifications<br/>hook"]
  node_node_format_date["Format Date<br/>helper<br/>[formatDate.js]"]
end

subgraph group_group_supabase["Supabase"]
  node_node_supabase_client["Supabase Client<br/>integration<br/>[supabaseClient.js]"]
end

node_node_main -->|"boots"| node_node_app
node_node_app -->|"provides auth"| node_node_auth_context
node_node_app -->|"guards pages"| node_node_protected_route
node_node_app -->|"public route"| node_node_login
node_node_app -->|"public route"| node_node_signup
node_node_app -->|"protected route"| node_node_dashboard
node_node_app -->|"protected route"| node_node_profile
node_node_dashboard -->|"uses"| node_node_navbar
node_node_dashboard -->|"creates notices"| node_node_notice_form
node_node_dashboard -->|"lists notices"| node_node_notice_card
node_node_dashboard -->|"shows alerts"| node_node_notification_bell
node_node_profile -->|"uploads avatar"| node_node_avatar_upload
node_node_login -->|"signs in"| node_node_auth_context
node_node_signup -->|"registers"| node_node_auth_context
node_node_auth_context -->|"auth session"| node_node_supabase_client
node_node_use_notices -->|"reads writes"| node_node_supabase_client
node_node_use_realtime -->|"subscribes"| node_node_supabase_client
node_node_use_notifications -->|"reads writes"| node_node_supabase_client
node_node_notice_form -->|"creates"| node_node_use_notices
node_node_notice_card -->|"formats time"| node_node_format_date
node_node_notification_bell -->|"reads state"| node_node_use_notifications
node_node_avatar_upload -->|"uploads"| node_node_supabase_client
node_node_use_realtime -->|"live feed"| node_node_dashboard

click node_node_main "https://github.com/chandan9335/campusboard/blob/main/src/main.jsx"
click node_node_app "https://github.com/chandan9335/campusboard/blob/main/src/App.jsx"
click node_node_protected_route "https://github.com/chandan9335/campusboard/blob/main/src/routes/ProtectedRoute.jsx"
click node_node_auth_context "https://github.com/chandan9335/campusboard/blob/main/src/context/AuthContext.jsx"
click node_node_login "https://github.com/chandan9335/campusboard/blob/main/src/pages/Login.jsx"
click node_node_signup "https://github.com/chandan9335/campusboard/blob/main/src/pages/Signup.jsx"
click node_node_dashboard "https://github.com/chandan9335/campusboard/blob/main/src/pages/Dashboard.jsx"
click node_node_profile "https://github.com/chandan9335/campusboard/blob/main/src/pages/Profile.jsx"
click node_node_navbar "https://github.com/chandan9335/campusboard/blob/main/src/components/Navbar.jsx"
click node_node_notice_form "https://github.com/chandan9335/campusboard/blob/main/src/components/NoticeForm.jsx"
click node_node_notice_card "https://github.com/chandan9335/campusboard/blob/main/src/components/NoticeCard.jsx"
click node_node_notification_bell "https://github.com/chandan9335/campusboard/blob/main/src/components/NotificationBell.jsx"
click node_node_avatar_upload "https://github.com/chandan9335/campusboard/blob/main/src/components/AvatarUpload.jsx"
click node_node_use_notices "https://github.com/chandan9335/campusboard/blob/main/src/hooks/useNotices.js"
click node_node_use_realtime "https://github.com/chandan9335/campusboard/blob/main/src/hooks/useRealtimeNotices.js"
click node_node_use_notifications "https://github.com/chandan9335/campusboard/blob/main/src/hooks/useNotifications.js"
click node_node_format_date "https://github.com/chandan9335/campusboard/blob/main/src/utils/formatDate.js"
click node_node_supabase_client "https://github.com/chandan9335/campusboard/blob/main/src/supabaseClient.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_node_main,node_node_app,node_node_protected_route,node_node_auth_context toneBlue
class node_node_login,node_node_signup,node_node_dashboard,node_node_profile,node_node_navbar,node_node_notice_form,node_node_notice_card,node_node_notification_bell,node_node_avatar_upload toneAmber
class node_node_use_notices,node_node_use_realtime,node_node_use_notifications,node_node_format_date toneMint
class node_node_supabase_client toneRose
```

## Components

### App Shell

Bootstrapping, routing, and auth-protected page composition.

- [Entry](https://github.com/chandan9335/campusboard/blob/main/src/main.jsx): bootstrap · Vite entry point that mounts the React app. · `src/main.jsx`
- [App](https://github.com/chandan9335/campusboard/blob/main/src/App.jsx): shell · Top-level layout and route wiring. · `src/App.jsx`
- [Protected Route](https://github.com/chandan9335/campusboard/blob/main/src/routes/ProtectedRoute.jsx): route guard · Gate for authenticated screens. · `src/routes/ProtectedRoute.jsx`
- [Auth Context](https://github.com/chandan9335/campusboard/blob/main/src/context/AuthContext.jsx): session state · Central session and auth action state for the app. · `src/context/AuthContext.jsx`

### UI Surface

Route-level pages and reusable visual components.

- [Login](https://github.com/chandan9335/campusboard/blob/main/src/pages/Login.jsx): page · Public sign-in screen. · `src/pages/Login.jsx`
- [Signup](https://github.com/chandan9335/campusboard/blob/main/src/pages/Signup.jsx): page · Public account creation screen. · `src/pages/Signup.jsx`
- [Dashboard](https://github.com/chandan9335/campusboard/blob/main/src/pages/Dashboard.jsx): page · Main signed-in feed and overview screen. · `src/pages/Dashboard.jsx`
- [Profile](https://github.com/chandan9335/campusboard/blob/main/src/pages/Profile.jsx): page · Signed-in user profile screen. · `src/pages/Profile.jsx`
- [Navbar](https://github.com/chandan9335/campusboard/blob/main/src/components/Navbar.jsx): Shared top-level navigation. · `src/components/Navbar.jsx`
- [Notice Form](https://github.com/chandan9335/campusboard/blob/main/src/components/NoticeForm.jsx): Creates new notice rows. · `src/components/NoticeForm.jsx`
- [Notice Card](https://github.com/chandan9335/campusboard/blob/main/src/components/NoticeCard.jsx): Renders a single notice item. · `src/components/NoticeCard.jsx`
- [Bell](https://github.com/chandan9335/campusboard/blob/main/src/components/NotificationBell.jsx): Unread/read notification indicator. · `src/components/NotificationBell.jsx`
- [Avatar Upload](https://github.com/chandan9335/campusboard/blob/main/src/components/AvatarUpload.jsx): Uploads user avatar files. · `src/components/AvatarUpload.jsx`

### Data Layer

Supabase client, hooks, and shared formatting helpers.

- [useNotices](https://github.com/chandan9335/campusboard/blob/main/src/hooks/useNotices.js): hook · Fetches and mutates notices. · `src/hooks/useNotices.js`
- [useRealtimeNotices](https://github.com/chandan9335/campusboard/blob/main/src/hooks/useRealtimeNotices.js): hook · Subscribes to live notice changes. · `src/hooks/useRealtimeNotices.js`
- [useNotifications](https://github.com/chandan9335/campusboard/blob/main/src/hooks/useNotifications.js): hook · Fetches and tracks user notifications. · `src/hooks/useNotifications.js`
- [Format Date](https://github.com/chandan9335/campusboard/blob/main/src/utils/formatDate.js): helper · Shared date formatting helper. · `src/utils/formatDate.js`

### Supabase

External system boundary for auth, database, storage, and realtime.

- [Supabase Client](https://github.com/chandan9335/campusboard/blob/main/src/supabaseClient.js): integration · Single client entry to Supabase services. · `src/supabaseClient.js`

## Connections

- Entry → App: boots · Application entry mounts the top-level app.
- App → Auth Context: provides auth · App composition depends on session state.
- App → Protected Route: guards pages · Protected routes wrap authenticated screens.
- App → Login: public route · Login page is reachable without auth.
- App → Signup: public route · Signup page is reachable without auth.
- App → Dashboard: protected route · Dashboard is shown only to signed-in users.
- App → Profile: protected route · Profile is shown only to signed-in users.
- Dashboard → Navbar: uses · Dashboard assembles shared navigation.
- Dashboard → Notice Form: creates notices · Dashboard includes the notice creation flow.
- Dashboard → Notice Card: lists notices · Dashboard renders notice entries.
- Dashboard → Bell: shows alerts · Dashboard surfaces notification state.
- Profile → Avatar Upload: uploads avatar · Profile manages avatar upload UI.
- Login → Auth Context: signs in · Login drives auth actions through context.
- Signup → Auth Context: registers · Signup drives auth actions through context.
- Auth Context → Supabase Client: auth session · Auth state is backed by Supabase auth.
- useNotices → Supabase Client: reads writes · Notice CRUD goes through the Supabase client.
- useRealtimeNotices → Supabase Client: subscribes · Realtime notice updates come from Supabase.
- useNotifications → Supabase Client: reads writes · Notification state is loaded from Supabase.
- Notice Form → useNotices: creates · Form delegates notice creation to the hook.
- Notice Card → Format Date: formats time · Notice timestamps use the shared formatter.
- Bell → useNotifications: reads state · Bell renders notification data from the hook.
- Avatar Upload → Supabase Client: uploads · Avatar files are stored through Supabase Storage.
- useRealtimeNotices → Dashboard: live feed · Realtime events drive dashboard updates.
