# iamkrisshk/bodhiki architecture

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

- Interactive diagram: https://gitdiagram.com/iamkrisshk/bodhiki
- Repository: https://github.com/iamkrisshk/bodhiki

## Overview

1. **Repo shape**
   - This is a two-part application: a **Node/Express backend** under `backend/` and a **React frontend** under `frontend/`.
   - The root `package.json` suggests the repo is organized as a workspace-style project, but the actual runtime boundary is still clearly split between client and server.

2. **Backend entry and server boundary**
   - `backend/backend.js` and `backend/app.js` appear to separate **process startup** from **Express app configuration**.
   - `backend/config/db.js` is the database connection layer, so the backend is responsible for persistence and API exposure, not just static serving.

3. **Backend API surface**
   - Routes are grouped by domain in `backend/routes/`:
     - `authRoutes.js` for authentication
     - `userRoutes.js` for user/profile operations
     - `discoverRoutes.js` for discovery/feed-related content
     - `actRoutes.js` for activity/study actions
   - Each route module maps to a controller in `backend/ctrl/`, keeping HTTP routing separate from business logic.

4. **Backend domain logic**
   - Controllers implement the main backend behaviors:
     - `authCtrl.js` handles sign-in/sign-up/session logic
     - `userCtrl.js` handles user data
     - `discoverCtrl.js` handles discovery/feed content
     - `actCtrl.js` handles activity/study-related operations
   - This suggests the backend is organized around application features rather than generic CRUD only.

5. **Backend data model**
   - Domain models live in `backend/models/`:
     - `Users.js`
     - `Posts.js`
     - `Comments.js`
     - `Likes.js`
     - `Activity.js`
   - These indicate a social/content model with posts, reactions, comments, and user activity tracking.
   - The presence of separate models for likes/comments suggests content relationships are first-class rather than embedded in a single document/table.

6. **Backend middleware**
   - `backend/mare/authMare.js` is the auth guard layer, likely protecting private routes and validating tokens/sessions.
   - `backend/mare/errorHandler.js` is centralized error middleware, which means request failures are normalized in one place before returning API responses.

7. **Frontend app shell**
   - React app structure lives under `frontend/src/`, with top-level composition in:
     - `src/main.jsx`
     - `src/index.js`
     - `src/app/app.jsx`
     - `src/app/protRoutes.jsx`
   - Routing is segmented by layout and access type, implying a client-side SPA with protected/private areas.

8. **Frontend layout and route boundaries**
   - Layouts are split into `authLayout.jsx`, `dashboardLayout.jsx`, and `publicLayout.jsx`.
   - This indicates three distinct UI zones:
     - unauthenticated/auth flow
     - logged-in dashboard experience
     - public-facing content
   - `protRoutes.jsx` suggests route protection is enforced on the client as well, not only on the backend.

9. **Frontend feature modules**
   - The `features/` folder is the main business UI layer:
     - `auth/` contains `Login.jsx`, `Register.jsx`, `authAPI.js`
     - `feed/` contains feed, post creation, discovery cards, and feed/discover APIs
     - `activity/` contains `studyAPI.js`
     - `services/apiClient.js` is the shared HTTP client
   - This shows a feature-sliced frontend architecture where UI components, API calls, and local helpers stay close together.

10. **Primary data flow**
   - User interaction starts in React pages/components, then goes through feature API modules like `authAPI.js`, `feedAPI.js`, `discoverAPI.js`, and `studyAPI.js`.
   - Those modules use `services/apiClient.js` to call backend routes.
   - The backend routes dispatch to controllers, which read/write domain models, then return data to the frontend for rendering.

11. **Feed and discovery subsystem**
   - The feed area is more than a single list: it includes posting, card rendering, normalization helpers (`norm.js`), and a discovery hook (`useDiscover.js`).
   - This suggests the app has a content surface where posts can be created, normalized into UI-friendly shape, and surfaced through discovery logic.

12. **Activity / study subsystem**
   - The presence of `study.jsx`, `zenGarden.jsx`, `studyAPI.js`, and sound assets under `public/sounds/` points to a focused “study mode” or wellness/ambient experience.
   - That part of the UI is likely independent from the feed, but still authenticated and backed by the `Activity` model and `actRoutes`.

13. **Static assets and presentation**
   - Global styling is centralized in `src/styles/global.css` and `src/styles/theme.js`.
   - `frontend/public/sounds/` contains MP3 assets used by a UI experience, likely the zen/study mode.
   - `Navbar.jsx` and shared layout components imply common chrome around the routed pages.

