> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quinnsambal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Workspaces

<style>
  {`
    [class*="max-w-none"][class*="table"] {
      display: block !important;
      overflow-x: auto !important;
      max-width: 100% !important;
      width: 100% !important;
      flex-grow: 0 !important;
    }
    [class*="max-w-none"][class*="table"] > table {
      width: 100% !important;
      max-width: 100% !important;
      table-layout: fixed !important;
    }
    .mermaid {
      max-width: 100% !important;
      overflow-x: auto !important;
    }
    article svg[role="img"] {
      max-width: 100% !important;
      height: auto !important;
    }
    article img, .prose img {
      max-width: 100% !important;
      height: auto !important;
    }
    img[src*="LOGO"], img[src*="logo"] {
      max-width: 120px !important;
      max-height: 40px !important;
      width: auto !important;
      height: auto !important;
      object-fit: contain !important;
    }
    `}
</style>

***

title: "Workspaces"
description: "Manajemen dan navigasi antar workspace tim dan departemen untuk kolaborasi lintas fungsi."
--------------------------------------------------------------------------------------------------------

# Workspaces

<img src="https://mintcdn.com/quinnofspicy/e4f_upKhVWcjsUmM/docs/mintlify/screenshots/core/workspaces.png?fit=max&auto=format&n=e4f_upKhVWcjsUmM&q=85&s=eba81a4b1998a18eb83e45696cbc8961" alt="Workspaces" width="1920" height="1080" data-path="docs/mintlify/screenshots/core/workspaces.png" />

Halaman **Workspaces** menampilkan direktori semua workspace yang tersedia di perusahaan kamu. Jika Workspace individual adalah ruang kerja personal, halaman ini adalah **peta seluruh ruang kerja kolaboratif** — mencakup workspace tim, departemen, project, dan cross-functional yang bisa kamu akses sesuai peran dan izin.

Halaman ini memudahkan perpindahan kontekstual antar workspace tanpa perlu navigasi panjang. Misalnya, pagi hari kamu kerja di workspace **Tim Sales** untuk cek target penjualan, lalu siang harinya pindah ke workspace **Tim Inventory** untuk review stok.

## Workspace vs Workspaces

| Aspek | Workspace (Personal) | Workspaces (Directory) |
| - | - | - |
| **Scope** | Ruang kerja individual | Direktori semua workspace tim |
| **Data** | Tugas, catatan, aktivitas personal | Daftar workspace + anggota + aktivitas |
| **Akses** | Otomatis 1 per user | Browse & join berdasarkan permission |
| **Tujuan** | Fokus individual | Kolaborasi tim & cross-functional |

## Struktur Workspace

```mermaid theme={null}
graph TD
    A[Perusahaan] --> B[Workspace Departemen]
    A --> C[Workspace Project]
    A --> D[Workspace Cross-Functional]
    A --> E[Workspace Cabang]
    
    B --> B1[Sales]
    B --> B2[Inventory]
    B --> B3[Finance]
    B --> B4[Produksi]
    B --> B5[HR]
    
    C --> C1[Peluncuran Produk Baru]
    C --> C2[Stock Opname Q4]
    C --> C3[Audit Tahunan]
    
    D --> D1[Tim B2B]
    D --> D2[Quality Control]

    E --> E1[Cabang Jakarta]
    E --> E2[Cabang Medan]
    E --> E3[Cabang Surabaya]
```

## Tipe Workspace

| Tipe | Deskripsi | Keanggotaan | Contoh |
| - | - | - | - |
| **Departemen** | Workspace berdasarkan divisi/fungsi | Otomatis berdasarkan role | Sales, Inventory, Finance |
| **Project** | Workspace untuk project spesifik | Di-assign oleh PM | Peluncuran Produk, Migrasi Sistem |
| **Cross-Functional** | Workspace lintas departemen | Multi-departemen | Tim B2B, Quality Control |
| **Cabang** | Workspace per lokasi/cabang | Berdasarkan lokasi | Cabang Jakarta, Cabang Medan |

## Konsep Utama

### Workspace dan Company

Setiap workspace selalu terasosiasi dengan sebuah **Company** (perusahaan). Workspace personal (`is_personal = true`) dibuat secara otomatis untuk setiap user dan tidak terikat pada company tertentu. Workspace kolaboratif (`is_personal = false`) selalu berada di bawah naungan sebuah company dan diwarisi konfigurasi serta permission dari company tersebut.

### Personal vs Kolaboratif

| Aspek | Personal Workspace | Kolaboratif Workspace |
| - | - | - |
| **Flag `is_personal`** | `true` | `false` |
| **Jumlah per User** | 1 (otomatis) | Banyak (sesuai keanggotaan) |
| **Keanggotaan** | Hanya pemilik | Multi-member dengan role |
| **Company** | Tidak terikat | Terikat ke satu company |
| **Visibility** | Selalu private | Public atau private |
| **Penggunaan** | Catatan, tugas, fokus individual | Kolaborasi tim, sharing task |

