๐ ๏ธ Development Setup Guide
This guide will help you set up the Backstage Cinema development environment on your local machine.
๐ Prerequisitesโ
Required Softwareโ
- Node.js (v18 or higher) - Download
- Docker & Docker Compose - Download
- Git - Download
- Make (optional, for convenience commands)
Recommended Toolsโ
- Visual Studio Code with extensions:
- REST Client (for API testing)
- PostgreSQL (for database management)
- Docker (for container management)
- Postman or Insomnia (for API testing)
- pgAdmin (included in Docker setup)
๐ Quick Startโ
1. Clone the Repositoryโ
git clone https://github.com/your-org/backstage-cinema
cd backstage-cinema
2. Backend Setupโ
cd backstage_backend
# Install dependencies
npm install
# Start services (PostgreSQL, pgAdmin, API)
make up
# Verify everything is running
make health
3. Documentation Setupโ
cd ../backstage_documentation
# Install dependencies
npm install
# Start documentation site
npm start
๐ง Detailed Setupโ
Backend Environmentโ
The backend uses Docker Compose for local development. Here's what gets started:
Services Overviewโ
Service | Port | Purpose |
---|---|---|
PostgreSQL | 5432 | Main database |
pgAdmin | 8080 | Database administration |
Cinema API | 3000 | REST API server |
Environment Variablesโ
The system uses these default environment variables:
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=cinema_management
DB_USER=cinema_user
DB_PASSWORD=cinema_pass
# API Configuration
NODE_ENV=development
PORT=3000
Make Commandsโ
The backend includes a comprehensive Makefile:
# Essential commands
make up # Start all services
make down # Stop all services
make restart # Restart all services
make health # Check service health
# Development
make dev # Start development mode
make test # Run tests
make lint # Run ESLint
# Database
make db-shell # Connect to database
make db-reset # Reset database (WARNING: destroys data)
make seed # Seed with sample data
# Maintenance
make logs # View logs
make clean # Clean up containers
make status # Show service status
๐๏ธ Database Setupโ
Initial Setupโ
The database is automatically initialized when you run make up
. The setup includes:
- Schema creation from
/database/init/02_create_tables.sql
- Sample data from
/database/init/03_seed_data.sql
- Enum types from
/database/init/01_create_enums.sql
Database Accessโ
Via pgAdmin (Recommended)โ
- Open http://localhost:8080
- Login with:
- Email:
admin@cinema.com
- Password:
admin123
- Email:
- Add server connection:
- Host:
postgres
- Port:
5432
- Database:
cinema_management
- Username:
cinema_user
- Password:
cinema_pass
- Host:
Via Command Lineโ
# Connect to PostgreSQL shell
make db-shell
# Or directly with psql
docker-compose exec postgres psql -U cinema_user -d cinema_management
Sample Dataโ
The system comes with sample data including:
- 5 movies (Avatar, Top Gun, Black Panther, Spider-Man, The Batman)
- Multiple sessions per movie
- Room configurations with different types
- Sample inventory items
๐งช Testingโ
Running Testsโ
# Run all tests
make test
# Run tests with coverage
npm run test -- --coverage
# Run specific test file
npm run test -- tests/movie.test.js
Test Databaseโ
Tests use the same database as development. The test suite:
- Creates test data
- Cleans up after each test
- Uses transactions when possible
- Runs isolated from production data
API Testingโ
Using cURLโ
# Check API health
curl http://localhost:3000/health
# Get all movies
curl http://localhost:3000/api/movies
# Create a movie
curl -X POST http://localhost:3000/api/movies \
-H "Content-Type: application/json" \
-d '{"title": "Test Movie", "duration_min": 120}'
Using VS Code REST Clientโ
Create a api-tests.http
file:
### Health Check
GET http://localhost:3000/health
### Get Movies
GET http://localhost:3000/api/movies
### Create Movie
POST http://localhost:3000/api/movies
Content-Type: application/json
{
"title": "New Movie",
"duration_min": 120,
"genre": "Action",
"description": "A test movie"
}
๐ Documentation Developmentโ
Docusaurus Setupโ
The documentation uses Docusaurus v3:
cd backstage_documentation
# Install dependencies
npm install
# Start development server
npm start
# Build for production
npm run build
Adding New Documentationโ
- Create new markdown files in
/docs
- Update sidebar in
sidebars.ts
- Add navigation if needed in
docusaurus.config.ts
Example: Adding New Pageโ
# Create new doc
touch docs/new-feature.md
# Add to sidebar
# Edit sidebars.ts and add 'new-feature' to the array
๐ Development Workflowโ
Daily Developmentโ
- Start services:
make up
- Check health:
make health
- Make changes to code
- Run tests:
make test
- Check logs if needed:
make logs
Code Qualityโ
# Lint code
make lint
# Fix linting issues
npm run lint -- --fix
# Format code (if prettier is setup)
npm run format
Database Changesโ
Schema Updatesโ
- Create migration file in
/database/migrations
- Update
/database/init
files for fresh installs - Test migration with
make db-reset
andmake up
Sample Data Updatesโ
- Update
/database/init/03_seed_data.sql
- Reset database:
make db-reset
- Restart services:
make up
๐จ Troubleshootingโ
Common Issuesโ
Port Already in Useโ
# Check what's using the port
lsof -i :3000
# Kill the process
kill -9 <PID>
# Or change the port
export PORT=3001
make up
Database Connection Issuesโ
# Check PostgreSQL is running
make status
# View database logs
docker-compose logs postgres
# Reset database
make db-reset
Docker Issuesโ
# Clean up all containers
make clean
# Rebuild from scratch
docker-compose down -v
docker system prune -f
make up
Performance Issuesโ
Database Queriesโ
# Monitor database performance
make db-shell
# Then in PostgreSQL:
# \x on
# SELECT * FROM pg_stat_activity;
Memory Usageโ
# Check container memory usage
docker stats
# Check system resources
htop
๐ง Configurationโ
Environment Filesโ
Create custom environment files:
# Development environment
cp .env.example .env.development
# Production environment
cp .env.example .env.production
Docker Configurationโ
Modify docker-compose.yml
for custom setups:
# Example: Change PostgreSQL port
postgres:
ports:
- "5433:5432" # Changed from 5432:5432
๐ Additional Resourcesโ
Documentation Linksโ
External Resourcesโ
Communityโ
๐ฏ Next Stepsโ
After completing the setup:
- Explore the API using the interactive documentation
- Review the codebase structure and patterns
- Run the test suite to understand functionality
- Try the demo script:
make demo
- Check out the user stories for development priorities
Need help? Check the troubleshooting section or create an issue in the project repository.