# njxue/photoasis architecture

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

- Interactive diagram: https://gitdiagram.com/njxue/photoasis
- Repository: https://github.com/njxue/photoasis

## Overview

1. **Overall shape**
   - This is a **Next.js App Router** application for a photo gallery product called **Photoasis**.
   - The app is split into **public** and **protected** route groups, with separate layouts and route-level access control.
   - It mixes server-rendered pages, client components, server actions, and a small number of API routes.

2. **Core product domain**
   - The domain centers on **users, albums, photos, and user preferences**.
   - Photos are not just images; they carry and display **EXIF metadata** such as ISO, aperture, exposure, and metering mode.
   - The main user workflows are: register/login, upload photos, organize them into albums, inspect photo metadata, and manage account settings.

3. **Route and UI boundaries**
   - **Public routes** handle onboarding and authentication: login, register, forgot/reset password, and email verification.
   - **Protected routes** contain the product shell: dashboard, gallery, album detail pages, album creation, and settings.
   - The protected area has its own layout and shared navigation, while the public area uses a simpler layout and forms.

4. **Stateful feature contexts**
   - The app uses several React contexts to isolate feature state:
     - **UserPreferencesContext** for app-level preferences.
     - **AlbumContext** for the selected album and album-level operations.
     - **ImageUploadContext** for upload state and photo metadata entry.
     - **ModalContext** and **SelectContext** for shared interactive UI state.
   - These contexts help keep complex album and upload flows organized without passing props deeply.

5. **Album and photo management**
   - Album detail pages are highly interactive and are built from multiple subcomponents: headers, body, selection controls, settings panels, and forms.
   - Album actions include **create, update, delete**, plus photo-level actions such as **update photo metadata**, **delete photos**, and **change album thumbnails**.
   - The UI supports selection workflows for bulk actions, indicating that album/photo manipulation is a first-class interaction pattern.

6. **Upload and EXIF entry flow**
   - The upload experience is a distinct subsystem under `ImageUpload`.
   - It appears to combine:
     - file dropping / file selection,
     - image previews,
     - camera settings input fields,
     - and upload-specific controls.
   - The presence of EXIF-specific inputs like exposure mode and metering mode shows that uploads likely enrich stored photos with structured metadata, not just binary image files.

7. **Storage and backend mutation layer**
   - The `actions/` directory contains the main server-side mutation and integration functions.
   - These include auth/account flows (`signUp`, `resetPassword`, `sendEmailVerification`, `sendPasswordResetEmail`) and domain mutations (`createAlbum`, `updateAlbum`, `deleteAlbum`, `updatePhoto`, `updateUser`, `updateUserPreferences`, etc.).
   - `actions/b2.js` strongly suggests integration with **Backblaze B2** for file storage, which is likely the external object store for uploaded images.

8. **Data and persistence**
   - The repository uses **Prisma** with migrations and a schema file, so the persistent data model is database-backed and centrally defined.
   - The schema likely covers users, albums, photos, and preference records, plus any auth-related fields needed for login and verification.
   - This database is the source of truth for app state; the object storage layer is used for the actual photo binaries.

9. **Authentication and account lifecycle**
   - Authentication is handled through `app/api/auth/[...nextauth]/route.js`, which indicates **NextAuth**-style auth integration.
   - The public auth flows include registration, login, email verification, and password reset, so account lifecycle is a major subsystem.
   - `middleware.js` likely enforces the public/protected split and redirects unauthenticated users away from protected pages.

10. **Export and media delivery**
   - `app/api/download-zip/route.js` provides a server endpoint for **bulk photo download** as a zip archive.
   - This is an important boundary because it packages stored media for client download rather than rendering it in the UI.
   - The image rendering layer includes optimized/common image components, implying the app uses a performance-conscious approach to gallery display.

