# RelSpec

> Database Relations Specification Tool for Go

RelSpec is a comprehensive database relations management tool that reads, transforms, and writes database table specifications across multiple formats and ORMs.

## Overview

RelSpec provides bidirectional conversion and comparison between various database specification formats, allowing you to:
- Inspect live databases and extract their structure
- Convert between different ORM models (GORM, Bun , etc.)
- Transform legacy schema definitions (Clarion DCTX, XML, JSON, etc.)
- Generate standardized specification files (JSON, YAML, etc.)

![1.00](./assets/image/relspec1_512.jpg)

## Features

### Readers (Input Formats)

RelSpec can read database schemas from multiple sources:

#### ORM Models
- [GORM](pkg/readers/gorm/README.md) - Go GORM model definitions
- [Bun](pkg/readers/bun/README.md) - Go Bun model definitions
- [Drizzle](pkg/readers/drizzle/README.md) - TypeScript Drizzle ORM schemas
- [Prisma](pkg/readers/prisma/README.md) - Prisma schema language
- [TypeORM](pkg/readers/typeorm/README.md) - TypeScript TypeORM entities

#### Database Inspection
- [PostgreSQL](pkg/readers/pgsql/README.md) - Direct PostgreSQL database introspection

#### Schema Formats
- [DBML](pkg/readers/dbml/README.md) - Database Markup Language (dbdiagram.io)
- [DCTX](pkg/readers/dctx/README.md) - Clarion database dictionary format
- [DrawDB](pkg/readers/drawdb/README.md) - DrawDB JSON format
- [GraphQL](pkg/readers/graphql/README.md) - GraphQL Schema Definition Language (SDL)
- [JSON](pkg/readers/json/README.md) - RelSpec canonical JSON format
- [YAML](pkg/readers/yaml/README.md) - RelSpec canonical YAML format

### Writers (Output Formats)

RelSpec can write database schemas to multiple formats:

#### ORM Models
- [GORM](pkg/writers/gorm/README.md) - Generate GORM-compatible Go structs
- [Bun](pkg/writers/bun/README.md) - Generate Bun-compatible Go structs
- [Drizzle](pkg/writers/drizzle/README.md) - Generate Drizzle ORM TypeScript schemas
- [Prisma](pkg/writers/prisma/README.md) - Generate Prisma schema files
- [TypeORM](pkg/writers/typeorm/README.md) - Generate TypeORM TypeScript entities

#### Database DDL
- [PostgreSQL](pkg/writers/pgsql/README.md) - PostgreSQL DDL (CREATE TABLE, etc.)

#### Schema Formats
- [DBML](pkg/writers/dbml/README.md) - Database Markup Language
- [DCTX](pkg/writers/dctx/README.md) - Clarion database dictionary format
- [DrawDB](pkg/writers/drawdb/README.md) - DrawDB JSON format
- [GraphQL](pkg/writers/graphql/README.md) - GraphQL Schema Definition Language (SDL)
- [JSON](pkg/writers/json/README.md) - RelSpec canonical JSON format
- [YAML](pkg/writers/yaml/README.md) - RelSpec canonical YAML format


## Use of AI
[Rules and use of AI](./AI_USE.md)

## Installation

```bash
go get github.com/wdevs/relspecgo

go install -v git.warky.dev/wdevs/relspecgo/cmd/relspec@latest
```

## Usage

```bash
# Inspect database and generate GORM models
relspec --input db --conn "postgres://..." --output gorm --out-file models.go

# Convert GORM models to Bun
relspec --input gorm --in-file existing.go --output bun --out-file bun_models.go

# Export database schema to JSON
relspec --input db --conn "mysql://..." --output json --out-file schema.json

# Convert Clarion DCTX to YAML
relspec --input dctx --in-file legacy.dctx --output yaml --out-file schema.yaml
```

## Project Structure

```
relspecgo/
├── cmd/              # CLI application
├── pkg/
│   ├── readers/      # Input format readers
│   ├── writers/      # Output format writers
│   ├── models/       # Internal data models
│   └── transform/    # Transformation logic
├── examples/         # Usage examples
└── tests/            # Test files
```

## Todo

[Todo List of Features](./TODO.md)

## Development

### Prerequisites
- Go 1.21 or higher
- Access to test databases (optional)

### Building

```bash
go build -o relspec ./cmd/relspec
```

### Testing

```bash
go test ./...
```

## License

Apache License 2.0 - See [LICENSE](LICENSE) for details.

Copyright 2025 Warky Devs

## Contributing

Contributions welcome. Please open an issue or submit a pull request.