This document describes the multi-phase setup process required to initialize both the reference implementation API and the documentation site. The setup includes dependency installation, framework preparation, database client generation, and optional data seeding.
For information about running the API locally after setup, see Running Locally. For details on available Makefile commands, see Makefile Commands.
The RealWorld repository contains two primary applications that require separate setup procedures:
| Application | Location | Setup Target | Purpose |
|---|---|---|---|
| Reference Implementation | apps/api/ | reference-implementation-setup | Node.js API server with Nitro + Prisma |
| Documentation Site | apps/documentation/ | documentation-setup | Astro + Starlight static site generator |
Both setups are orchestrated through the root Makefile1-113 using declarative targets that abstract multi-step initialization processes.
The following tools must be installed before beginning setup:
The reference implementation requires a three-phase setup process that prepares the Nitro framework, installs dependencies, and generates the Prisma database client.
Sources: Makefile46-52 apps/api/package.json3-10
The first phase installs all npm dependencies specified in package.json.
Makefile Target:
make reference-implementation-setup-install-dependencies
Implementation: Makefile37-38
Installed Dependencies:
| Package | Type | Purpose |
|---|---|---|
@prisma/client | production | Generated database client for type-safe queries |
bcryptjs | production | Password hashing for user authentication |
slugify | production | Article slug generation |
nitropack | development | Server framework and build tool |
prisma | development | ORM and database migration CLI |
jsonwebtoken | development | JWT token generation and validation |
@ngneat/falso | development | Fake data generation for seeding |
Output: Creates apps/api/node_modules/ directory with all dependencies.
Sources: Makefile37-38 apps/api/package.json15-25
The second phase initializes the Nitro framework's build cache and development environment.
Makefile Target:
make reference-implementation-setup-nitro-prepare
Implementation: Makefile40-41
Executed Script:
apps/api/package.json6 - "prepare": "nitro prepare"
Purpose: The nitro prepare command:
.nitro/ build cache directoryOutput: Creates apps/api/.nitro/ directory with framework cache files.
Sources: Makefile40-41 apps/api/package.json6
The third phase generates the Prisma client from the database schema and creates the SQLite database file.
Makefile Target:
make reference-implementation-setup-db-generate
Implementation: Makefile43-44
Executed Script:
apps/api/package.json9 - "db:generate": "npx prisma generate"
Process Flow:
Generated Artifacts:
| Path | Description |
|---|---|
node_modules/@prisma/client/ | Type-safe database client with TypeScript definitions |
node_modules/.prisma/client/ | Generated runtime code for database access |
prisma/dev.db | SQLite database file (created if doesn't exist) |
Sources: Makefile43-44 apps/api/package.json9
All three phases can be executed sequentially with a single command:
make reference-implementation-setup
Implementation: Makefile46-52
This target executes all three phases in order and prints colored status messages:
INSTALLED DEPENDENCIES after Phase 1PREPARED NITRO after Phase 2GENERATED PRISMA after Phase 3Sources: Makefile46-52
After setup, the database can be populated with sample data using the seed script:
npm run db:seed
Implementation:
apps/api/package.json10 - "db:seed": "npx prisma db seed"
Seed Configuration:
apps/api/package.json12-13 - Executes prisma/seed.ts using ts-node --transpile-only
The seed script uses @ngneat/falso to generate realistic fake data for users, articles, comments, and tags.
Sources: apps/api/package.json10-13
The documentation site requires a simpler single-phase setup using bun.
Makefile Target:
make documentation-setup
Implementation: Makefile96-97
Process:
Installed Dependencies:
astro - Static site generator@astrojs/starlight - Documentation theme@astrojs/tailwind - TailwindCSS integration@astrojs/check - TypeScript validationOutput: Creates apps/documentation/node_modules/ directory.
Sources: Makefile96-97
The reference implementation requires specific environment variables for operation. These are typically set during testing but can be configured for development.
| Variable | Purpose | Example Value | Used By |
|---|---|---|---|
JWT_SECRET | Secret key for signing JWT tokens | dxLmhnE0pRY2+vUlu+i5Pxh8LTxLBTgBWdp82W74mMs= | Authentication middleware |
When running API tests, additional variables configure the test environment:
| Variable | Purpose | Default | Source |
|---|---|---|---|
APIURL | API endpoint URL | https://api.realworld.io/api | api/run-api-tests.sh6 |
USERNAME | Test user username | u{timestamp} | api/run-api-tests.sh7 |
EMAIL | Test user email | {USERNAME}@mail.com | api/run-api-tests.sh8 |
PASSWORD | Test user password | password | api/run-api-tests.sh9 |
DELAY_REQUEST | Delay between test requests (ms) | 500 | api/run-api-tests.sh11 |
Example Test Execution:
Makefile58 sets JWT_SECRET when running the development server for testing.
Sources: Makefile58 api/run-api-tests.sh6-11
After successful setup, the following directory structure is created:
Sources: Makefile37-97
After completing setup, verify the installation:
Check dependencies installed:
Should contain generated Prisma client files.
Check Nitro prepared:
Should contain build cache directory.
Check database created:
Should exist as SQLite database file.
Start development server:
Should start Nitro server on http://localhost:3000
Check dependencies installed:
Should contain Astro package.
Start development server:
Should start Astro dev server on http://localhost:4321
Sources: apps/api/package.json5 Makefile99-100
To reset the environment and remove all generated files:
make non-default-files-clean
Implementation: Makefile89-91
Removes:
apps/api/node_modules/ - All npm dependenciesapps/api/prisma/dev.db - SQLite database filemake documentation-clean
Implementation: Makefile111-112
Removes:
apps/documentation/.astro/ - Astro build cacheapps/documentation/dist/ - Built static siteapps/documentation/node_modules/ - All dependenciesSources: Makefile89-112
| Issue | Cause | Solution |
|---|---|---|
npm i fails | Node version < 18.18 | Upgrade Node.js to >= 18.18 |
prisma generate fails | Corrupted schema cache | Run npx prisma format to validate schema |
nitro prepare fails | Permission issues | Check write permissions in apps/api/ directory |
| Port 3000 already in use | Another process using port | Kill existing process or set PORT environment variable |
If setup fails at any phase:
make non-default-files-cleannode_modules: rm -rf apps/api/node_modulesmake reference-implementation-setupSources: Makefile46-91
Refresh this wiki