# burakorkmez/mern-thinkboard architecture

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

- Interactive diagram: https://gitdiagram.com/burakorkmez/mern-thinkboard
- Repository: https://github.com/burakorkmez/mern-thinkboard

## Overview

##### Project type & purpose (what you’re diagramming)
This is a **full-stack MERN note-taking application** with:
- **React (Vite) frontend** for a responsive UI
- **Node + Express backend** exposing a **REST API** for CRUD operations on notes
- **MongoDB** as the primary datastore (via `MONGO_URI`)
- **Upstash Redis** used for **rate limiting** (a cross-cutting concern applied as middleware)

##### Top-level
- `/frontend`: React UI (Vite + Tailwind)
- `/backend`: Express server, routes, controllers, models, middleware, config

##### Backend (`/backend/src`)
Key architectural layers are clearly separated:
- `server.js`: **entrypoint** / Express app creation, middleware registration, route mounting, listening
- `routes/notesRoutes.js`: **HTTP route definitions** (REST endpoints)
- `controllers/notesController.js`: **request handlers** implementing business logic
- `models/Note.js`: **data model / schema** (Mongo/Mongoose style)
- `config/db.js`: **MongoDB connection**
- `config/upstash.js`: **Upstash Redis client/config**
- `middleware/rateLimiter.js`: **rate limiting middleware** (calls Upstash Redis)

This is a classic **Express layered architecture**: `server -> middleware -> routes -> controllers -> models -> database`.

##### Frontend (`/frontend/src`)
- `main.jsx`, `App.jsx`: app bootstrap + routing/layout composition
- `pages/*`: route-level screens (Home/Create/Detail)
- `components/*`: reusable UI (Navbar, NoteCard, etc.)
- `lib/axios.js`: centralized HTTP client configuration (base URL, interceptors if any)
- `lib/utils.js`: helper functions
- Tailwind config indicates UI styling approach; include it as a note but not a runtime “component”.

##### React Frontend (Vite app)
- Pages: `HomePage`, `CreatePage`, `NoteDetailPage`
- Components: `Navbar`, `NoteCard`, etc.
- API client: `src/lib/axios.js`
##### Express Backend API (Node.js)
- `server.js` (Express app)
- `notesRoutes.js` (routing)
- `notesController.js` (CRUD logic)
- `Note.js` (model)
- `rateLimiter.js` (middleware)
##### MongoDB
- “Notes” collection (implied by `Note` model)
##### Upstash Redis
- rate limit counters / keys

##### Primary request flow (CRUD)
**Browser → React UI → Axios → Express REST API → MongoDB**
- `GET /api/notes` (list)
- `POST /api/notes` (create)
- `GET /api/notes/:id` (detail)
- `PUT/PATCH /api/notes/:id` (update)
- `DELETE /api/notes/:id` (delete)

##### Rate limiting flow (cross-cutting)
**Every API request → rateLimiter middleware → Upstash Redis**
- As either:
- a side dependency from “Express API” to “Upstash Redis” labeled “rate limit check/increment”.

Frontend UI state:
- **Express returns 429 Too Many Requests** → React shows **RateLimitedUI**.

##### Error/empty state flow
`NotesNotFound.jsx` suggests:
- `GET notes returns empty[]` → show “no notes state” (optional, but it’s a real UX branch)

##### Architectural patterns & principles to highlight (what to call out
- **Layered backend**: Routes → Controllers → Models
- **Middleware for cross-cutting concerns**: rate limiting before route handlers
- **RESTful API boundary**: frontend and backend are decoupled via HTTP/JSON
- **Single data owner**: MongoDB is source of truth for notes; Redis is not a data store for notes, only for rate limiting counters
- **Configuration isolation**: `config/db.js` and `config/upstash.js` as integration points

- User (Browser)
- Frontend: React (Vite)
- Backend: Node/Express REST API
- MongoDB
- Upstash Redis

- Browser ↔ Frontend (static assets)
- Frontend → Backend (HTTP/JSON)
- Backend → MongoDB (CRUD)
- Backend → Upstash Redis (rate limit)
- Backend → Frontend (HTTP status codes; specifically note 429 path)

This is the “resume-level” architecture.

- `server.js` (Express app / middleware pipeline)
- `rateLimiter.js` middleware (depends on `upstash.js`)
- `notesRoutes.js`
- `notesController.js`
- `Note.js`
- `db.js` (Mongo connection)