### Workspace Owner

Setiap workspace memiliki seorang **owner** yang tercatat di field `owner_id`. Owner memiliki kontrol penuh atas workspace termasuk pengaturan konfigurasi, pengelolaan anggota, dan keputusan untuk mengarsipkan workspace. Sebuah workspace dapat memiliki **multiple owners** — role `owner` pada `WorkspaceMember` bisa diberikan ke lebih dari satu anggota.

## Komponen Utama

### 1. Daftar Workspace

Tampilan semua workspace yang tersedia dengan informasi kunci:

| Kolom | Deskripsi |
| - | - |
| **Nama Workspace** | Nama tim/departemen/project |
| **Deskripsi** | Tujuan dan scope workspace |
| **Icon & Warna** | Identitas visual workspace |
| **Jumlah Anggota** | Berapa orang yang tergabung |
| **Tugas Aktif** | Jumlah tugas yang belum selesai |
| **Last Activity** | Kapan terakhir ada aktivitas |
| **Role Kamu** | Peran kamu di workspace ini (Owner/Admin/Member/Viewer) |
| **Status** | Active / Archived |

### 2. Indikator Aktivitas

Setiap workspace memiliki indikator visual untuk membantu kamu memprioritaskan:

| Indikator | Arti | Tindakan |
| - | - | - |
| 🟢 **Aktif** | Banyak aktivitas hari ini | Perlu perhatian |
| 🟡 **Normal** | Aktivitas biasa | Cek secara berkala |
| ⚪ **Low** | Sedikit aktivitas | Tidak urgent |
| 🔴 **Alert** | Ada item yang butuh action segera | Prioritas tinggi |

### 3. Pencarian & Filter

| Filter | Opsi |
| - | - |
| **Tipe** | Departemen, Project, Cross-Functional, Cabang |
| **Status** | Active, Archived |
| **Role** | Owner, Admin, Member, Viewer |
| **Aktivitas** | Semua, Dengan tugas pending, Tanpa aktivitas |
| **Urutkan** | Nama, Aktivitas terakhir, Jumlah anggota, Tugas aktif |

### 4. Buat Workspace Baru

Jika kamu memiliki akses admin, kamu bisa membuat workspace baru:

| Field | Deskripsi | Wajib |
| - | - | - |
| **Nama** | Nama workspace yang jelas | Ya |
| **Deskripsi** | Tujuan dan scope workspace | Ya |
| **Icon** | Ikon emoji atau simbol untuk workspace | Tidak |
| **Warna** | Warna tema workspace (default: `#2563eb`) | Tidak |
| **Anggota** | User yang ditambahkan ke workspace | Ya (min 1) |
| **Visibility** | Public (semua bisa lihat) / Private (invite only) | Ya |
| **Parent** | Workspace induk (opsional, untuk hierarki) | Tidak |

**Workspace Creation Flow**:

```mermaid theme={null}
flowchart TD
    A[Click Buat Workspace] --> B[Isi detail form]
    B --> C[Pilih tipe workspace]
    C --> D[Set visibility]
    D --> E[Tambahkan anggota]
    E --> F{Validasi}
    F -->|OK| G[Create workspace entity]
    F -->|Error| H[Show validation errors]
    H --> B
    G --> I[Add members to workspace]
    I --> J[Send invitation notifications]
    J --> K[Workspace ready]
```

## Cara Akses

| Metode | Cara |
| - | - |
| **Sidebar** | Klik menu **Workspaces** |
| **Workspace Dropdown** | Dari Workspace individual, klik dropdown di pojok kiri atas |
| **Home** | Klik widget "Team Workspaces" di halaman Home |
| **Command Palette** | Tekan `Ctrl+K` → ketik "Workspaces" |

## Flow Penggunaan

```mermaid theme={null}
flowchart TD
    A[Buka halaman Workspaces] --> B[Lihat daftar workspace]
    B --> C{Perlu workspace baru?}
    C -->|Ya| D[Klik Buat Workspace]
    D --> E[Isi detail workspace]
    E --> F[Tambahkan anggota]
    F --> G[Workspace siap digunakan]
    C -->|Tidak| H[Pilih workspace yang ingin dibuka]
    H --> I[Masuk ke workspace]
    I --> J[Lihat tugas & aktivitas]
    J --> K[Kerjakan tugas atau kolaborasi]
```

## Perizinan Akses

| Role | Lihat Workspace | Bergabung | Buat Baru | Arsipkan |
| - | - | - | - | - |
| **Owner** | Semua | Semua | Ya | Ya |
| **Admin** | Semua | Semua | Ya | Ya |
| **Manager** | Departemen sendiri + cross-functional | Dengan approval | Departemen sendiri | Tidak |
| **Staff** | Public workspace | Dengan invite | Tidak | Tidak |

