Skip to the content.

Complete Examples

This directory contains complete application examples demonstrating how to use Firebase ORM in real-world scenarios.

Available Examples

1. Blog Application

A complete blog system with users, posts, comments, and tags.

Features:

Models:

File: blog-example.ts

2. E-commerce Store

An online store with products, orders, and inventory management.

Features:

Models:

File: ecommerce-example.ts

3. Task Management System

A project management tool with teams, projects, and tasks.

Features:

Models:

File: task-management-example.ts

4. Social Media Platform

A social networking application with posts, friendships, and messaging.

Features:

Models:

File: social-media-example.ts

5. Learning Management System

An educational platform with courses, lessons, and student progress tracking.

Features:

Models:

File: lms-example.ts

Quick Start

1. Choose an Example

Select the example that best matches your use case or interests.

2. Setup Firebase

# Install dependencies
npm install @arbel/firebase-orm firebase moment

# Set up Firebase project
firebase init

3. Configure Firebase

// firebase-config.ts
export const firebaseConfig = {
  apiKey: "your-api-key",
  authDomain: "your-project.firebaseapp.com",
  projectId: "your-project-id",
  storageBucket: "your-project.appspot.com",
  messagingSenderId: "your-sender-id",
  appId: "your-app-id"
};

4. Initialize Firebase ORM

// app.ts
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
import { FirestoreOrmRepository } from '@arbel/firebase-orm';
import { firebaseConfig } from './firebase-config';

const app = initializeApp(firebaseConfig);
const firestore = getFirestore(app);
FirestoreOrmRepository.initGlobalConnection(firestore);

5. Run the Example

// Import and run your chosen example
import { BlogExample } from './examples/blog-example';

const example = new BlogExample();
await example.run();

Framework Integration Examples

React Integration

See how to integrate Firebase ORM with React applications:

Files:

Next.js Integration

Server-side rendering and static generation examples:

Files:

Node.js Backend

Backend API examples:

Files:

Vue.js Integration

Vue.js application examples:

Files:

Testing Examples

Unit Testing

Examples of unit testing Firebase ORM models and services:

// tests/user.test.ts
import { User } from '../models/User';
import { TestDataFactory } from '../utils/TestDataFactory';

describe('User Model', () => {
  test('should create user with valid data', async () => {
    const userData = {
      name: 'John Doe',
      email: 'john@example.com'
    };
    
    const user = TestDataFactory.createUser(userData);
    await user.save();
    
    expect(user.getId()).toBeDefined();
    expect(user.name).toBe('John Doe');
  });
});

Integration Testing

Examples of testing Firebase ORM with actual Firebase services:

// tests/integration/blog.test.ts
import { BlogService } from '../services/BlogService';
import { setupTestEnvironment, cleanupTestEnvironment } from '../utils/test-setup';

describe('Blog Service Integration', () => {
  beforeEach(async () => {
    await setupTestEnvironment();
  });

  afterEach(async () => {
    await cleanupTestEnvironment();
  });

  test('should create and retrieve blog post', async () => {
    const blogService = new BlogService();
    const post = await blogService.createPost({
      title: 'Test Post',
      content: 'Test content'
    });

    const retrievedPost = await blogService.getPost(post.getId());
    expect(retrievedPost.title).toBe('Test Post');
  });
});

Performance Examples

Optimization Techniques

Examples demonstrating performance optimization:

Files:

Monitoring

Examples of performance monitoring and analytics:

// monitoring/performance-monitor.ts
import { PerformanceMonitor } from '../utils/PerformanceMonitor';

// Monitor query performance
const monitor = new PerformanceMonitor();
monitor.startMonitoring();

// Track specific operations
const users = await monitor.trackOperation(
  'User.getAll',
  () => User.getAll()
);

Security Examples

Authentication Patterns

Examples of user authentication and authorization:

Files:

Data Validation

Examples of input validation and sanitization:

// security/validation-examples.ts
import { ValidationService } from '../services/ValidationService';

const userInput = {
  name: '<script>alert("xss")</script>John',
  email: 'user@example.com'
};

// Sanitize input
const sanitizedData = ValidationService.sanitizeUserInput(userInput);

Advanced Examples

Real-time Features

Examples of implementing real-time functionality:

Files:

File Upload and Storage

Examples of file handling:

Files:

Search and Analytics

Examples of search implementation:

Files:

Deployment Examples

Production Deployment

Examples of deploying Firebase ORM applications:

Files:

Scaling Examples

Examples of scaling Firebase ORM applications:

Files:

Contributing Examples

If you have a useful example that demonstrates Firebase ORM capabilities, please contribute!

Guidelines for Contributing Examples

  1. Complete and Working: Examples should be complete, working applications
  2. Well Documented: Include clear documentation and comments
  3. Best Practices: Follow Firebase ORM best practices
  4. Real-world Scenarios: Focus on practical, real-world use cases
  5. Testing: Include tests where appropriate

Example Structure

examples/
├── your-example/
│   ├── README.md           # Example-specific documentation
│   ├── models/             # Model definitions
│   ├── services/           # Business logic
│   ├── tests/              # Test files
│   ├── package.json        # Dependencies
│   └── src/
│       ├── index.ts        # Main application file
│       └── config/         # Configuration files

Support

If you need help with any of these examples:

  1. Check the individual example documentation
  2. Review the main Firebase ORM documentation
  3. Open an issue on GitHub with specific questions
  4. Join the community discussions

License

All examples are provided under the same license as Firebase ORM. Feel free to use them as starting points for your own applications.


These examples are designed to help you understand Firebase ORM capabilities and get started quickly with your own projects. Each example includes detailed comments and documentation to guide you through the implementation.