# sithilsemitha/deathbed-backend architecture

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

- Interactive diagram: https://gitdiagram.com/sithilsemitha/deathbed-backend
- Repository: https://github.com/sithilsemitha/deathbed-backend

## Overview

DeathBed is a backend for reflecting on decisions to help prevent regret. Users authenticate, classify and save decisions, track regret, find similar stories, compare outcomes, and keep journal entries that can be exported as PDFs. The routes own these operations and access Supabase; authentication validates bearer tokens through the admin client. Classification calls an external ML service, while story search and seeding use Gemini embeddings and Chroma. README content was empty, so capabilities and relationships here are based on the sampled route source; the SQLite file’s role is not established.

Main entry points: [`app.js`](https://github.com/sithilsemitha/deathbed-backend/blob/main/app.js) (Express server), [`routes/users.js`](https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/users.js) (Account and profile), [`config/supabaseAdmin.js`](https://github.com/sithilsemitha/deathbed-backend/blob/main/config/supabaseAdmin.js) (Supabase admin client), [`routes/decisions.js`](https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/decisions.js) (Decision workflows)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry"]
  node_server["Express server<br/>[app.js]"]
  node_status["Status endpoint<br/>[index.js]"]
end

subgraph group_identity["Identity"]
  node_user_routes["Account and profile<br/>[users.js]"]
  node_auth_middleware["Bearer auth<br/>[auth.js]"]
end

subgraph group_reflection["Decision reflection"]
  node_decision_routes["Decision workflows<br/>[decisions.js]"]
  node_user_insights["Matches and comparison<br/>[users.js]"]
end

subgraph group_journal["Journaling"]
  node_journal_routes["Journal entries and PDF<br/>[journals.js]"]
end

subgraph group_similarity["Story similarity"]
  node_search_routes["Similar stories<br/>[search.js]"]
end

subgraph group_infrastructure["Data and services"]
  node_admin_client["Supabase admin client<br/>[supabaseAdmin.js]"]
  node_auth_client["Supabase auth client<br/>[supabaseAuth.js]"]
  node_supabase[("Supabase")]
  node_ml_service["ML classifier"]
  node_gemini["Gemini embeddings"]
  node_chroma[("Chroma stories")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_server
node_server -->|"mounts route"| node_status
node_server -->|"mounts route"| node_user_routes
node_server -->|"mounts route"| node_decision_routes
node_server -->|"mounts route"| node_journal_routes
node_server -->|"mounts route"| node_search_routes
node_client -.->|"uses account APIs"| node_user_routes
node_client -.->|"uses decision APIs"| node_decision_routes
node_client -.->|"uses journal APIs"| node_journal_routes
node_client -.->|"uses search APIs"| node_search_routes
node_user_routes -->|"signs up and in"| node_auth_client
node_user_routes -->|"reads and updates"| node_admin_client
node_decision_routes -->|"requires auth"| node_auth_middleware
node_journal_routes -->|"requires auth"| node_auth_middleware
node_search_routes -->|"requires auth"| node_auth_middleware
node_user_routes -->|"requires auth"| node_auth_middleware
node_auth_middleware -->|"validates token"| node_admin_client
node_admin_client -.->|"connects"| node_supabase
node_auth_client -.->|"connects"| node_supabase
node_decision_routes -->|"stores and queries"| node_admin_client
node_user_routes -->|"queries decision data"| node_admin_client
node_journal_routes -->|"stores and reads"| node_admin_client
node_decision_routes -->|"classifies text"| node_ml_service
node_search_routes -->|"embeds text"| node_gemini
node_search_routes -->|"queries and seeds"| node_chroma

click node_server "https://github.com/sithilsemitha/deathbed-backend/blob/main/app.js"
click node_status "https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/index.js"
click node_user_routes "https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/users.js"
click node_auth_middleware "https://github.com/sithilsemitha/deathbed-backend/blob/main/middleware/auth.js"
click node_decision_routes "https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/decisions.js"
click node_user_insights "https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/users.js"
click node_journal_routes "https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/journals.js"
click node_search_routes "https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/search.js"
click node_admin_client "https://github.com/sithilsemitha/deathbed-backend/blob/main/config/supabaseAdmin.js"
click node_auth_client "https://github.com/sithilsemitha/deathbed-backend/blob/main/config/supabaseAuth.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_server,node_status,node_client toneBlue
class node_user_routes,node_auth_middleware toneAmber
class node_decision_routes,node_user_insights toneMint
class node_journal_routes toneRose
class node_search_routes toneIndigo
class node_admin_client,node_auth_client,node_supabase,node_ml_service,node_gemini,node_chroma toneTeal
```

## Components

### API entry

- [Express server](https://github.com/sithilsemitha/deathbed-backend/blob/main/app.js): `app.js`
- [Status endpoint](https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/index.js): `routes/index.js`

### Identity

- [Account and profile](https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/users.js): `routes/users.js`
- [Bearer auth](https://github.com/sithilsemitha/deathbed-backend/blob/main/middleware/auth.js): `middleware/auth.js`

### Decision reflection

- [Decision workflows](https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/decisions.js): `routes/decisions.js`
- [Matches and comparison](https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/users.js): `routes/users.js`

### Journaling

- [Journal entries and PDF](https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/journals.js): `routes/journals.js`

### Story similarity

- [Similar stories](https://github.com/sithilsemitha/deathbed-backend/blob/main/routes/search.js): `routes/search.js`

### Data and services

- [Supabase admin client](https://github.com/sithilsemitha/deathbed-backend/blob/main/config/supabaseAdmin.js): `config/supabaseAdmin.js`
- [Supabase auth client](https://github.com/sithilsemitha/deathbed-backend/blob/main/config/supabaseAuth.js): `config/supabaseAuth.js`
- **Supabase**
- **ML classifier**
- **Gemini embeddings**
- **Chroma stories**

### Other components

- **API client**

## Connections

- API client → Express server: sends requests (evidence: `app.js`)
- Express server → Status endpoint: mounts route (evidence: `app.js`)
- Express server → Account and profile: mounts route (evidence: `app.js`)
- Express server → Decision workflows: mounts route (evidence: `app.js`)
- Express server → Journal entries and PDF: mounts route (evidence: `app.js`)
- Express server → Similar stories: mounts route (evidence: `app.js`)
- API client → Account and profile: uses account APIs
- API client → Decision workflows: uses decision APIs
- API client → Journal entries and PDF: uses journal APIs
- API client → Similar stories: uses search APIs
- Account and profile → Supabase auth client: signs up and in (evidence: `routes/users.js`)
- Account and profile → Supabase admin client: reads and updates (evidence: `routes/users.js`)
- Decision workflows → Bearer auth: requires auth (evidence: `routes/decisions.js`)
- Journal entries and PDF → Bearer auth: requires auth (evidence: `routes/journals.js`)
- Similar stories → Bearer auth: requires auth (evidence: `routes/search.js`)
- Account and profile → Bearer auth: requires auth (evidence: `routes/users.js`)
- Bearer auth → Supabase admin client: validates token (evidence: `middleware/auth.js`)
- Supabase admin client → Supabase: connects
- Supabase auth client → Supabase: connects
- Decision workflows → Supabase admin client: stores and queries (evidence: `routes/decisions.js`)
- Account and profile → Supabase admin client: queries decision data (evidence: `routes/users.js`)
- Journal entries and PDF → Supabase admin client: stores and reads (evidence: `routes/journals.js`)
- Decision workflows → ML classifier: classifies text (evidence: `routes/decisions.js`)
- Similar stories → Gemini embeddings: embeds text (evidence: `routes/search.js`)
- Similar stories → Chroma stories: queries and seeds (evidence: `routes/search.js`)
