# irfan-rg/inkwell architecture

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

- Interactive diagram: https://gitdiagram.com/irfan-rg/inkwell
- Repository: https://github.com/irfan-rg/inkwell

## Overview

#### Purpose and Runtime

Inkwell is a multi-user Markdown blogging platform: readers browse and search published posts, while authenticated authors manage categories, drafts, posts, and media. It runs as a TypeScript Next.js App Router application with React, Tailwind/Radix UI, tRPC, Drizzle, PostgreSQL/Supabase, and Vercel-oriented deployment.

Primary application shell and route fallback are in `app/layout.tsx`, `app/page.tsx`, and `app/not-found.tsx`.

#### Route Domains and Entry Points

Public pages are grouped independently from authoring routes:
- Landing, about, blog index, and slugged reader pages: `app/(public)/page.tsx`, `app/(public)/blogs/page.tsx`, `app/(public)/blogs/[slug]/page.tsx`.
- Authenticated dashboard, new-post, edit-post, and category management: `app/(auth)/dashboard/page.tsx`, `app/(auth)/dashboard/new/page.tsx`, `app/(auth)/dashboard/edit/[id]/page.tsx`.
- Login/signup flow is isolated under `app/auth/login/page.tsx` and `app/auth/signup/page.tsx`.

Route-group layouts provide public versus authenticated composition at `app/(public)/layout.tsx` and `app/(auth)/layout.tsx`.

#### Authentication and Authorization Boundary

Supabase Auth is the identity provider. Client/server Supabase adapters and auth utilities form the boundary between route/UI code and identity/session handling: `lib/supabase/client.ts`, `lib/supabase/server.ts`, `lib/auth.ts`.

`components/auth/AuthGuard.tsx` protects author-facing UI. Database-level access control is expected through Supabase Row Level Security policy definitions in `supabase-rls-policies.sql`, complementing application authorization for authoring and editing.

#### API and Backend Composition

Browser data operations use a typed tRPC client/provider layer in `lib/trpc.tsx`, routed by the Next route handler at `app/api/trpc/[trpc]/route.ts`. The server assembles router namespaces in `server/api/root.ts` and exposes tRPC context/transport setup from `server/api/trpc.ts`.

Core backend capabilities are separated into:
- Post lifecycle, reading/querying, drafts, and editing: `server/api/routers/post.ts`.
- Category management/filtering: `server/api/routers/category.ts`.
- Media upload operations backed by Supabase Storage: `server/api/routers/upload.ts`.

This keeps page/components dependent on typed procedures rather than directly on SQL or storage credentials.

#### Editorial Workflow and Reader Presentation

`components/blog/PostForm.tsx` is the central authoring surface, composed with `components/blog/MarkdownEditor.tsx`, `components/blog/MarkdownRenderer.tsx`, and `components/blog/ImageUpload.tsx`. It supports Markdown composition, live rendering, cover/inline media upload, and persisted post state.

Public discovery is built from `components/blog/PostList.tsx`, `components/blog/PostCard.tsx`, `components/blog/SearchBar.tsx`, and `components/blog/CategoryFilter.tsx`; selected posts resolve into the public slug route. This is the principal flow: reader query/filter → tRPC post/category fetch → rendered published content.

#### Persistence, Schema, and Media

Drizzle connects application server code to PostgreSQL via `server/db/index.ts`; the relational model is defined in `server/db/schema.ts`. Versioned schema evolution is captured in `drizzle/0001_magenta_chat.sql`, `drizzle/0002_wakeful_malice.sql`, and `drizzle/0003_add_archived_field.sql`.

Supabase serves two distinct infrastructure roles: Auth/RLS for user-scoped access and Storage for uploaded images. `lib/supabase/keep-alive.ts` and `app/api/keep-alive/route.ts` provide an operational endpoint intended to keep the database/service active.

#### Shared Presentation and Client State

The global visual system starts at `app/globals.css`; shared navigation/chrome lives in `components/layout/Navbar.tsx` and `components/layout/Footer.tsx`. Theme state is supplied through `components/theme/ThemeProvider.tsx`.

Client-side transient state is centralized in `lib/store.ts`, while React Query is used through the tRPC integration for asynchronous API cache/state. Reusable primitives under `components/ui` establish the shared accessible design-system boundary without embedding domain behavior.

Main entry points: [`app/layout.tsx`](https://github.com/irfan-rg/inkwell/blob/main/app/layout.tsx) (Application shell), [`server/api/root.ts`](https://github.com/irfan-rg/inkwell/blob/main/server/api/root.ts) (tRPC server composition), [`lib/trpc.tsx`](https://github.com/irfan-rg/inkwell/blob/main/lib/trpc.tsx) (tRPC client provider), [`app/(auth)/dashboard/page.tsx`](https://github.com/irfan-rg/inkwell/blob/main/app/(auth)/dashboard/page.tsx) (Author dashboard routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_routes["Next.js routes"]
  node_app_shell["Application shell<br/>Next.js layout<br/>[layout.tsx]"]
  node_public_routes["Public reader routes<br/>Next.js route group<br/>[page.tsx]"]
  node_author_routes["Author dashboard routes<br/>Next.js route group<br/>[page.tsx]"]
  node_auth_routes["Login and signup<br/>Next.js auth routes<br/>[page.tsx]"]
  node_keep_alive["Keep-alive endpoint<br/>operational API route<br/>[route.ts]"]
end

subgraph group_ui["UI and client state"]
  node_auth_guard["Author access guard<br/>React auth boundary<br/>[AuthGuard.tsx]"]
  node_reader_ui["Discovery UI<br/>React blog components<br/>[PostList.tsx]"]
  node_editorial_ui["Post authoring UI<br/>React editor components<br/>[PostForm.tsx]"]
  node_shared_ui["Shared chrome and theme<br/>React presentation<br/>[Navbar.tsx]"]
  node_client_state["Client state and query cache<br/>Zustand and React Query<br/>[store.ts]"]
end

subgraph group_api["Typed API"]
  node_trpc_client["tRPC client provider<br/>typed client API<br/>[trpc.tsx]"]
  node_trpc_handler["tRPC route handler<br/>Next.js API route<br/>[route.ts]"]
  node_trpc_server["tRPC server composition<br/>router and context<br/>[root.ts]"]
  node_post_router["Post procedures<br/>tRPC router<br/>[post.ts]"]
  node_category_router["Category procedures<br/>tRPC router<br/>[category.ts]"]
  node_upload_router["Media upload procedures<br/>tRPC router<br/>[upload.ts]"]
end

subgraph group_data["Data and infrastructure"]
  node_supabase_auth{{"Supabase Auth and RLS<br/>identity and access control<br/>[server.ts]"}}
  node_drizzle_db["Drizzle data access<br/>database layer<br/>[index.ts]"]
  node_postgres[("PostgreSQL / Supabase<br/>relational database")]
  node_supabase_storage[("Supabase Storage<br/>media object storage")]
end

node_app_shell -->|"hosts"| node_public_routes
node_app_shell -->|"hosts"| node_author_routes
node_app_shell -->|"hosts"| node_auth_routes
node_app_shell -->|"uses"| node_shared_ui
node_author_routes -->|"protected by"| node_auth_guard
node_auth_guard -->|"checks session"| node_supabase_auth
node_auth_routes -->|"authenticates with"| node_supabase_auth
node_public_routes -->|"renders"| node_reader_ui
node_author_routes -->|"renders"| node_editorial_ui
node_reader_ui -->|"queries"| node_trpc_client
node_editorial_ui -->|"persists through"| node_trpc_client
node_trpc_client -->|"caches in"| node_client_state
node_trpc_client -->|"calls"| node_trpc_handler
node_trpc_handler -->|"dispatches to"| node_trpc_server
node_trpc_server -->|"mounts"| node_post_router
node_trpc_server -->|"mounts"| node_category_router
node_trpc_server -->|"mounts"| node_upload_router
node_post_router -->|"reads and writes"| node_drizzle_db
node_category_router -->|"reads and writes"| node_drizzle_db
node_drizzle_db -->|"connects to"| node_postgres
node_supabase_auth -.->|"enforces RLS on"| node_postgres
node_upload_router -->|"uploads media"| node_supabase_storage
node_keep_alive -.->|"keeps active"| node_postgres

click node_app_shell "https://github.com/irfan-rg/inkwell/blob/main/app/layout.tsx"
click node_public_routes "https://github.com/irfan-rg/inkwell/blob/main/app/(public)/page.tsx"
click node_author_routes "https://github.com/irfan-rg/inkwell/blob/main/app/(auth)/dashboard/page.tsx"
click node_auth_routes "https://github.com/irfan-rg/inkwell/blob/main/app/auth/login/page.tsx"
click node_auth_guard "https://github.com/irfan-rg/inkwell/blob/main/components/auth/AuthGuard.tsx"
click node_reader_ui "https://github.com/irfan-rg/inkwell/blob/main/components/blog/PostList.tsx"
click node_editorial_ui "https://github.com/irfan-rg/inkwell/blob/main/components/blog/PostForm.tsx"
click node_shared_ui "https://github.com/irfan-rg/inkwell/blob/main/components/layout/Navbar.tsx"
click node_client_state "https://github.com/irfan-rg/inkwell/blob/main/lib/store.ts"
click node_trpc_client "https://github.com/irfan-rg/inkwell/blob/main/lib/trpc.tsx"
click node_trpc_handler "https://github.com/irfan-rg/inkwell/blob/main/app/api/trpc/%5Btrpc%5D/route.ts"
click node_trpc_server "https://github.com/irfan-rg/inkwell/blob/main/server/api/root.ts"
click node_post_router "https://github.com/irfan-rg/inkwell/blob/main/server/api/routers/post.ts"
click node_category_router "https://github.com/irfan-rg/inkwell/blob/main/server/api/routers/category.ts"
click node_upload_router "https://github.com/irfan-rg/inkwell/blob/main/server/api/routers/upload.ts"
click node_supabase_auth "https://github.com/irfan-rg/inkwell/blob/main/lib/supabase/server.ts"
click node_drizzle_db "https://github.com/irfan-rg/inkwell/blob/main/server/db/index.ts"
click node_keep_alive "https://github.com/irfan-rg/inkwell/blob/main/app/api/keep-alive/route.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_app_shell,node_public_routes,node_author_routes,node_auth_routes,node_keep_alive toneBlue
class node_auth_guard,node_reader_ui,node_editorial_ui,node_shared_ui,node_client_state toneAmber
class node_trpc_client,node_trpc_handler,node_trpc_server,node_post_router,node_category_router,node_upload_router toneMint
class node_supabase_auth,node_drizzle_db,node_postgres,node_supabase_storage toneRose
```

## Components

### Next.js routes

- [Application shell](https://github.com/irfan-rg/inkwell/blob/main/app/layout.tsx): Next.js layout · Global layout, fallback, and visual foundation. · `app/layout.tsx`
- [Public reader routes](https://github.com/irfan-rg/inkwell/blob/main/app/(public)/page.tsx): Next.js route group · Landing, blog index, and slugged post pages. · `app/(public)/page.tsx`
- [Author dashboard routes](https://github.com/irfan-rg/inkwell/blob/main/app/(auth)/dashboard/page.tsx): Next.js route group · Dashboard, post creation, editing, and categories. · `app/(auth)/dashboard/page.tsx`
- [Login and signup](https://github.com/irfan-rg/inkwell/blob/main/app/auth/login/page.tsx): Next.js auth routes · `app/auth/login/page.tsx`
- [Keep-alive endpoint](https://github.com/irfan-rg/inkwell/blob/main/app/api/keep-alive/route.ts): operational API route · Keeps the database/service active. · `app/api/keep-alive/route.ts`

### UI and client state

- [Author access guard](https://github.com/irfan-rg/inkwell/blob/main/components/auth/AuthGuard.tsx): React auth boundary · `components/auth/AuthGuard.tsx`
- [Discovery UI](https://github.com/irfan-rg/inkwell/blob/main/components/blog/PostList.tsx): React blog components · Lists, cards, search, and category filtering. · `components/blog/PostList.tsx`
- [Post authoring UI](https://github.com/irfan-rg/inkwell/blob/main/components/blog/PostForm.tsx): React editor components · Form combines Markdown editing, rendering, and image upload. · `components/blog/PostForm.tsx`
- [Shared chrome and theme](https://github.com/irfan-rg/inkwell/blob/main/components/layout/Navbar.tsx): React presentation · `components/layout/Navbar.tsx`
- [Client state and query cache](https://github.com/irfan-rg/inkwell/blob/main/lib/store.ts): Zustand and React Query · `lib/store.ts`

### Typed API

- [tRPC client provider](https://github.com/irfan-rg/inkwell/blob/main/lib/trpc.tsx): typed client API · `lib/trpc.tsx`
- [tRPC route handler](https://github.com/irfan-rg/inkwell/blob/main/app/api/trpc/%5Btrpc%5D/route.ts): Next.js API route · `app/api/trpc/[trpc]/route.ts`
- [tRPC server composition](https://github.com/irfan-rg/inkwell/blob/main/server/api/root.ts): router and context · Root router namespaces and server transport context. · `server/api/root.ts`
- [Post procedures](https://github.com/irfan-rg/inkwell/blob/main/server/api/routers/post.ts): tRPC router · Published reads, drafts, editing, and lifecycle operations. · `server/api/routers/post.ts`
- [Category procedures](https://github.com/irfan-rg/inkwell/blob/main/server/api/routers/category.ts): tRPC router · `server/api/routers/category.ts`
- [Media upload procedures](https://github.com/irfan-rg/inkwell/blob/main/server/api/routers/upload.ts): tRPC router · `server/api/routers/upload.ts`

### Data and infrastructure

- [Supabase Auth and RLS](https://github.com/irfan-rg/inkwell/blob/main/lib/supabase/server.ts): identity and access control · Session adapters and database row-level policies enforce user access. · `lib/supabase/server.ts`
- [Drizzle data access](https://github.com/irfan-rg/inkwell/blob/main/server/db/index.ts): database layer · Database connection and relational schema. · `server/db/index.ts`
- **PostgreSQL / Supabase**: relational database · Stores users' scoped editorial data.
- **Supabase Storage**: media object storage · Stores uploaded post images.

## Connections

- Application shell → Public reader routes: hosts
- Application shell → Author dashboard routes: hosts
- Application shell → Login and signup: hosts
- Application shell → Shared chrome and theme: uses
- Author dashboard routes → Author access guard: protected by
- Author access guard → Supabase Auth and RLS: checks session
- Login and signup → Supabase Auth and RLS: authenticates with
- Public reader routes → Discovery UI: renders
- Author dashboard routes → Post authoring UI: renders
- Discovery UI → tRPC client provider: queries
- Post authoring UI → tRPC client provider: persists through
- tRPC client provider → Client state and query cache: caches in
- tRPC client provider → tRPC route handler: calls
- tRPC route handler → tRPC server composition: dispatches to
- tRPC server composition → Post procedures: mounts
- tRPC server composition → Category procedures: mounts
- tRPC server composition → Media upload procedures: mounts
- Post procedures → Drizzle data access: reads and writes
- Category procedures → Drizzle data access: reads and writes
- Drizzle data access → PostgreSQL / Supabase: connects to
- Supabase Auth and RLS → PostgreSQL / Supabase: enforces RLS on
- Media upload procedures → Supabase Storage: uploads media
- Keep-alive endpoint → PostgreSQL / Supabase: keeps active
