@akis05/akis
v0.1.13
Published
CLI pour gérer les collections Appwrite depuis les types TypeScript
Maintainers
Readme
AKIS - Appwrite CLI Tool
AKIS is a CLI tool that automatically syncs your Appwrite collections with your TypeScript types. Define your types once, and AKIS creates/updates your collections and generates the corresponding schema.
Features
- Auto-generation: Creates Appwrite collections from your TypeScript types
- Synchronization: Detects differences between your types and Appwrite
- Auto-generated schema: The
schema.tsfile is automatically generated during migration - Automatic indexes: Creates indexes for common fields (storeId, email, etc.)
- Users permissions: Collections are created with CRUD permissions for authenticated users
- Dry-run mode: Preview changes before applying them
Installation
With npm
npm install @akis05/akisWith pnpm
pnpm add @akis05/akisGlobal installation (optional)
npm install -g @akis05/akisConfiguration
1. Environment Variables
Create a .env file at the root of your project:
# Appwrite Endpoint (Cloud or Self-hosted)
APPWRITE_ENDPOINT=https://cloud.appwrite.io/v1
# Your Appwrite project ID
APPWRITE_PROJECT_ID=your_project_id
# Your database ID
APPWRITE_DATABASE_ID=your_database_id
# API Key with Database permissions (Create, Read, Update, Delete)
APPWRITE_API_KEY=your_api_key2. Getting Appwrite Credentials
- Log in to Appwrite Console
- Project ID: Settings → Project ID
- Database ID: Databases → Click on your DB → Settings
- API Key: Settings → API Keys → Create API Key (check Database permissions)
Quick Start
Step 1: Initialize the project
npx akis initThis command creates the following structure:
core/
└── appwrite-model/
├── types.ts # Your TypeScript definitions
├── schema.ts # Generated schema (do not edit manually)
├── client.ts # Configured Appwrite client
└── setup-collections.ts # Utility functionsStep 2: Define your types
Edit core/appwrite-model/types.ts:
export type Client = {
_id: string; // Appwrite ID (required)
_creationTime: number; // Creation timestamp (required)
name: string; // Required field
email?: string; // Optional field (?)
phone?: string;
status: "active" | "inactive"; // Enum
tags?: string[]; // String array
storeId: string;
createdAt: number;
deletedAt?: number;
};
export type Product = {
_id: string;
_creationTime: number;
name: string;
price: number;
quantity: number;
category: "electronics" | "clothing" | "food";
storeId: string;
createdAt: number;
};Step 3: Migrate to Appwrite
# Preview changes (recommended)
npx akis migrate --dry-run
# Create collections
npx akis migrateResult:
- Collections created in Appwrite
schema.tsfile automatically generated
Step 4: Check status
npx akis statusHow it Works
Collection IDs
When AKIS creates collections in Appwrite, it uses the collection name as the collection ID:
Clienttype → collection ID:clientsStoretype → collection ID:storesMouvementStocktype → collection ID:mouvements_stock
This makes it easy to reference collections by their predictable IDs.
Automatic Permissions
When AKIS creates a new collection, it automatically sets the following permissions:
| Permission | Role | Description | |------------|------|-------------| | Create | Users | Authenticated users can create documents | | Read | Users | Authenticated users can read documents | | Update | Users | Authenticated users can update documents | | Delete | Users | Authenticated users can delete documents |
All collections are created with documentSecurity: false (collection-level permissions).
Automatic Indexes
AKIS creates the following indexes automatically:
storeIdindex on all collections (if field exists)- Indexes for common fields:
email,clientId,produitId,dossierId,employeId,statut,type, etc.
Commands
akis init
Initializes the project structure.
npx akis init # Create files
npx akis init --force # Overwrite existing filesOptions:
| Option | Description |
|--------|-------------|
| -f, --force | Overwrites existing files |
akis migrate
Creates missing collections in Appwrite and generates schema.ts.
npx akis migrate # Migrate all collections
npx akis migrate --name clients # Migrate a specific collection
npx akis migrate --dry-run # Preview without executingOptions:
| Option | Description |
|--------|-------------|
| -n, --name <name> | Name of the collection to migrate |
| -d, --dry-run | Shows actions without executing them |
Example output:
🚀 AKIS Migrate - Creating missing collections
📖 Reading types.ts...
2 collection(s) to process
📡 Connecting to Appwrite...
📦 Creating clients...
✓ name
✓ email
✓ phone
✓ status
✓ storeId
🔑 idx_storeId
🔑 idx_email
✅ clients created
📝 schema.ts generated with 2 collections
✨ Migration complete: 1 created, 1 skippedakis update
Adds new attributes to existing collections.
npx akis update # Update all collections
npx akis update --name clients # Update a specific collection
npx akis update --dry-run # Preview without executingOptions:
| Option | Description |
|--------|-------------|
| -n, --name <name> | Name of the collection to update |
| -d, --dry-run | Shows actions without executing them |
Use cases:
- You added a new field in
types.ts - You want to sync without recreating the collection
akis status
Compares local types with Appwrite collections.
npx akis status # View all collections
npx akis status --name clients # View a specific collectionOptions:
| Option | Description |
|--------|-------------|
| -n, --name <name> | Name of the collection to check |
Example output:
📊 AKIS Status - Collection Status
┌─────────────────────────────┬────────┬────────────┬─────────────┐
│ Collection │ Status │ Attributes │ Missing │
├─────────────────────────────┼────────┼────────────┼─────────────┤
│ clients │ ✅ │ 9/9 │ 0 │
│ products │ ⚠️ │ 5/7 │ 2 │
│ orders │ ❌ │ - │ - │
└─────────────────────────────┴────────┴────────────┴─────────────┘
📈 Summary:
✅ 1 synchronized
⚠️ 1 needs update (akis update)
❌ 1 missing (akis migrate)akis delete
Deletes collections in Appwrite.
npx akis delete --name clients # Delete a collection (with confirmation)
npx akis delete --force # Delete ALL collections without confirmation
npx akis delete --name clients -f # Delete without confirmationOptions:
| Option | Description |
|--------|-------------|
| -n, --name <name> | Name of the collection to delete |
| -f, --force | Delete without asking for confirmation |
⚠️ Warning: This action is irreversible!
akis resetdb
Deletes all documents from collections without deleting the collections themselves.
npx akis resetdb # Purge all collections
npx akis resetdb --name clients # Purge a specific collection
npx akis resetdb --force # Purge without confirmation
npx akis resetdb --name clients -f # Purge specific collection without confirmationOptions:
| Option | Description |
|--------|-------------|
| -n, --name <name> | Name of the collection to purge |
| -f, --force | Purge without asking for confirmation |
Example output:
🧹 AKIS ResetDB - Purging all collections data
📡 Connecting to Appwrite...
5 collection(s) found
🧹 Purging data...
🗑️ clients... 12 document(s) deleted
🗑️ products... 34 document(s) deleted
🗑️ orders... 8 document(s) deleted
✨ Reset complete: 3 collection(s) purged, 54 document(s) deleted, 0 error(s)⚠️ Warning: This deletes all data but keeps the collection structure intact.
Supported TypeScript Types
AKIS automatically recognizes the following types:
| TypeScript | Appwrite Attribute |
|------------|-------------------|
| string | String (auto-detected size) |
| number | Float or Integer (based on field name) |
| boolean | Boolean |
| string[] | String Array |
| number[] | Integer Array |
| "a" \| "b" \| "c" | Enum |
Naming Conventions
AKIS automatically infers certain properties:
| Field Name | Inferred Type | Size |
|------------|---------------|------|
| *Id, storeId | string | 36 |
| email | string | 255 |
| phone, tel | string | 50 |
| note, description | string | 2000 |
| address | string | 500 |
| quantity*, *Minutes | integer | - |
| createdAt, deletedAt | integer | - |
System Fields (ignored)
These fields are automatically ignored as they are managed by Appwrite:
_id- Document ID_creationTime- Creation timestamp
Recommended Workflow
┌─────────────────────────────────────────────────────────────┐
│ 1. Define types in types.ts │
│ export type Client = { ... } │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 2. Preview changes │
│ npx akis migrate --dry-run │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 3. Migrate to Appwrite │
│ npx akis migrate │
│ → Collections created + schema.ts generated │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 4. Verify synchronization │
│ npx akis status │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ 5. Adding new fields? → Back to step 1 │
│ npx akis update │
└─────────────────────────────────────────────────────────────┘Using with pnpm
If you use pnpm, add a script to your package.json:
{
"scripts": {
"akis": "akis"
}
}Then use:
pnpm akis status
pnpm akis migrate
pnpm akis update
pnpm akis resetdbExamples
Complete types.ts Example
/* ═══════════════════════════════════════════════════════════
Types for my application
═══════════════════════════════════════════════════════════ */
export type Client = {
_id: string;
_creationTime: number;
name: string;
email?: string;
phone?: string;
address?: string;
status: "active" | "inactive" | "prospect";
discount?: number;
tags?: string[];
storeId: string;
createdAt: number;
deletedAt?: number;
};
export type Product = {
_id: string;
_creationTime: number;
name: string;
description?: string;
price: number;
costPrice?: number;
quantity: number;
minStock?: number;
category: "electronics" | "clothing" | "food" | "other";
image?: string;
storeId: string;
createdAt: number;
};
export type Sale = {
_id: string;
_creationTime: number;
number: string;
clientId?: string;
lines: string; // Stringified JSON
total: number;
status: "draft" | "validated" | "paid" | "cancelled";
storeId: string;
createdAt: number;
};
// Utilities
export type NewDoc<T> = Omit<T, "_id" | "_creationTime">;
export type UpdateDoc<T> = Partial<Omit<T, "_id" | "_creationTime">>;Troubleshooting
Error: APPWRITE_API_KEY not configured
Check that your .env file exists and contains the API key:
cat .env | grep APPWRITE_API_KEYError: Collection not found in types.ts
Make sure the type name corresponds to a name recognized by AKIS:
Client→clientsProduct→productsSale→sales
Attributes are not created
Appwrite has size limits for attributes. Check:
- String size (max 16000 characters)
- Number of attributes per collection (max ~100)
License
MIT
