Documentation Index Fetch the complete documentation index at: https://docs.cadcamfun.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Database Schema Documentation
Overview
The CAD/CAM FUN application uses PostgreSQL with Prisma ORM. Below is the detailed schema documentation.
Core Models
model User {
id String @id @default ( cuid ())
email String @unique
name String ?
password String // Hashed
role UserRole @default ( USER )
organization Organization ? @relation ( fields : [ orgId ], references : [ id ] )
orgId String ?
projects Project []
createdAt DateTime @default ( now ())
updatedAt DateTime @updatedAt
@@index ( [ email ] )
}
enum UserRole {
ADMIN
USER
VIEWER
}
model Project {
id String @id @default ( cuid ())
name String
description String ?
owner User @relation ( fields : [ ownerId ], references : [ id ] )
ownerId String
models Model []
shared ProjectShare []
createdAt DateTime @default ( now ())
updatedAt DateTime @updatedAt
@@index ( [ ownerId ] )
}
model Model {
id String @id @default ( cuid ())
name String
type ModelType
data Json // CAD/CAM data
project Project @relation ( fields : [ projectId ], references : [ id ] )
projectId String
versions ModelVersion []
toolpaths Toolpath []
createdAt DateTime @default ( now ())
updatedAt DateTime @updatedAt
@@index ( [ projectId ] )
}
enum ModelType {
CAD_2D
CAD_3D
CAM
}
Manufacturing Models
model Machine {
id String @id @default ( cuid ())
name String
type String
config Json // Machine configuration
organization Organization @relation ( fields : [ orgId ], references : [ id ] )
orgId String
toolpaths Toolpath []
createdAt DateTime @default ( now ())
updatedAt DateTime @updatedAt
@@index ( [ orgId ] )
}
model Material {
id String @id @default ( cuid ())
name String
type String
properties Json // Material properties
organization Organization @relation ( fields : [ orgId ], references : [ id ] )
orgId String
models Model []
createdAt DateTime @default ( now ())
updatedAt DateTime @updatedAt
@@index ( [ orgId ] )
}
Versioning Models
model ModelVersion {
id String @id @default ( cuid ())
version Int
data Json // Version data
model Model @relation ( fields : [ modelId ], references : [ id ] )
modelId String
createdBy User @relation ( fields : [ userId ], references : [ id ] )
userId String
createdAt DateTime @default ( now ())
@@index ( [ modelId ] )
@@index ( [ userId ] )
}
Organization Models
model Organization {
id String @id @default ( cuid ())
name String
plan PlanType @default ( FREE )
users User []
machines Machine []
tools Tool []
materials Material []
createdAt DateTime @default ( now ())
updatedAt DateTime @updatedAt
}
enum PlanType {
FREE
BASIC
PRO
ENTERPRISE
}
model ProjectShare {
id String @id @default ( cuid ())
project Project @relation ( fields : [ projectId ], references : [ id ] )
projectId String
user User @relation ( fields : [ userId ], references : [ id ] )
userId String
permission Permission
createdAt DateTime @default ( now ())
@@unique ( [ projectId , userId ] )
@@index ( [ userId ] )
}
enum Permission {
VIEW
EDIT
MANAGE
}
Database Operations
Migrations
Creating Migrations
Seeding Data
# Generate migration from schema changes
npx prisma migrate dev --name migration_name
# Apply migrations to database
npx prisma migrate deploy
Key Indexes
User email (unique)
Project ownership
Model project association
Organization associations
Share permissions
Query Optimization
Use included relations
Implement pagination
Cache frequent queries
Backup and Recovery
Backup Strategy
Daily full backups
Hourly incremental backups
Transaction log backups
Recovery Procedures
Point-in-time recovery
Full database restoration
Table-level recovery
Security Considerations
Data Protection
Encrypted sensitive fields
Row-level security
Access control policies
Audit Trail
Creation timestamps
Update timestamps
User tracking
Best Practices
Use appropriate data types
Implement proper constraints
Maintain referential integrity
Use transactions
Implement validation
Maintain data consistency
Remember to always follow security best practices and maintain proper documentation of any schema changes.