npm package: @sunny-pirate/backend-dreamlab-datacenter
Description: Type definitions for DreamLab Datacenter Supabase database
Author: Sunny-Pirate
Latest version: 1.0.5

# DreamLab Datacenter

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

A centralized Supabase-based backend infrastructure for DreamLab services, including the SimGarage racing platform.

## Overview

DreamLab Datacenter is the core backend infrastructure that powers multiple DreamLab services:

- **SimGarage Platform**: A comprehensive sim racing community platform
- **DreamLab Website**: Corporate website and CMS with multilingual support
- **Contact Management**: Form submission processing with workflow system

This repository contains database schema definitions, migrations, edge functions, and TypeScript type definitions for the entire ecosystem.

## Architecture

### Database Structure

The project uses a multi-schema approach in PostgreSQL:

- **public**: Shared tables and utilities
- **simgarage**: Racing platform-specific schemas
- **auth**: Supabase authentication tables
- **storage**: File storage management

Key features:

- Row-Level Security (RLS) policies for fine-grained access control
- Custom roles system for SimGarage users
- Storage buckets for various asset types
- Edge functions for serverless operations

### SimGarage Platform

The SimGarage platform ("Motorhome - The SimGarage") is a modular, multi-tenant web application for the sim racing community with features for:

- User and team management
- Championship organization
- Racing session tracking
- Car setup and telemetry storage
- Custom liveries and driver customization
- Subscription management with Stripe integration

### Storage System

The project leverages Supabase Storage with multiple buckets:

- `acc-car-setups`: Car setup files with restricted access
- `acc-motec-telemetry`: Telemetry data files
- `acc-custom-cars`: Custom car configuration files
- `acc-driver-customization`: Driver appearance customizations
- `acc-liveries`: Livery textures and assets (public readable)

## Getting Started

### Prerequisites

- [Node.js](https://nodejs.org/) (v18+)
- [pnpm](https://pnpm.io/) package manager
- [Supabase CLI](https://supabase.com/docs/guides/cli)
- [Docker](https://www.docker.com/) and Docker Compose

### Installation

1. Clone the repository:
   ```bash
   git clone https://github.com/dreamlab/backend-dreamlab-datacenter.git
   cd backend-dreamlab-datacenter
   ```

2. Install dependencies:
   ```bash
   pnpm install
   ```

3. Start the local Supabase instance:
   ```bash
   supabase start
   ```

4. Apply migrations:
   ```bash
   supabase migration up
   ```

5. Load seed data:
   ```bash
   supabase db reset
   ```

6. Generate TypeScript types:
   ```bash
   ./bin/generate-types.sh
   ```

### Development Commands

```bash
# Generate TypeScript types from Supabase schema
pnpm run generate:ts

# Build the TypeScript project
pnpm run build

# Generate types with custom schema selection
./bin/generate-types.sh --schema "public,simgarage,auth,storage"

# Connect to local Supabase instance
supabase start

# Apply migrations
supabase migration up

# Create a new migration
supabase migration new migration_name
```

## Documentation

Comprehensive documentation is maintained using Antora and can be found in the `docs/` directory:

- Documentation is written in AsciiDoc format
- UML diagrams visualize system components and workflows
- The `docs/modules/simgarage/` directory contains SimGarage-specific documentation

To build the documentation:

```bash
npx antora antora-playbook.yml
```

This will generate static documentation in the `public/` directory.

## SimGarage Modules

- **User Management**: Profiles, authentication, and roles
- **Team Organization**: Teams, communities, and memberships
- **Racing Structure**: Championships, races, and sessions
- **Racing Resources**: Games, cars, and tracks
- **Technical Resources**: Setups, strategies, and telemetry
- **Customization**: Liveries, mods, and driver customizations
- **Subscription Management**: Plans, billing, and access

## Working with Edge Functions

Edge Functions provide serverless capabilities:

1. Navigate to function directory in `supabase/functions/`
2. Use Deno for local development
3. Deploy using Supabase CLI

## Contributing

1. Create a new branch for your feature
2. Follow the established code style and patterns
3. Add appropriate database migrations
4. Document your changes
5. Create a pull request for review

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## Contact

For questions or support, contact the DreamLab development team.