BiaoTech API
Cloud-Deployed REST API & CI/CD
A TypeScript/Express REST API built to take a backend through the complete engineering path — from authentication and database integration to automated testing, CI/CD and deployment on AWS EC2.
- TypeScript
- Node.js
- Express
- PostgreSQL
- AWS EC2
- GitHub Actions
- PM2
The EC2 environment is offline, so no live endpoints are linked. Everything here is derived from the source repository.
- React SPAbuilt on deploy
- Nginxserves the SPA
- Express · TSREST API
- PM2process manager
A small scope, carried through the whole lifecycle
An end-to-end backend and cloud-deployment exercise. The business scope is intentionally small — authentication, user management and administrative operations — so the engineering effort goes into everything around it.
- 01API designExpress 5 · REST · OpenAPI 3
- 02DatabasePostgreSQL · SQL migrations
- 03Auth & securityJWT · RBAC · Helmet
- 04TestingJest · Supertest
- 05CI/CDGitHub Actions
- 06Cloud deployAWS EC2 · PM2
11 routes, three access levels, layered controls
Documented with swagger-jsdoc annotations and served as Swagger UI. Every user route requires a JWT; every write also requires the admin role.
- GET/Public
- GET/api/healthPublicDatabase-aware health check
- GET/api/docsDocsSwagger UI · OpenAPI 3.0
- POST/api/auth/loginPublic
- POST/api/auth/refreshPublic
- GET/api/auth/meJWT
- GET/api/usersJWT?page · limit · search
- GET/api/users/:idJWT
- POST/api/usersJWT + Admin
- PUT/api/users/:idJWT + Admin
- DELETE/api/users/:idJWT + Admin
- JWT access tokens · 1h default
- Refresh tokens · 7d default
- Separate signing secrets
- bcrypt password hashing
- RBAC with admin and user roles
- authorizeRoles("admin") on every user write
- JWT required on all user reads
- Helmet security headers
- Rate limit · 100 req / 15 min
- CORS allowlist from config
- Zod request validation
- Health check runs SELECT 1 · HTTP 500 when the database is unreachable
- X-Request-Id on every response
- Pino structured request logs
- Centralized 404 and error handling
- Admin seed refuses to run without ADMIN_PASSWORD
The React client keeps both tokens in localStorage — simple, and documented in the repository, but readable by any script on the page. The identified improvement is an httpOnly refresh cookie with the access token held in memory.
{ "success": true, "status": "ok",
"service": "biaotech-api",
"environment": <NODE_ENV>,
"database": "connected",
"uptime": <process.uptime()>,
"timestamp": <ISO-8601> }Deployment gated behind a real test suite
One GitHub Actions workflow runs on every push to main. The deploy job declares needs: test — nothing reaches EC2 unless types, lint and the integration suite pass against a real PostgreSQL.
- Push to mainWorkflow trigger
- Type checktsc --noEmit
- LintESLint
- TestsJest + Supertest against a PostgreSQL 16 service container
- SSHappleboy/ssh-action
- AWS EC2Reset to main · npm build
- PM2Restart the backend process
- NginxSPA build copied · config test · reload
tests
- Auth
- 2
- Health
- 1
- Users
- 8
- Logs in and returns a JWT
- Denies access without a token
- Validates the user name
- Denies delete for the user role
- Allows delete for the admin role
- Reports API health
Run history is public in the repository's Actions tab; no live pipeline status is shown here.
Boundaries of the original approach
The right column is direction, not retrofit — none of it was implemented in BiaoTech API.
One host, no horizontal scaling.
The original deployment was not defined as Infrastructure as Code.
CI held a long-lived SSH key in repository secrets.
Production ran as a PM2-managed Node process, not containers.
Compose ran the API, PostgreSQL and Adminer locally — never the production runtime.
Simple to build, but readable by any script on the page.
Evidence boundaries: the previously deployed AWS environment is currently offline, and the repository does not preserve the API reverse-proxy/TLS configuration or where production PostgreSQL was hosted.
From deployment to reproducible infrastructure
The limits of a manually provisioned, SSH-deployed server motivated the next infrastructure exercise.
- AWS EC2
- GitHub Actions
- SSH deploy
- PM2
- Manual provisioning
- Terraform
- Containers
- GitHub OIDC
- Least privilege
- Zero-spend guardrails
AWS architecture defined in Terraform — not deployed.
