# kadakwnl/crowd-connect architecture

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

- Interactive diagram: https://gitdiagram.com/kadakwnl/crowd-connect
- Repository: https://github.com/kadakwnl/crowd-connect

## Overview

**CrowdConnect** is a classic **MERN, two-tier web app**:
- **Frontend**: React (Vite) SPA with React Router, Leaflet maps, Axios.
- **Backend**: Node/Express REST API with JWT auth + bcrypt, MongoDB via Mongoose.
- **Purpose**: discover and create local events, with map-based browsing and pin-drop event creation; role-gated “host” capabilities.

- SPA → REST API → MongoDB
- Auth flows (JWT issuance + JWT-protected routes)
- Event/map data flow (events list used to render markers/cards; event creation captures lat/lng)
- Role/authorization constraints (host-only create; owner-only update/delete)

Use the repository structure to drive a **high-fidelity decomposition**.

From `frontend/src`:
- **Entry + routing shell**
- `main.jsx` (bootstraps app)
- `App.jsx` (router/layout orchestration)
- **Pages (route-level components)**: `src/pages/*`
- `Home.jsx` (likely map + event list)
- `EventDetail.jsx`
- `CreateEvent.jsx` (pin-drop / geolocation)
- `ManageEvents.jsx` (host CRUD)
- `AttendeesList.jsx` (implies event-attendance or participants view)
- `HostToggle.jsx` (host status switch)
- `Login.jsx`, `Signup.jsx`
- `UserProfile.jsx`, `About.jsx`
- **Reusable components**
- `components/Navbar.jsx`
- `components/EventCard.jsx`
- **API client / integration point**
- `services/api.js` (Axios wrapper; attaches JWT from `localStorage`)
- **Styling**
- `src/styles/*` including `Leaflet.css` and per-page CSS
- **External dependency shown in README**
- Leaflet / react-leaflet using OpenStreetMap tiles

From `backend/`:
- **App entry**
- `server.js` (Express app, routing mount points, CORS, env, listen)
- **DB connectivity**
- `config/db.js` (connect MongoDB via Mongoose)
- **Models (domain objects)**
- `models/User.js` (includes `isHost` flag; hashed password)
- `models/Event.js` (title/details + geolocation fields; probably owner/user reference)
- **Middleware (cross-cutting)**
- `middleware/auth.js` (JWT verification; attaches user to request; used by protected routes)
- **Routes (REST surface area)**
- `routes/auth.js` → `/api/auth/*` (signup/login issues JWT)
- `routes/users.js` → `/api/users/*` (me, toggle-host)
- `routes/events.js` → `/api/events/*` (CRUD; host-only create; owner-only update/delete)

- Collections correspond to **User** and **Event** Mongoose schemas.

##### Frontend renders
- Leaflet markers (lat/lng from events)
- EventCard list

##### `CreateEvent.jsx` captures lat/lng by
- Click (pin drop), or
- Browser geolocation API (“Use My Location”)

##### Important architectural patterns to highlight (from tree + README)
- **SPA + REST** separation (frontend independent of backend)
- **Express Router modularization** (`routes/*`) + cross-cutting **auth middleware**
- **Mongoose ODM** as data access layer
- **Role-based access** (host flag) and **resource ownership** checks (owner-only updates)
- **External dependency** for mapping tiles (OpenStreetMap) + client-side map rendering (Leaflet)

##### What “very detailed” means for this repo (specific checklist)
- Explicit mention of **localStorage** as token store on the frontend
- Explicit **role constraint**: host-only event creation
- Explicit **owner constraint**: update/delete by owner
- Explicit **Leaflet + OpenStreetMap tiles** dependency (often missed, but core to the product)

## Diagram (Mermaid)

