This project follows an industry-standard, feature-based architecture optimized for scalability and maintainability.
lern/
├── src/
│ ├── app/ # Next.js App Router (routes only)
│ │ ├── (auth)/ # Auth route group
│ │ │ ├── login/
│ │ │ └── signup/
│ │ ├── (marketing)/ # Public pages
│ │ │ ├── page.tsx # Landing page
│ │ │ ├── about/
│ │ │ ├── features/
│ │ │ └── pricing/
│ │ ├── (dashboard)/ # Protected dashboard pages
│ │ │ ├── chat/
│ │ │ │ └── page.tsx
│ │ │ ├── notes/
│ │ │ ├── overview/
│ │ │ └── settings/
│ │ ├── api/ # API Routes
│ │ │ ├── chat/
│ │ │ │ └── route.ts
│ │ │ ├── notes/
│ │ │ └── ai/generate/
│ │ ├── layout.tsx
│ │ └── globals.css
│ │
│ ├── features/ # Feature modules (self-contained)
│ │ ├── chat/
│ │ │ ├── components/ # Feature-specific components
│ │ │ │ ├── ChatEmptyState.tsx
│ │ │ │ ├── ChatInputArea.tsx
│ │ │ │ ├── ChatMessageList.tsx
│ │ │ │ └── index.ts
│ │ │ ├── hooks/ # Feature-specific hooks
│ │ │ │ └── useConversations.ts
│ │ │ ├── context/ # Feature contexts
│ │ │ │ └── ChatContext.tsx
│ │ │ ├── services/ # Feature business logic
│ │ │ │ └── chatService.ts
│ │ │ ├── types.ts # Feature-specific types
│ │ │ ├── styles.ts # Feature-specific styles
│ │ │ └── index.ts # Public API exports
│ │ │
│ │ ├── auth/
│ │ │ ├── components/
│ │ │ ├── hooks/
│ │ │ ├── context/
│ │ │ │ └── AuthContext.tsx
│ │ │ ├── services/
│ │ │ ├── types.ts
│ │ │ └── index.ts
│ │ │
│ │ └── notes/ # Future feature
│ │ ├── components/
│ │ ├── hooks/
│ │ ├── services/
│ │ ├── types.ts
│ │ └── index.ts
│ │
│ ├── components/ # Shared components
│ │ ├── ui/ # Generic UI components
│ │ │ ├── Button.tsx
│ │ │ ├── Input.tsx
│ │ │ ├── Card.tsx
│ │ │ ├── Modal.tsx
│ │ │ └── Toast.tsx
│ │ │
│ │ ├── layout/ # Layout components
│ │ │ ├── DashboardLayout.tsx
│ │ │ ├── navConfig.tsx
│ │ │ ├── types.ts
│ │ │ └── index.ts
│ │ │
│ │ └── shared/ # Shared utility components
│ │ ├── Markdown.tsx
│ │ ├── decrypted-text.tsx
│ │ ├── rotating-text.tsx
│ │ ├── ShinyText.tsx
│ │ └── styles/
│ │
│ │ └── marketing/ # Marketing components
│ │ ├── Hero.tsx
│ │ ├── Feature1.tsx
│ │ ├── Feature2.tsx
│ │ ├── CardStack.tsx
│ │ ├── Footer.tsx
│ │ └── Header.tsx
│ │
│ ├── lib/ # Shared utilities & configs
│ │ ├── api/ # API clients
│ │ │ ├── api-client.ts
│ │ │ └── server-client.ts
│ │ │
│ │ ├── services/ # External service integrations
│ │ │ ├── firebase/
│ │ │ │ ├── auth.ts
│ │ │ │ ├── config.ts
│ │ │ │ └── firestore.ts
│ │ │ └── ai/
│ │ │ └── groqClient.ts
│ │ │
│ │ ├── utils/ # Utility functions
│ │ │ ├── formatters.ts
│ │ │ ├── validators.ts
│ │ │ └── helpers.ts
│ │ │
│ │ └── constants.ts
│ │
│ ├── hooks/ # Global shared hooks only
│ │ ├── useMediaQuery.ts
│ │ ├── useLocalStorage.ts
│ │ └── useDebounce.ts
│ │
│ ├── store/ # State management (Zustand)
│ │ ├── slices/
│ │ │ ├── authSlice.ts
│ │ │ ├── notesSlice.ts
│ │ │ └── chatSlice.ts
│ │ └── index.ts
│ │
│ ├── types/ # Global shared types only
│ │ ├── api.ts
│ │ ├── index.ts
│ │ └── shared/
│ │ └── components.ts
│ │
│ ├── theme/ # Theme configuration
│ │ ├── index.tsx
│ │ ├── palette.ts
│ │ └── typography.ts
│ │
│ └── styles/ # Global styles
│ └── themes/
│
├── config/
│ ├── site.ts # Site metadata
│ └── env.ts # Environment validation
│
├── public/
│ ├── images/ # All images organized here
│ ├── icons/
│ └── fonts/
│
├── tsconfig.json # Path aliases configured
├── next.config.mjs
├── tailwind.config.js
└── package.json
Configured in tsconfig.json:
@/components/*- Shared components@/features/*- Feature modules@/lib/*- Utilities and libraries@/hooks/*- Custom hooks@/store/*- State management@/config/*- Configuration files
(marketing)- Public pages (landing, pricing, about)(dashboard)- Protected user pages (notes, chat, settings)(auth)- Authentication pages (login, signup)
Using Zustand for global state:
useAuth()- Authentication stateuseNotes()- Notes managementuseChat()- Chat functionality
RESTful API endpoints:
/api/chat- Chat functionality/api/notes- Notes CRUD/api/ai/generate- AI content generation
import {
ChatEmptyState,
ChatMessageList,
ChatInputArea,
} from '@/features/chat';
import { useChatContext } from '@/features/chat';
import { useConversations } from '@/features/chat';import { DashboardLayout } from '@/components/layout';
import { Markdown } from '@/components/shared/Markdown';import { useAuth, useNotes } from '@/store';
const { user, login } = useAuth();
const { notes, addNote } = useNotes();import { formatDate } from '@/lib/utils/formatters';
import { validateEmail } from '@/lib/utils/validators';
import { AI_MODELS } from '@/lib/constants';import apiClient from '@/lib/api/api-client';
import { conversationAPI } from '@/lib/api/server-client';
const notes = await apiClient.get('/notes');
const chat = await apiClient.post('/chat', { message, model });
const conversations = await conversationAPI.list();src/features/new-feature/
├── components/
│ └── NewFeatureComponent.tsx
├── hooks/
│ └── useNewFeature.ts
├── services/
│ └── newFeatureService.ts
├── context/
│ └── NewFeatureContext.tsx
├── types.ts
├── styles.ts
└── index.ts
src/app/(dashboard)/new-feature/
└── page.tsx
src/app/api/new-feature/
└── route.ts
// src/store/slices/newFeatureSlice.ts
export const createNewFeatureSlice = (set, get) => ({
// state and actions
});- Copy
.env.exampleto.env.local - Add your API keys and configuration
- Update
config/env.tsif you add required variables
- Keep components small - Single responsibility
- Use feature folders - Feature-specific code stays together
- Leverage path aliases - Cleaner imports
- Centralize utilities - Reusable functions in
lib/utils - Type your code - Use TypeScript for better IDE support
- Follow naming conventions - PascalCase for components, camelCase for utilities
- Feature self-containment - Each feature should be self-contained with its own components, hooks, services, and types
- Feature Self-Containment: Each feature in
src/features/contains all its components, hooks, services, types, and styles - Clear Separation: Shared code in
src/components/,src/lib/,src/hooks/; feature code insrc/features/ - Scalability: Easy to add new features by creating a new folder in
src/features/ - Consistency: All features follow the same internal structure
- Route Pages Stay Thin: Pages in
src/app/should only compose features, not contain business logic
- Old
src/app/features/chat/*→ Nowsrc/features/chat/ - Old
src/layouts/dashboard/*→ Nowsrc/components/layout/ - Old
src/lib/api-client.ts→ Nowsrc/lib/api/api-client.ts - Old
src/lib/server-client.ts→ Nowsrc/lib/api/server-client.ts - Old
src/lib/groqClient.ts→ Nowsrc/lib/services/ai/groqClient.ts - Old
src/lib/firebase/*→ Nowsrc/lib/services/firebase/ - Old
src/hooks/useConversations.ts→ Nowsrc/features/chat/hooks/useConversations.ts