Prerequisites
Before you begin, ensure you have:- Bun >= 1.3.1 installed (installation guide)
- Docker and Docker Compose (for infrastructure services)
- Git for cloning the repository
- At least 4GB of available RAM
Development setup
Install dependencies
Install all workspace dependencies using Bun:This installs packages for all workspaces in the monorepo using the versions defined in the root
package.json catalog.Configure environment variables
Copy the example environment file for the server:Edit
apps/server/.env and configure the required variables:apps/server/.env
The infrastructure services (PostgreSQL, Redis, Elasticsearch) will run in Docker, but the server and web apps will run locally with hot reload.
Start infrastructure services
Start PostgreSQL, Redis, Elasticsearch, and Kibana using Docker Compose:This reads environment variables from
apps/server/.env and starts the development infrastructure stack.The infrastructure containers run in the background. To view logs:
Generate database migration
On first setup, generate the initial database migration:This creates SQL migration files in
packages/db/src/migrations/ based on the Drizzle schema definitions in packages/db/src/schema/.Migrations run automatically when the server starts via
runMigrations() in apps/server/src/index.ts:252.Start development servers
Start both the server and web interface with hot reload:This uses Turborepo to run all dev tasks in parallel. You can also run services individually:Once running, access:
- Web interface: http://localhost:3001
- Server API: http://localhost:3000
- API reference: http://localhost:3000/api-reference
- Bull Board: http://localhost:3000/admin/queues/
Monorepo structure
Nanahoshi uses a Bun workspaces + Turborepo monorepo:Key directories
apps/server/src/index.ts- Server entry point, mounts routes and starts workersapps/web/src/routes/- TanStack Router file-based routespackages/api/src/routers/- oRPC router definitionspackages/api/src/infrastructure/- Queue, search, and worker infrastructurepackages/db/src/schema/- Database schema definitionspackages/db/src/migrations/- Generated SQL migrations
Database workflow
Nanahoshi uses Drizzle ORM with SQL migrations:Modify the schema
Edit schema files in
packages/db/src/schema/:general.ts- Application tables (books, libraries, authors, etc.)auth.ts- better-auth tables (users, sessions, organizations)
Generate a migration
After modifying the schema, generate a new SQL migration:This creates a timestamped migration file in
packages/db/src/migrations/.Database tools
Additional database commands:Development commands
Running services
Building
Code quality
- Tabs for indentation
- Double quotes for strings
Infrastructure management
Infrastructure services use
docker-compose.dev.yml and read configuration from apps/server/.env.Clean up
Testing
Nanahoshi uses Bun’s built-in test runner. Tests live in__tests__/ directories next to the code they test:
Tests mock all external dependencies (database, queues, filesystem) using
mock.module(). No infrastructure needs to be running.Project conventions
Package manager
Nanahoshi uses Bun as the package manager and runtime. Always use:Type safety
The project uses oRPC for end-to-end type safety between backend and frontend:- Backend exports
AppRoutertype frompackages/api/src/routers/index.ts - Frontend imports the type and gets full autocomplete and type checking
- Changes to API routes automatically update frontend types
Workspace imports
Packages reference each other via workspace aliases:package.json files with workspace:* version specifiers.
Dependency versions
Shared dependency versions are defined in the rootpackage.json workspaces.catalog field:
package.json
catalog::
packages/api/package.json
Troubleshooting
Port conflicts
If you see “port already in use” errors:- Server uses port 3000
- Web uses port 3001
- PostgreSQL uses port 5432
- Redis uses port 6379
- Elasticsearch uses port 9200
- Kibana uses port 5601
Database connection errors
Verify that:- Infrastructure is running:
docker compose -f docker-compose.dev.yml ps DATABASE_URLinapps/server/.envmatches the PostgreSQL container- PostgreSQL is healthy:
docker compose -f docker-compose.dev.yml logs postgres
Elasticsearch not starting
Elasticsearch requires at least 2GB of RAM. On Linux, you may need to increasevm.max_map_count:
Type errors after schema changes
After modifying database schema:- Run
bun run db:generateto create a migration - Restart the server to apply the migration
- Run
bun run check-typesto verify types
What’s next?
Architecture
Learn about Nanahoshi’s architecture and design patterns
Contributing
Guidelines for contributing to Nanahoshi