```mermaid
flowchart TD

%% =========================
%% Diagram A — Context / Container (C4-ish)
%% =========================
subgraph "A) Context / Container (runtime boundaries)"
direction TB

U["User (Browser)"]:::external

subgraph "Client"
direction TB
SPA["React SPA (Vite)"]:::frontend
LS[("localStorage\nJWT token store")]:::store
MAP["Leaflet / react-leaflet\n(Map rendering + marker/pin interactions)"]:::external
end

subgraph "Server"
direction TB
API["Express REST API (Node.js)"]:::backend
end

MDB[("MongoDB\n(users,events collections)")]:::database
OSM["OpenStreetMap tile servers"]:::external

U -->|"HTTP(S)\nloads SPA assets"| SPA
SPA -->|"stores JWT"| LS
LS -->|"reads JWT\n(Authorization header injection)"| SPA

SPA -->|"HTTP/JSON (Axios)\nCORS in dev\nAuthorization: Bearer JWT"| API
API -->|"Mongoose queries"| MDB

SPA -->|"Map UI events\nrender markers/pins"| MAP
MAP -->|"HTTPS tile requests\n(raster tiles)"| OSM
end


%% =========================
%% Diagram B — Backend component diagram (Express internals)
%% =========================
subgraph "B) Backend components (Express internals)"
direction TB

subgraph "Express API Server"
direction TB
SRV["server.js\n(Express app + mounts + CORS + listen)"]:::backend
DB["config/db.js\n(Mongoose connection lifecycle)"]:::backend

subgraph "Routers (routes/*)"
direction TB
R_AUTH["routes/auth.js\nPOST /api/auth/signup|login\nIssues JWT"]:::backend
R_USERS["routes/users.js\n/api/users/*\n(me,toggle-host)"]:::backend
R_EVENTS["routes/events.js\n/api/events/*\nCRUD + role/ownership checks"]:::backend
end

MW["middleware/auth.js\n(JWT verify -> req.user)"]:::middleware

subgraph "Models (Mongoose)"
direction TB
M_USER["models/User.js\n(isHost flag, hashed password)"]:::model
M_EVENT["models/Event.js\n(geolocation lat/lng, owner ref)"]:::model
end
end

MDB2[("MongoDB")]:::database

SRV -->|"connect()"| DB
DB -->|"connects via Mongoose"| MDB2

SRV -->|"mounts /api/auth"| R_AUTH
SRV -->|"mounts /api/users"| R_USERS
SRV -->|"mounts /api/events"| R_EVENTS

R_USERS -->|"protected-by"| MW
R_EVENTS -->|"GET public\nPOST/PUT/DELETE protected-by"| MW

R_AUTH -->|"bcrypt hash/compare\n(signup/login)"| M_USER
R_AUTH -->|"creates JWT\n(jwt sign)"| MW

R_USERS -->|"read/update user\n(toggle isHost)"| M_USER
R_EVENTS -->|"read/write events"| M_EVENT
R_EVENTS -->|"lookup owner/host"| M_USER

M_USER -->|"CRUD (Mongoose)"| MDB2
M_EVENT -->|"CRUD (Mongoose)"| MDB2

%% Backend authorization notes
NOTE_HOST["Rule: create event requires user.isHost"]:::note
NOTE_OWNER["Rule: update/delete requires event.owner == req.user.id"]:::note
R_EVENTS -->|"enforces"| NOTE_HOST
R_EVENTS -->|"enforces"| NOTE_OWNER
end


%% =========================
%% Diagram C — Frontend component diagram (SPA routing + API + map)
%% =========================
subgraph "C) Frontend components (SPA routing + API client + map)"
direction TB

subgraph "Entry + Shell"
direction TB
MAIN["main.jsx\n(bootstraps React)"]:::frontend
APP["App.jsx\n(Router/layout orchestration)"]:::frontend
NAV["components/Navbar.jsx"]:::frontend
end

subgraph "Pages (src/pages/*)"
direction TB
P_HOME["pages/Home.jsx\n(map + events list + cards)"]:::frontend
P_DETAIL["pages/EventDetail.jsx"]:::frontend
P_CREATE["pages/CreateEvent.jsx\n(pin-drop + geolocation)"]:::frontend
P_MANAGE["pages/ManageEvents.jsx\n(host CRUD)"]:::frontend
P_ATT["pages/AttendeesList.jsx"]:::frontend
P_TOGGLE["pages/HostToggle.jsx"]:::frontend
P_LOGIN["pages/Login.jsx"]:::frontend
P_SIGNUP["pages/Signup.jsx"]:::frontend
P_PROFILE["pages/UserProfile.jsx"]:::frontend
P_ABOUT["pages/About.jsx"]:::frontend
end

subgraph "Reusable UI"
direction TB
CARD["components/EventCard.jsx"]:::frontend
STYLES["src/styles/*\n(incl. Leaflet.css)"]:::frontend
end

APIJS["services/api.js\n(Axios wrapper + JWT from localStorage)"]:::api

MAP2["Leaflet / react-leaflet\n(Map, markers, click->lat/lng)"]:::external
OSM2["OpenStreetMap tile servers"]:::external
API2["Express REST API"]:::backend

MAIN -->|"renders"| APP
APP -->|"layout includes"| NAV
APP -->|"routes to"| P_HOME
APP -->|"routes to"| P_DETAIL
APP -->|"routes to"| P_CREATE
APP -->|"routes to"| P_MANAGE
APP -->|"routes to"| P_ATT
APP -->|"routes to"| P_TOGGLE
APP -->|"routes to"| P_LOGIN
APP -->|"routes to"| P_SIGNUP
APP -->|"routes to"| P_PROFILE
APP -->|"routes to"| P_ABOUT

P_HOME -->|"renders list"| CARD
P_HOME -->|"GET /api/events"| APIJS
P_DETAIL -->|"GET /api/events/:id"| APIJS

P_LOGIN -->|"POST /api/auth/login\n(receive JWT -> localStorage)"| APIJS
P_SIGNUP -->|"POST /api/auth/signup\n(receive JWT -> localStorage)"| APIJS

P_TOGGLE -->|"PATCH /api/users/toggle-host\n(Authorization: Bearer JWT)"| APIJS
P_MANAGE -->|"host CRUD\nPOST/PUT/DELETE /api/events\n(Authorization: Bearer JWT)"| APIJS

P_CREATE -->|"capture lat/lng\n(map click or browser geolocation)"| MAP2
P_CREATE -->|"POST /api/events\n(host-only; Authorization: Bearer JWT)"| APIJS

P_HOME -->|"render markers\nfrom events lat/lng"| MAP2
P_DETAIL -->|"render event location"| MAP2

MAP2 -->|"HTTPS tile requests"| OSM2

APIJS -->|"HTTP/JSON (Axios)\nAuthorization: Bearer JWT"| API2
end


%% =========================
%% Legend
%% =========================
subgraph "Legend"
direction TB
L1["Blue = Frontend (React components/pages)"]:::frontend
L2["Green = Backend (Express/server/routes)"]:::backend
L3["Purple = Middleware/Models"]:::middleware
L4["Orange = Data store (MongoDB)"]:::database
L5["Gray = External services (OSM tiles / Leaflet runtime)"]:::external
L6["Protected route = requires Authorization: Bearer JWT\nJWT verified by middleware -> req.user"]:::note
end


%% =========================
%% Click events (from component_mapping)
%% =========================
click MAIN "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/main.jsx"
click APP "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/App.jsx"

click P_HOME "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/Home.jsx"
click P_DETAIL "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/EventDetail.jsx"
click P_CREATE "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/CreateEvent.jsx"
click P_MANAGE "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/ManageEvents.jsx"
click P_ATT "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/AttendeesList.jsx"
click P_TOGGLE "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/HostToggle.jsx"
click P_LOGIN "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/Login.jsx"
click P_SIGNUP "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/Signup.jsx"
click P_PROFILE "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/UserProfile.jsx"
click P_ABOUT "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/pages/About.jsx"

click NAV "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/components/Navbar.jsx"
click CARD "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/components/EventCard.jsx"
click APIJS "https://github.com/kadakwnl/crowd-connect/blob/main/frontend/src/services/api.js"
click STYLES "https://github.com/kadakwnl/crowd-connect/tree/main/frontend/src/styles/"
click P_HOME "https://github.com/kadakwnl/crowd-connect/tree/main/frontend/src/pages/"

click SRV "https://github.com/kadakwnl/crowd-connect/blob/main/backend/server.js"
click DB "https://github.com/kadakwnl/crowd-connect/blob/main/backend/config/db.js"
click MW "https://github.com/kadakwnl/crowd-connect/blob/main/backend/middleware/auth.js"
click R_AUTH "https://github.com/kadakwnl/crowd-connect/blob/main/backend/routes/auth.js"
click R_USERS "https://github.com/kadakwnl/crowd-connect/blob/main/backend/routes/users.js"
click R_EVENTS "https://github.com/kadakwnl/crowd-connect/blob/main/backend/routes/events.js"
click M_USER "https://github.com/kadakwnl/crowd-connect/blob/main/backend/models/User.js"
click M_EVENT "https://github.com/kadakwnl/crowd-connect/blob/main/backend/models/Event.js"


%% =========================
%% Styles
%% =========================
classDef frontend fill:#d7ebff,stroke:#1d4ed8,stroke-width:1.5px,color:#0b1b3a
classDef backend fill:#d1fae5,stroke:#047857,stroke-width:1.5px,color:#052e1a
classDef api fill:#c7d2fe,stroke:#4338ca,stroke-width:1.5px,color:#111827
classDef middleware fill:#ede9fe,stroke:#6d28d9,stroke-width:1.5px,color:#1f1147
classDef model fill:#f5d0fe,stroke:#a21caf,stroke-width:1.5px,color:#2a0a2a
classDef database fill:#ffedd5,stroke:#c2410c,stroke-width:1.5px,color:#2b1607
classDef external fill:#e5e7eb,stroke:#374151,stroke-width:1.5px,color:#111827
classDef store fill:#fff7ed,stroke:#9a3412,stroke-width:1.5px,color:#2b1607
classDef note fill:#fef9c3,stroke:#a16207,stroke-width:1.2px,color:#2a1c00
```
