A RESTful API service for managing movie ratings and reviews, built with TypeScript, Express.js, and Prisma ORM.
This service allows users to register anonymously and submit ratings and reviews for movies. It provides a clean API for managing user registrations and movie reviews with unique constraints to prevent duplicate reviews per user per movie.
- Backend Framework: Express.js 5.1.0
- Language: TypeScript 5.9.2
- Database ORM: Prisma 6.16.1
- Database: PostgreSQL
- Additional Libraries:
- CORS for cross-origin resource sharing
- UUID for unique identifier generation
The application uses PostgreSQL with the following models:
id: UUID (Primary Key)reviews: Relation to Review model
id: UUID (Primary Key)movieId: String (Movie identifier)rating: Integer (Movie rating)comment: String (Review comment)createdAt: DateTime (Timestamp)userId: UUID (Foreign Key to User)- Unique Constraint: (userId, movieId) - Prevents duplicate reviews
POST /v1/users/register- Register a new anonymous user
POST /v1/reviews- Add a new movie reviewGET /v1/reviews/:movieId- Get all reviews for a specific movie
Before running the application, make sure you have:
- Node.js (v16 or higher)
- npm or yarn
- PostgreSQL database running
- Git (for cloning the repository)
git clone <repository-url>
cd movies-rating-servicenpm installCreate a .env file in the root directory with your database configuration:
DATABASE_URL="postgresql://username:password@localhost:5432/database_name?schema=public"
PORT=3000# Generate Prisma client
npx prisma generate
# Apply migration
npx prisma migrate dev
# (Optional) View your database in Prisma Studio
npx prisma studionpm run dev# Build the project
npm run build
# Start the production server
npm startThe server will start on http://localhost:3000 (or the port specified in your .env file).
npm run dev- Start development server with auto-reloadnpm run build- Build TypeScript to JavaScriptnpm start- Start production server
- Controllers: Handle HTTP requests and responses
- Services: Contain business logic and database operations
- Routes: Define API endpoints and middleware
- Prisma Client: Database access layer