**Permission Resolution Flow**:

```mermaid theme={null}
flowchart TD
    A[User requests workspace access] --> B{Workspace visibility?}
    B -->|Public| C[Allow view]
    B -->|Private| D{User is member?}
    D -->|Yes| C
    D -->|No| E[Deny access]
    
    C --> F{User action?}
    F -->|View| G[Show workspace content]
    F -->|Join| H{Self-join allowed?}
    H -->|Yes| I[Add as member]
    H -->|No| J[Request approval from admin]
    F -->|Create| K{Has permission?}
    K -->|Yes| L[Allow creation]
    K -->|No| E
```

## Workspace Hierarchy

```mermaid theme={null}
flowchart TD
    subgraph "Level 0: Company"
        CO[Perusahaan]
    end

    subgraph "Level 1: Departments"
        D1[Sales]
        D2[Inventory]
        D3[Finance]
        D4[Produksi]
    end

    subgraph "Level 2: Sub-teams / Projects"
        S1[Tim B2B]
        S2[Tim Enterprise]
        S3[Stock Opname Q4]
        S4[Audit Tahunan]
    end

    CO --> D1 & D2 & D3 & D4
    D1 --> S1 & S2
    D2 --> S3
    D3 --> S4
```

## Tips

* **Buat workspace terpisah per departemen** supaya tugas dan diskusi tetap terorganisir dan tidak tercampur
* **Perhatikan badge jumlah tugas pending** di setiap workspace untuk tahu workspace mana yang butuh perhatian kamu saat ini
* **Kamu bisa menjadi anggota beberapa workspace sekaligus** — berpindah-pindah sesuai kebutuhan kerja hari ini
* **Arsipkan workspace yang sudah tidak aktif** supaya daftar workspace tetap rapi dan fokus pada yang relevan
* **Gunakan workspace project** untuk inisiatif lintas departemen yang memiliki deadline jelas, supaya kolaborasi lebih terstruktur
* **Set workspace default** yang paling sering kamu gunakan supaya setiap login langsung masuk ke workspace yang tepat

***

## Entity Relationship Diagram

```mermaid theme={null}
erDiagram
    Company ||--o{ Workspace : "memiliki banyak workspace"
    Company ||--o{ CompanyMember : "memiliki banyak anggota"
    User ||--o{ WorkspaceMember : "bergabung di banyak workspace"
    User ||--o{ CompanyMember : "terdaftar di banyak company"
    User ||--o| Workspace : "memiliki/membuat workspace"
    Workspace ||--o{ WorkspaceMember : "memiliki banyak anggota"
    Workspace ||--o| Workspace : "parent-child hierarchy"
    WorkspaceMember }o--|| User : "referensi ke user"
    WorkspaceMember }o--|| Workspace : "referensi ke workspace"

    Company {
        string id PK
        string name "Nama perusahaan"
        string owner_id FK "ID owner perusahaan"
        string owner_email "Email owner"
        string owner_subscription_plan "Plan membership owner"
        string description "Deskripsi perusahaan"
        string industry "Sektor industri"
        string address "Alamat perusahaan"
        string phone "Nomor telepon"
        string email "Email perusahaan"
        string website "URL website"
        string logo_url "URL logo"
        string tax_id "NPWP"
        number employee_count "Jumlah karyawan"
        object metadata "Data tambahan / legacy"
        object landing_page_config "Konfigurasi landing page"
        string business_type "Kategori bisnis"
        string active_modules "JSON modul aktif"
        object settings "Konfigurasi perusahaan"
    }

    Workspace {
        string id PK
        string company_id FK "ID perusahaan (null untuk personal)"
        string name "Nama workspace"
        string description "Deskripsi workspace"
        string icon "Icon workspace"
        string color "Warna tema workspace"
        string owner_id FK "ID pemilik workspace"
        boolean is_personal "Apakah workspace pribadi"
        object settings "Konfigurasi workspace"
    }

    WorkspaceMember {
        string id PK
        string workspace_id FK "ID workspace"
        string user_id FK "ID pengguna"
        string role "Peran dalam workspace"
        string invited_by "Email pengundang"
        datetime joined_at "Waktu bergabung"
        string description "Catatan tambahan anggota"
        object permissions "Hak akses detail member"
    }

    User {
        string id PK
        string email "Email pengguna"
        string full_name "Nama lengkap"
        string role "Role di aplikasi"
        string subscription_plan "Plan membership"
        string active_company_id FK "Company yang sedang aktif"
        number company_slots_purchased "Slot company tambahan"
        string admin_type "Tipe admin aplikasi"
        string admin_tier "Tier admin company"
        number productivity_score "Skor produktivitas"
        number user_level "Level pengguna"
        object preferences "Preferensi user"
    }

    CompanyMember {
        string id PK
        string company_id FK "ID perusahaan"
        string user_id FK "ID pengguna"
        string user_email "Email pengguna"
        string user_name "Nama pengguna"
        string role "Role dalam perusahaan"
        string employee_id FK "Link ke Employee"
        string department "Departemen"
        string position "Jabatan"
        string status "Status keanggotaan"
        date joined_date "Tanggal bergabung"
        string invited_by "Email pengundang"
        object permissions "Hak akses detail"
        array assigned_locations "Lokasi yang diizinkan"
        object working_hours "Jam kerja"
        number salary "Gaji karyawan"
        string notes "Catatan tambahan"
    }
```

