# CodeFlash AI

## Overview

CodeFlash AI is a JavaScript/TypeScript monorepo that provides a scalable and modular architecture for web applications, focusing on efficient code sharing and robust development practices.

## Project Structure

```
js/
├── common/           # Shared code and database schema
├── cf-api/           # Backend API service
└── cf-webapp/        # Next.js web application
```

## Prerequisites

- Node.js (v18+ recommended)
- npm (v9+)
- Prisma CLI

## Setup

### 1. Clone the Repository

```bash
git clone https://github.com/your-org/codeflash-ai.git
cd codeflash-ai/js
```

### 2. Install Dependencies

```bash
# Install root and project dependencies
npm install
cd common && npm install
cd ../cf-api && npm install
cd ../cf-webapp && npm install
```

### 3. Database Configuration

```bash
# Generate Prisma client and run migrations
cd common
npx prisma generate
npx prisma migrate dev
```

## Development Workflow

### Start Development Servers

```bash
# Start API server
cd cf-api
For local development, developers would use `npm run dev`
For production (Azure), the system would use `npm run start`

# Start web application
cd cf-webapp
npm run dev
```

### Build Common Package

```bash
cd common
npm run build
```

## Key Components

### Common Package (`@codeflash-ai/common`)

- Shared TypeScript utilities
- Prisma database schema
- Reusable functions across projects

#### Installation in Other Projects

```bash
npm install @codeflash-ai/common
```

#### Usage Example

```typescript
import { createOrUpdateUser } from "@codeflash-ai/common"
```

## Best Practices

1. Always build the common package after making changes
2. Keep shared logic in the `common` package
3. Use TypeScript for type safety
4. Follow existing code structure
5. Never commit sensitive data or build artifacts

## Publishing common Package

```bash
# Publish common package to npm
cd common
npm run build
npm publish
```
