A minimal REST API for managing users and menu sessions. Lightweight, middleware-driven TypeScript app (Bun/Node).
Users are identified by a username (or other identifier) and authenticate using a short numeric PIN — the project does not require or use email addresses.
- User creation and authentication (PIN codes)
- Menu session management
- Middleware for authentication, error handling and rate limiting
- TypeScript
- Bun (recommended) or Node.js
- Minimal file-based structure under
src/
- Runtime: Bun (recommended) or Node.js
- Language: TypeScript
- Authentication: JWT-based middleware (
src/middleware/auth.ts) - Rate limiting: middleware in
src/middleware/rateLimit.ts - Storage: check
src/db.tsfor the chosen adapter (DB connection is configurable)
Prerequisites: Bun (recommended) or a recent Node.js. Clone the repo and install dependencies:
bun installStart the development server:
bun run dev
# or with npm / pnpm (if configured)Create a .env file or export environment variables used by the app. Common variables:
PORT— port to bind (default:3000)DATABASE_URL— connection string for the databaseJWT_SECRET— secret used bysrc/middleware/auth.tsfor signing/verifying tokensRATE_LIMIT_WINDOW/RATE_LIMIT_MAX— optional rate-limit settings
Check src/db.ts and src/middleware/auth.ts for exact expectations.
- src/index.ts — application entry
- src/db.ts — database connection
- src/createUser.ts — helper to create users
- src/routes/user.ts — user-related routes
- src/routes/session.ts — session-related routes
- src/models/User.ts —
Usermodel - src/models/MenuSession.ts —
MenuSessionmodel - src/middleware/auth.ts — auth middleware
- src/middleware/errorHandler.ts — global error handler
- src/middleware/rateLimit.ts — rate limiting
Below are the most common endpoints; see route files for full details and payload shapes.
-
POST /users— create a new userNotes: the
passwordfield is a PIN code (numeric, short). Users are identified byusername(or another non-email identifier).Example:
curl -X POST http://localhost:3000/users \ -H "Content-Type: application/json" \ -d '{"username":"alice","password":"1234"}'
-
POST /sessions— create a session / loginExample:
curl -X POST http://localhost:3000/sessions \ -H "Content-Type: application/json" \ -d '{"username":"alice","password":"1234"}'
Other routes and protected endpoints are implemented in src/routes/session.ts and src/routes/user.ts. Authentication is enforced by src/middleware/auth.ts.
- The app exposes middleware for error handling and rate limiting; review
src/middlewareto adjust behavior. - Models live in
src/modelsand are small single-responsibility modules.
Open an issue or submit a PR. Keep changes small and focused.