# rupesh6410/bookshare architecture

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

- Interactive diagram: https://gitdiagram.com/rupesh6410/bookshare
- Repository: https://github.com/rupesh6410/bookshare

## Overview

1. **Overall shape**
   - This is a **Next.js App Router** application that combines the UI, server-side mutations, and API endpoints in one repo.
   - The architecture is centered around **book listing and sharing**, with persistence in **PostgreSQL via Prisma** and file uploads handled through a dedicated upload API.

2. **Primary user-facing routes**
   - The `app/` directory defines the main screens:
     - `app/page.tsx` — landing/home
     - `app/books/page.tsx` — book browsing/listing
     - `app/books/upload/page.tsx` — upload flow
     - `app/about/page.tsx` — informational page
   - These are route-level boundaries and likely compose the main product flow: browse books, create a listing, and view details through shared UI components.

3. **Shared UI and presentation layer**
   - Reusable components live under `components/`, including:
     - `BookCard.tsx` for book display
     - `theme-provider.tsx` for theme handling
     - `components/ui/*` for the ShadCN-style design system primitives
   - `app/globals.css` and the UI primitives suggest a **Tailwind + component library** front end, with visual styling isolated from business logic.

4. **Server actions for domain mutations**
   - `app/actions/book.ts` is the main server-action boundary visible in the tree.
   - This is likely where **book create/update/delete** operations are executed from forms in the App Router, keeping mutation logic close to the UI while still running on the server.

5. **Persistence layer**
   - `prisma/schema.prisma` and the migration files define the app’s database schema and evolution.
   - `lib/prisma.ts` is the Prisma client singleton/entry point, which is the main database access layer used by server actions and route handlers.
   - `docker-compose.yml` implies a local **PostgreSQL** database is part of the deployment/dev environment.

6. **Validation and error boundaries**
   - `lib/validations.ts` contains Zod schemas for type-safe input validation.
   - `lib/app-error.ts` suggests a custom error abstraction for translating backend failures into app-level responses.
   - This means input likely flows: **form/UI → validation → server action / API → Prisma**.

7. **File upload subsystem**
   - `app/api/uploadthing/core.ts` and `app/api/uploadthing/route.ts` define a dedicated API boundary for uploads.
   - `utils/uplaodthing.ts` appears to configure the upload integration.
   - This subsystem is separate from the book CRUD path and likely returns uploaded file metadata/URLs that are later saved with book records.

8. **Access control and route protection**
   - `proxy.ts` and `lib/checkUser.ts` indicate a request-time gate or auth-checking layer.
   - The README mentions **NextAuth** with Google/email login, so auth is a major boundary even though the concrete auth files are not present in the tree.
   - In diagram terms, protected routes likely sit behind the proxy/auth check before reaching book mutation or upload actions.

9. **External services and integrations**
   - The README advertises integrations with **NextAuth**, **OpenAI/LangGraph**, **Socket.IO**, and storage backends like **AWS S3 / Cloudinary**.
   - In the visible tree, the only clearly implemented integration boundary is **UploadThing** for file uploads.
   - The AI and real-time chat features are described in the README, but their concrete implementation is not visible here, so they should be treated as external/planned subsystems unless present elsewhere.

10. **End-to-end data flow**
   - Typical flow appears to be:
     - user visits a route in `app/`
     - interacts with a form/component in `components/`
     - form submits to a server action or API route
     - input is validated with Zod
     - Prisma writes/reads from PostgreSQL
     - uploaded images are handled through the upload API and stored as references on book records
   - That makes the repo a **single-deployment full-stack app** with clear boundaries around UI, mutations, persistence, auth, and uploads.

