# Torus Bootstrap

CLI tool to bootstrap ASP.NET Core applications with Onion Architecture using the Torus Backend Framework.

> **Rule:** see [`.tas/rules/csharp/torus-core-framework.md`](../rules/csharp/torus-core-framework.md) for the guardrails `/tas-plan` and `/tas-dev` apply when scaffolding.

## Installation

```bash
dotnet tool install --global Torus.Bootstrap
```

Or build from source:

```bash
cd Torus.Bootstrap
dotnet pack
dotnet tool install --global --add-source ./bin/Debug Torus.Bootstrap
```

## Usage

### Interactive Mode (Default)

```bash
torus-bootstrap create --name Torus.Org
```

This will prompt you for:
- Cache configuration (Memory/Redis/Both)
- Messaging (Kafka)
- Background Jobs (Quartz)
- Telemetry (OpenTelemetry)
- Captcha (Google/Turnstile)
- OPA Authorization
- Blob Storage (FileSystem/MinIO/S3)
- Email (MailKit/SES)
- Database type (SQL Server/PostgreSQL/MySQL/MongoDB)
- Multi-tenancy

### Non-Interactive Mode

```bash
torus-bootstrap create --name Torus.Org --interactive false
```

Uses default configuration:
- Memory Cache
- OpenTelemetry
- SQL Server

### Command-Line Options

You can specify configuration options via command-line flags:

```bash
torus-bootstrap create --name Torus.Org \
  --cache redis \
  --distributed-lock \
  --messaging \
  --kafka \
  --background-jobs \
  --quartz \
  --telemetry \
  --otel \
  --captcha google \
  --opa \
  --blob-storage s3 \
  --email ses \
  --database postgresql \
  --multi-tenancy
```

#### Available Options

**Cache:**
- `--cache <none|memory|redis|both>` - Cache type (default: memory)
- `--distributed-lock` - Enable distributed locks (requires Redis)

**Messaging:**
- `--messaging` - Enable messaging
- `--kafka` - Use Kafka (requires --messaging)

**Background Jobs:**
- `--background-jobs` - Enable background jobs
- `--quartz` - Use Quartz.NET (requires --background-jobs)

**Telemetry:**
- `--telemetry` - Enable telemetry
- `--otel` - Use OpenTelemetry (requires --telemetry)

**Captcha:**
- `--captcha <none|google|turnstile|both>` - Captcha type

**Authorization:**
- `--opa` - Use OPA (Open Policy Agent) for policy-based authorization

**Blob Storage:**
- `--blob-storage <none|filesystem|minio|s3|both>` - Blob storage type

**Email:**
- `--email <none|mailkit|ses|both>` - Email type

**Database:**
- `--database <sqlserver|postgresql|mysql|mongodb>` - Database type (default: sqlserver)

**Multi-Tenancy:**
- `--multi-tenancy` - Enable multi-tenancy

#### Combining Interactive and Command-Line Options

Command-line options override interactive prompts:

```bash
torus-bootstrap create --name Torus.Org --cache redis --database postgresql
```

This will use interactive mode but skip prompts for cache and database, using the provided values instead.

### Output Directory

```bash
torus-bootstrap create --name Torus.Org --output ./MyProjects
```

## Generated Project Structure

```
Torus.Org/
├── Torus.Org.Domain.Shared/     # Shared domain types
├── Torus.Org.Domain/            # Domain layer
├── Torus.Org.Application.Contracts/  # Application contracts
├── Torus.Org.Application/        # Application layer
├── Torus.Org.Persistence.EfCore/ # Data access layer
├── Torus.Org.Infrastructure/      # Infrastructure layer
├── Torus.Org.WebApi/             # Web API layer
└── Torus.Org.sln                 # Solution file
```

## Next Steps

After generating the project:

1. Navigate to the project directory:
   ```bash
   cd Torus.Org
   ```

2. Restore packages:
   ```bash
   dotnet restore
   ```

3. Update `appsettings.json` with your configuration

4. Add database provider package to `Persistence.EfCore` project:
   - SQL Server: `Microsoft.EntityFrameworkCore.SqlServer`
   - PostgreSQL: `Npgsql.EntityFrameworkCore.PostgreSQL`
   - MySQL: `Pomelo.EntityFrameworkCore.MySql`

5. Create initial migration:
   ```bash
   dotnet ef migrations add InitialCreate --project Torus.Org.Persistence.EfCore
   ```

6. Build and run:
   ```bash
   dotnet build
   dotnet run --project Torus.Org.WebApi
   ```

## Features

The tool generates:

- Onion Architecture project structure
- DbContext and UnitOfWork setup
- Program.cs with configured services
- appsettings.json with configuration templates
- Solution file with all projects
- README.md with setup instructions

## Configuration Options

### Cache
- **Memory**: In-memory caching
- **Redis**: Distributed Redis cache
- **Both**: Memory + Redis with invalidation

### Messaging
- **Kafka**: Kafka message broker integration

### Background Jobs
- **Quartz.NET**: Scheduled and recurring jobs

### Telemetry
- **OpenTelemetry**: Distributed tracing and metrics

### Captcha
- **Google reCAPTCHA**: Bot detection
- **Cloudflare Turnstile**: Privacy-focused captcha

### Authorization
- **OPA**: Open Policy Agent integration

### Blob Storage
- **FileSystem**: Local file storage
- **MinIO**: S3-compatible object storage
- **AWS S3**: Amazon S3 storage

### Email
- **MailKit**: SMTP email sending
- **AWS SES**: Amazon Simple Email Service

### Database
- **SQL Server**: Microsoft SQL Server
- **PostgreSQL**: PostgreSQL database
- **MySQL**: MySQL database
- **MongoDB**: MongoDB (NoSQL)

## License

Part of the Torus Backend Framework.
