# sample-app-java-mflix **Repository Path**: mirrors_mongodb/sample-app-java-mflix ## Basic Information - **Project Name**: sample-app-java-mflix - **Description**: This is an artifact repository that packages up the frontend and backend components for the Java Driver sample app in the sample app monorepo. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-26 - **Last Updated**: 2025-11-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Java Spring Boot MongoDB Sample MFlix Application This is a full-stack movie browsing application built with Java Spring Boot and Next.js, demonstrating MongoDB operations using the `sample_mflix` dataset. The application showcases CRUD operations, aggregations, and MongoDB Search using Spring Data MongoDB. ## Project Structure ``` ├── README.md ├── client/ # Next.js frontend (TypeScript) └── server/ # Java Spring Boot backend ├── src/ ├── pom.xml ├── .env.example └── mvnw ``` ## Prerequisites - **Java 21** or higher - **Node.js 20** or higher - **MongoDB Atlas cluster or local deployment** with the `sample_mflix` dataset loaded - [Load sample data](https://www.mongodb.com/docs/atlas/sample-data/) - **Maven** (included via Maven Wrapper) - **Voyage AI API key** (For MongoDB Vector Search) - [Get a Voyage AI API key](https://www.voyageai.com/) ## Getting Started ### 1. Configure the Backend Navigate to the Java Spring server directory: ```bash cd server ``` Create a `.env` file from the example: ```bash cp .env.example .env ``` Edit the `.env` file and set your MongoDB connection string: ```env # MongoDB Connection # Replace with your MongoDB Atlas connection string or local MongoDB URI MONGODB_URI=mongodb+srv://:@.mongodb.net/sample_mflix?retryWrites=true&w=majority # Voyage AI Configuration # API key for Voyage AI embedding model (required for Vector Search) VOYAGE_API_KEY=your_voyage_api_key # Server Configuration # Port on which the Spring Boot application will run PORT=3001 # CORS Configuration # Allowed origin for cross-origin requests (frontend URL) # For multiple origins, separate with commas CORS_ORIGIN=http://localhost:3000 # Optional: Enable MongoDB Search tests # Uncomment the following line to enable Search tests # ENABLE_SEARCH_TESTS=true ``` **Note:** Replace `username`, `password`, and `cluster` with your actual MongoDB Atlas credentials. Replace `your_voyage_api_key` with your key. ### 2. Start the Backend Server From the `server` directory, run: ```bash # Using Maven Wrapper (recommended) ./mvnw spring-boot:run # Or on Windows mvnw.cmd spring-boot:run ``` The server will start on `http://localhost:3001`. You can verify it's running by visiting: - API root: http://localhost:3001/ - API documentation (Swagger UI): http://localhost:3001/swagger-ui.html ### 3. Configure and Start the Frontend Open a new terminal and navigate to the client directory: ```bash cd client ``` Install dependencies: ```bash npm install ``` Start the development server: ```bash npm run dev ``` The Next.js application will start on `http://localhost:3000`. ### 4. Access the Application Open your browser and navigate to: - **Frontend:** http://localhost:3000 - **Backend API:** http://localhost:3001 - **API Documentation:** http://localhost:3001/swagger-ui.html ## Features - **Browse Movies:** View a paginated list of movies from the sample_mflix dataset - **CRUD Operations:** Create, read, update and delete movies by using the MongoDB Java driver - **Search:** Search movies with filters by using MongoDB Search - **Vector Search:** Search movie plots with similar search terms by using MongoDB Vector Search - **Aggregations:** View data aggregations and analytics built with aggregation pipelines ## Development ### Backend Development The Java Spring Boot backend uses: - **Spring Data MongoDB** for database operations - **Spring Boot Web** for REST API - **SpringDoc OpenAPI** for API documentation - **Maven** for dependency management To run tests: ```bash cd server ./mvnw test ``` ### Frontend Development The Next.js frontend uses: - **React 19** with TypeScript - **Next.js 16** with App Router - **Turbopack** for fast development builds #### Development Mode For active development with hot reloading and fast refresh: ```bash cd client npm run dev ``` This starts the development server on `http://localhost:3000` with Turbopack for fast rebuilds. #### Production Build To create an optimized production build and run it: ```bash cd client npm run build # Creates optimized production build npm start # Starts production server ``` The production build: - Minifies and optimizes JavaScript and CSS - Optimizes images and assets - Generates static pages where possible - Provides better performance for end users #### Linting To check code quality: ```bash cd client npm run lint ``` ## Issues If you have problems running the sample app, please check the following: - [ ] Verify that you have set your MongoDB connection string in the `.env` file. - [ ] Verify that you have started the Java Spring server. - [ ] Verify that you have started the Next.js client. - [ ] Verify that you have no firewalls blocking access to the server or client ports. If you have verified the above and still have issues, please [open an issue](https://github.com/mongodb/docs-sample-apps/issues/new/choose) on the source repository `mongodb/docs-sample-apps`.