Saivion/SwiftPieces
About
Swift Pieces provides a library of designed SwiftUI components featuring integrated motion, haptics, and states. Developers can easily integrate these elements via a single Swift file, CLI tool, or AI-assisted installation.
Developer ToolsMeasured star growth
- in 24h
- +1
- in 7 days
- +6
- in 15 days
- +19
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalAn open-source library of animated SwiftUI components.
SwiftPieces is a library of designed SwiftUI interactions: swipe decks, glass menus, floating docks, scrubbable charts. Not primitives, and not a dependency. Each piece is a single .swift file with a #Preview, built on Apple frameworks only, that you copy into your project and own outright. Motion, haptics and states are already done.
Quick start
Add any piece with the CLI:
npx swiftpieces add AssistantOrb
Several at once:
npx swiftpieces add AssistantOrb SwipeDeck GlassActionMenu
Or open the file on swiftpieces.com/components and copy it. There is nothing to install and no package to track.
120 pieces across 14 categories: text, backgrounds, Liquid Glass, buttons and controls, inputs and forms, cards, lists, navigation, sheets, feedback, motion, data and charts, AI and media.
Blocks: whole sections of a screen, laid out, wired and given their states: sign in, account settings, a stats overview, checkout and more. Blocks come with SwiftPieces Pro: npx swiftpieces add SignInBlock installs one with Pro's design system once your license is signed in. All blocks.
Guides: SwiftUI animations · SwiftUI buttons · SwiftUI cards · SwiftUI haptics · Loading states · Liquid Glass
Agent skill: App Design is a free skill for Claude Code, Cursor or Codex that makes any SwiftUI app better, with or without SwiftPieces: study real apps first, pick the right navigation, keep motion native, and record the whole flow in the simulator before calling a screen done. Copy the folder into your agent's skills folder, or run npx swiftpieces add tool-app-design.
What you get
- iOS 17 baseline. Liquid Glass effects are gated behind
#available(iOS 26, *)with a Material fallback, so a piece never fails to build on an older SDK. - Apple frameworks only. No third-party dependencies, ever. A
.metalsibling ships alongside the.swiftfile where a shader is involved. - Accessible by default. Reduce Motion and Reduce Transparency are respected, colors are semantic, and Dynamic Type works.
- Documented parameters. Every init parameter carries a doc comment, which becomes the parameters table on the site.
- Type-checked in CI. Every piece is compiled against the iOS simulator SDK on every change, so an API that does not exist cannot land.
Sponsors
SwiftPieces is maintained by one developer and funded by its sponsors. Sponsorship pays for new free pieces, fixes for every iOS release, and the docs, CLI and MCP server.
Become a sponsor from $5 a month. Company tiers put your logo on swiftpieces.com, the docs and this README.
SwiftPieces Pro
The free library is the pieces and a first set of blocks. Pro is the layer above them: production-ready screens, more blocks, complete app templates, and the Build Kit, a set of agent skills that build the rest of your app in the same design language. One purchase, lifetime access.
Pro is closed source and lives in a private repository. This repo holds the free library and the site, and it stays that way.
Running locally
git clone https://github.com/Saivion/SwiftPieces.git
cd SwiftPieces
npm install
npm run brand:build # @swiftpieces/brand -> dist (first run only)
npm run registry:build # .swift -> registry JSON, docs pages, llms.txt
npm run dev
Use Node 22.22.0 or newer: .nvmrc pins 22.22.0, the line CI and Cloudflare's builds use. Pieces live in registry/swift/<category>/; after changing one, or registry.json, rerun npm run registry:build to regenerate the registry output.
| Path | Purpose |
|---|---|
registry/swift/<category>/ |
Source of truth. One .swift per piece with a // swiftpieces: header; .metal siblings for shaders. |
registry/__registry__/ |
Generated registry JSON. Do not hand-edit. |
content/docs/ |
Fumadocs content. Per-piece pages are generated. |
app/ |
Next.js App Router: marketing, docs, /api/registry/[name], /api/mcp, search. |
components/previews/ |
Web recreations of the pieces, used for live previews. |
packages/cli/ |
swiftpieces on npm: init, add, list, login, whoami. |
packages/brand/ |
@swiftpieces/brand on npm: tokens, Tailwind theme, shared primitives. |
previews/ |
Xcode preview harness and recorder. |
scripts/ |
Registry build, Swift type-check, preview recorder, bundle gate, public-safety audit. |
Useful checks, all of which CI runs too:
npm run typecheck # TypeScript
npm run swift:typecheck # every piece against the iOS simulator SDK
npm run bundle:check # the Worker must stay under 8 MB compressed
npm run audit:public # nothing Pro-shaped, nothing secret
Deployment, reviews and analytics (maintainers)
swiftpieces.com deploys from GitHub with Cloudflare Workers Builds. Nothing is deployed from a laptop: package.json has no deploy, upload or publish script, and the deploy commands below live only in the Workers Builds settings.
| Branch | What happens |
|---|---|
main |
Builds and deploys to production (swiftpieces.com). |
| any other branch in this repo | Builds a preview version with its own URL. Production traffic is untouched. |
| a fork's branch, opened as a PR | Not built. Cloudflare only sees branches in this repo. |
A preview version runs with the production Worker's bindings and secrets, so only maintainers push branches here. Contributors work from forks.
GitHub Actions is here for safety and releases. The safety checks exist because this repo is public and takes contributions: ci.yml checks every push and PR for leaked secrets, Pro-only code, a stale registry, type errors and bundle size. swift.yml type-checks every piece against the iOS SDK, and runs only when Swift, Metal or the preview app changes. protected-files.yml fails a PR from a fork that changes dependency, CI, build, deploy or Xcode project files (the list is in CONTRIBUTING.md). release.yml publishes a GitHub release for every merge to main. It's the only workflow that writes to the repo, and all it writes is a tag and a release. Actions never deploys and holds no Cloudflare credentials; Cloudflare does the deploying.
Releases. Each merge to main is tagged with the next version, worked out from the Conventional Commit types since the last release: a feat bumps the minor version, a ! after any type (or a BREAKING CHANGE footer) bumps the major, and anything else bumps the patch. The notes group the changes by type and link each pull request. Put [skip release] in the squash commit's message to hold a merge back, and the next release lists it. Actions › Release › Run workflow releases main by hand or forces a bump.
Reviewing a PR from a fork. The fork's branch never exists in this repo, but every PR does, as refs/pull/<number>/head. Read it under Files changed on GitHub, or with gh pr diff <number>, and look at the Protected files check first. To run it, check it out into a worktree of its own:
git fetch origin pull/35/head:pr-35
git worktree add ../SwiftPieces-pr-35 pr-35
A worktree holds only tracked files, so .env.local and .dev.vars aren't there for the PR's code to read. It doesn't hide your Cloudflare, npm or GitHub logins, so read the diff before running anything, and if a package.json or package-lock.json changed, read that before npm install. To push a fix to the contributor's branch, check it out with gh pr checkout <number> or GitHub Desktop's pull request list instead; both add the fork as a remote. When you're done: git worktree remove ../SwiftPieces-pr-35 && git branch -D pr-35.
Workers Builds settings (Cloudflare dashboard → Workers → swiftpieces → Settings → Build):
| Setting | Value |
|---|---|
| Git repository | this repo, production branch main |
| Build command | npm run cf:build |
| Deploy command | npx opennextjs-cloudflare deploy |
| Non-production branch deploy command | npx opennextjs-cloudflare upload |
| Builds for non-production branches | on |
| Build variables | NODE_VERSION = 22.23.4, NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN, NEXT_PUBLIC_POSTHOG_HOST and NEXT_PUBLIC_DATABUDDY_CLIENT_ID (optional) |
Build variables are read while building, not by the running Worker. PostHog and Databuddy only start on swiftpieces.com itself, so preview URLs and local builds never count toward the numbers.
ISR cache retention. The prerendered pages and ISR entries live in the swiftpieces-cache R2 bucket under incremental-cache/<build id>/. Every deploy and every preview upload writes the whole site again under a new build ID, about 160 MB, and nothing reads the old build's copy after that. R2 has no per-object expiry, so a lifecycle rule on the bucket removes cache entries a week after they were last written:
npx wrangler r2 bucket lifecycle add swiftpieces-cache expire-isr-cache incremental-cache/ --expire-days 7
npx wrangler r2 bucket lifecycle list swiftpieces-cache
Or in the dashboard: R2 → swiftpieces-cache → Settings → Object lifecycle rules → Add rule, prefix incremental-cache/, delete objects 7 days after upload. Only that prefix is affected. The VIEWS KV namespace (view count, star count) is separate storage and keeps its keys. Entries that are in use are rewritten each time they regenerate, so they never reach a week old. A page whose entry has expired is rendered on its next request and cached again, the same as a cache miss. lib/cache-retention.test.ts checks that this rule, open-next.config.ts and the pages' revalidate values still agree.
Analytics (swiftpieces.com only). The official deploy measures page views, visits and Playground usage with PostHog, and shows the all-time page views in the hero ("Explored N times"). PostHog never starts anywhere else, so forks, previews and local builds send nothing, and there is nothing to configure to run this project.
Databuddy runs beside PostHog, on swiftpieces.com only too: page views, errors, outbound link clicks and the Playground's key events (lib/analytics.ts), plus AI crawlers' reads of pages, llms.txt and llms-full.txt, reported by middleware.ts. Its script waits until the page has loaded and the browser is idle. Error tracking needs Databuddy's Hobby plan or above.
| Variable | Where | What |
|---|---|---|
NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN |
Build variable, .env.local |
The project token (phc_…). Public by design; inlined at build. |
NEXT_PUBLIC_POSTHOG_HOST |
Build variable, .env.local |
https://us.i.posthog.com, or the EU host. |
POSTHOG_PERSONAL_API_KEY |
Worker secret | A personal API key with Query: Read, for the hero's count. A real credential: never commit it. |
POSTHOG_PROJECT_ID |
Worker secret | The project's number (PostHog → Settings → Project). |
NEXT_PUBLIC_DATABUDDY_CLIENT_ID |
Build variable, .env.local |
The Databuddy website's Client ID. Public by design; inlined at build. Without it Databuddy is off and the CSP leaves its hosts out. |
Set the two secrets with npx wrangler secret put <NAME>. The site sets no cookies, so the PostHog project needs Cookieless tracking switched on in its settings; without it, PostHog ignores the site's events. Those events carry no country: PostHog hashes the IP address before GeoIP runs.
The count is Cloudflare Web Analytics' last total, from before the switch, plus PostHog's page views on swiftpieces.com since. It is read at most every two minutes and kept in KV, so polling never reaches PostHog.
If the number stays still. Every failure logs itself, and observability is on, so one command tells you which it is:
npx wrangler tail swiftpieces --format pretty | grep "\[views\]"
| Line | Meaning |
|---|---|
not configured: … |
A secret or the host variable is not reaching the Worker. Until then the hero shows the last total and holds still. |
posthog 401 … or posthog 403 … |
The personal API key is wrong, or lacks Query: Read. |
posthog 404 … |
POSTHOG_PROJECT_ID is not the key's project. |
posthog failed: … |
PostHog did not answer in time. The next read retries. |
Contributing
New pieces, fixes, docs and previews are all welcome. CONTRIBUTING.md is the full walkthrough, from a .swift file to a working npx swiftpieces add command.
By taking part you agree to the Code of Conduct. Found a security issue? SECURITY.md says how to report it privately.
License
MIT + Commons Clause License Condition v1.0.
- You can use, copy, modify and ship the pieces in any app, website or product, personal or commercial, including client work.
- You can't sell, sublicense or redistribute the pieces themselves, whether alone, in a bundle, or as a ported version.
Explore related projects
Loading…