Main entry points: [`app/actions/book.ts`](https://github.com/rupesh6410/bookshare/blob/main/app/actions/book.ts) (Book actions), [`app/books/upload/page.tsx`](https://github.com/rupesh6410/bookshare/blob/main/app/books/upload/page.tsx) (Upload), [`proxy.ts`](https://github.com/rupesh6410/bookshare/blob/main/proxy.ts) (Proxy), [`app/books/page.tsx`](https://github.com/rupesh6410/bookshare/blob/main/app/books/page.tsx) (Books)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_app["App routes"]
  node_n_home["Home<br/>route<br/>[page.tsx]"]
  node_n_books["Books<br/>route<br/>[page.tsx]"]
  node_n_upload_page["Upload<br/>route<br/>[page.tsx]"]
  node_n_about["About<br/>route<br/>[page.tsx]"]
  node_n_layout["Layout<br/>shell<br/>[layout.tsx]"]
end

subgraph group_grp_ui["UI components"]
  node_n_bookcard["BookCard<br/>ui component<br/>[BookCard.tsx]"]
  node_n_theme["Theme<br/>ui provider<br/>[theme-provider.tsx]"]
  node_n_ui["UI kit<br/>primitives"]
end

subgraph group_grp_server["Server logic"]
  node_n_actions_book["Book actions<br/>server actions<br/>[book.ts]"]
  node_n_validations["Validations<br/>zod schemas<br/>[validations.ts]"]
  node_n_errors["App errors<br/>error model<br/>[app-error.ts]"]
  node_n_checkuser["User check<br/>auth guard<br/>[checkUser.ts]"]
  node_n_proxy["Proxy<br/>middleware<br/>[proxy.ts]"]
end

subgraph group_grp_data["Data layer"]
  node_n_prisma_client[("Prisma client<br/>db client<br/>[prisma.ts]")]
  node_n_schema["Schema<br/>[schema.prisma]"]
end

subgraph group_grp_upload["Uploads"]
  node_n_upload_route["Upload route<br/>api route<br/>[route.ts]"]
  node_n_upload_core["Upload core<br/>upload config<br/>[core.ts]"]
  node_n_upload_utils["Upload setup<br/>integration config<br/>[uplaodthing.ts]"]
end

node_n_layout -->|"wraps"| node_n_theme
node_n_layout -->|"styles"| node_n_ui
node_n_home -->|"renders"| node_n_bookcard
node_n_books -->|"lists"| node_n_bookcard
node_n_upload_page -->|"forms"| node_n_ui
node_n_about -->|"uses"| node_n_ui
node_n_books -->|"reads"| node_n_actions_book
node_n_upload_page -->|"submits"| node_n_actions_book
node_n_actions_book -->|"validates"| node_n_validations
node_n_actions_book -->|"throws"| node_n_errors
node_n_actions_book -->|"guards"| node_n_checkuser
node_n_actions_book -->|"persists"| node_n_prisma_client
node_n_prisma_client -->|"maps"| node_n_schema
node_n_upload_route -->|"serves"| node_n_upload_core
node_n_upload_core -->|"configured by"| node_n_upload_utils
node_n_upload_page -->|"uploads"| node_n_upload_route
node_n_proxy -->|"enforces"| node_n_checkuser
node_n_proxy -->|"protects"| node_n_books
node_n_proxy -->|"protects"| node_n_upload_page

click node_n_home "https://github.com/rupesh6410/bookshare/blob/main/app/page.tsx"
click node_n_books "https://github.com/rupesh6410/bookshare/blob/main/app/books/page.tsx"
click node_n_upload_page "https://github.com/rupesh6410/bookshare/blob/main/app/books/upload/page.tsx"
click node_n_about "https://github.com/rupesh6410/bookshare/blob/main/app/about/page.tsx"
click node_n_layout "https://github.com/rupesh6410/bookshare/blob/main/app/layout.tsx"
click node_n_bookcard "https://github.com/rupesh6410/bookshare/blob/main/components/BookCard.tsx"
click node_n_theme "https://github.com/rupesh6410/bookshare/blob/main/components/theme-provider.tsx"
click node_n_ui "https://github.com/rupesh6410/bookshare/tree/main/components/ui"
click node_n_actions_book "https://github.com/rupesh6410/bookshare/blob/main/app/actions/book.ts"
click node_n_validations "https://github.com/rupesh6410/bookshare/blob/main/lib/validations.ts"
click node_n_errors "https://github.com/rupesh6410/bookshare/blob/main/lib/app-error.ts"
click node_n_checkuser "https://github.com/rupesh6410/bookshare/blob/main/lib/checkUser.ts"
click node_n_prisma_client "https://github.com/rupesh6410/bookshare/blob/main/lib/prisma.ts"
click node_n_schema "https://github.com/rupesh6410/bookshare/blob/main/prisma/schema.prisma"
click node_n_upload_route "https://github.com/rupesh6410/bookshare/blob/main/app/api/uploadthing/route.ts"
click node_n_upload_core "https://github.com/rupesh6410/bookshare/blob/main/app/api/uploadthing/core.ts"
click node_n_upload_utils "https://github.com/rupesh6410/bookshare/blob/main/utils/uplaodthing.ts"
click node_n_proxy "https://github.com/rupesh6410/bookshare/blob/main/proxy.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_n_home,node_n_books,node_n_upload_page,node_n_about,node_n_layout toneBlue
class node_n_bookcard,node_n_theme,node_n_ui toneAmber
class node_n_actions_book,node_n_validations,node_n_errors,node_n_checkuser,node_n_proxy toneMint
class node_n_prisma_client,node_n_schema toneRose
class node_n_upload_route,node_n_upload_core,node_n_upload_utils toneIndigo
```

## Components

### App routes

Route-level UI and request boundaries

- [Home](https://github.com/rupesh6410/bookshare/blob/main/app/page.tsx): route · Landing page · `app/page.tsx`
- [Books](https://github.com/rupesh6410/bookshare/blob/main/app/books/page.tsx): route · Book browsing page · `app/books/page.tsx`
- [Upload](https://github.com/rupesh6410/bookshare/blob/main/app/books/upload/page.tsx): route · Book upload page · `app/books/upload/page.tsx`
- [About](https://github.com/rupesh6410/bookshare/blob/main/app/about/page.tsx): route · Informational page · `app/about/page.tsx`
- [Layout](https://github.com/rupesh6410/bookshare/blob/main/app/layout.tsx): shell · Root app shell · `app/layout.tsx`

### UI components

Shared presentation layer

- [BookCard](https://github.com/rupesh6410/bookshare/blob/main/components/BookCard.tsx): ui component · Book display card · `components/BookCard.tsx`
- [Theme](https://github.com/rupesh6410/bookshare/blob/main/components/theme-provider.tsx): ui provider · Theme context/provider · `components/theme-provider.tsx`
- [UI kit](https://github.com/rupesh6410/bookshare/tree/main/components/ui): primitives · Shared design-system primitives · `components/ui`

### Server logic

Mutations, auth, validation, and app errors

- [Book actions](https://github.com/rupesh6410/bookshare/blob/main/app/actions/book.ts): server actions · Book create/update/delete boundary · `app/actions/book.ts`
- [Validations](https://github.com/rupesh6410/bookshare/blob/main/lib/validations.ts): zod schemas · Input validation schemas · `lib/validations.ts`
- [App errors](https://github.com/rupesh6410/bookshare/blob/main/lib/app-error.ts): error model · Application error abstraction · `lib/app-error.ts`
- [User check](https://github.com/rupesh6410/bookshare/blob/main/lib/checkUser.ts): auth guard · Request-time user access check · `lib/checkUser.ts`
- [Proxy](https://github.com/rupesh6410/bookshare/blob/main/proxy.ts): middleware · Route protection boundary · `proxy.ts`

### Data layer

Database client and schema

- [Prisma client](https://github.com/rupesh6410/bookshare/blob/main/lib/prisma.ts): db client · Database access entry point · `lib/prisma.ts`
- [Schema](https://github.com/rupesh6410/bookshare/blob/main/prisma/schema.prisma): prisma schema · Data model and migrations source · `prisma/schema.prisma`

### Uploads

Dedicated file upload boundary

- [Upload route](https://github.com/rupesh6410/bookshare/blob/main/app/api/uploadthing/route.ts): api route · UploadThing API endpoint · `app/api/uploadthing/route.ts`
- [Upload core](https://github.com/rupesh6410/bookshare/blob/main/app/api/uploadthing/core.ts): upload config · UploadThing router/core config · `app/api/uploadthing/core.ts`
- [Upload setup](https://github.com/rupesh6410/bookshare/blob/main/utils/uplaodthing.ts): integration config · UploadThing client/server wiring · `utils/uplaodthing.ts`

## Connections

- Layout → Theme: wraps · Provides theme context to the app
- Layout → UI kit: styles · Root shell uses shared primitives
- Home → BookCard: renders · Home surfaces book previews
- Books → BookCard: lists · Book browsing uses the card component
- Upload → UI kit: forms · Upload flow is built from shared inputs and controls
- About → UI kit: uses · About page shares the design system
- Books → Book actions: reads · Book page depends on server-side book data operations
- Upload → Book actions: submits · Upload flow creates or updates book records
- Book actions → Validations: validates · Server actions validate incoming form data
- Book actions → App errors: throws · Domain failures are normalized as app errors
- Book actions → User check: guards · Mutations check the current user
- Book actions → Prisma client: persists · Server actions read and write through Prisma
- Prisma client → Schema: maps · Client is shaped by the Prisma schema
- Upload route → Upload core: serves · Route handler exposes the upload core
- Upload core → Upload setup: configured by · Core is wired through the upload helper
- Upload → Upload route: uploads · Upload UI sends files to the dedicated API route
- Proxy → User check: enforces · Request protection reuses the user check boundary
- Proxy → Books: protects · Book workflow sits behind access control
- Proxy → Upload: protects · Upload flow is gated before entry
