# AutoChangelog

AutoChangelog is a powerful, self-hosted changelog generation service that automatically creates beautiful, comprehensive changelogs from your GitHub repositories. Built with Node.js, Express, and MongoDB, it provides a complete solution for tracking and documenting your project's evolution.

## Features

### 🚀 Core Features
- **Automatic Changelog Generation**: Generate changelogs for any time period from your GitHub repositories
- **Multiple Output Formats**: Support for Markdown, HTML, and JSON formats
- **GitHub Integration**: Seamless integration with GitHub repositories and pull requests
- **Conventional Commits Support**: Parse and categorize commits using conventional commit standards
- **Multi-Project Support**: Manage multiple projects and repositories in one dashboard
- **Subscription-Based Limits**: Flexible plans with usage limits for projects, repositories, and changelogs

### 🔐 Authentication & Security
- **JWT Authentication**: Secure token-based authentication
- **GitHub OAuth**: Easy sign-up and authentication via GitHub
- **Role-Based Access**: Project ownership and access control
- **Rate Limiting**: API rate limiting to prevent abuse
- **CORS Protection**: Configurable CORS settings for frontend integration

### 📊 Project Management
- **Project Organization**: Create and manage multiple projects
- **Repository Management**: Connect and sync multiple GitHub repositories per project
- **Usage Tracking**: Monitor subscription usage and limits
- **Statistics & Analytics**: Detailed statistics for projects and repositories
- **Search & Filter**: Advanced search and filtering capabilities

### 🔄 Automation & Integration
- **GitHub Webhooks**: Automatic changelog generation on commits
- **API-First Design**: Complete REST API for integration with other tools
- **Webhook Support**: Receive changelog generation events
- **Scheduled Generation**: Plan and schedule changelog generation

### 🎨 Customization
- **Multiple Templates**: Different changelog templates (default, Angular, Conventional)
- **Custom Formatting**: Configure commit categorization and formatting
- **Branding Options**: Customize changelog appearance and branding
- **Shareable Links**: Generate shareable links for public changelogs

## Tech Stack

### Backend
- **Node.js** - JavaScript runtime
- **Express.js** - Web application framework
- **MongoDB** - NoSQL database
- **Mongoose** - MongoDB object modeling
- **JWT** - Authentication tokens
- **Axios** - HTTP client for GitHub API
- **Winston** - Logging library

### Frontend (Integration Ready)
- **React/Vue/Angular** - Framework agnostic
- **REST API** - Full API for frontend integration
- **CORS Support** - Cross-origin resource sharing

### DevOps
- **Docker** - Containerization
- **Environment Variables** - Configuration management
- **Rate Limiting** - API protection
- **Security Headers** - Helmet.js for security

## Installation

### Prerequisites
- Node.js (v16 or higher)
- MongoDB (local or cloud instance)
- GitHub account for OAuth integration

### Quick Start

1. **Clone the repository:**
   ```bash
   git clone <repository-url>
   cd autochangelog
   ```

2. **Install dependencies:**
   ```bash
   npm install
   ```

3. **Set up environment variables:**
   ```bash
   cp .env.example .env
   # Edit .env with your configuration
   ```

4. **Initialize the database:**
   ```bash
   npm run init:db
   ```

5. **Start the server:**
   ```bash
   npm start
   ```

### Environment Configuration

Create a `.env` file with the following variables:

```env
# Server Configuration
NODE_ENV=development
PORT=5000
FRONTEND_URL=http://localhost:3000

# Database
MONGODB_URI=mongodb://localhost:27017/autochangelog
MONGODB_URI_TEST=mongodb://localhost:27017/autochangelog_test

# Authentication
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRES_IN=7d

# GitHub Integration
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret
GITHUB_CALLBACK_URL=http://localhost:5000/api/auth/github/callback
GITHUB_API_BASE_URL=https://api.github.com

# Logging
LOG_LEVEL=info
```

## API Documentation

### Authentication Endpoints

#### POST /api/auth/register
Register a new user account.

**Request:**
```json
{
  "email": "user@example.com",
  "password": "password123",
  "name": "John Doe"
}
```

#### POST /api/auth/login
Login with email and password.

**Request:**
```json
{
  "email": "user@example.com",
  "password": "password123"
}
```

#### GET /api/auth/github/login
Get GitHub OAuth URL for authentication.

#### GET /api/auth/github/callback
Handle GitHub OAuth callback.

### Project Endpoints

#### POST /api/projects
Create a new project.

**Headers:** `Authorization: Bearer <token>`

**Request:**
```json
{
  "name": "My Project",
  "description": "A description of my project",
  "tags": ["web", "api"],
  "settings": {
    "defaultBranch": "main",
    "changelogTemplate": "default"
  }
}
```

#### GET /api/projects
Get all projects for the authenticated user.

#### GET /api/projects/:id
Get a specific project.

#### PUT /api/projects/:id
Update a project.

#### DELETE /api/projects/:id
Delete a project (soft delete).

### Repository Endpoints

#### POST /api/repositories
Connect a GitHub repository to a project.

