Skip to content

Repository files navigation

API Platform

CILicense: MIT

Description

Built a production-grade REST API with JWT authentication, refresh token rotation, rate limiting, and auto-generated OpenAPI documentation, using TypeScript, Express, Drizzle ORM, and PostgreSQL.

Features

  • JWT authentication with access/refresh token rotation
  • Role-based CRUD for users, projects, and tasks
  • Rate limiting and HTTP security headers
  • Input sanitization and Zod validation
  • Auto-generated Swagger/OpenAPI documentation
  • GitHub Actions CI/CD pipeline
  • One-click Railway deployment

Tech Stack

TechnologyPurpose
TypeScriptStrongly typed JavaScript
ExpressWeb framework
Drizzle ORMType-safe SQL ORM
PostgreSQLRelational database
HelmetSecurity headers
express-rate-limitRate limiting
ZodRequest validation
JWTAuthentication
JestTesting
Swagger UIAPI documentation

API Endpoints

Auth

MethodEndpointDescription
POST/api/auth/registerRegister new user
POST/api/auth/loginLogin
POST/api/auth/refreshRefresh access token
POST/api/auth/logoutRevoke refresh token

Users

MethodEndpointDescriptionAuth
GET/api/users/meGet current user profileYes
PUT/api/users/meUpdate profileYes
PUT/api/users/me/passwordChange passwordYes

Projects

MethodEndpointDescriptionAuth
GET/api/projectsList projects (paginated)Yes
GET/api/projects/:idGet project by IDYes
POST/api/projectsCreate projectYes
PUT/api/projects/:idUpdate projectYes
DELETE/api/projects/:idDelete projectYes

Tasks

MethodEndpointDescriptionAuth
GET/api/tasksList tasks (paginated)Yes
GET/api/tasks/:idGet task by IDYes
POST/api/tasksCreate taskYes
PUT/api/tasks/:idUpdate taskYes
DELETE/api/tasks/:idDelete taskYes

Getting Started

Prerequisites

  • Node.js 20+
  • PostgreSQL 16+

Installation

git clone https://github.com/casper-justus/api-platform.git
cd api-platform
npm install

Configuration

Copy .env.example to .env and update the values:

cp .env.example .env

Database Setup

npm run db:migrate

Run the Server

npm start

API runs at http://localhost:3000

  • Swagger docs: http://localhost:3000/api-docs
  • Health check: http://localhost:3000/health

Running Tests

npm test

Environment Variables

All required variables — set these in the Railway Variables tab or in your local .env file.

VariableRequiredDescriptionExample
DATABASE_URLPostgreSQL connection string. Auto-injected by the Railway PostgreSQL plugin.postgresql://user:pass@host:5432/db
JWT_SECRETSecret key for signing access tokens. Use a long random string.openssl rand -hex 64
JWT_REFRESH_SECRETSeparate secret for signing refresh tokens. Must differ from JWT_SECRET.openssl rand -hex 64
JWT_EXPIRES_INAccess token lifetime. Keep short for security.15m
JWT_REFRESH_EXPIRES_INRefresh token lifetime.7d
PORTPort the server listens on. Railway injects this automatically.3000
NODE_ENVRuntime environment.production
CORS_ORIGINOptionalAllowed CORS origin. Defaults to *. Set to your frontend URL in production.https://your-frontend.vercel.app

Tip: Generate secure secrets with openssl rand -hex 64 and never reuse the same value for JWT_SECRET and JWT_REFRESH_SECRET.

Project Structure

api-platform/
├── .github/workflows/ci.yml # CI/CD pipeline
├── src/
│ ├── app.ts # Express app setup
│ ├── config/
│ │ └── swagger.ts # Swagger configuration
│ ├── db/
│ │ ├── connection.ts # Database connection
│ │ ├── middleware/ # Auth, validation, security
│ │ ├── migrations/ # Drizzle migrations
│ │ └── schema/ # Drizzle schema definitions
│ └── modules/
│ ├── auth/ # Authentication logic
│ ├── users/ # User endpoints
│ ├── projects/ # Project endpoints
│ └── tasks/ # Task endpoints
├── test/ # Test suites
├── .env.example # Environment template
├── drizzle.config.ts # Drizzle configuration
├── jest.config.json # Jest configuration
├── railway.json # Railway deployment config
└── tsconfig.json # TypeScript configuration

Deploy to Railway

  1. Sign up at Railway
  2. Connect your GitHub repository
  3. Add a PostgreSQL database service — Railway will auto-inject DATABASE_URL
  4. Set all required environment variables from the table above in the Variables tab
  5. Deploy — Railway handles build and start automatically

License

MIT

About

Production-grade TypeScript REST API with PostgreSQL, Prisma, JWT auth, and Jest tests

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages