# suki-amalie/journal-habit-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/suki-amalie/journal-habit-tracker
- Repository: https://github.com/suki-amalie/journal-habit-tracker

## Overview

Hibi is a personal journaling and habit-tracking application. Users register or log in, then write and revisit journal entries, manage habits, record completions, and review activity summaries. The client uses authenticated API requests; server routes apply authentication and controllers validate requests and read or mutate user-scoped data. The README documents draft recovery, notebook-style history, heatmaps, and session security. Some UI and server modules were not excerpted, so uncertain connections are omitted or marked unverified.

Main entry points: [`client/src/App.tsx`](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/App.tsx) (Route shell), [`client/src/pages/Dashboard.tsx`](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/Dashboard.tsx) (Dashboard), [`client/src/services/apiClient.ts`](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/services/apiClient.ts) (API client), [`client/src/pages/JournalHistory.tsx`](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/JournalHistory.tsx) (Journal history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client_ui["Client experience"]
  node_routing["Route shell<br/>[App.tsx]"]
  node_protected["Protected routes"]
  node_dashboard["Dashboard<br/>[Dashboard.tsx]"]
  node_habit_ui["Habit tracking<br/>[Habits.tsx]"]
  node_journal_write["Journal writing<br/>[Journal.tsx]"]
  node_journal_history["Journal history<br/>[JournalHistory.tsx]"]
  node_heatmap["Activity heatmaps"]
  node_daybook["Notebook view<br/>[JournalDayBook.tsx]"]
  node_drafts["Draft recovery<br/>[useDraft.ts]"]
  node_auth_pages["Account pages<br/>[Login.tsx]"]
end

subgraph group_client_data["Client data access"]
  node_habit_hooks["Habit data hooks<br/>[useHabits.ts]"]
  node_completion_hooks["Completion hooks"]
  node_journal_hooks["Journal data hooks"]
  node_activity_hooks["Journal activity hooks"]
  node_habit_service["Habit API service<br/>[habitService.ts]"]
  node_journal_service["Journal API service<br/>[journalService.ts]"]
  node_api_client["API client<br/>[apiClient.ts]"]
  node_query_cache["Query cache<br/>[queryClient.ts]"]
  node_auth_hooks["Current user hook<br/>[useCurrentUser.ts]"]
end

subgraph group_server_api["API and domain"]
  node_api_server["Express API<br/>[app.ts]"]
  node_habit_routes["Habit routes<br/>[habitRoutes.ts]"]
  node_habit_controller["Habit operations<br/>[habitController.ts]"]
  node_journal_routes["Journal routes<br/>[journalRoutes.ts]"]
  node_journal_controller["Journal operations"]
  node_validation["Request validation<br/>[schemas.ts]"]
end

subgraph group_server_auth["Authentication"]
  node_auth_routes["Auth routes<br/>[authRoutes.ts]"]
  node_auth_controller["Account and sessions<br/>[authController.ts]"]
  node_auth_middleware["Session guard<br/>[requireAuth.ts]"]
  node_session_service["Session service<br/>[sessionService.ts]"]
  node_cookie["Session cookie<br/>[authCookie.ts]"]
end

subgraph group_persistence["Persistence"]
  node_prisma["Prisma client<br/>[prisma.ts]"]
  node_database[("PostgreSQL")]
end

node_user(("Hibi user"))
node_browser_storage[("Browser localStorage")]

node_user -->|"uses"| node_routing
node_routing -->|"guards routes"| node_protected
node_protected -->|"checks session"| node_auth_hooks
node_routing -->|"routes to"| node_dashboard
node_routing -->|"routes to"| node_habit_ui
node_routing -->|"routes to"| node_journal_write
node_routing -->|"routes to"| node_journal_history
node_dashboard -->|"loads habits"| node_habit_hooks
node_dashboard -->|"loads completions"| node_completion_hooks
node_dashboard -->|"loads entries"| node_journal_hooks
node_dashboard -->|"loads activity"| node_activity_hooks
node_dashboard -->|"renders"| node_heatmap
node_habit_ui -->|"uses"| node_habit_hooks
node_habit_ui -->|"uses"| node_completion_hooks
node_journal_write -->|"uses"| node_journal_hooks
node_journal_write -->|"recovers drafts"| node_drafts
node_journal_history -->|"loads entries"| node_journal_hooks
node_journal_history -->|"loads activity"| node_activity_hooks
node_journal_history -->|"renders"| node_heatmap
node_journal_history -->|"renders"| node_daybook
node_journal_write -->|"renders"| node_daybook
node_drafts -->|"persists drafts"| node_browser_storage
node_habit_hooks -->|"calls"| node_habit_service
node_completion_hooks -->|"calls"| node_habit_service
node_journal_hooks -.->|"calls"| node_journal_service
node_activity_hooks -.->|"calls"| node_journal_service
node_habit_service -->|"requests"| node_api_client
node_journal_service -->|"requests"| node_api_client
node_api_client -->|"clears on 401"| node_query_cache
node_auth_pages -.->|"submits credentials"| node_api_client
node_auth_pages -->|"checks account"| node_auth_hooks
node_auth_hooks -->|"requests user"| node_api_client
node_api_client -.->|"sends API requests"| node_api_server
node_api_server -->|"mounts routes"| node_habit_routes
node_api_server -->|"mounts routes"| node_journal_routes
node_api_server -->|"mounts routes"| node_auth_routes
node_habit_routes -->|"requires auth"| node_auth_middleware
node_habit_routes -->|"dispatches"| node_habit_controller
node_journal_routes -->|"requires auth"| node_auth_middleware
node_journal_routes -->|"dispatches"| node_journal_controller
node_auth_routes -->|"dispatches"| node_auth_controller
node_habit_controller -->|"validates requests"| node_validation
node_journal_controller -->|"validates requests"| node_validation
node_habit_controller -->|"reads and writes"| node_prisma
node_journal_controller -->|"reads and writes"| node_prisma
node_auth_controller -->|"accesses records"| node_prisma
node_auth_controller -->|"manages sessions"| node_session_service
node_auth_controller -->|"sets cookie"| node_cookie

click node_routing "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/App.tsx"
click node_protected "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/components/ProtectedRoutes.tsx"
click node_dashboard "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/Dashboard.tsx"
click node_habit_ui "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/Habits.tsx"
click node_journal_write "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/Journal.tsx"
click node_journal_history "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/JournalHistory.tsx"
click node_heatmap "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/components/ActivityHeatmap.tsx"
click node_daybook "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/components/JournalDayBook.tsx"
click node_drafts "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useDraft.ts"
click node_habit_hooks "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useHabits.ts"
click node_completion_hooks "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useHabitsCompletions.ts"
click node_journal_hooks "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useJournalEntries.ts"
click node_activity_hooks "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useJournalActivity.ts"
click node_habit_service "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/services/habitService.ts"
click node_journal_service "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/services/journalService.ts"
click node_api_client "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/services/apiClient.ts"
click node_query_cache "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/lib/queryClient.ts"
click node_auth_pages "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/Login.tsx"
click node_auth_hooks "https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useCurrentUser.ts"
click node_api_server "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/app.ts"
click node_habit_routes "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/routes/habitRoutes.ts"
click node_habit_controller "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/controllers/habitController.ts"
click node_journal_routes "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/routes/journalRoutes.ts"
click node_journal_controller "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/controllers/journalController.ts"
click node_validation "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/validation/schemas.ts"
click node_auth_routes "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/routes/authRoutes.ts"
click node_auth_controller "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/controllers/authController.ts"
click node_auth_middleware "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/middleware/requireAuth.ts"
click node_session_service "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/lib/sessionService.ts"
click node_cookie "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/lib/authCookie.ts"
click node_prisma "https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/lib/prisma.ts"

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_routing,node_protected,node_dashboard,node_habit_ui,node_journal_write,node_journal_history,node_heatmap,node_daybook,node_drafts,node_auth_pages,node_user toneBlue
class node_habit_hooks,node_completion_hooks,node_journal_hooks,node_activity_hooks,node_habit_service,node_journal_service,node_api_client,node_query_cache,node_auth_hooks,node_browser_storage toneAmber
class node_api_server,node_habit_routes,node_habit_controller,node_journal_routes,node_journal_controller,node_validation toneMint
class node_auth_routes,node_auth_controller,node_auth_middleware,node_session_service,node_cookie toneRose
class node_prisma,node_database toneIndigo
```

## Components

### Client experience

- [Route shell](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/App.tsx): `client/src/App.tsx`
- [Protected routes](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/components/ProtectedRoutes.tsx): `client/src/components/ProtectedRoutes.tsx`
- [Dashboard](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/Dashboard.tsx): `client/src/pages/Dashboard.tsx`
- [Habit tracking](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/Habits.tsx): `client/src/pages/Habits.tsx`
- [Journal writing](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/Journal.tsx): `client/src/pages/Journal.tsx`
- [Journal history](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/JournalHistory.tsx): `client/src/pages/JournalHistory.tsx`
- [Activity heatmaps](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/components/ActivityHeatmap.tsx): `client/src/components/ActivityHeatmap.tsx`
- [Notebook view](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/components/JournalDayBook.tsx): `client/src/components/JournalDayBook.tsx`
- [Draft recovery](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useDraft.ts): `client/src/hooks/useDraft.ts`
- [Account pages](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/pages/Login.tsx): `client/src/pages/Login.tsx`

### Client data access

- [Habit data hooks](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useHabits.ts): `client/src/hooks/useHabits.ts`
- [Completion hooks](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useHabitsCompletions.ts): `client/src/hooks/useHabitsCompletions.ts`
- [Journal data hooks](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useJournalEntries.ts): `client/src/hooks/useJournalEntries.ts`
- [Journal activity hooks](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useJournalActivity.ts): `client/src/hooks/useJournalActivity.ts`
- [Habit API service](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/services/habitService.ts): `client/src/services/habitService.ts`
- [Journal API service](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/services/journalService.ts): `client/src/services/journalService.ts`
- [API client](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/services/apiClient.ts): `client/src/services/apiClient.ts`
- [Query cache](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/lib/queryClient.ts): `client/src/lib/queryClient.ts`
- [Current user hook](https://github.com/suki-amalie/journal-habit-tracker/blob/main/client/src/hooks/useCurrentUser.ts): `client/src/hooks/useCurrentUser.ts`

### API and domain

- [Express API](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/app.ts): `server/src/app.ts`
- [Habit routes](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/routes/habitRoutes.ts): `server/src/routes/habitRoutes.ts`
- [Habit operations](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/controllers/habitController.ts): `server/src/controllers/habitController.ts`
- [Journal routes](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/routes/journalRoutes.ts): `server/src/routes/journalRoutes.ts`
- [Journal operations](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/controllers/journalController.ts): `server/src/controllers/journalController.ts`
- [Request validation](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/validation/schemas.ts): `server/src/validation/schemas.ts`

### Authentication

- [Auth routes](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/routes/authRoutes.ts): `server/src/routes/authRoutes.ts`
- [Account and sessions](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/controllers/authController.ts): `server/src/controllers/authController.ts`
- [Session guard](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/middleware/requireAuth.ts): `server/src/middleware/requireAuth.ts`
- [Session service](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/lib/sessionService.ts): `server/src/lib/sessionService.ts`
- [Session cookie](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/lib/authCookie.ts): `server/src/lib/authCookie.ts`

### Persistence

- [Prisma client](https://github.com/suki-amalie/journal-habit-tracker/blob/main/server/src/lib/prisma.ts): `server/src/lib/prisma.ts`
- **PostgreSQL**

### Other components

- **Hibi user**
- **Browser localStorage**

## Connections

- Hibi user → Route shell: uses (evidence: `client/src/App.tsx`)
- Route shell → Protected routes: guards routes (evidence: `client/src/App.tsx`)
- Protected routes → Current user hook: checks session (evidence: `client/src/components/ProtectedRoutes.tsx`)
- Route shell → Dashboard: routes to (evidence: `client/src/App.tsx`)
- Route shell → Habit tracking: routes to (evidence: `client/src/App.tsx`)
- Route shell → Journal writing: routes to (evidence: `client/src/App.tsx`)
- Route shell → Journal history: routes to (evidence: `client/src/App.tsx`)
- Dashboard → Habit data hooks: loads habits (evidence: `client/src/pages/Dashboard.tsx`)
- Dashboard → Completion hooks: loads completions (evidence: `client/src/pages/Dashboard.tsx`)
- Dashboard → Journal data hooks: loads entries (evidence: `client/src/pages/Dashboard.tsx`)
- Dashboard → Journal activity hooks: loads activity (evidence: `client/src/pages/Dashboard.tsx`)
- Dashboard → Activity heatmaps: renders (evidence: `client/src/pages/Dashboard.tsx`)
- Habit tracking → Habit data hooks: uses (evidence: `client/src/pages/Habits.tsx`)
- Habit tracking → Completion hooks: uses (evidence: `client/src/pages/Habits.tsx`)
- Journal writing → Journal data hooks: uses (evidence: `client/src/pages/Journal.tsx`)
- Journal writing → Draft recovery: recovers drafts (evidence: `README.md`)
- Journal history → Journal data hooks: loads entries (evidence: `client/src/pages/JournalHistory.tsx`)
- Journal history → Journal activity hooks: loads activity (evidence: `client/src/pages/JournalHistory.tsx`)
- Journal history → Activity heatmaps: renders (evidence: `client/src/pages/JournalHistory.tsx`)
- Journal history → Notebook view: renders (evidence: `client/src/pages/JournalHistory.tsx`)
- Journal writing → Notebook view: renders (evidence: `client/src/pages/Journal.tsx`)
- Draft recovery → Browser localStorage: persists drafts (evidence: `README.md`)
- Habit data hooks → Habit API service: calls
- Completion hooks → Habit API service: calls (evidence: `client/src/hooks/useHabitsCompletions.ts`)
- Journal data hooks → Journal API service: calls
- Journal activity hooks → Journal API service: calls
- Habit API service → API client: requests (evidence: `client/src/services/habitService.ts`)
- Journal API service → API client: requests (evidence: `client/src/services/journalService.ts`)
- API client → Query cache: clears on 401 (evidence: `client/src/services/apiClient.ts`)
- Account pages → API client: submits credentials (evidence: `client/src/pages/Login.tsx`)
- Account pages → Current user hook: checks account (evidence: `client/src/pages/Login.tsx`)
- Current user hook → API client: requests user (evidence: `client/src/hooks/useCurrentUser.ts`)
- API client → Express API: sends API requests
- Express API → Habit routes: mounts routes (evidence: `server/src/app.ts`)
- Express API → Journal routes: mounts routes (evidence: `server/src/app.ts`)
- Express API → Auth routes: mounts routes (evidence: `server/src/app.ts`)
- Habit routes → Session guard: requires auth (evidence: `server/src/routes/habitRoutes.ts`)
- Habit routes → Habit operations: dispatches (evidence: `server/src/routes/habitRoutes.ts`)
- Journal routes → Session guard: requires auth (evidence: `server/src/routes/journalRoutes.ts`)
- Journal routes → Journal operations: dispatches (evidence: `server/src/routes/journalRoutes.ts`)
- Auth routes → Account and sessions: dispatches (evidence: `server/src/routes/authRoutes.ts`)
- Habit operations → Request validation: validates requests (evidence: `server/src/controllers/habitController.ts`)
- Journal operations → Request validation: validates requests (evidence: `server/src/controllers/journalController.ts`)
- Habit operations → Prisma client: reads and writes (evidence: `server/src/controllers/habitController.ts`)
- Journal operations → Prisma client: reads and writes (evidence: `server/src/controllers/journalController.ts`)
- Account and sessions → Prisma client: accesses records (evidence: `server/src/controllers/authController.ts`)
- Account and sessions → Session service: manages sessions (evidence: `server/src/controllers/authController.ts`)
- Account and sessions → Session cookie: sets cookie (evidence: `server/src/controllers/authController.ts`)
