- Station is a pnpm workspace monorepo for gaming guild/organization management with a NestJS backend and React frontend.
- RBAC uses JSONB permissions, JWT auth with refresh rotation, and Redis caching with in-memory fallback.
- Public repository: https://github.com/GitAddRemote/station
- Monorepo managed with pnpm + Turbo. Backend:
backend/(NestJS insrc/, migrations insrc/migrations, tests intest/). Frontend:frontend/(React/Vite insrc/). - Shared tooling at root (
turbo.json,pnpm-workspace.yaml,tsconfig.json, husky hooks); infra indocker-compose.yml,k8s/, and packageDockerfiles. - Copy env templates before running services:
backend/.env.example,frontend/.env.example.
- Install once at root:
pnpm install. - Run both apps:
pnpm dev. Scoped dev:pnpm dev:backend(http://localhost:3001) andpnpm dev:frontend(http://localhost:5173). - Build:
pnpm buildorpnpm --filter <pkg> build. - Local data stack:
docker-compose up -d(Postgres 5433, Redis 6379); runpnpm --filter backend migration:runafter services are healthy.
- Backend tests from
backend/:pnpm test,pnpm test:e2e,pnpm test:watch,pnpm test:cov. Root:pnpm test. - Lint/format/typecheck:
pnpm lint,pnpm format,pnpm typecheck. - E2E requires PostgreSQL running (
docker-compose up -d database); tests drop/recreate schema (synchronize: true,dropSchema: true) and run serially.
- TypeScript everywhere; ESLint configs (
backend/eslint.config.js,frontend/.eslintrc.cjs) and Prettier defaults (2-space indent). - Naming:
camelCasevars/functions,PascalCaseclasses/components,SCREAMING_SNAKE_CASEconstants/envs. Backend follows Nest patterns (*.module.ts,*.service.ts,*.controller.ts); React components live one per file. - Code quality standards: prioritize scalability, industry best practices, performance (queries/caching/complexity), and modern TS/JS features and patterns.
- Prefer typed DTOs/interfaces; use async/await with explicit HTTP exceptions and validation.
- Backend modules:
auth,users,organizations,roles,user-organization-roles,permissions,audit-logs; each with module/controller/service/entity/dto/guards. - Database: PostgreSQL + TypeORM manual migrations (no prod sync). Schema includes users, roles, organizations, user_organization_role (composite indexes), audit_log, refresh_tokens, password_resets. Permissions stored in JSONB.
- Caching: Redis default (
REDIS_HOST:6379), automatic in-memory fallback; tests force in-memory viaUSE_REDIS_CACHE=false; default TTL 5 minutes. Cached: organization members, aggregated permissions. - Auth flow: register → login → protected routes with bearer access token (15m) + refresh token (7d) rotation; refresh endpoint issues new pair; logout revokes refresh tokens. Guards:
JwtAuthGuard,LocalAuthGuard,RefreshTokenAuthGuard. Passwords hashed with bcrypt (10 rounds), JWT signed withJWT_SECRET. - Audit logging: use
AuditLogsServiceto record actions with resource metadata.
- Backend
.envessentials:DATABASE_HOST=localhost,DATABASE_PORT=5433,DATABASE_USER=stationDbUser,DATABASE_PASSWORD=stationDbPassword1,DATABASE_NAME=stationDb,JWT_SECRET,REDIS_HOST=localhost,REDIS_PORT=6379,PORT=3001,APP_NAME=STATION BACKEND,USE_REDIS_CACHE=true(false for tests)..env.testmirrors.envwithUSE_REDIS_CACHE=false.
- Commands from
backend/:pnpm migration:create src/migrations/YourMigrationName,pnpm migration:run,pnpm migration:revert,pnpm db:backup,pnpm db:health-check,pnpm seed. Always create a backup before production migrations. - Every production migration needs working
up/down, tested rollback (migration:revert), pre-migration backup, post-migration health check, and alignment withbackend/src/migrations/templates/PRE_MIGRATION_CHECKLIST.mdplus rollback decision tree inbackend/docs/database/migrations.md. Use templatebackend/src/migrations/templates/migration-template.ts.
- lint-staged runs on commit: backend ESLint + Prettier; root Prettier on JSON/MD. Prefer fixing hooks rather than bypassing;
git commit --no-verifyonly if necessary. - Turbo coordinates builds/tests; use
pnpm --filter <package>for scoped tasks.
- Never commit code directly. Provide git commands only, formatted for terminal execution with
-mper line, blank lines via-m "", and conventional first-line type (feat/fix/docs/test/refactor/perf/chore). Group related changes with bullet points; no attribution or AI notices. User executes commands manually.
- Ensure database running (
docker-compose up -d database) before app/tests; port defaults: backend 3001, frontend 5173, Postgres 5433. - Migration errors: test rollback early; prod uses
migrationsRun: false. - Redis connection warnings expected in tests due to in-memory fallback.
- Requires pnpm 8+ and Node 18+ (see package engines).
- Never include AI attribution in code, comments, or commit messages. Code should read as human-written.