Backend for Soldank++ website built with NestJS and TypeScript with Postgres database via TypeORM. The frontend architecture can be found here.
Configuration is read from a .env file at the project root. .env.example is provided as a template with sensible local-dev defaults — copy it to get started:
cp .env.example .envVariables:
NODE_ENV- application environment (e.g.development,production)DB_HOST- Postgres hostDB_PORT- Postgres portDB_USER- Postgres user, used by TypeORM and bydocker-compose.ymlDB_PASSWORD- Postgres password, used by TypeORM and bydocker-compose.ymlDB_DATABASE- Postgres database name, used by TypeORM and bydocker-compose.ymlDB_LOCAL_ROOT_PASSWORD- root/superuser password for the local dockerized Postgres instance
The project uses the following packages:
- NestJS: Framework that handles HTTP connections, routing and dependency injection
- TypeORM: ORM used to talk to Postgres and manage schema migrations
- nestjs-paginate: Pagination, sorting and filtering for the list endpoints
- class-validator / class-transformer: Request validation and response serialization (only fields marked
@Expose()are returned) - Joi: Validates environment variables on startup
- @nestjs/swagger: Generates the OpenAPI spec and the docs served at
/apiin development
Make sure you have Node.js v16 (or higher) and clone this repository:
git clone https://github.com/soldank-plus-plus/spp-webstats
cd spp-websiteThen install the dependencies:
npm installThis project uses PostgreSQL via TypeORM. Set up the required environment variables as described above, then start a local Postgres instance with Docker Compose:
docker compose up -dTo stop it:
docker compose down
# also remove the postgres_data volume
docker compose down -vMigrations live in src/migrations/ and are driven by src/data-source.ts. The migrations table in Postgres tracks which ones have run.
Generate a migration from the diff between the entities and the current database schema (the DB from docker compose up -d must be running):
npm run migration:generate --name=<MigrationName>Apply pending migrations:
npm run migration:runRevert the last applied migration:
npm run migration:revertDrop everything in the database and reapply all migrations from a clean state:
npm run migration:reloadPopulate the database with a small set of real sample users, maps,
map_creators, events, and stats for local development (migrations must
already be applied):
npm run fixturesThis is insert-only, not idempotent: running it again against a database that already has this data fails with a constraint error rather than overwriting anything.
# development
npm run start
# watch mode
npm run start:dev
# production mode
npm run start:prod# unit tests
npm run test
# e2e tests
npm run test:e2e
# test coverage
npm run test:covBoth run automatically before every git push (via husky's pre-push hook), so you don't need to run them manually.