- `server.js` → `rateLimiter.js` → `notesRoutes.js`
- `notesRoutes.js` → `notesController.js`
- `notesController.js` → `Note.js` → MongoDB
- `rateLimiter.js` → `upstash.js` → Upstash Redis
- `server.js` → `db.js` → MongoDB

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================================================
  %% System Context (Container-level)
  %% =========================================================
  subgraph "System Context (C4: Container)"
    U["User / Browser"]:::external

    subgraph "Frontend (React + Vite + Tailwind)"
      FE["React Frontend (Vite App)"]:::frontend
      FE_BOOT["Bootstrap (main.jsx)"]:::frontend
      FE_APP["App Shell / Routing (App.jsx)"]:::frontend

      subgraph "Pages"
        FE_HOME["HomePage"]:::frontend
        FE_CREATE["CreatePage"]:::frontend
        FE_DETAIL["NoteDetailPage"]:::frontend
      end

      subgraph "UI Components"
        FE_NAV["Navbar"]:::frontend
        FE_CARD["NoteCard"]:::frontend
        FE_EMPTY["NotesNotFound (empty state)"]:::frontend
        FE_429["RateLimitedUI (429 state)"]:::frontend
      end

      subgraph "Frontend Libraries"
        FE_AXIOS["Axios Client (lib/axios.js)"]:::frontend
        FE_UTILS["Utilities (lib/utils.js)"]:::frontend
      end
    end

    subgraph "Backend (Node.js + Express REST API)"
      BE["Express API Server (server.js)"]:::backend

      subgraph "Middleware Pipeline"
        BE_RL["Rate Limiter Middleware"]:::backend
      end

      subgraph "REST Layer"
        BE_ROUTES["Notes Routes"]:::backend
        BE_CTRL["Notes Controller (CRUD)"]:::backend
      end

      subgraph "Data Access Layer"
        BE_MODEL["Note Model / Schema"]:::backend
        BE_DB["MongoDB Connection (db.js)"]:::backend
        BE_UP["Upstash Redis Client (upstash.js)"]:::backend
      end
    end

    MONGO[("MongoDB\nNotes collection")]:::datastore
    REDIS[("Upstash Redis\nrate limit counters")]:::datastore

    ENV["Environment Variables\n(MONGO_URI, UPSTASH_*)"]:::config
    ROOTPKG["Root Scripts (package.json)"]:::config
  end

  %% =========================================================
  %% Primary UX + API request flows
  %% =========================================================
  U -->|"uses"| FE
  FE -->|"renders"| FE_NAV
  FE_HOME -->|"renders list + cards"| FE_CARD
  FE_HOME -->|"empty[] -> shows"| FE_EMPTY
  FE -->|"routing"| FE_APP
  FE_BOOT -->|"mounts"| FE_APP

  FE_APP -->|"routes to"| FE_HOME
  FE_APP -->|"routes to"| FE_CREATE
  FE_APP -->|"routes to"| FE_DETAIL

  FE_HOME -->|"GET_/api/notes"| FE_AXIOS
  FE_CREATE -->|"POST_/api/notes"| FE_AXIOS
  FE_DETAIL -->|"GET_/api/notes/:id"| FE_AXIOS
  FE_DETAIL -->|"PUT/PATCH_/api/notes/:id"| FE_AXIOS
  FE_DETAIL -->|"DELETE_/api/notes/:id"| FE_AXIOS

  FE_AXIOS -->|"HTTP/JSON"| BE
  BE -->|"429_TooManyRequests"| FE_429

  %% =========================================================
  %% Backend internals (layered architecture)
  %% =========================================================
  BE -->|"registers_middleware"| BE_RL
  BE_RL -->|"allows_request"| BE_ROUTES
  BE_ROUTES -->|"maps_endpoints_to_handlers"| BE_CTRL
  BE_CTRL -->|"uses"| BE_MODEL
  BE -->|"initializes"| BE_DB

  %% =========================================================
  %% Persistence + rate-limiting dependencies
  %% =========================================================
  BE_MODEL -->|"CRUD_notes"| MONGO
  BE_DB -.->|"connects_to"| MONGO

  BE_RL -->|"check/increment"| BE_UP
  BE_UP -->|"read/write_counters"| REDIS

  %% =========================================================
  %% Configuration / tooling (non-runtime annotations)
  %% =========================================================
  ENV -.->|"provides_MONGO_URI"| BE_DB
  ENV -.->|"provides_UPSTASH_*"| BE_UP
  ROOTPKG -.->|"dev/build_scripts"| FE
  ROOTPKG -.->|"dev/start_scripts"| BE

  %% =========================================================
  %% Click Events (from component_mapping paths)
  %% =========================================================
  click FE_BOOT "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/main.jsx"
  click FE_APP "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/App.jsx"

  click FE_HOME "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/pages/HomePage.jsx"
  click FE_CREATE "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/pages/CreatePage.jsx"
  click FE_DETAIL "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/pages/NoteDetailPage.jsx"

  click FE_NAV "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/components/Navbar.jsx"
  click FE_CARD "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/components/NoteCard.jsx"
  click FE_EMPTY "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/components/NotesNotFound.jsx"
  click FE_429 "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/components/RateLimitedUI.jsx"

  click FE_AXIOS "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/lib/axios.js"
  click FE_UTILS "https://github.com/burakorkmez/mern-thinkboard/blob/master/frontend/src/lib/utils.js"

  click BE "https://github.com/burakorkmez/mern-thinkboard/blob/master/backend/src/server.js"
  click BE_ROUTES "https://github.com/burakorkmez/mern-thinkboard/blob/master/backend/src/routes/notesRoutes.js"
  click BE_CTRL "https://github.com/burakorkmez/mern-thinkboard/blob/master/backend/src/controllers/notesController.js"
  click BE_MODEL "https://github.com/burakorkmez/mern-thinkboard/blob/master/backend/src/models/Note.js"
  click BE_DB "https://github.com/burakorkmez/mern-thinkboard/blob/master/backend/src/config/db.js"
  click BE_UP "https://github.com/burakorkmez/mern-thinkboard/blob/master/backend/src/config/upstash.js"
  click BE_RL "https://github.com/burakorkmez/mern-thinkboard/blob/master/backend/src/middleware/rateLimiter.js"

  click ROOTPKG "https://github.com/burakorkmez/mern-thinkboard/blob/master/package.json"

  %% =========================================================
  %% Styles (color is critical)
  %% =========================================================
  classDef frontend fill:#dbeafe,stroke:#1d4ed8,stroke-width:1.5px,color:#0b1b3a
  classDef backend fill:#dcfce7,stroke:#166534,stroke-width:1.5px,color:#06210f
  classDef datastore fill:#fef9c3,stroke:#a16207,stroke-width:1.5px,color:#2a1a00
  classDef external fill:#e5e7eb,stroke:#374151,stroke-width:1.5px,color:#111827
  classDef config fill:#ede9fe,stroke:#6d28d9,stroke-width:1.5px,color:#1f1147
```
