This is the backend for the RPG application, built using Node.js, Express.js, TypeScript, PostgreSQL, and TypeORM. The app supports user authentication, role-based access, and a PostgreSQL database for data storage.
The system now features a unified Session-Event lifecycle that seamlessly integrates event management with session management:
When an event is created:
- Existing Free Role Session → Event Role Session (
isEvent = true) - The session name changes from "Free Role - Location X" to "Event: [Event Title]"
- The session becomes linked to the event via
eventId
When an event is closed:
- Event Role Session → Free Role Session (
isEvent = false) - The session name changes back to "Free Role - Location X"
- The
eventIdlink is removed
Session actions are now role-based:
- Master/Admin Users: Can freeze/unfreeze, close/open, and go to sessions
- Regular Users: Can only "Go Here" to visit sessions
Events now have the same management capabilities as sessions:
- Freeze Event: Freezes the underlying session and saves chat state
- Unfreeze Event: Unfreezes the session and restores chat state
- Close Event: Closes the event and reverts session to free roleplay
- Event Sessions: Green left border with event badge showing event title
- Free Role Sessions: Blue left border with free role badge
- Role Notice: Users see their permission level clearly indicated
This unified approach ensures that events and sessions work together seamlessly, providing masters with comprehensive control while maintaining clear boundaries for regular users.
- User authentication and authorization
- Character creation and management
- Dynamic chat system with skill integration
- Session management with role-based permissions
- Event management with automatic session transformation
- Skill system with usage tracking and rank progression
- Combat rounds with action resolution
- Master panel with comprehensive oversight tools
Before you begin, ensure you have the following installed on your system:
- Node.js (v16 or higher)
- npm
- PostgreSQL (v12 or higher)
- TypeORM CLI
git clone <repository_url>
cd rpg-backendnpm installCreate a .env file in the root directory and configure the following variables:
NODE_ENV=development
PORT=5001
DATABASE_URL=postgres://<username>:<password>@<host>:<port>/<database>
JWT_SECRET=your_secret_keyReplace <username>, <password>, <host>, <port>, and <database> with your PostgreSQL database credentials.
To start the app in development mode:
npm run devThe server will run on http://localhost:<PORT> (default is 5001).
This project has a docker-compose.yml for a quick start. Run:
docker compose create
Go into data-source.js and change synchronize to true
run the container and let the db sync.
Set synchronize back to false
It will try to populate the db with the src/seed.js at first start with some Admin and normal user, a map and a location to avoid fetching error.
If it fails or prefer manual, comment the last line in Dockerfile and launch it manual with:
docker compose exec app node src/jobs/seed.js
If there are changes to the TypeORM entities, generate a new migration:
npx typeorm migration:generate ./src/migrations/<MigrationName> -d ./dist/data-source.jsTo apply the latest migrations to your database:
npx typeorm migration:run -d ./dist/data-source.jsTo undo the last applied migration:
npx typeorm migration:revert -d ./dist/data-source.jsThis project uses Jest for unit testing. To run the tests:
npm testRun tests in watch mode for continuous testing during development:
npm run test:watchBefore deploying, compile the TypeScript code to JavaScript:
npm run buildRun the compiled code using Node.js:
npm startEnsure the .env file is correctly configured for the production environment.
| Command | Description |
|---|---|
npm run dev |
Start the development server |
npm run build |
Compile TypeScript to JavaScript |
npm start |
Start the server in production mode |
npx typeorm migration:generate |
Generate a new migration |
npx typeorm migration:run |
Apply migrations to the database |
npx typeorm migration:revert |
Revert the last migration |
npm test |
Run unit tests |
npm run test:watch |
Run tests in watch mode |
├── src
│ ├── controllers # Route handlers
│ ├── middleware # Middleware functions
│ ├── migrations # Database migrations
│ ├── models # TypeORM entities
│ ├── routes # API routes
│ ├── services # Business logic
│ ├── utils # Utility functions
│ ├── index.ts # Entry point
├── tests # Unit tests
├── .env # Environment variables
├── package.json # NPM configuration
This project is licensed under the MIT License.
The API provides endpoints for:
- User management and authentication
- Character CRUD operations
- Session and event management
- Chat and skill systems
- Combat and master tools
For detailed API documentation, see the individual controller files in /src/controllers/.