|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Development Commands |
| 6 | + |
| 7 | +### Development Server |
| 8 | +- `bun run dev` - Start development server with Turbo |
| 9 | +- Open http://localhost:3000 to view the application |
| 10 | + |
| 11 | +### Database Operations |
| 12 | +- `bun run db:generate` - Generate database migrations from schema changes |
| 13 | +- `bun run db:push` - Push schema changes to database |
| 14 | +- `bun run db:studio` - Open Drizzle Studio (database GUI) |
| 15 | + |
| 16 | +### Build & Deployment |
| 17 | +- `bun run build` - Build for production |
| 18 | +- `bun run start` - Start production server |
| 19 | +- `bun run lint` - Run ESLint checks |
| 20 | + |
| 21 | +### Backend Development |
| 22 | +- `bun run play` - Run backend playground script (`src/backend/play.ts`) |
| 23 | + |
| 24 | +## Architecture Overview |
| 25 | + |
| 26 | +### Technology Stack |
| 27 | +- **Frontend**: Next.js 15 (App Router), React 19, TypeScript |
| 28 | +- **Styling**: Tailwind CSS, shadcn/ui components |
| 29 | +- **Backend**: Next.js API routes, Drizzle ORM |
| 30 | +- **Database**: PostgreSQL |
| 31 | +- **Authentication**: GitHub OAuth |
| 32 | +- **Search**: MeilSearch |
| 33 | +- **File Storage**: Cloudinary |
| 34 | +- **State Management**: Jotai, React Hook Form with Zod validation |
| 35 | + |
| 36 | +### Backend & Database |
| 37 | +- **[SQLKit](https://github.com/sqlkit-dev/sqlkit)** - Very light sql query builder, we are using most of the sql query using this. |
| 38 | +- **[Drizzle ORM](https://orm.drizzle.team/)** - Awesome sql tool but we are only using for migration |
| 39 | +- **[PostgreSQL](https://www.postgresql.org/)** - Primary database |
| 40 | +- **[Next.js API Routes](https://nextjs.org/docs/api-routes/introduction)** - Backend API |
| 41 | + |
| 42 | +### Core Directory Structure |
| 43 | + |
| 44 | +#### Frontend (`/src/app/`) |
| 45 | +- Route groups using Next.js App Router: |
| 46 | + - `(home)` - Main homepage and article feed |
| 47 | + - `(dashboard-editor)` - Protected dashboard routes |
| 48 | + - `[username]` - User profile pages |
| 49 | + - `[username]/[articleHandle]` - Individual article pages |
| 50 | +- API routes in `/api/` for OAuth and development |
| 51 | + |
| 52 | +#### Backend (`/src/backend/`) |
| 53 | +- **Domain Models** (`/domain/`) - Core business logic entities |
| 54 | +- **Persistence** (`/persistence/`) - Database schemas and repositories |
| 55 | +- **Services** (`/services/`) - Business logic actions |
| 56 | +- **Input Validation** - Zod schemas for type-safe inputs |
| 57 | + |
| 58 | +#### Component Architecture (`/src/components/`) |
| 59 | +- **UI Components** - shadcn/ui based design system |
| 60 | +- **Feature Components** - Domain-specific (Editor, Navbar, etc.) |
| 61 | +- **Layout Components** - Page layouts and providers |
| 62 | + |
| 63 | +### Database Schema Architecture |
| 64 | + |
| 65 | +Key entities and their relationships: |
| 66 | +- **Users** - User profiles with social authentication |
| 67 | +- **Articles** - Blog posts with markdown content and metadata |
| 68 | +- **Series** - Article collections/sequences |
| 69 | +- **Comments** - Nested commenting system with resource association |
| 70 | +- **Tags** - Article categorization |
| 71 | +- **Bookmarks** - User content saving |
| 72 | +- **Reactions** - Emoji-based reactions (LOVE, FIRE, WOW, etc.) |
| 73 | +- **User Sessions** - Session management |
| 74 | +- **User Socials** - OAuth provider connections |
| 75 | + |
| 76 | +### Content Management |
| 77 | +- **Rich Text**: Markdoc for markdown parsing and rendering |
| 78 | +- **File Uploads**: Cloudinary integration for images/media |
| 79 | +- **Search**: MeilSearch for full-text search capabilities |
| 80 | +- **Internationalization**: Custom i18n implementation (Bengali/English) |
| 81 | + |
| 82 | +### State Management Patterns |
| 83 | +- **Server State**: Drizzle ORM with PostgreSQL |
| 84 | +- **Client State**: Jotai for global state management |
| 85 | +- **Form State**: React Hook Form with Zod validation |
| 86 | +- **Environment**: Type-safe environment variables with @t3-oss/env-nextjs |
| 87 | + |
| 88 | +## Required Environment Variables |
| 89 | + |
| 90 | +Server-side: |
| 91 | +- `DATABASE_URL` - PostgreSQL connection string |
| 92 | +- `GITHUB_CLIENT_ID` - GitHub OAuth client ID |
| 93 | +- `GITHUB_CLIENT_SECRET` - GitHub OAuth client secret |
| 94 | +- `GITHUB_CALLBACK_URL` - OAuth callback URL |
| 95 | +- `CLOUDINARY_URL` - Cloudinary configuration |
| 96 | +- `MEILISEARCH_ADMIN_API_KEY` - MeilSearch admin API key |
| 97 | + |
| 98 | +Client-side: |
| 99 | +- `NEXT_PUBLIC_MEILISEARCH_API_HOST` - MeilSearch API host URL |
| 100 | +- `NEXT_PUBLIC_MEILISEARCH_SEARCH_API_KEY` - MeilSearch search API key |
| 101 | + |
| 102 | +## Key Features Implementation |
| 103 | + |
| 104 | +### Authentication Flow |
| 105 | +- GitHub OAuth integration via `/api/auth/github` |
| 106 | +- User sessions managed in `userSessionsTable` |
| 107 | +- Social provider connections in `userSocialsTable` |
| 108 | + |
| 109 | +### Content Creation |
| 110 | +- Rich markdown editor with drag-and-drop support |
| 111 | +- Image upload and optimization via Cloudinary |
| 112 | +- Article series management for content organization |
| 113 | +- Tag-based categorization system |
| 114 | + |
| 115 | +### Search Implementation |
| 116 | +- MeilSearch for full-text search across articles |
| 117 | +- Search configuration and indexing handled in backend services |
| 118 | +- Client-side search interface with real-time results |
| 119 | + |
| 120 | +### Community Features |
| 121 | +- Nested commenting system with resource association |
| 122 | +- Emoji-based reactions (LOVE, FIRE, WOW, etc.) |
| 123 | +- User following and bookmarking functionality |
| 124 | +- Social sharing and user profiles |
| 125 | + |
| 126 | +## Development Workflow |
| 127 | + |
| 128 | +1. Database changes require running `bun run db:generate` followed by `bun run db:push` |
| 129 | +2. Backend logic testing can be done via `bun run play` playground script |
| 130 | +3. Type safety is enforced through Zod schemas for all inputs |
| 131 | +4. UI components follow shadcn/ui patterns and conventions |
| 132 | +5. All forms use React Hook Form with Zod validation schemas |
| 133 | +6. When querying data in component always use Tanstack Query. |
| 134 | +7. When interacting with DB, create a action in `src/backend/services` and use sqlkit package (https://github.com/sqlkit-dev/sqlkit) |
| 135 | +8. For Database schema reference look here for drizzle schema `src/backend/persistence/schemas.ts` |
| 136 | + |
| 137 | +## Special Considerations |
| 138 | + |
| 139 | +- **Bengali Language Support**: Custom font loading (Kohinoor Bangla) and i18n |
| 140 | +- **SEO Optimization**: Dynamic sitemaps, Open Graph tags, and schema markup |
| 141 | +- **Performance**: Next.js Image optimization, bundle splitting, and caching |
| 142 | +- **Security**: Input validation via Zod, secure OAuth flow, environment variable validation |
0 commit comments