A RESTful API for managing books and reviews with caching support using Express.js, Prisma, PostgreSQL, and Redis.
π Want to get started quickly? Check out QUICK_START.md for a 2-minute setup!
- Books Management: Create and retrieve books
- Reviews Management: Add and retrieve reviews for books
- Caching: Redis-based caching for improved performance
- Database: PostgreSQL with Prisma ORM
- API Documentation: Swagger/OpenAPI documentation
- Testing: Comprehensive unit and integration tests
Choose one setup method:
- Docker and Docker Compose
- Node.js 18+
- Internet connection for cloud databases
- Node.js 18+ and Docker
git clone <your-repo-url>
cd processvenue-assessmentCopy the environment template:
cp .env.example .envThe default values in env.example work perfectly with Docker Compose setup.
Option A: Full Application Stack
# Build and start all services (PostgreSQL, Redis, and the API)
docker-compose up --build
# Or run in detached mode
docker-compose up -d --buildOption B: Development Mode (External Dependencies Only)
# Start only PostgreSQL and Redis for local development
docker-compose -f docker-compose.dev.yml up -d
# Then run the application locally
npm install
npm run db:migrate
npm run devAfter the services are running, initialize the database:
# If using full Docker setup
docker-compose exec app npm run db:migrate
# If running locally
npm run db:migrate- API Base URL: http://localhost:3000
- API Documentation: http://localhost:3000/api-docs
- Health Check: http://localhost:3000/
git clone <your-repo-url>
cd processvenue-assessment# Option A: Use the automated cloud setup script
./setup-cloud.sh
# Option B: Manual cloud setup
cp env.example .env
# Edit .env file with your cloud database URLs
npm install
npm run db:migrate
npm startFree Cloud Databases:
- Supabase (PostgreSQL): https://supabase.com - 500MB free
- Redis Cloud: https://redis.com/try-free - 30MB free
- Railway: https://railway.app - PostgreSQL hosting
- PlanetScale: https://planetscale.com - MySQL (requires schema modification)
Shared Demo Databases:
- Use our pre-configured demo databases (included in setup script)
- No registration required - perfect for testing
Same as Docker setup - your API will be available at http://localhost:3000
| Feature | Docker Setup | Cloud Databases | Hybrid Setup |
|---|---|---|---|
| Prerequisites | Docker only | Node.js only | Docker + Node.js |
| Setup Time | ~2 minutes | ~1 minute | ~2 minutes |
| Internet Required | No (after images) | Yes (always) | Partial |
| Data Persistence | Local volumes | Cloud storage | Flexible |
| Performance | Fastest | Network dependent | Mixed |
| Best For | Local development | Quick testing | Production |
| Scalability | Single machine | Cloud scalable | Hybrid approach |
- π³ Docker Setup: Best for development, offline work, full control
- βοΈ Cloud Databases: Best for quick testing, demos, sharing
- π§ Hybrid Setup: Best for production, team development
GET /api/books- Get all booksPOST /api/books- Create a new book
GET /api/reviews/:bookId- Get reviews for a specific bookPOST /api/reviews- Create a new review
id(UUID, Primary Key)title(String)author(String)createdAt(DateTime)updatedAt(DateTime)
id(UUID, Primary Key)bookId(String, Foreign Key)name(String, Reviewer Name)rating(Integer, 1-5)comment(String, Optional)createdAt(DateTime)updatedAt(DateTime)
| Variable | Description | Local Docker Default | Cloud Example |
|---|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql://admin:password123@localhost:5432/processvenue |
postgresql://postgres:pass@project.supabase.co:5432/postgres |
REDIS_URL |
Redis connection string | redis://localhost:6379 |
redis://default:pass@host.redis.com:12345 |
PORT |
Server port | 3000 |
3000 |
API_BASE_URL |
Base URL for API documentation | http://localhost:3000 |
http://localhost:3000 |
Local Docker:
DATABASE_URL=postgresql://admin:password123@localhost:5432/processvenue
REDIS_URL=redis://localhost:6379Cloud Databases:
DATABASE_URL=postgresql://postgres:your_password@abc123.supabase.co:5432/postgres
REDIS_URL=redis://default:your_password@your-redis.redis.com:12345# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage# Run database migrations
npm run db:migrate
# Generate Prisma client
npm run db:generate
# Reset database (careful in production!)
npx prisma migrate reset# Build and start services
docker-compose up --build
# Start services in background
docker-compose up -d
# Stop services
docker-compose down
# View logs
docker-compose logs app
# Restart a service
docker-compose restart app
# Execute commands in containers
docker-compose exec app npm test
docker-compose exec postgres psql -U admin -d processvenueThe application implements intelligent caching:
- Books: Cached for 5 minutes (300 seconds)
- Cache Invalidation: Automatically clears when new books are created
- Fallback: Gracefully falls back to database when Redis is unavailable
- Cache Miss Handling: Seamlessly serves from database and populates cache
- PostgreSQL Data: Stored in Docker volume
postgres_data - Redis Data: Stored in Docker volume
redis_data - Data Survival: Data persists between container restarts
For production deployment:
- Update environment variables in
.env - Use proper PostgreSQL and Redis credentials
- Consider using managed database services
- Set up proper logging and monitoring
- Use container orchestration (Kubernetes, Docker Swarm)
Docker Compose fails to start:
# Check if ports are already in use
docker-compose down
docker system prune -f
docker-compose up --buildDatabase connection issues:
# Check if PostgreSQL is ready
docker-compose logs postgres
# Manually test connection
docker-compose exec postgres psql -U admin -d processvenueRedis connection issues:
# Check Redis status
docker-compose logs redis
# Test Redis connection
docker-compose exec redis redis-cli ping# All services
docker-compose logs
# Specific service
docker-compose logs app
docker-compose logs postgres
docker-compose logs redis
# Follow logs in real-time
docker-compose logs -f appprocessvenue-assessment/
βββ src/
β βββ routes/ # API route handlers
β βββ lib/ # Shared utilities (Prisma, Redis, Swagger)
β βββ __tests__/ # Test files
β βββ index.ts # Application entry point
βββ prisma/
β βββ schema.prisma # Database schema
β βββ migrations/ # Database migrations
βββ docs/
β βββ swagger.yaml # API documentation
βββ docker-compose.yml # Full application stack
βββ docker-compose.dev.yml # Development dependencies only
βββ Dockerfile # Application container
βββ README.md # This file
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
npm test - Submit a pull request
ISC