## Entity Schema Tables

### Workspace

| Field | Type | Required | Default | Description |
| - | - | - | - | - |
| `id` | `string` (UUID) | Ya (auto) | — | Unique identifier untuk workspace |
| `company_id` | `string` (UUID) | Tidak | — | ID perusahaan. `null` untuk personal workspace |
| `name` | `string` | **Ya** | — | Nama workspace yang ditampilkan ke anggota |
| `description` | `string` | Tidak | — | Deskripsi singkat tujuan dan scope workspace |
| `icon` | `string` | Tidak | — | Icon workspace (emoji atau simbol visual) |
| `color` | `string` | Tidak | `#2563eb` | Warna tema workspace dalam format hex |
| `owner_id` | `string` (UUID) | **Ya** | — | ID user yang membuat/memiliki workspace |
| `is_personal` | `boolean` | Tidak | `false` | Flag apakah ini workspace pribadi (otomatis 1 per user) |
| `settings` | `object` | Tidak | — | Konfigurasi spesifik workspace (lihat sub-table di bawah) |

#### Workspace Settings (Nested Object)

| Field | Type | Default | Description |
| - | - | - | - |
| `settings.allow_public_sharing` | `boolean` | `false` | Izinkan sharing konten workspace ke publik |
| `settings.default_task_priority` | `enum` | `medium` | Prioritas default untuk task baru di workspace ini |

### WorkspaceMember

| Field | Type | Required | Default | Description |
| - | - | - | - | - |
| `id` | `string` (UUID) | Ya (auto) | — | Unique identifier untuk keanggotaan |
| `workspace_id` | `string` (UUID) | **Ya** | — | ID workspace yang dimasuki |
| `user_id` | `string` (UUID) | **Ya** | — | ID user yang menjadi anggota |
| `role` | `enum` | Tidak | `member` | Peran user dalam workspace |
| `invited_by` | `string` | Tidak | — | Email user yang mengundang anggota ini |
| `joined_at` | `datetime` | Tidak | — | Timestamp kapan user bergabung |
| `description` | `string` (max 1000) | Tidak | — | Catatan atau keterangan tambahan mengenai anggota |
| `permissions` | `object` | Tidak | — | Hak akses granular untuk member (lihat sub-table di bawah) |

#### WorkspaceMember Permissions (Nested Object)

| Field | Type | Default | Description |
| - | - | - | - |
| `permissions.can_create_tasks` | `boolean` | `true` | Dapat membuat task baru di workspace |
| `permissions.can_edit_tasks` | `boolean` | `true` | Dapat mengedit task yang ada |
| `permissions.can_delete_tasks` | `boolean` | `false` | Dapat menghapus task dari workspace |
| `permissions.can_invite_members` | `boolean` | `false` | Dapat mengundang anggota baru ke workspace |
| `permissions.can_access_all_tasks` | `boolean` | `false` | Akses ke semua task terlepas dari assignment |

### Company

| Field | Type | Required | Default | Description |
| - | - | - | - | - |
| `id` | `string` (UUID) | Ya (auto) | — | Unique identifier untuk perusahaan |
| `name` | `string` | **Ya** | — | Nama perusahaan |
| `owner_id` | `string` (UUID) | **Ya** | — | ID user pemilik perusahaan |
| `owner_email` | `string` | **Ya** | — | Email pemilik perusahaan |
| `owner_subscription_plan` | `enum` | Tidak | — | Plan membership owner saat ini |
| `description` | `string` | Tidak | — | Deskripsi perusahaan |
| `industry` | `enum` | Tidak | — | Sektor industri perusahaan |
| `address` | `string` | Tidak | — | Alamat fisik perusahaan |
| `phone` | `string` | Tidak | — | Nomor telepon perusahaan |
| `email` | `string` | Tidak | — | Email perusahaan |
| `website` | `string` | Tidak | — | URL website perusahaan |
| `logo_url` | `string` | Tidak | — | URL logo perusahaan |
| `tax_id` | `string` | Tidak | — | NPWP perusahaan |
| `employee_count` | `number` | Tidak | `0` | Jumlah karyawan |
| `metadata` | `object` | Tidak | — | Data tambahan / legacy |
| `landing_page_config` | `object` | Tidak | — | Konfigurasi landing page perusahaan |
| `business_type` | `string` | Tidak | — | Kategori bisnis yang dipilih saat onboarding |
| `active_modules` | `string` | Tidak | — | JSON string berisi array ID modul aktif |
| `settings` | `object` | Tidak | — | Konfigurasi operasional perusahaan |

