# farhadnuri/lifeflow-client architecture

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

- Interactive diagram: https://gitdiagram.com/farhadnuri/lifeflow-client
- Repository: https://github.com/farhadnuri/lifeflow-client

## Overview

1. **What this repository is**
   - This is the **client/front-end** for LifeFlow, built with **Next.js App Router** and **React 19**.
   - The repo is mostly a presentation and workflow layer; the core blood-request/business data appears to live in the separate **Express/MongoDB backend** referenced in the README.

2. **Top-level architecture**
   - The app is organized around **route-based features** under `src/app`.
   - It has three clear authenticated workspaces: **Admin**, **Donor**, and **Volunteer**, plus public user-facing pages for browsing requests, login/register, search, and funding.

3. **Authentication and session boundary**
   - Authentication is handled through the `src/app/api/auth/*` routes and the shared auth helpers in `src/lib/auth.js` and `src/lib/auth-client.js`.
   - `src/context/AuthContext.jsx` is the browser-side state layer that likely exposes the current user/session to the rest of the UI.
   - The README indicates **Better Auth + JWT** semantics, so the app separates identity/session management from the domain backend.

4. **Role-based navigation and layout isolation**
   - Role-specific layouts exist for `admin`, `donor`, and `volunteer`, each with its own sidebar component:
     - `src/components/admin/AdminSidebar.jsx`
     - `src/components/donor/DonorSidebar.jsx`
     - `src/components/volunteer/VolunteerSidebar.jsx`
   - `src/components/ConditionalLayout.jsx`, `Navbar.jsx`, and `Footer.jsx` provide shared shell behavior for public vs authenticated sections.

5. **Public request discovery flow**
   - Public entry points include `src/app/page.jsx`, `src/app/requests/page.jsx`, `src/app/search/page.jsx`, and the login/register screens.
   - These pages are the discovery layer for blood requests: browsing, searching, and filtering before a user authenticates or acts on a request.

6. **Donor workflow**
   - The donor area contains pages for:
     - profile management
     - creating a blood request
     - viewing “my requests”
   - This suggests donors can both maintain their profile and participate in request creation/tracking, not just browse.

7. **Volunteer workflow**
   - The volunteer area mirrors the donor workspace but is oriented around operational response:
     - creating requests
     - listing “all blood donation requests”
     - tracking “my requests”
     - profile management
   - The `RespondButton` component indicates a direct action path for volunteers to answer an emergency request.

8. **Admin control plane**
   - The admin section contains dedicated pages for:
     - user management
     - request management
     - admin profile
   - This is the administrative boundary for moderation and platform oversight, likely backed by privileged API access and role checks.

9. **Funding / payment flow**
   - `src/app/funding/*` contains separate success and cancel landing pages, which is a strong indicator of an external payment redirect flow.
   - The README says the app uses **Stripe.js**, so payment processing is handled client-side with Stripe redirect/confirmation pages as the return boundary.

10. **Static reference data and location filtering**
    - `public/districts.json`, `public/divisions.json`, and `public/upazilas.json` provide static geography data.
    - `src/hooks/useLocationData.js` likely combines those files into cascading location selectors for request forms and filters.
    - This is an important data boundary because location data is served locally rather than fetched from the main backend.

11. **Backend integration boundary**
    - The README points to an external backend repo and exposes `NEXT_PUBLIC_API_URL`, so UI pages likely call the Express API for:
      - authentication state and credentials
      - blood request CRUD
      - user/role management
      - responses and request status
    - The frontend is therefore a **thin client over a domain API**, with the app router pages acting as feature shells around backend data.

12. **Likely persistence model behind the UI**
    - The backend data model mentioned in the README centers on `users`, `bloodRequests`, and `responses`.
    - Those collections map cleanly to the app’s major screens: auth/user profile, request browsing/management, and volunteer response tracking.

13. **Runtime and tooling**
    - Styling is done with **Tailwind CSS v4** via `globals.css` and PostCSS.
    - The app uses **Lucide React** for icons.
    - `eslint.config.mjs`, `next.config.mjs`, and the App Router layout files indicate a standard Next.js deployment model, likely on **Vercel** as noted in the README.

