Skip to main content

Type-Safe Firestore ORM for Node.js

Build production-ready Firestore applications with validation, soft deletes, lifecycle hooks, and a powerful query builder. Designed for Firebase Admin SDK with full TypeScript support.

Quick start

Get up and running with FirestoreORM in minutes

1

Install the package

Install FirestoreORM along with its peer dependencies using your preferred package manager.
npm install @spacelabstech/firestoreorm firebase-admin zod
2

Define your schema

Create a Zod schema for type-safe validation and TypeScript inference.
import { z } from 'zod';

export const userSchema = z.object({
  id: z.string().optional(),
  name: z.string().min(1, 'Name is required'),
  email: z.string().email('Invalid email address'),
  status: z.enum(['active', 'inactive']).default('active'),
  createdAt: z.string().datetime(),
  updatedAt: z.string().datetime()
});

export type User = z.infer<typeof userSchema>;
3

Create a repository

Initialize Firebase Admin and create a repository instance.
import { initializeApp, cert } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
import { FirestoreRepository } from '@spacelabstech/firestoreorm';

const app = initializeApp({
  credential: cert('./serviceAccountKey.json')
});

const db = getFirestore(app);

export const userRepo = FirestoreRepository.withSchema<User>(
  db,
  'users',
  userSchema
);
4

Start building

Use the repository to perform CRUD operations with full type safety.
// Create a user
const user = await userRepo.create({
  name: 'John Doe',
  email: '[email protected]',
  status: 'active',
  createdAt: new Date().toISOString(),
  updatedAt: new Date().toISOString()
});

// Query users
const activeUsers = await userRepo.query()
  .where('status', '==', 'active')
  .orderBy('createdAt', 'desc')
  .limit(10)
  .get();
Learn more in the quickstart guide or explore the API reference.

Core features

Everything you need to build production-ready Firestore applications

Type-safe

Full TypeScript support with Zod validation ensures your data is always correct

Soft deletes

Never lose data accidentally with built-in soft delete functionality

Lifecycle hooks

Add custom logic at any point in the data lifecycle without cluttering your code

Query builder

Intuitive, chainable queries with pagination, aggregation, and streaming

Transactions

ACID guarantees for critical operations with full transaction support

Bulk operations

Efficient batch writes with automatic chunking for large datasets

Explore documentation

Deep dive into concepts, guides, and API reference

Core concepts

Learn the fundamentals of the repository pattern, validation, and hooks

Guides

Step-by-step guides for common operations and advanced patterns

Framework integration

Integrate with Express, NestJS, and other Node.js frameworks

API reference

Complete API documentation with all methods and parameters

Ready to get started?

Install FirestoreORM and start building type-safe Firestore applications today

Install Now

Build docs developers (and LLMs) love