### User

| Field | Type | Required | Default | Description |
| - | - | - | - | - |
| `id` | `string` (UUID) | Ya (auto) | — | Unique identifier untuk user |
| `email` | `string` | **Ya** | — | Email pengguna (unik) |
| `full_name` | `string` | **Ya** | — | Nama lengkap pengguna |
| `role` | `enum` | Tidak | — | Role global user di aplikasi |
| `subscription_plan` | `enum` | Tidak | `free` | Plan membership aktif |
| `subscription_start` | `datetime` | Tidak | — | Tanggal mulai subscription |
| `subscription_end` | `datetime` | Tidak | — | Tanggal berakhir subscription |
| `membership_duration_type` | `enum` | Tidak | — | Tipe durasi membership |
| `membership_start_date` | `date` | Tidak | — | Tanggal mulai membership |
| `membership_end_date` | `date` | Tidak | — | Tanggal berakhir membership |
| `is_readonly_mode` | `boolean` | Tidak | `false` | Mode read-only saat expired dalam grace period 3 hari |
| `trial_end` | `datetime` | Tidak | — | Tanggal berakhir trial |
| `active_company_id` | `string` (UUID) | Tidak | — | ID company yang sedang aktif digunakan |
| `company_slots_purchased` | `number` | Tidak | `0` | Slot company tambahan yang dibeli di luar limit plan |
| `ai_monthly_usage` | `number` | Tidak | `0` | Penggunaan AI bulan ini |
| `ai_credits` | `number` | Tidak | `10` | Kredit AI yang tersedia |
| `ai_addon_quota` | `number` | Tidak | `0` | Kuota addon AI |
| `ai_usage_period_start` | `date` | Tidak | — | Awal periode penggunaan AI |
| `last_credit_reset` | `datetime` | Tidak | — | Terakhir kali kredit AI di-reset |
| `storage_used` | `number` | Tidak | `0` | Penyimpanan yang terpakai |
| `referred_by` | `string` | Tidak | — | User yang mereferensikan |
| `referral_code` | `string` | Tidak | — | Kode referral unik user |
| `balance` | `number` | Tidak | `0` | Saldo deposit untuk membership/addon |
| `commission_balance` | `number` | Tidak | `0` | Saldo komisi referral yang dapat ditarik |
| `admin_commission_balance` | `number` | Tidak | `0` | Saldo komisi admin basic dari transaksi |
| `total_earnings` | `number` | Tidak | `0` | Total komisi yang pernah diterima (akumulasi) |
| `admin_type` | `enum` | Tidak | — | Tipe admin aplikasi (owner/basic) |
| `admin_tier` | `enum` | Tidak | `none` | Tier admin untuk company management |
| `productivity_score` | `number` | Tidak | `0` | Skor produktivitas pengguna |
| `current_streak` | `number` | Tidak | `0` | Streak hari berturut-turut menyelesaikan tugas |
| `longest_streak` | `number` | Tidak | `0` | Streak terpanjang yang pernah dicapai |
| `last_active_date` | `date` | Tidak | — | Tanggal terakhir user aktif |
| `total_tasks_completed` | `number` | Tidak | `0` | Total tugas yang pernah diselesaikan |
| `total_notes_created` | `number` | Tidak | `0` | Total catatan yang pernah dibuat |
| `achievement_points` | `number` | Tidak | `0` | Poin achievement |
| `user_level` | `number` | Tidak | `1` | Level user berdasarkan achievement points |
| `trial_plan` | `string` | Tidak | — | Plan trial yang dipilih |
| `trial_expires` | `datetime` | Tidak | — | Tanggal berakhir trial |
| `trial_used` | `object` | Tidak | — | Track trial mana yang sudah digunakan |
| `preferences` | `object` | Tidak | — | Preferensi personalisasi user |

### CompanyMember

| Field | Type | Required | Default | Description |
| - | - | - | - | - |
| `id` | `string` (UUID) | Ya (auto) | — | Unique identifier |
| `company_id` | `string` (UUID) | **Ya** | — | ID perusahaan |
| `user_id` | `string` (UUID) | Tidak | — | ID pengguna |
| `user_email` | `string` | **Ya** | — | Email pengguna |
| `user_name` | `string` | Tidak | — | Nama pengguna |
| `role` | `enum` | Tidak | `employee` | Role dalam perusahaan |
| `employee_id` | `string` | Tidak | — | Link ke entitas Employee |
| `department` | `string` | Tidak | — | Departemen pengguna |
| `position` | `string` | Tidak | — | Jabatan pengguna |
| `status` | `enum` | Tidak | `active` | Status keanggotaan |
| `joined_date` | `date` | Tidak | — | Tanggal bergabung |
| `invited_by` | `string` | Tidak | — | Email yang mengundang |
| `permissions` | `object` | Tidak | — | Hak akses granular (30+ permission flags) |
| `assigned_locations` | `array<string>` | Tidak | — | Daftar ID lokasi gudang/outlet yang diizinkan |
| `working_hours` | `object` | Tidak | — | Jam kerja karyawan (start, end) |
| `salary` | `number` | Tidak | — | Gaji karyawan (opsional) |
| `notes` | `string` | Tidak | — | Catatan tambahan |

