# MKStack A template for building Nostr apps with AI agents. It's a working React app with login, relay management, publishing and file uploads already wired up, plus an `AGENTS.md` and a set of skills that teach coding agents how to build on it safely. ## Stack - **React 19** with **TypeScript** - **Vite 8** for the dev server and build - **Tailwind CSS 4** and **shadcn/ui** (Radix UI) components - **Nostrify** and **nostr-tools** for the Nostr protocol - **TanStack Query** for data fetching and caching - **React Router 7** - **Vitest 5** with React Testing Library ## Getting started ```bash git clone https://gitlab.com/soapbox-pub/mkstack.git my-app cd my-app npm run dev ``` The dev server runs on [localhost:8080](http://localhost:8080). The `dev`, `build` and `test` scripts install dependencies themselves. | Command | What it does | | --------------- | --------------------------------------------------------------- | | `npm run dev` | Start the dev server | | `npm run build` | Build to `dist/`, with `404.html` copied from `index.html` | | `npm test` | Type-check, lint, run the tests, then build | ### The template fails `npm test` on purpose A fresh copy fails lint until it's made into a real app. The rules check for things every app needs, so an agent can't finish without them: - a ``, a meta description and Open Graph tags in `index.html` - a web manifest at `public/manifest.webmanifest` - no `FIXME` comments left (the starter page and the font setup have them) ## What's included - **Login:** `LoginArea` opens a dialog for signing up, a browser extension (NIP-07), a private key or a remote signer (NIP-46), and becomes an account switcher once logged in. Extension logins use the optional `window.nostr.connect`, `getSigner` and `disconnect` where the extension offers them (Din and Tenna do), so the app keeps signing as each login's own account when the user switches accounts in the extension. - **Hooks:** `useCurrentUser`, `useAuthor`, `useNostrPublish`, `useUploadFile` (Blossom), `useLoggedInAccounts`, `useTheme`, `useIsMobile` and others in `src/hooks/`. - **Relays:** a default relay pool, and the user's NIP-65 relay list loaded on login and published when it changes. - **NIP-19 routing:** `npub`, `nprofile`, `note`, `nevent` and `naddr` identifiers are routed at the URL root to `src/pages/NIP19Page.tsx`. - **UI:** about 50 shadcn/ui components in `src/components/ui/`, with light and dark themes. - **Security defaults:** a strict Content Security Policy in `index.html` and lint rules against inline scripts. ## Building with an agent `AGENTS.md` is the system prompt for agents working in a project made from this template. It covers the project's conventions, how to design Nostr events, and its security model: private keys live in `localStorage`, so any XSS can steal them. Bigger features come as skills in `.agents/skills/`, which agents load when a task needs them. Several ship ready-made code in a `files/` folder: | Skill | For | | ----------------------- | ---------------------------------------------------------- | | `nostr-security` | The full threat model, URL and CSS sanitizing | | `nip19-routing` | Filling in `NIP19Page` for each identifier type | | `note-content` | Rendering note text with links, mentions, media and embeds | | `nostr-comments` | NIP-22 comments on events or any external content | | `nostr-infinite-scroll` | Paginated feeds | | `nostr-encryption` | NIP-44 and NIP-04 encryption through the user's signer | | `nostr-relay-pools` | Querying or publishing to specific relays | | `relay-management` | A settings UI for the user's relay list | | `edit-profile` | A profile editing form | | `file-uploads` | Blossom uploads and NIP-94 `imeta` tags | | `nip85-stats` | Follower, reaction and zap counts from NIP-85 providers | | `nwc` | Lightning wallets (NWC, WebLN) and zaps | | `onchain-bitcoin` | A Bitcoin wallet derived from the user's Nostr key | | `ai-chat` | Streaming AI chat interfaces | | `capacitor` | Native iOS and Android apps | | `lockdown-mode` | What works under Apple's Lockdown Mode | | `plausible-analytics` | Plausible Analytics | | `theming` | Fonts, colors and themes | | `testing` | Writing Vitest tests with the `TestApp` wrapper | `.mcp.json` (Claude Code) and `opencode.json` (OpenCode) connect agents to the [Nostrbook](https://nostrbook.dev) MCP server, which looks up NIPs and event kinds. ## Project structure ``` src/ ├── components/ │ ├── ui/ shadcn/ui components │ └── auth/ login dialog and account switcher ├── contexts/ app config context ├── hooks/ Nostr, account and UI hooks ├── lib/ utilities, polyfills, default relays and Blossom servers ├── pages/ Index, NIP19Page, NotFound ├── test/ TestApp wrapper and test setup ├── App.tsx providers └── AppRouter.tsx routes eslint-rules/ the template's custom lint rules .agents/skills/ skills for agents AGENTS.md agent instructions ``` ## Deploying `npm run build` produces a static site in `dist/` that any static host can serve. The app routes on the client, so the host has to serve `index.html` for unknown paths. Hosts that fall back to `404.html`, such as GitHub Pages and nsite gateways, get that from the build. ## Apps built with MKStack - [Chorus](https://chorus.community/): groups on Nostr with a built-in eCash wallet - [Blobbi](https://www.blobbi.pet/): digital pets that live on Nostr - [Treasures](https://treasures.to/): geocaching on Nostr [More apps made with MKStack](https://nostrhub.io/apps/t/mkstack/) ## License MKStack is dedicated to the public domain. To the extent possible under law, the authors have waived all copyright and related or neighboring rights to it.