A full-stack dividends tracking application built with NestJS, Angular, and PostgreSQL in an Nx monorepo.
- Backend: NestJS 12 with Prisma ORM 7
- Frontend: Angular 22 (standalone components)
- Database: PostgreSQL 16
- Monorepo: Nx 24
- Styling: Tailwind CSS v4 and SCSS
This monorepo contains:
- Backend API (
apps/api) - NestJS application with Prisma ORM for PostgreSQL - Frontend (
apps/dividends) - Angular 22 standalone application - Shared Library (
packages/shared) - Shared types and utilities (@dividends/shared) - E2E Tests (
apps/api-e2e) - End-to-end tests for the API
Key Features:
- Frontend automatically proxies
/apirequests to the backend viaproxy.conf.json - Running
nx serve dividendsautomatically starts the API server first - Prisma schema located at
apps/api/prisma/schema.prismawith custom client output toapps/api/generated/prisma
- Node.js v24.22.3 (see
.nvmrc) - Docker and Docker Compose (for PostgreSQL)
- npm
npm installnpm may print npm warn install-scripts for some dependencies. This is expected: their install scripts are not needed because prebuilt binaries are installed as optional dependencies (see allowScripts in package.json).
Copy the example environment file:
cp .env.example .envDATABASE_URL already matches the Docker Compose database:
DATABASE_URL="postgresql://dividends:dividends@localhost:5432/dividends?schema=public"Review the remaining variables and replace the placeholders:
| Variable | Required | Description |
|---|---|---|
DATABASE_URL |
yes | Connection string to PostgreSQL (postgresql://... or postgres://...) |
JWT_SECRET |
yes | Secret for signing acc F831 ess tokens; must not be empty |
ADMIN_PASSWORD |
yes | Password of the login user created by the seed |
ADMIN_EMAIL, ADMIN_NAME |
no | Login user created by the seed (defaults: admin@example.com, Admin User) |
DEFAULT_CURRENCY, DEFAULT_CURRENCY_NAME |
yes | Default currency created by the seed (e.g. EUR, Euro); DEFAULT_CURRENCY is a code of three uppercase letters |
ALLOW_REGISTRATION |
no | Enables POST /api/auth/register (true or false, case-insensitive; default false) |
SECURITY_PRICE_HISTORY_START |
no | Start date for historical price and exchange-rate sync (YYYY-MM-DD, default 2017-01-01) |
SEED_SAMPLE_DATA |
no | true makes the seed create sample securities, transactions and dividends (default false, see Set up the database schema) |
The API validates its environment variables at startup (apps/api/src/app/config/environment.validation.ts): if a required variable is missing or a variable has an invalid value, it does not start and lists every invalid variable (without its value). Besides the variables above, it also checks PORT (integer from 1 to 65535, default 3000) and NODE_ENV (development, production or test, optional). Empty values count as not set.
The application runs in single-user mode. The login user is created by the database seed from ADMIN_EMAIL, ADMIN_PASSWORD and ADMIN_NAME. Self-registration (POST /api/auth/register) is disabled by default and returns 403 Forbidden; set ALLOW_REGISTRATION=true only if you need it, because data is not separated per user and every account can access all data.
Use Docker Compose to start only the PostgreSQL service:
docker compose up -d postgresThis starts PostgreSQL 16 on localhost:5432 with default credentials configured for local development.
Note: docker compose up -d without a service name builds and starts the complete stack (database, API and frontend). The API container then occupies port 3000 and conflicts with nx serve. See Running with Docker.
# Generate Prisma Client
npm run db:generate
# Run migrations to set up the database schema
npm run db:migrate
# Seed the database (creates the login user and the default currency)
npm run db:seedThe seed is required for logging in, because it creates the only user account. It aborts if ADMIN_PASSWORD, DEFAULT_CURRENCY or DEFAULT_CURRENCY_NAME is missing.
To try the application with data, set SEED_SAMPLE_DATA=true before seeding. The seed then also creates 12 securities, transactions and dividend payments derived from the import samples in docs/samples (defined in apps/api/prisma/sample-data.ts). Sample data is only created if the database contains no securities yet and DEFAULT_CURRENCY is EUR; otherwise the seed skips it and logs the reason.
# Start both API and frontend (recommended)
nx serve dividends
# Or start only the API
nx serve apiThe API will be available at http://localhost:3000/api and the frontend at http://localhost:4200. The interactive API documentation (Swagger UI) is served at http://localhost:3000/api/docs.
Note: Running nx serve dividends automatically starts the backend API first before starting the frontend dev server.
# Serve the full stack (starts API + Angular dev server)
nx serve dividends
# Serve only the API
nx serve api# Build a specific project
nx build api
nx build dividends
# Build all projects
nx run-many -t build
# Build only affected projects (based on git changes)
nx affected -t buildThe API, the API e2e tests and the shared package use Jest; the Angular frontend uses Vitest (via the Angular @angular/build:unit-test builder).
# Run tests for a specific project
nx test api
nx test dividends
nx test shared
# Frontend tests in watch mode (re-run on file changes)
nx test dividends -c watch
# Run tests for all projects
nx run-many -t test
# Run tests for affected projects only
nx affected -t test
# Run API end-to-end tests (requires a running PostgreSQL)
nx e2e api-e2eThe e2e tests use a separate database <db>_e2e derived from DATABASE_URL (or E2E_DATABASE_URL). It is created and migrated automatically, and the tests delete all its data.
# Lint a specific project
nx lint api
nx lint dividends
# Lint all projects
nx run-many -t lint
# Lint affected projects only
nx affected -t lintAll database commands use Prisma with a custom configuration file (apps/api/prisma.config.ts). The Prisma schema is located at apps/api/prisma/schema.prisma.
# Start PostgreSQL database
docker compose up -d postgres
# Stop database
docker compose stop postgres
# Stop all services and remove volumes (WARNING: deletes all data)
docker compose down -v
# View database logs
docker compose logs postgres# Generate Prisma Client (run after schema changes)
npm run db:generate
# Push schema changes to database (prototyping, skips migrations)
npm run db:push
# Open Prisma Studio to view/edit data in browser
npm run db:studio
# Format Prisma schema file
npm run db:format
# Validate Prisma schema for errors
npm run db:validate# Create and apply a new migration (development)
npm run db:migrate
# Create migration file without applying it
npm run db:migrate:create
# Apply pending migrations (production)
npm run db:migrate:deploy
# Check migration status
npm run db:migrate:status
# Reset database and reapply all migrations (WARNING: deletes all data)
npm run db:migrate:reset# Seed the database (login user and default currency)
npm run db:seed
# Seed including sample securities, transactions and dividends (empty database, EUR only)
SEED_SAMPLE_DATA=true npm run db:seed
# Reset database without running seeds
npm run db:resetdocker-compose.yml defines three services that together run the complete application:
| Service | Description | Port |
|---|---|---|
postgres |
PostgreSQL 16 database | 127.0.0.1:5432 |
api |
NestJS API (apps/api/Dockerfile) |
127.0.0.1:3000 |
frontend |
Angular app served by nginx, proxies /api to the API (apps/dividends/Dockerfile) |
80 (all interfaces) |
Docker Compose reads the variables from the .env file in the project root. Set at least JWT_SECRET, ADMIN_PASSWORD, DEFAULT_CURRENCY and DEFAULT_CURRENCY_NAME before the first start (see Set up environment variables).
# Build and start all services
docker compose up -d
# View logs
docker compose logs -f
# Stop all services
docker compose down
# Stop all services and remove volumes (WARNING: deletes all data)
docker compose down -vOn every start, the API container applies pending migrations (prisma migrate deploy), runs the seed and then starts the server. The seed only creates the login user and the default currency if they do not exist yet and marks DEFAULT_CURRENCY as the default currency; changing ADMIN_PASSWORD later does not update an existing password. With SEED_SAMPLE_DATA=true, the first start on an empty database also creates the sample data.
The application is then available at http://localhost. Stop any running nx serve processes first, because the API container uses port 3000.
To rebuild and restart everything after a code change, run scripts/redeploy.sh (or npm run docker:redeploy); see docs/DOCKER.md.
Details on configuration, access from other machines and Podman are described in docs/DOCKER.md.
The API has special targets to prepare it for containerization or deployment:
# Generate pruned lockfile and copy workspace modules
nx run api:pruneThis runs both prune-lockfile and copy-workspace-modules to prepare the API build with only the necessary dependencies.
chicago/
├── apps/
│ ├── api/ # NestJS backend API
│ │ ├── src/ # Application source code
│ │ ├── prisma/ # Database schema and migrations
│ │ │ ├── schema.prisma # Prisma schema definition
│ │ │ ├── migrations/ # Database migration files
│ │ │ ├── seed.ts # Database seeding script
│ │ │ └── sample-data.ts # Sample data for SEED_SAMPLE_DATA=true
│ │ ├── generated/ # Generated Prisma client
│ │ ├── prisma.config.ts # Prisma configuration used by the npm db:* scripts
│ │ ├── Dockerfile # API container image
│ │ └── webpack.config.js # Custom Webpack configuration
│ ├── api-e2e/ # API end-to-end tests
│ └── dividends/ # Angular frontend
│ ├── src/
│ │ ├── app/ # Application components
│ │ └── main.ts # Application entry point
│ ├── Dockerfile # Frontend container image (nginx)
│ ├── nginx.conf # nginx configuration incl. /api proxy
│ └── proxy.conf.json # Dev server proxy configuration
├── packages/
│ └── shared/ # Shared library (@dividends/shared)
│ └── src/ # Shared types and utilities
├── docs/ # Project documentation (Docker, features, architecture)
├── scripts/
│ └── redeploy.sh # Rebuild and restart the Docker stack after a change
├── docker-compose.yml # Full stack: PostgreSQL, API and frontend
├── .env.example # Template for environment variables
├── .nvmrc # Node version specification
└── package.json # Root package configuration
- docs/DOCKER.md - Docker and Podman deployment
- docs/architecture/ - Architecture documentation (arc42)
- docs/CURRENCY_FEATURE.md - Currencies and exchange rates
- docs/SECURITY_PRICES.md - End-of-day security prices
- docs/TOAST_NOTIFICATION_SYSTEM.md - Toast notifications in the frontend
# Open interactive project graph
nx graphNx Console is an editor extension that lets you run tasks, generate code, and improves code autocompletion. Available for VSCode and IntelliJ.
To set up continuous integration with Nx Cloud (optional):
npx nx connectLearn more about Nx on CI.