## Workspace Lifecycle

```mermaid theme={null}
stateDiagram-v2
    [*] --> Draft : Admin memulai pembuatan workspace
    Draft --> Active : Workspace divalidasi dan diaktifkan
    Active --> Active : Anggota bergabung / task ditambahkan
    Active --> Archived : Workspace tidak lagi digunakan
    Archived --> Active : Workspace di-reactivate oleh admin
    Archived --> [*] : Workspace dihapus permanen
    Active --> [*] : Workspace dihapus permanen oleh owner

    state Active {
        [*] --> Operating
        Operating --> MembersJoined : Undangan diterima
        MembersJoined --> TasksCreated : Task baru dibuat
        TasksCreated --> Operating : Aktivitas berlanjut
    }

    state Archived {
        [*] --> ReadOnly
        ReadOnly --> [*]
    }
```

## Sequence Diagrams

### Flow 1: Membuat Workspace Baru

```mermaid theme={null}
sequenceDiagram
    participant U as User (Admin/Owner)
    participant UI as Halaman Workspaces
    participant API as Backend API
    participant DB as Database
    participant N as Notification Service

    U->>UI: Klik "Buat Workspace"
    UI->>U: Tampilkan form pembuatan workspace
    U->>UI: Isi nama, deskripsi, icon, warna, visibility
    U->>UI: Tambahkan anggota awal (min 1)
    U->>UI: Submit form
    UI->>API: POST /api/workspaces
    API->>API: Validasi field required (name, owner_id)
    API->>DB: INSERT INTO workspace (name, description, icon, color, owner_id, company_id, is_personal, settings)
    DB-->>API: Return created workspace
    API->>DB: INSERT INTO workspace_member (workspace_id, user_id, role='owner')
    loop Untuk setiap anggota yang diundang
        API->>DB: INSERT INTO workspace_member (workspace_id, user_id, role='member', invited_by)
        API->>N: Kirim notifikasi undangan workspace
        N-->>U: Email / in-app notification
    end
    API-->>UI: Return workspace + members
    UI-->>U: Redirect ke workspace baru
```

### Flow 2: Mengundang Anggota ke Workspace

```mermaid theme={null}
sequenceDiagram
    participant A as Admin Workspace
    participant UI as Halaman Workspace
    participant API as Backend API
    participant DB as Database
    participant N as Notification Service
    participant B as User yang Diundang

    A->>UI: Klik "Tambah Anggota"
    UI->>A: Tampilkan form pencarian user
    A->>UI: Cari dan pilih user
    A->>UI: Set role (admin/member/viewer) + permissions
    A->>UI: Submit undangan
    UI->>API: POST /api/workspaces/:id/members
    API->>API: Cek permission: apakah user bisa invite members?
    API->>DB: SELECT workspace_member WHERE workspace_id AND user_id
    alt User sudah menjadi anggota
        API-->>UI: Error: User sudah menjadi anggota
        UI-->>A: Tampilkan pesan error
    else User belum menjadi anggota
        API->>DB: INSERT INTO workspace_member (workspace_id, user_id, role, invited_by, permissions)
        DB-->>API: Return created member
        API->>N: Kirim notifikasi undangan
        N->>B: Email + in-app notification
        B->>UI: Klik link undangan
        UI->>API: POST /api/workspaces/:id/join
        API->>DB: UPDATE workspace_member SET joined_at = NOW()
        DB-->>API: Updated member
        API-->>UI: Redirect ke workspace
    end
```

### Flow 3: Beralih Antar Workspace

```mermaid theme={null}
sequenceDiagram
    participant U as User
    participant UI as Workspace Dropdown
    participant API as Backend API
    participant DB as Database
    participant Cache as Local Cache

    U->>UI: Klik dropdown workspace di pojok kiri atas
    UI->>API: GET /api/workspaces?user_id=current
    API->>DB: SELECT w.*, wm.role FROM workspace w JOIN workspace_member wm ON w.id = wm.workspace_id WHERE wm.user_id = current
    DB-->>API: Return daftar workspace user
    API-->>UI: Return workspace list + role per workspace
    UI->>U: Tampilkan daftar workspace dengan role & indikator aktivitas
    U->>UI: Pilih workspace target
    UI->>Cache: Simpan selected_workspace_id di local state
    UI->>API: GET /api/workspaces/:id/dashboard
    API->>DB: Load tasks, members, aktivitas workspace
    DB-->>API: Return workspace data
    API-->>UI: Return dashboard data
    UI-->>U: Tampilkan konten workspace baru
```

