This project is a template for a backend system using TypeScript, Node.js, Express, PostgreSQL, and Prisma ORM. It provides a foundation for building a robust API with database integration, perfect for handling job applications and candidate information.
To create a new project using this template:
-
Navigate to the GitHub repository: https://github.com/AtlasNft/popp-backend-coding-exercise
-
Click on the "Use this template" button near the top-right of the page.
-
Choose a name for your new repository and select where you want to create it.
-
Click "Create repository from template".
-
Once created, clone your new repository to your local machine:
git clone https://github.com/<your-username>/<your-new-repo-name>.git cd <your-new-repo-name> -
Follow the "Getting Started" instructions below to set up your new project.
Before you begin, ensure you have the following installed on your system:
- Docker and Docker Compose
- Git
- Node.js (v14 or later)
- Yarn
-
If you haven't already, clone your repository:
git clone https://github.com/<your-username>/<your-new-repo-name>.git cd <your-new-repo-name> -
Install dependencies:
yarn install -
Create a
.envfile in the root directory and add the following environment variables:POSTGRES_PASSWORD=your_postgres_password DATABASE_URL=postgres://postgres:${POSTGRES_PASSWORD}@localhost:5432/postgresNote: The
DATABASE_URLformat ispostgresql://username:password@host:port/database_name -
Start the PostgreSQL database using Docker:
docker-compose up -d db -
Run database migrations and generate Prisma client:
yarn prisma:migrate:deploy -
Start the development server:
yarn dev
The application should now be running at http://localhost:3000. You can verify this by accessing the hello world
endpoint at http://localhost:3000/api/hello.
popp-backend-coding-exercise/
├── Dockerfile
├── README.md
├── docker-compose.yml
├── package.json
├── prisma/
│ ├── migrations/
│ └── schema.prisma
├── src/
│ ├── app.ts
│ ├── common/
│ ├── controllers/
│ ├── middleware/
│ ├── routes/
│ ├── server.ts
│ └── services/
├── tests/
├── tsconfig.json
├── webpack.config.js
└── yarn.lock
yarn start: Run the production buildyarn dev: Start the development server with hot-reloadingyarn build: Build the project using Webpackyarn build:start: Build and start the Docker containersyarn prisma:generate: Generate Prisma clientyarn prisma:migrate: Run Prisma migrations in development (also generates the client)yarn prisma:migrate:deploy: Run Prisma migrations in production (also generates the client)yarn prisma:studio: Open Prisma Studio for database management
- Hello World
- URL:
/api/hello - Method: GET
- Response: Returns a simple string
- URL:
The project uses Prisma ORM with a PostgreSQL database. Here's an overview of the main models:
- Fields:
id,candidateId,jobId,status,createdAt,updatedAt - Status can be:
CREATED,ONGOING,COMPLETED - Unique constraint on
candidateIdandjobIdcombination
- Fields:
id,phoneNumber,firstName,lastName,emailAddress - Has a one-to-many relationship with
Conversation
For the full schema details, refer to the prisma/schema.prisma file in the project.
If you make changes to the schema.prisma file, follow these steps:
- Update the
schema.prismafile with your changes. - Run the migration command:
This command will generate a new migration, apply it to your database, and generate the updated Prisma client.
yarn prisma:migrate
If you prefer to run the entire application using Docker:
-
Build and start the Docker containers:
yarn build:start -
Run the database migrations:
docker-compose exec app yarn prisma:migrate:deploy
The application will be available at http://localhost:3000, and the PostgreSQL database will be accessible on port
5432.
The PostgreSQL data is persisted in a Docker volume. If you need to delete this volume and start fresh, you can use the following command:
docker volume remove <your-new-repo-name>_postgres-data
Note: This will delete all data in the database. Use with caution.
- If you encounter connection issues with the database, ensure that the PostgreSQL container is running and that the
DATABASE_URLin your.envfile is correct. - If you see Prisma-related errors, try running
yarn prisma:generateto ensure your Prisma client is up-to-date with your schema. - For Docker-related issues, ensure Docker is running on your machine and try rebuilding the containers with
docker-compose up --build.
Contributions are welcome! Please feel free to submit a Pull Request.
- The project uses Prisma as an ORM. When you run migrations (either
prisma:migrateorprisma:migrate:deploy), it automatically generates the Prisma client. - Always run migrations after pulling changes from the repository that include schema modifications.
- The
src/directory contains the main application code, including controllers, routes, and services. - Tests can be added to the
tests/directory. - The project uses Webpack for bundling, configured in
webpack.config.js.
This project is licensed under the MIT License.