This project manages cafes and their employees, providing a backend built with Node.js and a frontend developed with React.
This application is hosted on Digital Ocean. Access the live version at HERE.
- Assignment is an associative entity between Employee and Cafe whereby Employee can possibly have more than 1 assignment.
- However to enforce the constraints that a single employee cannot be assigned to more than 1 cafe, the exposed endpoint on the backend limits the creation of the employee together with the assignment to their respective cafe.
- Subsequently we want to update the employee's assignment, we cannot put a NULL field and have to select an existing cafe.
- Node.js (v18 or later)
- Docker and Docker Compose
- MySQL (if running without Docker)
- I have included both
.envfiles for both backend and frontend for ease of deployment and testing by other users. The following steps below for Environment Setup should be the apprioriate way of managing.env.
Important: I understand that this is not recommended and
.envshould not be uploaded onto Github, especially for production.
Create a .env file in both the backend and frontend directories with the following contents based on example.env for the required variables:
Backend .env:
DATABASE_URL=mysql://root:root@db:3306/cafedb
FRONTEND_URL=http://localhost:5173
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=cafedb
Frontend .env:
VITE_BACKEND_URL="http://localhost:3000"
-
Ensure Docker and Docker Compose are installed.
-
Set up the environment variables in the
.envfile. -
Navigate to the project root directdory (where the
docker-compose.ymlfile is located). -
Run the following command to build and start the containers:
docker-compose up --build
-
The backend will be available at
http://localhost:3000.
The frontend will automatically spin up alongside the backend. Access it at http://localhost:5173.
Commands except step (1) must be run in /backend directory
-
Create a MySQL database:
mysql -u root -p -- enter your password --- CREATE DATABASE cafedb; # must match the .env
-
Install dependencies:
npm install
-
Generate Prisma client:
npx prisma generate
-
Push the database schema:
npx prisma db push
-
Seed the database:
npm run seed
-
Start the development server:
npm run start
Commands must be run in /frontend directory
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
GET /api/cafes: Get all cafes or filter by location- Query Parameters:
location(optional): Filter cafes by location
- Response: List of cafes sorted by the highest number of employees first
- Query Parameters:
-
POST /api/cafe: Create a new cafe- Body: Cafe details (including logo upload)
-
PUT /api/cafe: Update a cafe by ID- Body: Updated cafe details (including logo upload)
-
GET /api/cafes/:id: Get a specific cafe by ID
DELETE /api/employee/:idDelete an employee by ID
GET /api/assignments/employee/:employeeId: Get assignment record by employee IDGET /api/employees: Get employees with their assignments
DELETE /api/cafe: Delete a cafe and its associated dataPUT /api/employee: Update an employee and their assignmentPOST /api/employee: Register a new employee for a cafe- Creates a new employee in the database and establishes the relationship between the employee and a café.
GET /api: Hello World test route
/api/cafe_logos/*: Serve cafe logo images, falling back to a default logo if the requested logo is not found.
The seed_db.js script in the /backend/prisma directory populates the database with initial data, reading from seed_data.json and creating cafes, employees, and random assignments.
- Backend: Express.js, Prisma ORM, MySQL, Docker, Node.js
- Frontend: React.js, Vite, Typescript, Tanstack Query, Tanstack Router, Redux Form, Material UI
