|
1 | | -# Basic-Web-Game-Backend |
| 1 | +# Basic Web Game Backend |
| 2 | + |
| 3 | +[](https://opensource.org/licenses/MIT) |
| 4 | +[](https://www.typescriptlang.org/) |
| 5 | +[](https://fastify.io/) |
| 6 | +[](https://trpc.io/) |
| 7 | +[](https://www.prisma.io/) |
| 8 | + |
| 9 | +A modern, type-safe backend for web games built with Fastify, tRPC, and Prisma. Features secure authentication with magic links and a robust API architecture. |
| 10 | + |
| 11 | +## ✨ Features |
| 12 | + |
| 13 | +- 🔐 **Magic Link Authentication** - Secure, passwordless login system |
| 14 | +- 🚀 **Fastify Server** - High-performance Node.js web framework |
| 15 | +- 🔗 **tRPC Integration** - End-to-end type safety |
| 16 | +- 🗄️ **Prisma ORM** - Type-safe database operations |
| 17 | +- 📱 **CORS Support** - Cross-origin resource sharing enabled |
| 18 | +- 🎮 **Game-Ready API** - Built specifically for web game backends |
| 19 | +- 📊 **User Management** - Complete user lifecycle management |
| 20 | +- 📢 **Announcement System** - Built-in announcement functionality |
| 21 | + |
| 22 | +## 🛠️ Tech Stack |
| 23 | + |
| 24 | +- **Runtime**: Node.js |
| 25 | +- **Framework**: Fastify |
| 26 | +- **API**: tRPC |
| 27 | +- **Database**: Prisma ORM (SQLite/PostgreSQL) |
| 28 | +- **Language**: TypeScript |
| 29 | +- **Authentication**: JWT + Magic Links |
| 30 | +- **Email**: Resend |
| 31 | + |
| 32 | +## 🚀 Quick Start |
| 33 | + |
| 34 | +### Prerequisites |
| 35 | + |
| 36 | +- Node.js 18+ |
| 37 | +- npm or yarn |
| 38 | +- Database (SQLite for development, PostgreSQL for production) |
| 39 | + |
| 40 | +### Installation |
| 41 | + |
| 42 | +1. **Clone the repository** |
| 43 | + ```bash |
| 44 | + git clone https://github.com/tobenot/Basic-Web-Game-Backend.git |
| 45 | + cd Basic-Web-Game-Backend |
| 46 | + ``` |
| 47 | + |
| 48 | +2. **Install dependencies** |
| 49 | + ```bash |
| 50 | + npm install |
| 51 | + ``` |
| 52 | + |
| 53 | +3. **Set up environment variables** |
| 54 | + ```bash |
| 55 | + cp .env.example .env |
| 56 | + ``` |
| 57 | + |
| 58 | + Configure your `.env` file: |
| 59 | + ```env |
| 60 | + DATABASE_URL="file:./dev.db" |
| 61 | + JWT_SECRET="your-secret-key" |
| 62 | + RESEND_API_KEY="your-resend-api-key" |
| 63 | + ``` |
| 64 | + |
| 65 | +4. **Generate Prisma schema and run migrations** |
| 66 | + ```bash |
| 67 | + npm run migrate:dev |
| 68 | + ``` |
| 69 | + |
| 70 | +5. **Start the development server** |
| 71 | + ```bash |
| 72 | + npm run dev |
| 73 | + ``` |
| 74 | + |
| 75 | +The server will be available at `http://localhost:3000` |
| 76 | + |
| 77 | +## 📚 API Documentation |
| 78 | + |
| 79 | +### Authentication Endpoints |
| 80 | + |
| 81 | +- `POST /api/trpc/auth.sendMagicLink` - Send magic link to user email |
| 82 | +- `POST /api/trpc/auth.verifyToken` - Verify magic link token |
| 83 | +- `GET /api/trpc/auth.me` - Get current user info |
| 84 | + |
| 85 | +### User Management |
| 86 | + |
| 87 | +- `GET /api/trpc/user.profile` - Get user profile |
| 88 | +- `PUT /api/trpc/user.update` - Update user information |
| 89 | + |
| 90 | +### Announcements |
| 91 | + |
| 92 | +- `GET /api/trpc.announcement.list` - Get announcement list |
| 93 | +- `POST /api/trpc.announcement.create` - Create new announcement |
| 94 | + |
| 95 | +## 🗄️ Database Schema |
| 96 | + |
| 97 | +The application uses Prisma with the following models: |
| 98 | + |
| 99 | +- **User**: Core user information and authentication |
| 100 | +- **AuthToken**: Magic link tokens for passwordless authentication |
| 101 | + |
| 102 | +## 🧪 Development |
| 103 | + |
| 104 | +### Available Scripts |
| 105 | + |
| 106 | +```bash |
| 107 | +# Development |
| 108 | +npm run dev # Start development server |
| 109 | +npm run build # Build for production |
| 110 | +npm run studio # Open Prisma Studio |
| 111 | + |
| 112 | +# Database |
| 113 | +npm run migrate:dev # Run migrations in development |
| 114 | +npm run migrate:prod # Deploy migrations to production |
| 115 | + |
| 116 | +# Utilities |
| 117 | +npm run prisma:generate:schema # Generate Prisma schema |
| 118 | +npm run copy-templates # Copy template files |
| 119 | +``` |
| 120 | + |
| 121 | +### Project Structure |
| 122 | + |
| 123 | +``` |
| 124 | +src/ |
| 125 | +├── routers/ # tRPC routers |
| 126 | +│ ├── auth.ts # Authentication routes |
| 127 | +│ ├── user.ts # User management |
| 128 | +│ └── announcement.ts # Announcement system |
| 129 | +├── templates/ # Email templates |
| 130 | +├── server.ts # Fastify server setup |
| 131 | +└── trpc.ts # tRPC configuration |
| 132 | +``` |
| 133 | + |
| 134 | +## 🚀 Deployment |
| 135 | + |
| 136 | +### Vercel Deployment |
| 137 | + |
| 138 | +This project is configured for Vercel deployment. The `vercel.json` file contains the necessary configuration. |
| 139 | + |
| 140 | +### Environment Variables for Production |
| 141 | + |
| 142 | +```env |
| 143 | +DATABASE_URL="postgresql://..." |
| 144 | +JWT_SECRET="your-production-secret" |
| 145 | +RESEND_API_KEY="your-resend-api-key" |
| 146 | +``` |
| 147 | + |
| 148 | +## 🤝 Contributing |
| 149 | + |
| 150 | +Contributions 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. |
| 151 | + |
| 152 | +### Development Guidelines |
| 153 | + |
| 154 | +1. Fork the repository |
| 155 | +2. Create a feature branch (`git checkout -b feature/amazing-feature`) |
| 156 | +3. Commit your changes (`git commit -m 'Add some amazing feature'`) |
| 157 | +4. Push to the branch (`git push origin feature/amazing-feature`) |
| 158 | +5. Open a Pull Request |
| 159 | + |
| 160 | +## 📄 License |
| 161 | + |
| 162 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 163 | + |
| 164 | +## 🙏 Acknowledgments |
| 165 | + |
| 166 | +- Built with [Fastify](https://fastify.io/) for high-performance web applications |
| 167 | +- Powered by [tRPC](https://trpc.io/) for end-to-end type safety |
| 168 | +- Database management with [Prisma](https://www.prisma.io/) |
| 169 | +- Email delivery via [Resend](https://resend.com/) |
| 170 | + |
| 171 | +## 📞 Support |
| 172 | + |
| 173 | +If you have any questions or need help, please: |
| 174 | + |
| 175 | +- Open an [issue](https://github.com/tobenot/Basic-Web-Game-Backend/issues) |
| 176 | +- Check the [documentation](https://github.com/tobenot/Basic-Web-Game-Backend#readme) |
| 177 | + |
| 178 | +--- |
| 179 | + |
| 180 | +**Made with ❤️ by [tobenot](https://github.com/tobenot)** |
| 181 | + |
| 182 | +*This project is maintained as an independent open-source effort to provide a solid foundation for web game backends.* |
0 commit comments