fluid-pwa
Version:
๐ The Ultimate Offline-First Progressive Web App Framework - Rapid PWA development with multiple batteries for seamless offline experiences
329 lines (243 loc) โข 10.6 kB
Markdown
# ๐ Fluid PWA Framework
> **The Ultimate Offline-First Progressive Web App Framework**
> Rapid PWA development with multiple batteries for seamless offline experiences
[](https://badge.fury.io/js/fluid-pwa)
[](https://opensource.org/licenses/Apache-2.0)
[](https://www.typescriptlang.org/)
[](https://nextjs.org/)
[](http://makeapullrequest.com)
---
## โจ What is Fluid PWA?
Fluid PWA is a **production-ready framework** that makes building offline-first Progressive Web Apps effortless. It provides a robust, configurable, and developer-friendly solution for rapid PWA development with multiple batteries for offline data management and automatic synchronization status tracking.
### ๐ฏ **Built for Developers, by a Developer**
- **๐ง Zero Configuration** - Works out of the box with sensible defaults
- **๐ฃ React Hooks** - Clean, composable API that feels natural
- **๐ฑ Offline-First** - Designed to work seamlessly without internet
- **๐ Sync Management** - Automatic tracking of pending changes
- **๐ช TypeScript** - Full type safety with intelligent inference
- **โก Performance** - Optimized for speed and efficiency
> **Open Source**: This project is created and maintained by [@harshalmore31](https://github.com/harshalmore31) as an open-source initiative to provide the ultimate offline-first PWA framework.
---
## ๐ Quick Start
### Installation
```bash
npm install fluid-pwa dexie dexie-react-hooks uuid
# or
yarn add fluid-pwa dexie dexie-react-hooks uuid
# or
pnpm add fluid-pwa dexie dexie-react-hooks uuid
```
### Basic Setup
```typescript
import { FluidPWAProvider, FluidPWAConfig } from 'fluid-pwa'
// 1. Define your data schema
const schema = {
notes: '++localId, title, content, syncStatus, lastModifiedOffline, userId',
tasks: '++localId, title, completed, priority, syncStatus, lastModifiedOffline, userId'
}
// 2. Configure Fluid PWA
const config: FluidPWAConfig = {
databaseName: 'MyApp',
schema,
version: 1,
enableLogging: true
}
// 3. Wrap your app
export default function App() {
return (
<FluidPWAProvider config={config}>
<MyApp />
</FluidPWAProvider>
)
}
```
### Use in Components
```typescript
import { useAddItem, useGetAllItems, useUpdateItem, useDeleteItem } from 'fluid-pwa'
function NotesApp() {
const addNote = useAddItem<Note>('notes')
const notes = useGetAllItems<Note>('notes')
const updateNote = useUpdateItem<Note>('notes')
const deleteNote = useDeleteItem('notes')
const handleAdd = async () => {
const result = await addNote({
title: 'My Note',
content: 'This works offline!'
})
if (result.success) {
console.log('โ
Note saved with ID:', result.data)
}
}
return (
<div>
<button onClick={handleAdd}>Add Note</button>
{notes?.map(note => (
<div key={note.localId}>
<h3>{note.title}</h3>
<span>{note.syncStatus}</span> {/* PENDING_CREATE, SYNCED, etc. */}
</div>
))}
</div>
)
}
```
---
## ๐ Key Features
### **๐ Automatic Sync Status Management**
Every data change is automatically tracked with sync statuses like `PENDING_CREATE`, `PENDING_UPDATE`, `SYNCED`, making it easy to implement data synchronization.
### **๐ฃ Powerful React Hooks**
- `useAddItem` - Create new items with validation hooks
- `useGetAllItems` - Reactive queries with filtering and sorting
- `useUpdateItem` - Update with automatic sync status handling
- `useDeleteItem` - Smart deletion (hard/soft delete based on sync status)
- `useGetPendingItems` - Get items that need to be synced
- `useFluidPWAStats` - Database statistics for monitoring
### **โก Live Reactive Updates**
Built on Dexie's live queries - your UI automatically updates when data changes, even across browser tabs!
### **๐ก๏ธ Type Safety**
Full TypeScript support with intelligent type inference:
```typescript
interface Note {
title: string
content: string
}
const notes = useGetAllItems<Note>('notes') // Fully typed!
```
### **๐ง Configurable & Extensible**
```typescript
const addNote = useAddItem<Note>('notes', {
onBeforeAdd: async (note) => {
// Validation, transformation, etc.
return { ...note, slug: generateSlug(note.title) }
},
onAfterAdd: async (note, id) => {
// Analytics, notifications, etc.
analytics.track('Note Created', { id })
}
})
```
---
## ๐ฑ Live Demo
Experience Fluid PWA in action:
๐ **[View the Demo](https://github.com/harshalmore31/fluid-pwa/tree/main/src/app/demo)**
The demo showcases:
- โ
Creating and managing notes offline
- โ
Real-time sync status indicators
- โ
Database statistics dashboard
- โ
Works completely offline
- โ
Multi-tab synchronization
---
## ๐ Documentation
### Core Concepts
- [Getting Started Guide](./src/lib/dexie/README.md)
- [Schema Design](./docs/schema-design.md)
- [Sync Status Management](./docs/sync-status.md)
- [React Hooks API](./docs/hooks-api.md)
- [Best Practices](./docs/best-practices.md)
### Advanced Topics
- [Custom Validation](./docs/validation.md)
- [Performance Optimization](./docs/performance.md)
- [Testing Strategies](./docs/testing.md)
- [Migration Guide](./docs/migration.md)
---
## ๐๏ธ Architecture
Fluid PWA is built on a solid foundation:
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ React Components โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Fluid PWA Hooks โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Dexie.js Database โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ IndexedDB API โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
**Phase 1 (Current)**: Foundation & Core CRUD Operations
**Phase 2 (Coming)**: Background Sync & Conflict Resolution
**Phase 3 (Future)**: Real-time Collaboration & Advanced Sync
---
## ๐ค Contributing
We welcome contributions! Fluid PWA is built by the community, for the community.
### ๐ **Quick Contribution Setup**
```bash
# 1. Fork & Clone
git clone https://github.com/YOUR_USERNAME/fluid-pwa.git
cd fluid-pwa
# 2. Install dependencies
npm install
# 3. Start development
npm run dev
# 4. Make your changes and test
npm run test
# 5. Submit a PR!
```
### ๐ **Contribution Areas**
- ๐ **Bug Fixes** - Help us squash bugs
- โจ **New Features** - Add hooks, utilities, or integrations
- ๐ **Documentation** - Improve guides and examples
- ๐งช **Testing** - Add test cases and improve coverage
- ๐จ **Examples** - Create real-world usage examples
- ๐ **Performance** - Optimize queries and operations
### ๐ **Development Guidelines**
1. **Code Style**: We use ESLint and Prettier
2. **Testing**: Add tests for new features
3. **Documentation**: Update docs for API changes
4. **TypeScript**: Maintain strict type safety
5. **Commits**: Use conventional commit messages
---
## ๐ฃ๏ธ Roadmap
### โ
**Phase 1: Foundation (Current)**
- [x] Core Dexie.js integration
- [x] React hooks for CRUD operations
- [x] Automatic sync status tracking
- [x] TypeScript support
- [x] Provider pattern
- [x] Comprehensive documentation
### ๐ง **Phase 2: Enhanced Sync (Next)**
- [ ] Background sync with Service Workers
- [ ] Conflict resolution strategies
- [ ] Retry mechanisms with exponential backoff
- [ ] Batch operations optimization
- [ ] Advanced error handling
### ๐ฎ **Phase 3: Advanced Features (Future)**
- [ ] Real-time collaboration
- [ ] Multi-device synchronization
- [ ] Encryption support
- [ ] Plugin architecture
- [ ] Cloud storage integrations
---
## ๐ Why Choose Fluid PWA?
| Feature | Fluid PWA | Manual Setup | Other Solutions |
|---------|-----------|--------------|-----------------|
| **Setup Time** | 5 minutes | Days/Weeks | Hours |
| **TypeScript** | โ
Built-in | ๐ง Manual | โ Limited |
| **Sync Status** | โ
Automatic | ๐ง Manual | โ None |
| **React Hooks** | โ
Optimized | ๐ง Build Your Own | โ Limited |
| **Offline-First** | โ
By Design | ๐ง Complex Setup | โ Afterthought |
| **Testing** | โ
Test Utils | ๐ง DIY | โ Difficult |
---
## ๐ Community
Join our growing community of developers building amazing offline-first apps!
- ๐ฌ **[GitHub Discussions](https://github.com/harshalmore31/fluid-pwa/discussions)** - Get help and share ideas
- ๐ **[GitHub Issues](https://github.com/harshalmore31/fluid-pwa/issues)** - Report bugs and request features
---
## ๐ License
Apache 2.0 License - see the [LICENSE](LICENSE) file for details.
---
## ๐ Sponsors
Fluid PWA is open source and free. If you find it useful, consider sponsoring the project:
[](https://github.com/sponsors/fluid-pwa)
---
## ๐ Acknowledgments
- **[Dexie.js](https://dexie.org/)** - Excellent IndexedDB wrapper used for offline data management
- **[Next.js](https://nextjs.org/)** - The React framework that makes PWAs awesome
- **Open Source Community** - For the amazing tools and libraries that make this possible
---
<div align="center">
**[๐ Repository](https://github.com/harshalmore31/fluid-pwa)** โข
**[๐ Documentation](https://github.com/harshalmore31/fluid-pwa/blob/main/README.md)** โข
**[๐ Demo](https://github.com/harshalmore31/fluid-pwa/tree/main/src/app/demo)** โข
**[๐ฌ Discussions](https://github.com/harshalmore31/fluid-pwa/discussions)**
**Built with โค๏ธ by [Harshal More](https://github.com/harshalmore31)**
</div>