Getting Started
Getting Started
Relevant source files
The following files were used as context for generating this wiki page:
This page provides a step-by-step guide for setting up the Primebrick backend development environment. It covers prerequisites, infrastructure orchestration via Docker, environment configuration, and database initialization.
Prerequisites
Before starting, ensure the following tools are installed on your system:
- Node.js: Version 20 or higher (recommended).
- pnpm: Fast, disk space efficient package manager.
- Docker & Docker Compose: Required for running PostgreSQL, Casdoor, and NATS.
- Git: For version control and managing the GitFlow workflow docs/gitflow.md:1-4.
1. Infrastructure Setup
The project uses Docker Compose to manage the local infrastructure stack. This includes PostgreSQL 18, Casdoor (Identity Provider), and NATS (Message Broker).
Start the Stack
From the repository root, run:
Code
Services Overview
| Service | Image | Internal Port | External Port | Role |
|---|---|---|---|---|
postgres | postgres:18-bookworm | 5432 | 5432 | Primary database with pg_partman infra/docker-compose.postgres.yml:31-52 |
casdoor | casbin/casdoor:3.75.0 | 8000 | 8000 | OIDC Identity Provider infra/docker-compose.postgres.yml:61-70 |
nats | nats:latest | 4222 | 4222 | Message broker with JetStream infra/docker-compose.postgres.yml:86-93 |
Persistence
Data is persisted in Docker named volumes to survive container restarts:
primebrick_pg18_data: PostgreSQL data infra/docker-compose.postgres.yml:103-105.primebrick_casdoor_data: Casdoor configurations and uploads infra/docker-compose.postgres.yml:106-108.primebrick_nats_data: NATS JetStream state infra/docker-compose.postgres.yml:109-111.
Sources: infra/docker-compose.postgres.yml:29-112, AGENTS.md:30-31
2. Environment Configuration
Create a .env file in the root directory. You can use the following default values for local development:
Code
Note: If port
5432is occupied by a local PostgreSQL instance, setPG_HOST_PORT=5433in your.envand recreate the containers infra/docker-compose.postgres.yml:39-40.
Sources: infra/docker-compose.postgres.yml:33-40, AGENTS.md:42
3. Installation and Initialization
Follow these steps to prepare the application and database:
Install Dependencies
Code
Setup Casdoor
Bootstrap the Identity Provider with necessary organizations, applications, and roles:
Code
This script initializes the Casdoor instance defined in the Docker stack package.json:18.
Database Migrations
The project uses a patch-based migration system. Apply the latest patches to the database:
Code
This command checks the public.primebrick_database_patch table and applies missing .sql files AGENTS.md:53-54.
Seed Demo Data
To populate the database with sample customers:
Code
Sources: package.json:15-18, AGENTS.md:19-26
4. Running the Development Server
The backend uses tsx watch for hot-reloading during development.
Code
The API will be available at http://localhost:3001.
Port Management
If you encounter EADDRINUSE on port 3001, you can use the utility script to kill the existing process:
Code
Sources: package.json:7-8, AGENTS.md:33-35
Development Workflow and Data Flow
The following diagram illustrates the relationship between local development commands and the resulting infrastructure state.
Infrastructure Initialization Flow
This diagram bridges the "Natural Language Space" of setup tasks to the "Code Entity Space" of scripts and configurations.
Code
Sources: package.json:6-18, infra/docker-compose.postgres.yml:29-62, AGENTS.md:51-54
Request Flow Overview
When the dev server is running, requests flow through the following layers:
Code
Sources: package.json:7, AGENTS.md:75-138, src/openapi/openapi.ts:7-22
GitFlow and Versioning
This repository strictly follows GitFlow. AI agents and developers must adhere to the following:
- Branching: Never work on
mainordevelop. Createfeature/<slug>,release/<version>, orhotfix/<version>branches docs/gitflow.md:18-21. - Version Sync: The
package.jsonversion is automatically updated byscripts/version-sync.mjsduring theprebuildhook andpre-commithook package.json:10, .githooks/pre-commit:5. - Commits: AI agents must never commit without explicit user instruction AGENTS.md:5-9.
Sources: docs/gitflow.md:1-21, scripts/version-sync.mjs:69-91, .githooks/pre-commit:1-10