14. **How to draw the architecture**
   - Draw two main boundaries: **React client** and **Express API server**.
   - Inside the client, show **layouts + routed pages** feeding into **feature modules**, which call a shared **API client**.
   - Inside the server, show **routes → controllers → models/db**, with **auth middleware** guarding protected endpoints and **error middleware** handling failures centrally.

Main entry points: [`backend/app.js`](https://github.com/iamkrisshk/bodhiki/blob/main/backend/app.js) (Express app), [`frontend/src/pages`](https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/pages) (Pages), [`frontend/src/features/services/apiClient.js`](https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/features/services/apiClient.js) (API client), [`backend/models`](https://github.com/iamkrisshk/bodhiki/tree/main/backend/models) (Domain models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_backend_entry(("Server start<br/>process<br/>[backend.js]"))
  node_backend_app["Express app<br/>http app<br/>[app.js]"]
  node_backend_db[("Database<br/>connection<br/>[db.js]")]
  node_backend_routes_auth["Auth routes<br/>route set<br/>[authRoutes.js]"]
  node_backend_routes_user["User routes<br/>route set<br/>[userRoutes.js]"]
  node_backend_routes_discover["Discover routes<br/>route set<br/>[discoverRoutes.js]"]
  node_backend_routes_act["Activity routes<br/>route set<br/>[actRoutes.js]"]
  node_backend_ctrl_auth["Auth ctrl<br/>controller<br/>[authCtrl.js]"]
  node_backend_ctrl_user["User ctrl<br/>controller<br/>[userCtrl.js]"]
  node_backend_ctrl_discover["Discover ctrl<br/>controller<br/>[discoverCtrl.js]"]
  node_backend_ctrl_act["Activity ctrl<br/>controller<br/>[actCtrl.js]"]
  node_backend_mw_auth{{"Auth guard<br/>middleware<br/>[authMare.js]"}}
  node_backend_mw_error{{"Error handler<br/>middleware<br/>[errorHandler.js]"}}
  node_backend_models[("Domain models")]
end

subgraph group_frontend["Frontend"]
  node_frontend_entry(("App boot<br/>[main.jsx]"))
  node_frontend_shell["App shell<br/>spa shell<br/>[app.jsx]"]
  node_frontend_routes["Protected routes<br/>router<br/>[protRoutes.jsx]"]
  node_frontend_layouts["Layouts<br/>layout set"]
  node_frontend_nav["Navbar<br/>ui chrome<br/>[Navbar.jsx]"]
  node_frontend_auth["Auth feature"]
  node_frontend_feed["Feed feature"]
  node_frontend_activity["Study feature"]
  node_frontend_api["API client<br/>http client<br/>[apiClient.js]"]
  node_frontend_pages["Pages<br/>screens"]
  node_frontend_style["Theme styles"]
end

node_backend_entry -->|"starts"| node_backend_app
node_backend_app -->|"uses"| node_backend_mw_auth
node_backend_app -->|"uses"| node_backend_mw_error
node_backend_app -->|"mounts"| node_backend_routes_auth
node_backend_app -->|"mounts"| node_backend_routes_user
node_backend_app -->|"mounts"| node_backend_routes_discover
node_backend_app -->|"mounts"| node_backend_routes_act
node_backend_routes_auth -->|"dispatches"| node_backend_ctrl_auth
node_backend_routes_user -->|"dispatches"| node_backend_ctrl_user
node_backend_routes_discover -->|"dispatches"| node_backend_ctrl_discover
node_backend_routes_act -->|"dispatches"| node_backend_ctrl_act
node_backend_ctrl_auth -->|"reads/writes"| node_backend_models
node_backend_ctrl_user -->|"reads/writes"| node_backend_models
node_backend_ctrl_discover -->|"reads/writes"| node_backend_models
node_backend_ctrl_act -->|"reads/writes"| node_backend_models
node_backend_app -->|"connects"| node_backend_db
node_frontend_entry -->|"renders"| node_frontend_shell
node_frontend_shell -->|"guards"| node_frontend_routes
node_frontend_shell -->|"composes"| node_frontend_layouts
node_frontend_layouts -->|"includes"| node_frontend_nav
node_frontend_routes -->|"routes to"| node_frontend_pages
node_frontend_pages -->|"uses"| node_frontend_auth
node_frontend_pages -->|"uses"| node_frontend_feed
node_frontend_pages -->|"uses"| node_frontend_activity
node_frontend_auth -->|"calls"| node_frontend_api
node_frontend_feed -->|"calls"| node_frontend_api
node_frontend_activity -->|"calls"| node_frontend_api
node_frontend_auth -->|"styles"| node_frontend_style
node_frontend_feed -->|"styles"| node_frontend_style
node_frontend_activity -->|"styles"| node_frontend_style
node_frontend_api -.->|"requests"| node_backend_app

click node_backend_entry "https://github.com/iamkrisshk/bodhiki/blob/main/backend/backend.js"
click node_backend_app "https://github.com/iamkrisshk/bodhiki/blob/main/backend/app.js"
click node_backend_db "https://github.com/iamkrisshk/bodhiki/blob/main/backend/config/db.js"
click node_backend_routes_auth "https://github.com/iamkrisshk/bodhiki/blob/main/backend/routes/authRoutes.js"
click node_backend_routes_user "https://github.com/iamkrisshk/bodhiki/blob/main/backend/routes/userRoutes.js"
click node_backend_routes_discover "https://github.com/iamkrisshk/bodhiki/blob/main/backend/routes/discoverRoutes.js"
click node_backend_routes_act "https://github.com/iamkrisshk/bodhiki/blob/main/backend/routes/actRoutes.js"
click node_backend_ctrl_auth "https://github.com/iamkrisshk/bodhiki/blob/main/backend/ctrl/authCtrl.js"
click node_backend_ctrl_user "https://github.com/iamkrisshk/bodhiki/blob/main/backend/ctrl/userCtrl.js"
click node_backend_ctrl_discover "https://github.com/iamkrisshk/bodhiki/blob/main/backend/ctrl/discoverCtrl.js"
click node_backend_ctrl_act "https://github.com/iamkrisshk/bodhiki/blob/main/backend/ctrl/actCtrl.js"
click node_backend_mw_auth "https://github.com/iamkrisshk/bodhiki/blob/main/backend/mare/authMare.js"
click node_backend_mw_error "https://github.com/iamkrisshk/bodhiki/blob/main/backend/mare/errorHandler.js"
click node_backend_models "https://github.com/iamkrisshk/bodhiki/tree/main/backend/models"
click node_frontend_entry "https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/main.jsx"
click node_frontend_shell "https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/app/app.jsx"
click node_frontend_routes "https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/app/protRoutes.jsx"
click node_frontend_layouts "https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/layouts"
click node_frontend_nav "https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/comp/Navbar.jsx"
click node_frontend_auth "https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/features/auth"
click node_frontend_feed "https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/features/feed"
click node_frontend_activity "https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/features/activity"
click node_frontend_api "https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/features/services/apiClient.js"
click node_frontend_pages "https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/pages"
click node_frontend_style "https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/styles"

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_backend_entry,node_backend_app,node_backend_db,node_backend_routes_auth,node_backend_routes_user,node_backend_routes_discover,node_backend_routes_act,node_backend_ctrl_auth,node_backend_ctrl_user,node_backend_ctrl_discover,node_backend_ctrl_act,node_backend_mw_auth,node_backend_mw_error,node_backend_models toneBlue
class node_frontend_entry,node_frontend_shell,node_frontend_routes,node_frontend_layouts,node_frontend_nav,node_frontend_auth,node_frontend_feed,node_frontend_activity,node_frontend_api,node_frontend_pages,node_frontend_style toneAmber
```

## Components

### Backend

Express API server, domain logic, and persistence

- [Server start](https://github.com/iamkrisshk/bodhiki/blob/main/backend/backend.js): process · Bootstraps the backend process · `backend/backend.js`
- [Express app](https://github.com/iamkrisshk/bodhiki/blob/main/backend/app.js): http app · Wires middleware and routes · `backend/app.js`
- [Database](https://github.com/iamkrisshk/bodhiki/blob/main/backend/config/db.js): connection · Database connection layer · `backend/config/db.js`
- [Auth routes](https://github.com/iamkrisshk/bodhiki/blob/main/backend/routes/authRoutes.js): route set · Authentication endpoints · `backend/routes/authRoutes.js`
- [User routes](https://github.com/iamkrisshk/bodhiki/blob/main/backend/routes/userRoutes.js): route set · User and profile endpoints · `backend/routes/userRoutes.js`
- [Discover routes](https://github.com/iamkrisshk/bodhiki/blob/main/backend/routes/discoverRoutes.js): route set · Discovery and feed endpoints · `backend/routes/discoverRoutes.js`
- [Activity routes](https://github.com/iamkrisshk/bodhiki/blob/main/backend/routes/actRoutes.js): route set · Study and activity endpoints · `backend/routes/actRoutes.js`
- [Auth ctrl](https://github.com/iamkrisshk/bodhiki/blob/main/backend/ctrl/authCtrl.js): controller · Sign-in, sign-up, session logic · `backend/ctrl/authCtrl.js`
- [User ctrl](https://github.com/iamkrisshk/bodhiki/blob/main/backend/ctrl/userCtrl.js): controller · User data operations · `backend/ctrl/userCtrl.js`
- [Discover ctrl](https://github.com/iamkrisshk/bodhiki/blob/main/backend/ctrl/discoverCtrl.js): controller · Discovery and content assembly · `backend/ctrl/discoverCtrl.js`
- [Activity ctrl](https://github.com/iamkrisshk/bodhiki/blob/main/backend/ctrl/actCtrl.js): controller · Study and activity operations · `backend/ctrl/actCtrl.js`
- [Auth guard](https://github.com/iamkrisshk/bodhiki/blob/main/backend/mare/authMare.js): middleware · Protects private routes · `backend/mare/authMare.js`
- [Error handler](https://github.com/iamkrisshk/bodhiki/blob/main/backend/mare/errorHandler.js): middleware · Centralized API error handling · `backend/mare/errorHandler.js`
- [Domain models](https://github.com/iamkrisshk/bodhiki/tree/main/backend/models): models · Users, posts, comments, likes, activity data · `backend/models`

### Frontend

React SPA, layouts, and feature modules

- [App boot](https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/main.jsx): boot · Client entry and render setup · `frontend/src/main.jsx`
- [App shell](https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/app/app.jsx): spa shell · Top-level client composition · `frontend/src/app/app.jsx`
- [Protected routes](https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/app/protRoutes.jsx): router · Client-side route access control · `frontend/src/app/protRoutes.jsx`
- [Layouts](https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/layouts): layout set · Public, auth, and dashboard chrome · `frontend/src/layouts`
- [Navbar](https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/comp/Navbar.jsx): ui chrome · Shared navigation component · `frontend/src/comp/Navbar.jsx`
- [Auth feature](https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/features/auth): feature · Login and registration UI plus auth API · `frontend/src/features/auth`
- [Feed feature](https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/features/feed): feature · Feed, posting, discovery, and normalization · `frontend/src/features/feed`
- [Study feature](https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/features/activity): feature · Study mode UI and activity API · `frontend/src/features/activity`
- [API client](https://github.com/iamkrisshk/bodhiki/blob/main/frontend/src/features/services/apiClient.js): http client · Shared client for backend calls · `frontend/src/features/services/apiClient.js`
- [Pages](https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/pages): screens · Landing and dashboard screens · `frontend/src/pages`
- [Theme styles](https://github.com/iamkrisshk/bodhiki/tree/main/frontend/src/styles): styles · Global styling and theme tokens · `frontend/src/styles`

## Connections

- Server start → Express app: starts · Process entry loads the Express app
- Express app → Auth guard: uses · Protects private routes
- Express app → Error handler: uses · Normalizes failures
- Express app → Auth routes: mounts · Registers auth endpoints
- Express app → User routes: mounts · Registers user endpoints
- Express app → Discover routes: mounts · Registers discover endpoints
- Express app → Activity routes: mounts · Registers activity endpoints
- Auth routes → Auth ctrl: dispatches · Routes delegate to auth controller
- User routes → User ctrl: dispatches · Routes delegate to user controller
- Discover routes → Discover ctrl: dispatches · Routes delegate to discover controller
- Activity routes → Activity ctrl: dispatches · Routes delegate to activity controller
- Auth ctrl → Domain models: reads/writes · Uses persistence for auth state
- User ctrl → Domain models: reads/writes · Uses user data models
- Discover ctrl → Domain models: reads/writes · Fetches content and relationships
- Activity ctrl → Domain models: reads/writes · Stores activity data
- Express app → Database: connects · Initializes database access
- App boot → App shell: renders · Bootstraps the SPA
- App shell → Protected routes: guards · Wraps protected client routes
- App shell → Layouts: composes · Selects layout boundaries
- Layouts → Navbar: includes · Shared chrome across views
- Protected routes → Pages: routes to · Maps navigation to screens
- Pages → Auth feature: uses · Auth screens depend on auth feature
- Pages → Feed feature: uses · Feed-related screens depend on feed feature
- Pages → Study feature: uses · Study screens depend on activity feature
- Auth feature → API client: calls · Uses shared HTTP client
- Feed feature → API client: calls · Uses shared HTTP client
- Study feature → API client: calls · Uses shared HTTP client
- Auth feature → Theme styles: styles · Consumes shared theme and global CSS
- Feed feature → Theme styles: styles · Consumes shared theme and global CSS
- Study feature → Theme styles: styles · Consumes shared theme and global CSS
- API client → Express app: requests · Client API traffic targets backend endpoints
