forked from
slices.network/slices
Highly ambitious ATProtocol AppView service and sdks
1# Introduction
2
3Slices is an open source platform for building structured data applications on
4the AT Protocol network.
5
6## What is Slices?
7
8Slices lets you define custom data schemas and build applications that store,
9query, and sync structured records across the decentralized AT Protocol network.
10Think of it as a schema-first backend that automatically handles data
11validation, indexing, and cross-network synchronization.
12
13## How Slices Works on AT Protocol
14
15```mermaid
16flowchart LR
17 Users[Users<br/>Create/Update Records] --> PDS[PDS Nodes<br/>Store user data]
18 PDS --> Firehose[Firehose<br/>Stream of all events]
19 Firehose --> SlicesNetwork[Slices Network - AppView<br/>• Monitors all AT Protocol data<br/>• Routes to relevant slices]
20 SlicesNetwork --> SliceA[Slice A<br/>• Blog lexicons<br/>• Post records<br/>• Comment queries]
21 SlicesNetwork --> SliceB[Slice B<br/>• Music lexicons<br/>• Album records<br/>• Playlist queries]
22 SliceA --> ClientA[Application<br/>Client<br/>• Read/write data]
23 SliceB --> ClientB[Application<br/>Client<br/>• Read/write data]
24```
25
26**Flow:**
27
281. Users create records on their Personal Data Server (PDS)
292. The Firehose streams all network events in real-time
303. The Slices Network monitors the firehose and routes data to relevant slices
314. Each slice indexes only records matching its specific lexicons
325. Application clients connect to specific slices to read/write data
33
34## Quick Start
35
36Get started in under a minute:
37
38```bash
39# Install the CLI globally
40deno install -g jsr:@slices/cli --name slices
41
42# Initialize a new slice project
43slices init my-app
44
45# Start developing
46cd my-app
47deno task dev
48```
49
50The `slices init` command creates a full-stack Deno app with OAuth authentication, automatically creates your slice on the network, and generates a type-safe TypeScript SDK.
51
52## Simple Example
53
54Define a schema for vinyl albums:
55
56```json lexicons/com/recordcollector/album.json
57{
58 "lexicon": 1,
59 "id": "com.recordcollector.album",
60 "defs": {
61 "main": {
62 "type": "record",
63 "record": {
64 "type": "object",
65 "required": ["title", "artist", "releaseDate"],
66 "properties": {
67 "title": { "type": "string" },
68 "artist": { "type": "string" },
69 "releaseDate": { "type": "string", "format": "datetime" },
70 "genre": { "type": "array", "items": { "type": "string" } },
71 "condition": { "type": "string" }
72 }
73 }
74 }
75 }
76}
77```
78
79Push your lexicon and regenerate the SDK:
80
81```bash
82# Push your lexicon to the slice
83slices lexicon push
84
85# Regenerate TypeScript SDK
86slices codegen
87```
88
89Use the auto-generated, type-safe client:
90
91```typescript
92import { AtprotoClient } from "./generated_client.ts";
93
94const client = new AtprotoClient({
95 baseUrl: "https://api.slices.network",
96 sliceUri: "at://your-slice-uri",
97});
98
99// Get all grunge albums
100const albums = await client.com.recordcollector.album.getRecords({
101 where: { genre: { contains: "grunge" } },
102 sortBy: [{ field: "releaseDate", direction: "desc" }],
103});
104```
105
106## Key Features
107
108- **Schema Validation**: Define lexicons that enforce data structure and constraints
109- **Auto-generated APIs**: REST endpoints created automatically from your schemas
110- **TypeScript SDKs**: Type-safe clients generated from your lexicons
111- **Real-time Sync**: Automatic synchronization across the AT Protocol network
112- **Advanced Querying**: Filter, sort, and paginate records with a powerful query API
113- **OAuth Built-in**: Authentication with any AT Protocol account
114
115## When to Use Slices
116
117Slices is ideal for:
118
119- **Social Applications**: Build specialized communities, forums, or social features
120- **Content Platforms**: Create blogs, documentation sites, or media libraries
121- **SaaS Products**: Develop collaborative tools with structured data needs
122- **Web APIs**: Design REST APIs with automatic validation and documentation
123- **Decentralized Apps**: Build on AT Protocol without managing infrastructure
124
125## Next Steps
126
127- [Getting Started](./getting-started.md) - Set up your first slice
128- [Core Concepts](./concepts.md) - Understand lexicons and collections
129- [API Reference](./api-reference.md) - Explore the full API