Skip to content

Shahriyar-fullstack/twitter

Repository files navigation

twitter

Overview

This repository hosts a compact Twitter-style social app built on the Next.js App Router. Visitors sign in with GitHub through NextAuth, gaining access to protected pages where they can browse profiles and toggle follow relationships. Prisma talks to a local SQLite database file, while TanStack React Query keeps client views aligned with server state.

Tech Stack

  • Next.js 15 (App Router, TypeScript, Turbopack dev server)
  • React 19 with Tailwind CSS utility styling
  • NextAuth + Prisma adapter with GitHub OAuth
  • Prisma ORM backed by SQLite (prisma/db.sqlite)
  • TanStack React Query and Axios for data fetching

Project Structure

  • src/app/layout.tsx wires global providers (session + React Query) and base styles.
  • src/app/page.tsx serves the public landing screen and redirects authenticated users to /app.
  • src/app/app/layout.tsx protects the authenticated area and renders the navigation shell.
  • src/app/app/page.tsx and src/app/app/profile/[userId]/page.tsx render protected content, including profile views and follow/unfollow interactions.
  • src/app/components contains reusable client helpers such as the navigation menu, QueryProvider, and the exported NextAuth SessionProvider.
  • src/app/api/**/* exposes Next.js route handlers for auth, profile lookup, and follow toggling.
  • src/lib/axios.ts centralises browser-side API calls; src/lib/prisma.ts exports the Prisma client singleton used by route handlers.

Data Model

prisma/schema.prisma defines the schema: User, OAuth Account, Session, VerificationToken, and the Follow join model. Migrations live under prisma/migrations, and the working SQLite file is prisma/db.sqlite.

Authentication Flow

GitHub OAuth credentials load from environment variables and feed into NextAuth. Successful sign-in creates or links a User record through the Prisma adapter. Server components use getServerSession(authOption) to guard routes, and client components rely on useSession for user context.

API Surface

  • GET /api/get-current-user returns the signed-in user document.
  • GET /api/get-user/[userId] returns a profile, related follow lists, and whether the viewer follows the profile.
  • POST /api/follow-user/[userId] toggles the follow state between the requester and target user. Each route validates the session before accessing Prisma.

Environment Variables

Create a .env file in the project root:

DATABASE_URL="file:/absolute/path/to/prisma/db.sqlite"
NEXTAUTH_SECRET="your_nextauth_secret"
GITHUB_ID="your_github_oauth_client_id"
GITHUB_SECRET="your_github_oauth_client_secret"

Update the placeholders with your actual values and restart the dev server whenever the file changes.

Setup Scripts

package.json exposes the following npm scripts:

  • npm run dev – start the Next.js dev server with Turbopack.
  • npm run build – create an optimized production build.
  • npm run start – run the production build locally.
  • npm run lint – execute ESLint (via next lint).

Useful supporting commands:

  • npm install – install dependencies.
  • npx prisma migrate deploy – apply migrations to the SQLite database.
  • npx prisma studio – inspect and edit database records through Prisma Studio.

Getting Started

  1. Install dependencies: npm install
  2. Apply migrations (optional for a clean DB): npx prisma migrate deploy
  3. Ensure .env contains valid DATABASE_URL, NEXTAUTH_SECRET, GITHUB_ID, and GITHUB_SECRET
  4. Launch the dev server: npm run dev
  5. Lint when needed: npm run lint

Visit http://localhost:3000 for the landing page. Signing in with GitHub redirects you to /app, unlocking the authenticated navigation shell and profile experience.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages