Coder Social home page Coder Social logo

next-ai-news's Introduction

Next AI News

A full-stack replica of HN using Next.js and AI generated content.

Design notes

  • Uses Next.js 14 with App Router and RSC on the Node.js runtime
    • All pages are server-rendered and dynamic, with no data caching
    • All mutations are done via Server Actions
    • Streaming is used throughout to maximize speed and concurrency
  • Uses pnpm for package management
  • Uses Drizzle ORM and Zod as the data layer
  • Uses Auth.js's Next-Auth for password authentication
  • Used v0 to generate all initial UIs with Tailwind, Shadcn UI and Radix UI
  • Developed entirely and tested with the new Next.js --turbo Rust compiler
  • Uses react-highlight-words for search highlights
  • PPR (experimental) is used to precompute the shells of pages
    • When deployed, these are served statically from the edge
    • This makes TTFB faster and speeds up CSS/fonts while origin streams
  • Deployed serverlessly on Vercel's Edge Network using:

AI

Deployment

  • Make sure the Vercel project is connected to a Vercel Postgres (Neon) database
  • Optionally, for rate limiting, add a Vercel KV (Upstash) database
  • Run pnpm drizzle-kit push:pg
  • Update metadataBase in app/layout.tsx to match your target domain

Local dev

  • Run vc env pull to get a .env.local file with your db credentials.
  • Run pnpm dev to start developing
  • For DB migrations with drizzle-kit:
    • Make sure ?sslmode=required is added to the POSTGRES_URL env for dev
    • Run pnpm drizzle-kit generate:pg to generate migrations
    • Run pnpm drizzle-kit push:pg to apply them

Performance

PageSpeed report for Emulated Moto G Power with Lighthouse 11.0.0, Slow 4G Throttling:

   💩 The SEO 98 score cannot be 100 without sacrificing stylistic fidelity to the original HN navigation

Codebase notes

  • Auth is initialized in app/auth.tsx, Drizzle in app/db.tsx.
  • Shared components are in ./components (exposed as @/components)
  • Only one component was not reused from npm / shadcn (components/time-ago.tsx)
    • I couldn't find something very light that worked well with server-rendering (takes a now prop with a timestamp)
  • The following db migrations were added manually:
    • CREATE EXTENSION IF NOT EXISTS pg_trgm; as part of #13
    • USING GIN (title gin_trgm_ops); as part of #13

TODO

This project is unique in that it's a full-stack replica of HN, with quite a few features. It'd be great for the community to fill in some important gaps, however:

  • Inline comment replies
  • "Forgot password" flow
  • Voting and ranking
  • "Next" and "Prev" comment links
  • Comment toggling
  • Flagging submissions and comments
  • Improve search further
  • Comment pagination
  • More efficient comment datastructures
  • Optimistic comments with useOptimistic
  • Local storage of comment and submission drafts
  • Improve the /next implementationa after login
  • Add support for passkeys
  • A basic admin panel
  • User profiles

License

MIT

next-ai-news's People

Contributors

rauchg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.