How tusharathub/kilogram works
Project type and purpose
• This is a full-stack social media web application (an “Instagram-lite”) built with Next.js (app router), TypeScript, Prisma ORM, Tailwind / Shadcn UI, Clerk for auth, and UploadThing for file uploads.
• Users can sign in/up, create posts (with images), follow others, and receive notifications.
File structure
• Top-level:
• next.config.mjs, tsconfig.json, package.json / lock, postcss.config.mjs – project config & build
• prisma/schema.prisma – database schema for NeonDB via Prisma
• components.json – probably design tokens or Shadcn UI config
• src/app (Next.js app router):
• layout.tsx, globals.css – root layout & global styles
• page.tsx – home feed
• /api/uploadthing – serverless endpoints for file upload
• /notifications, /profile/[username] – dynamic routes & UI
• src/actions – server actions (notification, post, profile, user) encapsulating Prisma calls
• src/components – UI primitives, composite components, Shadcn UI wrappers in components/ui
• src/lib – shared utilities: prisma client, UploadThing client, misc utils
• middleware.ts – Next.js middleware (authentication checks, redirects)
Key insights from README
• Uses Clerk for authentication & authorization
• UploadThing handles file uploads to a storage backend
• NeonDB is the production PostgreSQL DB accessed via Prisma
• Hosted on Vercel
Main components
a. Frontend (Next.js React app)
• App Router pages & React Server Components
• Client Components (forms, buttons, PostCard, NavBar)
• Shadcn UI / Tailwind styling
• Clerk JS SDK for sign-in UI & session management
b. API Layer (Next.js Route Handlers & Server Actions)
• /api/uploadthing routes (core.ts, route.ts)
• src/actions/*.action.ts functions that perform Prisma queries
c. Business Logic & Data Access
• Prisma Client (src/lib/prisma.ts)
• Schema (prisma/schema.prisma)
• NeonDB (hosted PostgreSQL)
d. File Storage
• UploadThing service (cloud storage)
e. External Services
• Clerk (user auth & profile management)
• Vercel (hosting & serverless functions)
• CDN for public assets
Relationships & data flows
• User browser ⇄ Next.js frontend
• Clerk widget handles auth, attaches JWT/cookie
• UI components call Server Actions (POST/GET)
• Next.js Server (Route Handlers & Actions) ⇄ Prisma Client
• CRUD on NeonDB
• Next.js Server ⇄ UploadThing API
• Pre-signed URLs or direct uploads
• Notifications subsystem listens for events (e.g., new follow or post) and writes to DB
• Vercel manages serverless deployment of both frontend and API routes
Architectural patterns & design principles
• React Server Components & Client Components separation
• Single unified codebase (monorepo style) for frontend & backend
• “Fat” Server Actions layer encapsulating all data access via Prisma
• Stateless serverless functions, horizontal scaling via Vercel
• Externalized auth & storage to minimize custom infrastructure
Essential elements to capture
• Authentication flow: Browser ↔ Clerk ↔ Next.js Middleware
• Upload flow: Browser → Next.js /api/uploadthing → UploadThing
• Database operations: Server Actions → Prisma Client → NeonDB
• UI modules: Feed, Profile, Notifications, Post Creation
1) Sketch the user journey: sign in → view feed → create post → follow user → get notification
2) System touchpoints along that journey
3) Related files & folders into logical subsystems