11. **Shared app shell and cross-cutting concerns**
   - `app/layout.jsx`, `app/Provider.jsx`, `app/PosthogProvider.jsx`, and `app/ToastContainerWrapper.jsx` establish global app-wide concerns.
   - These likely wire up theming/state providers, analytics, and toast notifications for both public and protected routes.
   - The app also includes reusable UI primitives such as inputs, buttons, modals, tooltips, loading states, and drag-and-drop helpers.

12. **External integrations and operational tooling**
   - The repo includes email templates for verification and password reset, so transactional email is part of the architecture.
   - `public/worker.js` and `utils/compress.js` suggest client-side or edge-assisted image processing/compression support.
   - There is GitHub Actions linting, indicating basic CI quality checks, and the app is structured for deployment on a Next.js-friendly platform such as Vercel.

13. **How the main data flow works**
   - A user authenticates through the public auth flow.
   - Once protected, they navigate to dashboard/gallery/album views that read from the database via server-rendered pages and client contexts.
   - Uploading photos sends files and EXIF metadata through the upload UI, then into storage and Prisma-backed records.
   - Album and photo edits are performed through server actions, with the UI updating through shared contexts and form components.

14. **What to emphasize in an architecture diagram**
   - Show three major boundaries: **public auth/onboarding**, **protected gallery management**, and **backend services**.
   - Place **Next.js UI/components** on the front end, **server actions + API routes** in the middle, and **Prisma DB + B2/email storage services** on the back end.
   - Highlight the photo pipeline separately from the account pipeline, because media upload/storage and authentication/verification are both major but distinct subsystems.

