# BMAD Task Manager - Code Conventions & Style Guide

## TypeScript Conventions
- **Strict Mode**: All TypeScript files use strict mode
- **No `any` Types**: Avoid `any` types; use `unknown` with proper type assertions
- **Type Imports**: Use `type` keyword for type-only imports
- **Interface Naming**: No `I` prefix for interfaces
- **File Extensions**: Use `.ts` for server, `.tsx` for React components

## Project Structure
```
/server/src/
  - index.ts           # Main MCP server class
  - database.ts        # SQLite operations
  - unified-server.ts  # Combined server with auto-browser
  - /tools/           # MCP tool implementations
  - /api/             # REST API routes

/web/src/
  - /components/      # React components
  - /store/           # Zustand state management
  - /lib/             # Utilities and API client
  - /hooks/           # Custom React hooks

/shared/
  - types.ts          # Shared type definitions
  - tool-types.ts     # MCP tool input/output types
```

## Naming Conventions
- **Files**: kebab-case for files (e.g., `bmad-hierarchy.tsx`)
- **Components**: PascalCase for React components
- **Functions**: camelCase for functions and methods
- **Constants**: UPPER_SNAKE_CASE for constants
- **Database**: snake_case for table and column names

## Import Order
1. External dependencies
2. Shared types
3. Local modules
4. Relative imports

## Database Patterns
- Use Better-SQLite3 with prepared statements
- Import as `BetterSqlite3` to avoid naming conflicts
- Always use transactions for multi-step operations

## React Patterns
- Functional components with hooks
- Custom hooks for business logic
- Zustand for global state management
- Socket.io for real-time updates

## Error Handling
- Use try-catch blocks for async operations
- Return proper error responses with status codes
- Display user-friendly error messages via toast notifications

## Environment Variables
- Use process.env with fallback defaults
- Configure via .env files
- Support both command-line and file-based configuration