Based on the provided files, here's a breakdown of the project's architecture:
Core Technologies:
- Next.js: The project is built using Next.js, leveraging its App Router for routing, React Server Components (RSCs) and Server Actions for server-side rendering and increased performance.
- AI SDK: The project uses Vercel's AI SDK for interacting with Language Models (LLMs). This provides a unified API for generating text, structured objects, and tool calls. It supports multiple providers like OpenAI (default), Anthropic, and Cohere.
- shadcn/ui: The project uses shadcn/ui for styling, which is based on Tailwind CSS and uses component primitives from Radix UI for accessibility and flexibility.
- Vercel Postgres: For data persistence, the project utilizes Vercel Postgres powered by Neon for saving chat history and user data.
- Vercel Blob: Vercel Blob is used for efficient file storage.
- NextAuth.js: This library is used for handling authentication, providing simple and secure user authentication.
Key Features and Components:
- Chatbot Functionality: The core functionality is an AI chatbot, utilizing the AI SDK to interact with LLMs. The chat interface is likely built using React components.
- Model Providers: The application defaults to OpenAI's
gpt-4o model, but the AI SDK allows switching to other LLM providers.
- Data Persistence: Chat history, user data, and other data (like documents and suggestions) are stored in a Postgres database using Drizzle ORM and Vercel Postgres. Vercel Blob is used for file storage.
- User Authentication: NextAuth.js is used to manage user accounts and authentication.
- Styling: Tailwind CSS is used to style the application via
shadcn/ui components, with custom themeing capabilities.
- Code Editor: Utilizes CodeMirror for code editing functionalities in the UI.
- Markdown Support: Utilizes
react-markdown to render markdown content.
- Theme Support:
next-themes for light/dark theme support
File Structure Insights:
README.md: Provides an overview of the project, including features, model providers, deployment instructions, and local development setup.
package.json: Lists the project's dependencies, including UI libraries, AI SDK, database libraries, and other utilities.
next.config.ts: Configuration for Next.js, including experimental features and image configurations.
drizzle.config.ts: Configuration for Drizzle ORM.
app/layout.tsx: Defines the root layout of the application, including theme setup and <head> content (theme-color meta tag).
app/globals.css: Defines global CSS styles for the application.
lib/ai/index.ts: Configures the AI SDK, including custom middleware and language model wrapping.
lib/db/schema.ts: Defines the database schema using Drizzle ORM.
middleware.ts: Configures middleware for authentication using NextAuth.js.
Database Schema (from lib/db/schema.ts):
The database uses PostgreSQL and includes the following tables:
- User: Stores user information (id, email, password).
- Chat: Stores chat information (id, createdAt, title, userId, visibility).
- Message: Stores chat messages (id, chatId, role, content, createdAt).
- Vote: Stores user votes on messages (chatId, messageId, isUpvoted).
- Document: Stores user created documents (id, createdAt, title, content, kind, userId)
- Suggestion: Stores suggestions for documents (id, documentId, documentCreatedAt, originalText, suggestedText, description, isResolved, userId, createdAt)
In summary, this project is a full-stack application with a focus on AI-powered chat, using Next.js and the Vercel AI SDK. It has robust data persistence, user authentication, and a modern component library to provide a rich user experience.