Project Structure
Comprehensive overview of the Earna AI Console repository organization and key files.
Repository Overview
The project consists of three independent Next.js applications:
- Main chat application (Next.js 15)
- README.md
- .gitignore
Console Application Structure
- layout.tsx
- page.tsx
- globals.css
- utils.ts
- constants.ts
- package.json
- tsconfig.json
- next.config.js
- tailwind.config.ts
- .env.example
Key Directories Explained
/app - Next.js App Router
The main application directory using Next.js 15 App Router:
(auth)/- Grouped authentication routesapi/- API route handlers for all endpointslayout.tsx- Root layout with providerspage.tsx- Main chat interface page
/components - React Components
Organized by feature:
chat/- Chat-specific componentsui/- Reusable UI components (shadcn/ui)avatar/- HeyGen avatar componentsvoice/- Voice/audio components
/lib - Core Libraries
Business logic and utilities:
ai/- AI model configurations and helperssupabase/- Database client and typeshooks/- Custom React hooksutils.ts- Utility functions
Important Files
Configuration Files
- next.config.js
- tsconfig.json
- tailwind.config.ts
- package.json
- .env.example
API Routes
/app/api/chat/route.ts
// Main chat endpoint - handles streaming responses
export async function POST(req: Request) {
const { messages, model } = await req.json();
// Stream AI response
}/app/api/models/route.ts
// List available models and their status
export async function GET() {
return Response.json(availableModels);
}Component Structure
/components/chat/chat-interface.tsx
// Main chat UI component
export function ChatInterface() {
// Manages conversation state
// Handles message sending
// Renders message list
}/lib/ai/models.ts
// Model configuration and management
export function getModel(modelId: string) {
// Returns configured AI model
}File Naming Conventions
Components
- PascalCase:
ChatInterface.tsx,MessageList.tsx - Suffix with type:
.tsxfor components,.tsfor utilities - Index files: Use
index.tsfor barrel exports
API Routes
- Lowercase:
route.tsfor App Router - Dynamic routes:
[id]/route.tsfor parameters - Nested structure: Mirror URL structure
Utilities
- camelCase:
useChat.ts,formatMessage.ts - Descriptive names:
generateChatTitle.ts - Group by feature:
/lib/ai/,/lib/supabase/
Environment Files
.env.example # Template with all variables
.env.local # Local development (gitignored)
.env.production # Production values (gitignored)
.env.test # Test environmentBuild Output
Database Structure
Located in Supabase, not in repository:
-- Main tables
users
conversations
messages
files
-- Functions
generate_chat_title()
check_message_limit()
-- RLS Policies
users_own_conversations
users_own_messagesDocumentation Structure
- index.mdx
- get-started.mdx
Scripts Reference
Development
{
"dev": "next dev",
"build": "next build",
"start": "next start"
}Type Checking
{
"type-check": "tsc --noEmit",
"lint": "next lint",
"format": "prettier --write ."
}Database
{
"generate:types": "supabase gen types",
"db:migrate": "supabase db push"
}Pro Tip: Use path aliases configured in tsconfig.json:
@/components/*→./components/*@/lib/*→./lib/*@/app/*→./app/*
Adding New Features
1. New API Endpoint
- Create route in
/app/api/[feature]/route.ts - Add types to
/lib/types/[feature].ts - Create hook in
/lib/hooks/use-[feature].ts
2. New UI Component
- Create component in
/components/[feature]/ - Add to barrel export in
/components/[feature]/index.ts - Import using
@/components/[feature]
3. New AI Model
- Add configuration to
/lib/ai/models.ts - Update environment variables
- Add to model selector UI
Best Practices
- Keep API routes thin - Business logic in
/lib - Use Server Components - Where possible for performance
- Colocate related files - Feature-based organization
- Type everything - Full TypeScript coverage
- Document complex logic - Inline comments for clarity
Last updated on