14. **Architecture summary for a diagram**
    - Think of this repo as:
      - a **public marketing/discovery layer**
      - three **role-based authenticated dashboards**
      - a small **auth API layer inside Next.js**
      - and a **backend API/payment service boundary** for all real domain state.

Main entry points: [`src/components/ConditionalLayout.jsx`](https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/ConditionalLayout.jsx) (Conditional layout), [`src/app/page.jsx`](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/page.jsx) (Discovery pages), [`src/app/layout.js`](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/layout.js) (App shell), [`src/app/admin/layout.jsx`](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/admin/layout.jsx) (Admin layout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public"]
  node_public_discovery["Discovery pages<br/>public pages<br/>[page.jsx]"]
  node_funding_flow["Funding flow<br/>checkout return<br/>[page.jsx]"]
  node_payment_gateway[("Stripe gateway<br/>external payment")]
end

subgraph group_auth["Auth"]
  node_auth_context(("Auth context<br/>client state<br/>[AuthContext.jsx]"))
  node_auth_api["Auth API<br/>next route<br/>[route.js]"]
  node_auth_routes["Auth routes<br/>route handlers<br/>[route.js]"]
  node_auth_lib["Auth helpers<br/>auth utils<br/>[auth.js]"]
  node_domain_api[("Domain API<br/>external backend")]
end

subgraph group_dashboards["Dashboards"]
  node_admin_layout["Admin layout<br/>workspace shell<br/>[layout.jsx]"]
  node_admin_sidebar["Admin sidebar<br/>nav sidebar<br/>[AdminSidebar.jsx]"]
  node_admin_pages["Admin pages<br/>admin views<br/>[page.jsx]"]
  node_donor_layout["Donor layout<br/>workspace shell<br/>[layout.jsx]"]
  node_donor_sidebar["Donor sidebar<br/>nav sidebar<br/>[DonorSidebar.jsx]"]
  node_donor_pages["Donor pages<br/>donor views<br/>[page.jsx]"]
  node_volunteer_layout["Volunteer layout<br/>workspace shell<br/>[layout.jsx]"]
  node_volunteer_sidebar["Volunteer sidebar<br/>nav sidebar"]
  node_volunteer_pages["Volunteer pages<br/>volunteer views<br/>[page.jsx]"]
end

subgraph group_shared["Shared"]
  node_app_shell["App shell<br/>next layout<br/>[layout.js]"]
  node_conditional_layout["Conditional layout<br/>shell switch"]
  node_navbar["Navbar<br/>navigation<br/>[Navbar.jsx]"]
  node_footer["Footer<br/>chrome<br/>[Footer.jsx]"]
  node_location_data["Location data<br/>geo helper<br/>[useLocationData.js]"]
  node_respond_button(("Respond button<br/>action component<br/>[RespondButton.jsx]"))
end

node_app_shell -->|"wraps"| node_conditional_layout
node_app_shell -->|"shares"| node_navbar
node_app_shell -->|"shares"| node_footer
node_conditional_layout -->|"renders"| node_public_discovery
node_conditional_layout -->|"renders"| node_funding_flow
node_conditional_layout -->|"switches to"| node_admin_layout
node_conditional_layout -->|"switches to"| node_donor_layout
node_conditional_layout -->|"switches to"| node_volunteer_layout
node_auth_context -->|"uses"| node_auth_lib
node_auth_api -->|"delegates"| node_auth_routes
node_auth_api -->|"uses"| node_auth_lib
node_auth_context -->|"syncs with"| node_auth_api
node_public_discovery -->|"reads"| node_auth_context
node_public_discovery -->|"fetches"| node_domain_api
node_funding_flow -->|"redirects"| node_payment_gateway
node_public_discovery -->|"filters by"| node_location_data
node_admin_layout -->|"contains"| node_admin_sidebar
node_admin_layout -->|"hosts"| node_admin_pages
node_admin_pages -->|"manages"| node_domain_api
node_donor_layout -->|"contains"| node_donor_sidebar
node_donor_layout -->|"hosts"| node_donor_pages
node_donor_pages -->|"manages"| node_domain_api
node_volunteer_layout -->|"contains"| node_volunteer_sidebar
node_volunteer_layout -->|"hosts"| node_volunteer_pages
node_volunteer_pages -->|"uses"| node_respond_button
node_volunteer_pages -->|"manages"| node_domain_api

click node_app_shell "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/layout.js"
click node_conditional_layout "https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/ConditionalLayout.jsx"
click node_navbar "https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/Navbar.jsx"
click node_footer "https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/Footer.jsx"
click node_auth_context "https://github.com/farhadnuri/lifeflow-client/blob/main/src/context/AuthContext.jsx"
click node_auth_api "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/api/auth/[...all]/route.js"
click node_auth_routes "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/api/auth/login/route.js"
click node_auth_lib "https://github.com/farhadnuri/lifeflow-client/blob/main/src/lib/auth.js"
click node_location_data "https://github.com/farhadnuri/lifeflow-client/blob/main/src/hooks/useLocationData.js"
click node_public_discovery "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/page.jsx"
click node_funding_flow "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/funding/page.jsx"
click node_admin_layout "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/admin/layout.jsx"
click node_admin_sidebar "https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/admin/AdminSidebar.jsx"
click node_admin_pages "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/admin/page.jsx"
click node_donor_layout "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/donor/layout.jsx"
click node_donor_sidebar "https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/donor/DonorSidebar.jsx"
click node_donor_pages "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/donor/page.jsx"
click node_volunteer_layout "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/volunteer/layout.jsx"
click node_volunteer_sidebar "https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/volunteer/VolunteerSidebar.jsx"
click node_volunteer_pages "https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/volunteer/page.jsx"
click node_respond_button "https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/RespondButton.jsx"

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_public_discovery,node_funding_flow,node_payment_gateway toneBlue
class node_auth_context,node_auth_api,node_auth_routes,node_auth_lib,node_domain_api toneAmber
class node_admin_layout,node_admin_sidebar,node_admin_pages,node_donor_layout,node_donor_sidebar,node_donor_pages,node_volunteer_layout,node_volunteer_sidebar,node_volunteer_pages toneMint
class node_app_shell,node_conditional_layout,node_navbar,node_footer,node_location_data,node_respond_button toneRose
```

## Components

### Public

Discovery, authentication entry points, and funding return pages.

- [Discovery pages](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/page.jsx): public pages · Homepage, requests browser, search, login, and register entry points. · `src/app/page.jsx`
- [Funding flow](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/funding/page.jsx): checkout return · Donation funding page and Stripe success/cancel return screens. · `src/app/funding/page.jsx`
- **Stripe gateway**: external payment · External payment flow reached from the funding pages.

### Auth

Session helpers and Next.js auth API routes.

- [Auth context](https://github.com/farhadnuri/lifeflow-client/blob/main/src/context/AuthContext.jsx): client state · Browser-side session and user state layer. · `src/context/AuthContext.jsx`
- [Auth API](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/api/auth/[...all]/route.js): next route · Next.js auth gateway for login, register, and session checks. · `src/app/api/auth/[...all]/route.js`
- [Auth routes](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/api/auth/login/route.js): route handlers · Concrete login, register, and me endpoints. · `src/app/api/auth/login/route.js`
- [Auth helpers](https://github.com/farhadnuri/lifeflow-client/blob/main/src/lib/auth.js): auth utils · Server-side auth utilities and client helpers. · `src/lib/auth.js`
- **Domain API**: external backend · Separate Express/MongoDB service providing users, requests, and responses.

### Dashboards

Role-based workspaces for admin, donor, and volunteer users.

- [Admin layout](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/admin/layout.jsx): workspace shell · Admin area layout and navigation container. · `src/app/admin/layout.jsx`
- [Admin sidebar](https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/admin/AdminSidebar.jsx): nav sidebar · Admin workspace navigation. · `src/components/admin/AdminSidebar.jsx`
- [Admin pages](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/admin/page.jsx): admin views · User, request, and profile management screens. · `src/app/admin/page.jsx`
- [Donor layout](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/donor/layout.jsx): workspace shell · Donor area layout and navigation container. · `src/app/donor/layout.jsx`
- [Donor sidebar](https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/donor/DonorSidebar.jsx): nav sidebar · Donor workspace navigation. · `src/components/donor/DonorSidebar.jsx`
- [Donor pages](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/donor/page.jsx): donor views · Profile, create-request, and my-requests screens. · `src/app/donor/page.jsx`
- [Volunteer layout](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/volunteer/layout.jsx): workspace shell · Volunteer area layout and navigation container. · `src/app/volunteer/layout.jsx`
- [Volunteer sidebar](https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/volunteer/VolunteerSidebar.jsx): nav sidebar · Volunteer workspace navigation. · `src/components/volunteer/VolunteerSidebar.jsx`
- [Volunteer pages](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/volunteer/page.jsx): volunteer views · Request operations, profile, and tracking screens. · `src/app/volunteer/page.jsx`

### Shared

Reusable shell components and local data helpers.

- [App shell](https://github.com/farhadnuri/lifeflow-client/blob/main/src/app/layout.js): next layout · Root app layout and global styling entrypoint. · `src/app/layout.js`
- [Conditional layout](https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/ConditionalLayout.jsx): shell switch · Chooses public vs authenticated page chrome. · `src/components/ConditionalLayout.jsx`
- [Navbar](https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/Navbar.jsx): navigation · Shared top navigation for public-facing sections. · `src/components/Navbar.jsx`
- [Footer](https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/Footer.jsx): chrome · Shared page footer. · `src/components/Footer.jsx`
- [Location data](https://github.com/farhadnuri/lifeflow-client/blob/main/src/hooks/useLocationData.js): geo helper · Cascading location lookup based on bundled district and division data. · `src/hooks/useLocationData.js`
- [Respond button](https://github.com/farhadnuri/lifeflow-client/blob/main/src/components/RespondButton.jsx): action component · Direct volunteer action for responding to requests. · `src/components/RespondButton.jsx`

## Connections

- App shell → Conditional layout: wraps · Root layout delegates section chrome selection.
- App shell → Navbar: shares · Global shell provides the navigation component.
- App shell → Footer: shares · Global shell provides the footer component.
- Conditional layout → Discovery pages: renders · Public pages use the shared public shell.
- Conditional layout → Funding flow: renders · Funding pages are part of the public shell.
- Conditional layout → Admin layout: switches to · Authenticated routes branch into role workspaces.
- Conditional layout → Donor layout: switches to · Authenticated routes branch into role workspaces.
- Conditional layout → Volunteer layout: switches to · Authenticated routes branch into role workspaces.
- Auth context → Auth helpers: uses · Client session state relies on shared auth helpers.
- Auth API → Auth routes: delegates · Catch-all route and concrete endpoints form the auth boundary.
- Auth API → Auth helpers: uses · API handlers rely on auth utilities.
- Auth context → Auth API: syncs with · Browser session state is validated against auth endpoints.
- Discovery pages → Auth context: reads · Login and register pages consume session state.
- Discovery pages → Domain API: fetches · Discovery views are thin clients over the domain backend.
- Funding flow → Stripe gateway: redirects · Checkout completion and cancellation return from Stripe.
- Discovery pages → Location data: filters by · Search and request forms use bundled geographic data.
- Admin layout → Admin sidebar: contains · Admin workspace is centered on its sidebar navigation.
- Admin layout → Admin pages: hosts · Admin pages live inside the admin workspace shell.
- Admin pages → Domain API: manages · Admin screens operate on users and requests through the backend.
- Donor layout → Donor sidebar: contains · Donor workspace is centered on its sidebar navigation.
- Donor layout → Donor pages: hosts · Donor pages live inside the donor workspace shell.
- Donor pages → Domain API: manages · Donor screens create and track request records through the backend.
- Volunteer layout → Volunteer sidebar: contains · Volunteer workspace is centered on its sidebar navigation.
- Volunteer layout → Volunteer pages: hosts · Volunteer pages live inside the volunteer workspace shell.
- Volunteer pages → Respond button: uses · Request lists expose the response action component.
- Volunteer pages → Domain API: manages · Volunteer screens operate on requests and responses through the backend.
