Database architecture and implementation using Drizzle ORM
Database Layer
ShipKit uses PostgreSQL with Drizzle ORM for type-safe database operations. The database layer is designed for scalability, type safety, and maintainability.
Overview
The database system provides:
Type-safe schema definitions
Automated migrations
Connection pooling
Development tools
Activity logging
Multi-tenant support
Core Files
The database system is organized into several key files:
src/server/db/index.ts - Database connection and configuration
src/server/db/schema.ts - Schema definitions
src/migrations/* - Database migrations
Database Connection
Connection Pooling
The connection is cached in development to avoid creating new connections on HMR updates:
Schema Design
Core Tables
Relations
Enums
Type Safety
Table Types
Query Types
All queries are fully typed, providing compile-time safety:
Migrations
Migration Scripts
Migration Commands
Activity Logging
The system includes comprehensive activity logging:
Multi-tenancy
The system supports multi-tenancy through teams and projects:
Development Tools
Drizzle Studio
Access the database GUI with:
Features:
Schema visualization
Data browsing
Query builder
Relationship explorer
Performance Considerations
Indexing
Automatic index creation on foreign keys
Custom indexes for frequently queried fields
Compound indexes for complex queries
Connection Pooling
Development connection caching
Production connection pooling
Automatic cleanup
Query Optimization
Type-safe query building
Relation preloading
Pagination support
Security Implementation
Data Protection
SQL injection prevention through parameterized queries
Type-safe schema validation
Automatic input sanitization
Access Control
Row-level security through team/project membership