**Request:**
```json
{
  "projectId": "project-id",
  "githubRepoId": "12345678",
  "githubRepoName": "my-repo",
  "githubRepoUrl": "https://github.com/user/my-repo",
  "githubRepoOwner": "user",
  "githubRepoFullName": "user/my-repo",
  "name": "My Repository",
  "description": "A description of my repository"
}
```

#### GET /api/repositories/:projectId
Get all repositories for a project.

#### POST /api/repositories/:id/sync
Sync repository data from GitHub.

### Changelog Endpoints

#### POST /api/changelogs
Generate a new changelog.

**Request:**
```json
{
  "projectId": "project-id",
  "repositoryId": "repository-id",
  "month": "03",
  "year": "2024",
  "format": "markdown",
  "template": "default",
  "includeCommitsWithoutPR": true
}
```

#### GET /api/changelogs/project/:projectId
Get all changelogs for a project.

#### GET /api/changelogs/repository/:repositoryId
Get all changelogs for a repository.

#### GET /api/changelogs/:id
Get a specific changelog.

#### POST /api/changelogs/:id/share
Make a changelog publicly shareable.

#### GET /api/changelogs/share/:shareToken
Get a public changelog by share token.

## Database Schema

### User Model
- **email**: Unique user email
- **password**: Hashed password
- **name**: User's display name
- **GitHub Integration**: GitHub OAuth tokens and user info
- **Subscription**: Plan type and usage limits
- **Usage Tracking**: Current usage statistics
- **Preferences**: User preferences and settings

### Project Model
- **name**: Project name
- **description**: Project description
- **slug**: URL-friendly project identifier
- **Ownership**: User and organization ownership
- **Settings**: Project-specific configuration
- **Metadata**: Statistics and tracking data
- **Tags**: Project categorization tags

### Repository Model
- **GitHub Information**: Repository metadata from GitHub
- **Authentication**: GitHub access tokens
- **Configuration**: Repository-specific settings
- **Sync Status**: Last sync information and status
- **Webhook**: GitHub webhook configuration
- **Features**: Enabled GitHub features (issues, PRs, releases)

### Changelog Model
- **Content**: Generated changelog content
- **Format**: Output format (markdown, html, json)
- **Status**: Generation status and metadata
- **Version Information**: Semantic versioning data
- **Sharing**: Public sharing configuration
- **Statistics**: Generation and view statistics

## Development

### Running in Development

1. **Start MongoDB:**
   ```bash
   # If using Docker
   docker run -d -p 27017:27017 mongo:latest
   
   # Or start local MongoDB instance
   mongod
   ```

2. **Start the development server:**
   ```bash
   npm run dev
   ```

3. **Run database initialization:**
   ```bash
   npm run init:db
   ```

### Available Scripts

- `npm start` - Start the production server
- `npm run dev` - Start the development server with nodemon
- `npm run init:db` - Initialize the database and create indexes
- `npm test` - Run tests (when implemented)
- `npm run lint` - Run linting (when configured)

### Project Structure

```
autochangelog/
├── src/
│   ├── app.js              # Main application file
│   ├── server.js           # Server entry point
│   ├── config/
│   │   └── database.js     # Database configuration
│   ├── controllers/        # Route controllers
│   │   ├── auth.js
│   │   ├── project.js
│   │   ├── repository.js
│   │   └── changelog.js
│   ├── middleware/         # Custom middleware
│   │   └── auth.js
│   ├── models/            # Mongoose models
│   │   ├── User.js
│   │   ├── Project.js
│   │   ├── Repository.js
│   │   └── Changelog.js
│   ├── routes/            # Route definitions
│   │   ├── auth.routes.js
│   │   ├── project.routes.js
│   │   ├── repository.routes.js
│   │   └── changelog.routes.js
│   ├── services/          # Business logic services
│   │   ├── github.js
│   │   └── changelog.js
│   └── utils/             # Utility functions
│       └── logger.js
├── scripts/               # Database scripts
├── logs/                  # Application logs
├── public/                # Static files
├── package.json
├── .env.example           # Environment variables template
└── README.md
```

## Deployment

### Docker Deployment

1. **Build the Docker image:**
   ```bash
   docker build -t autochangelog .
   ```

2. **Run with Docker Compose:**
   ```bash
   docker-compose up -d
   ```

### Production Deployment

1. **Set production environment variables**
2. **Build and optimize the application**
3. **Set up a production MongoDB instance**
4. **Configure reverse proxy (nginx)**
5. **Set up SSL/TLS certificates**
6. **Configure monitoring and logging**

## Contributing

We welcome contributions! Please follow these steps:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support

- **Documentation**: [API Documentation](#api-documentation)
- **Issues**: [GitHub Issues](https://github.com/your-repo/autochangelog/issues)
- **Discussions**: [GitHub Discussions](https://github.com/your-repo/autochangelog/discussions)

## Contributing

Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- [GitHub API](https://docs.github.com/en/rest) - For providing access to repository data
- [Conventional Commits](https://www.conventionalcommits.org/) - For commit message standards
- [Express.js](https://expressjs.com/) - For the web framework
- [Mongoose](https://mongoosejs.com/) - For MongoDB object modeling