{"id":30035025,"url":"https://github.com/tobenot/basic-web-game-backend","last_synced_at":"2026-04-09T12:32:21.265Z","repository":{"id":306951767,"uuid":"1027768041","full_name":"tobenot/Basic-Web-Game-Backend","owner":"tobenot","description":"🚀 Modern TypeScript backend for web games with Fastify, tRPC \u0026 Prisma. Features magic link auth, type-safe APIs, and game-ready architecture.","archived":false,"fork":false,"pushed_at":"2025-08-04T18:16:14.000Z","size":157,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-04T19:21:41.884Z","etag":null,"topics":["api","authentication","backend","database","deployment","fastify","game-backend","game-development","jwt","magic-link","nodejs","orm","prisma","serverless","trpc","typesafe","typescript","vercel","web-game","web-game-backend"],"latest_commit_sha":null,"homepage":"https://basic-web-game-backend.vercel.app","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tobenot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-28T13:59:54.000Z","updated_at":"2025-08-04T18:16:17.000Z","dependencies_parsed_at":"2025-07-28T17:28:47.599Z","dependency_job_id":null,"html_url":"https://github.com/tobenot/Basic-Web-Game-Backend","commit_stats":null,"previous_names":["tobenot/basic-web-game-backend"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tobenot/Basic-Web-Game-Backend","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobenot%2FBasic-Web-Game-Backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobenot%2FBasic-Web-Game-Backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobenot%2FBasic-Web-Game-Backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobenot%2FBasic-Web-Game-Backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tobenot","download_url":"https://codeload.github.com/tobenot/Basic-Web-Game-Backend/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobenot%2FBasic-Web-Game-Backend/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269181055,"owners_count":24373853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","authentication","backend","database","deployment","fastify","game-backend","game-development","jwt","magic-link","nodejs","orm","prisma","serverless","trpc","typesafe","typescript","vercel","web-game","web-game-backend"],"created_at":"2025-08-07T01:00:35.318Z","updated_at":"2025-12-30T21:49:40.461Z","avatar_url":"https://github.com/tobenot.png","language":"HTML","readme":"# Basic Web Game Backend\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?logo=typescript\u0026logoColor=white)](https://www.typescriptlang.org/)\n[![Fastify](https://img.shields.io/badge/Fastify-000000?logo=fastify\u0026logoColor=white)](https://fastify.io/)\n[![tRPC](https://img.shields.io/badge/tRPC-2596BE?logo=trpc\u0026logoColor=white)](https://trpc.io/)\n[![Prisma](https://img.shields.io/badge/Prisma-2D3748?logo=prisma\u0026logoColor=white)](https://www.prisma.io/)\n\nA modern, type-safe backend for web games built with Fastify, tRPC, and Prisma. Features secure authentication with magic links and a robust API architecture.\n\n## ✨ Features\n\n- 🔐 **Magic Link Authentication** - Secure, passwordless login system\n- 🚀 **Fastify Server** - High-performance Node.js web framework\n- 🔗 **tRPC Integration** - End-to-end type safety\n- 🗄️ **Prisma ORM** - Type-safe database operations\n- 📱 **CORS Support** - Cross-origin resource sharing enabled\n- 🎮 **Game-Ready API** - Built specifically for web game backends\n- 📊 **User Management** - Complete user lifecycle management\n- 📢 **Announcement System** - Built-in announcement functionality\n\n## 🛠️ Tech Stack\n\n- **Runtime**: Node.js\n- **Framework**: Fastify\n- **API**: tRPC\n- **Database**: Prisma ORM (SQLite/PostgreSQL)\n- **Language**: TypeScript\n- **Authentication**: JWT + Magic Links\n- **Email**: Resend\n\n## 🚀 Quick Start\n\n### Prerequisites\n\n- Node.js 22+ \n- npm or yarn\n- Database (SQLite for development, PostgreSQL for production)\n\n### Installation\n\n1. **Clone the repository**\n   ```bash\n   git clone https://github.com/tobenot/Basic-Web-Game-Backend.git\n   cd Basic-Web-Game-Backend\n   ```\n\n2. **Install dependencies**\n   ```bash\n   npm install\n   ```\n\n3. **Set up environment variables**\n   ```bash\n   cp .env.example .env\n   ```\n   \n   Configure your `.env` file:\n   ```env\n   DATABASE_URL=\"file:./dev.db\"\n   JWT_SECRET=\"your-secret-key\"\n   RESEND_API_KEY=\"your-resend-api-key\"\n   EMAIL_FROM=\"noreply@sendmail.tobenot.top\"\n   EMAIL_FROM_NAME=\"YourApp\"\n   ```\n\n4. **Generate Prisma schema and run migrations**\n   ```bash\n   npm run migrate:dev\n   ```\n\n5. **Start the development server**\n   ```bash\n   npm run dev\n   ```\n\nThe server will be available at `http://localhost:3000`\n\n## 📚 API Documentation\n\n### Authentication Endpoints\n\n- `POST /api/trpc/auth.sendMagicLink` - Send magic link to user email\n- `POST /api/trpc/auth.verifyToken` - Verify magic link token\n- `GET /api/trpc/auth.me` - Get current user info\n\nMagic link generation:\n- Uses frontend URL (`FRONTEND_LOCAL_URL` / `FRONTEND_PRODUCTION_URL`) as base\n- Appends `token` as a query param\n- If the frontend URL contains a hash route, the query is inserted before the hash so the frontend can read it\n\n### User Management\n\n- `GET /api/trpc/user.profile` - Get user profile\n- `PUT /api/trpc/user.update` - Update user information\n\n### Announcements\n\n- `GET /api/trpc.announcement.list` - Get announcement list\n- `POST /api/trpc.announcement.create` - Create new announcement\n\n## 🗄️ Database Schema\n\nThe application uses Prisma with the following models:\n\n- **User**: Core user information and authentication\n- **AuthToken**: Magic link tokens for passwordless authentication\n\n## 🧪 Development\n\n### Available Scripts\n\n```bash\n# Development\nnpm run dev              # Start development server\nnpm run build           # Build for production\nnpm run studio          # Open Prisma Studio\n\n# Database\nnpm run migrate:dev     # Run migrations in development\nnpm run migrate:prod    # Deploy migrations to production\n\n# Utilities\nnpm run prisma:generate:schema  # Generate Prisma schema\nnpm run copy-templates          # Copy template files\n```\n\n### 发布到 GitHub Packages\n\n1. 手动触发工作流 `Update Version`，选择 `patch|minor|major`\n2. 流水线将提交版本更新，随后自动触发 `Publish API Contract` 完成发布\n3. 验证版本：\n   ```bash\n   npm view @tobenot/basic-web-game-backend-contract version --registry=https://npm.pkg.github.com\n   ```\n4. 前端安装：\n   ```bash\n   yarn add @tobenot/basic-web-game-backend-contract@latest\n   ```\n\n备用：本地直接发布\n```bash\nnpm login --scope=@tobenot --registry=https://npm.pkg.github.com\nnpm run build\nnpm version patch --no-git-tag-version\nnpm publish --registry=https://npm.pkg.github.com\n```\n\n### Project Structure\n\n```\nsrc/\n├── ai/               # AI service \u0026 queue\n│   ├── AiService.ts\n│   ├── AiRequestQueueService.ts\n│   └── types.ts\n├── routers/          # tRPC/Fastify routers\n│   ├── auth.ts\n│   ├── user.ts\n│   ├── announcement.ts\n│   └── llm-proxy.ts\n├── utils/            # Utilities (e.g. LLM upstream client)\n│   └── llm-client.ts\n├── templates/        # Email templates\n├── server.ts         # Fastify server setup\n└── trpc.ts           # tRPC configuration\n```\n\n## 🚀 Deployment\n\n### Vercel Deployment\n\nThis project is configured for Vercel deployment. The `vercel.json` file contains the necessary configuration.\n\n### Environment Variables for Production\n\n```env\nDATABASE_URL=\"postgresql://...\"\nJWT_SECRET=\"your-production-secret\"\nRESEND_API_KEY=\"your-resend-api-key\"\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n### Development Guidelines\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🙏 Acknowledgments\n\n- Built with [Fastify](https://fastify.io/) for high-performance web applications\n- Powered by [tRPC](https://trpc.io/) for end-to-end type safety\n- Database management with [Prisma](https://www.prisma.io/)\n- Email delivery via [Resend](https://resend.com/)\n\n## 📞 Support\n\nIf you have any questions or need help, please:\n\n- Open an [issue](https://github.com/tobenot/Basic-Web-Game-Backend/issues)\n- Check the [documentation](https://github.com/tobenot/Basic-Web-Game-Backend#readme)\n\n---\n\n**Made with ❤️ by [tobenot](https://github.com/tobenot)**\n\n*This project is maintained as an independent open-source effort to provide a solid foundation for web game backends.*\n\n## Template Updates\n\n- Use the bundled script to preview/apply template updates:\n  - Preview latest: `bash scripts/update-from-template.sh`\n  - Apply a specific tag with backup: `APPLY=1 bash scripts/update-from-template.sh vX.Y.Z`\n- The template source and version are recorded in `template.lock`.\n- Install a non-blocking pre-commit reminder:\n  ```bash\n  bash scripts/install-git-hooks.sh\n  ```\n- Controlled areas (prefer updating via template): `.github/`, `scripts/`, `src/framework/`, template-marked blocks in `src/server.ts`, `tsconfig.json`, `vercel.json`, and docs listed in `MIGRATION.md`.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobenot%2Fbasic-web-game-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftobenot%2Fbasic-web-game-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobenot%2Fbasic-web-game-backend/lists"}