## Enum Reference Tables

### Workspace Enums

#### `settings.default_task_priority`

| Nilai | Deskripsi |
| - | - |
| `low` | Prioritas rendah — task bisa dikerjakan nanti |
| `medium` | Prioritas sedang — default untuk task baru |
| `high` | Prioritas tinggi — perlu segera diselesaikan |
| `urgent` | Sangat mendesak — harus diselesaikan hari ini |

### WorkspaceMember Enums

#### `role`

| Nilai | Deskripsi | Permission Level |
| - | - | - |
| `owner` | Pemilik workspace — kontrol penuh, bisa ada multiple owners | Full access |
| `admin` | Administrator workspace — kelola anggota dan konten | High access |
| `member` | Anggota standar — bisa membuat dan mengedit task | Standard access |
| `viewer` | Hanya bisa melihat konten, tidak bisa mengubah | Read-only |

### User Enums

#### `role`

| Nilai | Deskripsi |
| - | - |
| `admin` | Administrator global aplikasi — akses penuh ke semua fitur |
| `user` | User standar — akses sesuai subscription dan permission |

#### `subscription_plan`

| Nilai | Deskripsi |
| - | - |
| `free` | Plan gratis — fitur dasar |
| `pro` | Plan profesional — fitur lanjutan |
| `business` | Plan bisnis — untuk tim dan perusahaan kecil |
| `advanced` | Plan advanced — fitur enterprise menengah |
| `enterprise` | Plan enterprise — fitur lengkap tanpa batas |

#### `membership_duration_type`

| Nilai | Deskripsi |
| - | - |
| `monthly` | Membership bulanan |
| `yearly` | Membership tahunan (lebih hemat) |
| `custom` | Durasi kustom yang ditentukan |
| `lifetime` | Akses seumur hidup |

#### `admin_type`

| Nilai | Deskripsi |
| - | - |
| `owner` | Full access ke seluruh aplikasi — berbeda dengan company owner |
| `basic` | Hanya akses transaksi produk digital |

#### `admin_tier`

| Nilai | Deskripsi |
| - | - |
| `none` | Bukan admin untuk company management |
| `business` | Admin tier business |
| `advanced` | Admin tier advanced |
| `enterprise` | Admin tier enterprise |

### Company Enums

#### `industry`

| Nilai | Deskripsi |
| - | - |
| `retail` | Ritel dan perdagangan |
| `manufacturing` | Manufaktur dan produksi |
| `services` | Jasa dan layanan |
| `technology` | Teknologi dan perangkat lunak |
| `food_beverage` | Makanan dan minuman (F\&B) |
| `healthcare` | Kesehatan dan farmasi |
| `education` | Pendidikan dan pelatihan |
| `other` | Industri lainnya |

#### `owner_subscription_plan`

| Nilai | Deskripsi |
| - | - |
| `free` | Plan gratis |
| `pro` | Plan profesional |
| `business` | Plan bisnis |
| `advanced` | Plan advanced |
| `enterprise` | Plan enterprise |

#### `settings.batch_allocation_strategy`

| Nilai | Deskripsi |
| - | - |
| `fifo` | First-In-First-Out — alokasi batch berdasarkan tanggal terima |
| `fefo` | First-Expiry-First-Out — alokasi batch berdasarkan tanggal kedaluwarsa |

#### `settings.spoilage_default_treatment`

| Nilai | Deskripsi |
| - | - |
| `absorbed_normal` | Spoilage masuk HPP unit baik (biaya diserap) |
| `expense_abnormal` | Spoilage dipisah sebagai beban periode |

#### `settings.tax.mode`

| Nilai | Deskripsi |
| - | - |
| `inclusive` | Pajak sudah termasuk dalam harga |
| `exclusive` | Pajak ditambah ke harga |

#### `settings.tax.rounding`

| Nilai | Deskripsi |
| - | - |
| `per_line` | Pembulatan per baris transaksi |
| `per_transaction` | Pembulatan per total transaksi |

### CompanyMember Enums

#### `role`

| Nilai | Deskripsi | Scope |
| - | - | - |
| `owner` | Pemilik perusahaan | Full access |
| `admin` | Administrator perusahaan | High access |
| `supervisor` | Supervisor / pengawas | Department access |
| `store_admin` | Admin toko/outlet | Store operations |
| `stock_admin` | Admin gudang/stok | Inventory operations |
| `finance_admin` | Admin keuangan | Finance operations |
| `hr_admin` | Admin HR | HR operations |
| `transaction_admin` | Admin transaksi | Transaction processing |
| `employee` | Karyawan standar | Basic access |
| `production_operator` | Operator produksi | Production operations |
| `qc_inspector` | Inspector quality control | QC operations |
| `sales_marketing` | Sales & marketing | Sales operations |
| `partner_distributor` | Partner / distributor | External partner access |