Main entry points: [`app/(protected)/layout.jsx`](https://github.com/njxue/photoasis/blob/master/app/(protected)/layout.jsx) (Protected shell), [`actions`](https://github.com/njxue/photoasis/tree/master/actions) (Actions), [`app/(protected)/album/[id]/page.jsx`](https://github.com/njxue/photoasis/blob/master/app/(protected)/album/[id]/page.jsx) (Album detail), [`app/(protected)/components/ImageUpload`](https://github.com/njxue/photoasis/tree/master/app/(protected)/components/ImageUpload) (Photo upload)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public routes"]
  node_public_shell["Public shell<br/>public layout<br/>[layout.jsx]"]
  node_register_login["Auth pages<br/>public auth UI"]
end

subgraph group_protected["Protected app"]
  node_protected_shell["Protected shell<br/>protected layout<br/>[layout.jsx]"]
  node_dashboard["Dashboard<br/>overview page<br/>[page.jsx]"]
  node_gallery["Gallery<br/>photo browser<br/>[page.jsx]"]
  node_album_detail["Album detail<br/>album workspace<br/>[page.jsx]"]
  node_album_create["New album<br/>album creation UI<br/>[page.jsx]"]
  node_settings["Settings<br/>[page.jsx]"]
  node_upload["Photo upload<br/>upload subsystem"]
  node_album_state["Album state<br/>album context<br/>[AlbumContext.jsx]"]
  node_prefs_state["Preferences state<br/>user preferences context"]
  node_modal_select["Modal & select<br/>shared interaction state<br/>[ModalContext.jsx]"]
end

subgraph group_backend["Server/backend"]
  node_middleware["Middleware<br/>route guard<br/>[middleware.js]"]
  node_nextauth["Auth API<br/>NextAuth route<br/>[route.js]"]
  node_download_zip["Zip download<br/>media API<br/>[route.js]"]
  node_server_actions["Actions<br/>server mutations"]
  node_b2["B2 storage<br/>object storage integration<br/>[b2.js]"]
  node_prisma[("Database<br/>Prisma data layer<br/>[schema.prisma]")]
end

subgraph group_shared["Shared platform"]
  node_app_layout["App layout<br/>Next.js root shell<br/>[layout.jsx]"]
  node_providers["Providers<br/>[Provider.jsx]"]
  node_posthog["Analytics"]
  node_toast["Toasts<br/>notification wrapper"]
  node_shared_ui["UI primitives<br/>shared components"]
end

node_app_layout -->|"wraps"| node_providers
node_app_layout -->|"contains"| node_public_shell
node_app_layout -->|"contains"| node_protected_shell
node_providers -->|"includes"| node_posthog
node_providers -->|"includes"| node_toast
node_middleware -->|"permits"| node_public_shell
node_middleware -->|"guards"| node_protected_shell
node_public_shell -->|"hosts"| node_register_login
node_register_login -->|"authenticates"| node_nextauth
node_register_login -->|"submits"| node_server_actions
node_protected_shell -->|"navigates to"| node_dashboard
node_protected_shell -->|"navigates to"| node_gallery
node_protected_shell -->|"navigates to"| node_album_detail
node_protected_shell -->|"navigates to"| node_album_create
node_protected_shell -->|"navigates to"| node_settings
node_protected_shell -->|"provides"| node_prefs_state
node_album_detail -->|"uses"| node_album_state
node_album_detail -->|"uses"| node_modal_select
node_album_detail -->|"mutates"| node_server_actions
node_album_detail -->|"exports"| node_download_zip
node_album_create -->|"creates"| node_server_actions
node_settings -->|"updates"| node_server_actions
node_upload -->|"stores"| node_b2
node_upload -->|"persists"| node_server_actions
node_upload -->|"uses"| node_shared_ui
node_gallery -->|"uses"| node_shared_ui
node_album_detail -->|"uses"| node_shared_ui
node_server_actions -->|"reads/writes"| node_prisma
node_server_actions -->|"integrates"| node_b2
node_server_actions -->|"supports"| node_nextauth

click node_app_layout "https://github.com/njxue/photoasis/blob/master/app/layout.jsx"
click node_providers "https://github.com/njxue/photoasis/blob/master/app/Provider.jsx"
click node_posthog "https://github.com/njxue/photoasis/blob/master/app/PosthogProvider.jsx"
click node_toast "https://github.com/njxue/photoasis/blob/master/app/ToastContainerWrapper.jsx"
click node_middleware "https://github.com/njxue/photoasis/blob/master/middleware.js"
click node_nextauth "https://github.com/njxue/photoasis/blob/master/app/api/auth/[...nextauth]/route.js"
click node_download_zip "https://github.com/njxue/photoasis/blob/master/app/api/download-zip/route.js"
click node_server_actions "https://github.com/njxue/photoasis/tree/master/actions"
click node_b2 "https://github.com/njxue/photoasis/blob/master/actions/b2.js"
click node_prisma "https://github.com/njxue/photoasis/blob/master/prisma/schema.prisma"
click node_public_shell "https://github.com/njxue/photoasis/blob/master/app/(public)/layout.jsx"
click node_register_login "https://github.com/njxue/photoasis/tree/master/app/(public)"
click node_protected_shell "https://github.com/njxue/photoasis/blob/master/app/(protected)/layout.jsx"
click node_dashboard "https://github.com/njxue/photoasis/blob/master/app/(protected)/dashboard/page.jsx"
click node_gallery "https://github.com/njxue/photoasis/blob/master/app/(protected)/gallery/page.jsx"
click node_album_detail "https://github.com/njxue/photoasis/blob/master/app/(protected)/album/[id]/page.jsx"
click node_album_create "https://github.com/njxue/photoasis/blob/master/app/(protected)/album/new/page.jsx"
click node_settings "https://github.com/njxue/photoasis/blob/master/app/(protected)/settings/page.jsx"
click node_upload "https://github.com/njxue/photoasis/tree/master/app/(protected)/components/ImageUpload"
click node_album_state "https://github.com/njxue/photoasis/blob/master/app/(protected)/album/[id]/AlbumContext.jsx"
click node_prefs_state "https://github.com/njxue/photoasis/blob/master/app/(protected)/UserPreferencesContext.jsx"
click node_modal_select "https://github.com/njxue/photoasis/blob/master/app/(protected)/components/Modal/ModalContext.jsx"
click node_shared_ui "https://github.com/njxue/photoasis/tree/master/app/common"

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_shell,node_register_login toneBlue
class node_protected_shell,node_dashboard,node_gallery,node_album_detail,node_album_create,node_settings,node_upload,node_album_state,node_prefs_state,node_modal_select toneAmber
class node_middleware,node_nextauth,node_download_zip,node_server_actions,node_b2,node_prisma toneMint
class node_app_layout,node_providers,node_posthog,node_toast,node_shared_ui toneRose
```

## Components

### Public routes

Onboarding, login, and password/email recovery.

- [Public shell](https://github.com/njxue/photoasis/blob/master/app/(public)/layout.jsx): public layout · Shared layout for onboarding and auth pages. · `app/(public)/layout.jsx`
- [Auth pages](https://github.com/njxue/photoasis/tree/master/app/(public)): public auth UI · Login, register, forgot/reset password, and email verification screens. · `app/(public)`

### Protected app

Authenticated gallery, album, upload, and settings experience.

- [Protected shell](https://github.com/njxue/photoasis/blob/master/app/(protected)/layout.jsx): protected layout · Authenticated application layout and navigation frame. · `app/(protected)/layout.jsx`
- [Dashboard](https://github.com/njxue/photoasis/blob/master/app/(protected)/dashboard/page.jsx): overview page · Primary authenticated landing page and summary surface. · `app/(protected)/dashboard/page.jsx`
- [Gallery](https://github.com/njxue/photoasis/blob/master/app/(protected)/gallery/page.jsx): photo browser · Main gallery view for browsing and inspecting photos. · `app/(protected)/gallery/page.jsx`
- [Album detail](https://github.com/njxue/photoasis/blob/master/app/(protected)/album/[id]/page.jsx): album workspace · Interactive album page with selection, settings, and bulk photo actions. · `app/(protected)/album/[id]/page.jsx`
- [New album](https://github.com/njxue/photoasis/blob/master/app/(protected)/album/new/page.jsx): album creation UI · Form flow for creating a new album. · `app/(protected)/album/new/page.jsx`
- [Settings](https://github.com/njxue/photoasis/blob/master/app/(protected)/settings/page.jsx): account settings · User preference and image fit settings surface. · `app/(protected)/settings/page.jsx`
- [Photo upload](https://github.com/njxue/photoasis/tree/master/app/(protected)/components/ImageUpload): upload subsystem · Drop/select files, preview them, and capture EXIF/photo settings during upload. · `app/(protected)/components/ImageUpload`
- [Album state](https://github.com/njxue/photoasis/blob/master/app/(protected)/album/[id]/AlbumContext.jsx): album context · Selected album state and album-level operations. · `app/(protected)/album/[id]/AlbumContext.jsx`
- [Preferences state](https://github.com/njxue/photoasis/blob/master/app/(protected)/UserPreferencesContext.jsx): user preferences context · App-level user preferences shared in the protected area. · `app/(protected)/UserPreferencesContext.jsx`
- [Modal & select](https://github.com/njxue/photoasis/blob/master/app/(protected)/components/Modal/ModalContext.jsx): shared interaction state · Reusable contexts for modal dialogs and selection workflows. · `app/(protected)/components/Modal/ModalContext.jsx`

### Server/backend

Server actions, API routes, auth, persistence, and external services.

- [Middleware](https://github.com/njxue/photoasis/blob/master/middleware.js): route guard · Enforces public vs protected access boundaries. · `middleware.js`
- [Auth API](https://github.com/njxue/photoasis/blob/master/app/api/auth/[...nextauth]/route.js): NextAuth route · Authentication endpoint for session and provider flow. · `app/api/auth/[...nextauth]/route.js`
- [Zip download](https://github.com/njxue/photoasis/blob/master/app/api/download-zip/route.js): media API · Server endpoint for bulk photo export as a zip. · `app/api/download-zip/route.js`
- [Actions](https://github.com/njxue/photoasis/tree/master/actions): server mutations · Main mutation and integration layer for auth, albums, photos, and preferences. · `actions`
- [B2 storage](https://github.com/njxue/photoasis/blob/master/actions/b2.js): object storage integration · Backblaze B2 integration for uploaded image binaries. · `actions/b2.js`
- [Database](https://github.com/njxue/photoasis/blob/master/prisma/schema.prisma): Prisma data layer · Database schema, migrations, and Prisma access layer. · `prisma/schema.prisma`

### Shared platform

Global providers and reusable UI primitives used across route groups.

- [App layout](https://github.com/njxue/photoasis/blob/master/app/layout.jsx): Next.js root shell · Global app entry that wraps both public and protected areas. · `app/layout.jsx`
- [Providers](https://github.com/njxue/photoasis/blob/master/app/Provider.jsx): global providers · App-wide state, analytics, and toast wiring. · `app/Provider.jsx`
- [Analytics](https://github.com/njxue/photoasis/blob/master/app/PosthogProvider.jsx): analytics provider · PostHog integration for product analytics. · `app/PosthogProvider.jsx`
- [Toasts](https://github.com/njxue/photoasis/blob/master/app/ToastContainerWrapper.jsx): notification wrapper · Global toast container used by the app. · `app/ToastContainerWrapper.jsx`
- [UI primitives](https://github.com/njxue/photoasis/tree/master/app/common): shared components · Common inputs, loaders, buttons, images, tooltips, and helpers used across the app. · `app/common`

## Connections

- App layout → Providers: wraps · Root layout mounts global providers.
- App layout → Public shell: contains · Root layout includes the public route group.
- App layout → Protected shell: contains · Root layout includes the protected route group.
- Providers → Analytics: includes · Providers wires analytics.
- Providers → Toasts: includes · Providers wires toast notifications.
- Middleware → Public shell: permits · Middleware keeps public routes accessible.
- Middleware → Protected shell: guards · Middleware protects authenticated pages.
- Public shell → Auth pages: hosts · Public layout renders onboarding and auth pages.
- Auth pages → Auth API: authenticates · Login/register pages rely on auth route integration.
- Auth pages → Actions: submits · Auth flows call server-side account mutations.
- Protected shell → Dashboard: navigates to · Protected shell frames the main dashboard.
- Protected shell → Gallery: navigates to · Protected shell frames the gallery browser.
- Protected shell → Album detail: navigates to · Protected shell frames album workspaces.
- Protected shell → New album: navigates to · Protected shell frames album creation.
- Protected shell → Settings: navigates to · Protected shell frames account settings.
- Protected shell → Preferences state: provides · Protected area shares user preference state.
- Album detail → Album state: uses · Album pages rely on selected album context.
- Album detail → Modal & select: uses · Album interactions use modal and selection state.
- Album detail → Actions: mutates · Album pages create, update, delete albums and photos.
- Album detail → Zip download: exports · Album/gallery UI can request zip downloads.
- New album → Actions: creates · New album flow submits create-album mutations.
- Settings → Actions: updates · Settings pages update user and preference records.
- Photo upload → B2 storage: stores · Upload flow sends binaries to object storage.
- Photo upload → Actions: persists · Upload flow records photo and metadata via actions.
- Photo upload → UI primitives: uses · Upload UI builds on shared inputs and helpers.
- Gallery → UI primitives: uses · Gallery relies on reusable image and card components.
- Album detail → UI primitives: uses · Album workspace relies on shared UI primitives.
- Actions → Database: reads/writes · Actions are the main database mutation layer.
- Actions → B2 storage: integrates · Actions coordinate file storage and deletion.
- Actions → Auth API: supports · Actions support authentication and account lifecycle flows.
