Overview
GAIA follows a feature-based architecture where components are organized by functionality rather than type. This approach improves maintainability, makes code easier to find, and naturally encourages encapsulation.Architecture Philosophy
Feature-Based
Organize by feature, not by file type
Colocation
Keep related code together
Encapsulation
Feature boundaries prevent tight coupling
Reusability
Shared components in dedicated folder
Directory Structure
Feature Structure
A typical feature follows this structure:Chat Feature Example
Component Patterns
Server vs Client Components
Next.js 16 uses Server Components by default:- Server Component
- Client Component
Component Composition
Break down complex components into smaller, focused pieces:- Single Responsibility: Each component has one clear purpose
- Composition: Build complex UIs from simple pieces
- Props Interface: Well-defined TypeScript interfaces
Compound Components
Create flexible APIs with compound components:Custom Hooks
Encapsulate complex logic in custom hooks:Data Fetching Hook
Streaming Hook
Shared Components
Components used across features live incomponents/:
UI Components
Layout Components
Common Components
Type Definitions
Organize types with your features:Styling Patterns
TailwindCSS with cn Utility
CSS Modules (Legacy)
Performance Optimization
Memoization
Lazy Loading
Virtual Lists
Testing Components
Best Practices
Colocate Related Code
Keep components, hooks, and utilities together by feature
Single Responsibility
Each component should do one thing well
Explicit Types
Always define TypeScript interfaces for props
Composition Over Props
Use children and composition instead of many props
Next Steps
Web App
Learn about Next.js architecture
State Management
Master Zustand patterns
Testing
Write component tests
API Integration
Connect to the backend