#### `status`

| Nilai | Deskripsi |
| - | - |
| `active` | Anggota aktif — akses penuh sesuai role |
| `inactive` | Anggota nonaktif — akses dibekukan sementara |
| `pending` | Undangan tertunda — belum menerima/menerima undangan |

## RBAC Permission Matrix

### Workspace-Level Permissions

Berdasarkan role `WorkspaceMember.role`:

| Aksi | Owner | Admin | Member | Viewer |
| - | :-: | :-: | :-: | :-: |
| Lihat konten workspace | ✅ | ✅ | ✅ | ✅ |
| Buat task baru | ✅ | ✅ | ✅\* | ❌ |
| Edit task | ✅ | ✅ | ✅\* | ❌ |
| Hapus task | ✅ | ✅ | ❌\* | ❌ |
| Undang anggota baru | ✅ | ✅ | ❌\* | ❌ |
| Akses semua task (tanpa assignment) | ✅ | ✅ | ❌\* | ❌ |
| Ubah role anggota | ✅ | ✅ | ❌ | ❌ |
| Hapus anggota | ✅ | ✅ | ❌ | ❌ |
| Edit pengaturan workspace | ✅ | ✅ | ❌ | ❌ |
| Arsipkan workspace | ✅ | ❌ | ❌ | ❌ |
| Hapus workspace | ✅ | ❌ | ❌ | ❌ |

> \*) Dapat dikonfigurasi per-member melalui field `permissions` di `WorkspaceMember`.

### Company-Level Permissions (Ringkasan)

Berdasarkan role `CompanyMember.role` dan field `permissions`:

| Modul | Owner | Admin | Supervisor | Store Admin | Stock Admin | Finance Admin | HR Admin | Employee |
| - | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: |
| Dashboard | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅\* |
| Task Management | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅\* |
| Notes | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅\* |
| HR Module | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
| Finance Module | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ |
| Inventory | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| Projects | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| POS | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| Reports | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ |
| Settings | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Member Management | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Production | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Quality Control | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Distribution | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| B2B Invoices | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ |

> \*) Tergantung konfigurasi `permissions` individual oleh admin/owner.

### WorkspaceMember Granular Permissions

Field `permissions` di `WorkspaceMember` memungkinkan konfigurasi hak akses per-individu:

| Permission | Default (Member) | Default (Admin) | Default (Viewer) | Deskripsi |
| - | :-: | :-: | :-: | - |
| `can_create_tasks` | `true` | `true` | `false` | Membuat task baru di workspace |
| `can_edit_tasks` | `true` | `true` | `false` | Mengedit task yang sudah ada |
| `can_delete_tasks` | `false` | `true` | `false` | Menghapus task dari workspace |
| `can_invite_members` | `false` | `true` | `false` | Mengundang anggota baru |
| `can_access_all_tasks` | `false` | `true` | `false` | Melihat semua task tanpa filter assignment |

## Best Practices

### Struktur Workspace yang Direkomendasikan

1. **Mulai dari departemen** — Buat workspace untuk setiap departemen utama (Sales, Inventory, Finance, Produksi, HR)
2. **Tambahkan sub-workspace** — Untuk tim besar, buat workspace child di bawah departemen (misal: Tim B2B di bawah Sales)
3. **Gunakan workspace project** — Untuk inisiatif temporer dengan deadline, buat workspace project yang bisa diarsipkan setelah selesai
4. **Workspace cabang terpisah** — Setiap lokasi fisik sebaiknya memiliki workspace sendiri untuk pelacakan operasional

### Manajemen Anggota

1. **Prinsip least privilege** — Berikan role `viewer` atau `member` dengan permission minimal, escalate hanya jika diperlukan
2. **Review berkala** — Cek daftar anggota workspace secara berkala, hapus yang sudah tidak relevan
3. **Gunakan granular permissions** — Untuk anggota tertentu yang butuh akses lebih, set permission individual tanpa harus mengubah role
4. **Dokumentasikan via description** — Gunakan field `description` di `WorkspaceMember` untuk mencatat peran spesifik anggota di workspace

### Pengaturan Workspace

1. **Set `default_task_priority` sesuai konteks** — Workspace operasional mungkin cocok dengan `high`, workspace planning cocok dengan `medium`
2. **Kontrol `allow_public_sharing`** — Matikan untuk workspace yang menangani data sensitif
3. **Gunakan `color` dan `icon`** — Memudahkan identifikasi visual saat berpindah-pindah workspace

***

**Related Documentation**:

* [Workspace (Personal)](/docs/core/workspace)
* [Home](/docs/core/home)
* [Dashboard](/docs/core/dashboard)
* [Settings](/docs/core/settings)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.