Backend API for WDS Healthcare project 2025, built with Express.js, TypeScript, and PostgreSQL.
- Runtime: Node.js
- Framework: Express.js 5
- Language: TypeScript
- Database: PostgreSQL (via Docker)
- ORM: Prisma
- Testing: Vitest
- Code Formatting: Prettier
Before you begin, ensure you have the following installed:
- Node.js (v20 or higher recommended)
- Docker and Docker Compose (for local PostgreSQL database)
- npm (comes with Node.js)
npm installCopy the example environment file:
cp .env.example .envThe .env file contains:
DATABASE_URL- PostgreSQL connection stringPORT- Server port (default: 3000)NODE_ENV- Environment (development/production)
Start PostgreSQL using Docker Compose:
npm run docker:upThis will:
- Pull the PostgreSQL 16 image (if not already downloaded)
- Start a container named
healthcare-postgres - Create a persistent volume for data
- Expose the database on
localhost:5432
Push the Prisma schema to create tables:
npm run db:pushOr create a migration (recommended for production):
npm run db:migrateGenerate the Prisma Client (usually done automatically, but can be run manually):
npm run db:generatenpm run devThe server will start on http://localhost:3000 (or the port specified in .env).
npm run dev- Start development server with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Start production server (requires build first)
npm run db:generate- Generate Prisma Clientnpm run db:push- Push schema changes to database (development)npm run db:migrate- Create and apply a migrationnpm run db:migrate:deploy- Deploy migrations (production)npm run db:studio- Open Prisma Studio (database GUI)npm run db:seed- Run database seed script
npm run docker:up- Start PostgreSQL containernpm run docker:down- Stop PostgreSQL containernpm run docker:logs- View PostgreSQL logs
npm test- Run tests oncenpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage report
npm run format- Format all code with Prettiernpm run format:check- Check code formatting without changes
backend/
├── src/
│ ├── controllers/ # Request handlers
│ ├── routes/ # API route definitions
│ ├── lib/ # Shared utilities
│ │ └── prisma.ts # Prisma client instance
│ └── index.ts # Application entry point
├── prisma/
│ └── schema.prisma # Database schema
├── docker-compose.yml # PostgreSQL container configuration
├── .env # Environment variables (gitignored)
├── .env.example # Environment variables template
└── package.json # Dependencies and scripts
Prisma Studio provides a visual interface to view and edit your database:
npm run db:studioThis opens a web interface at http://localhost:5555.
- Edit
prisma/schema.prisma - Push changes (development):
npm run db:push
- Or create a migration (recommended):
This creates a migration file in
npm run db:migrate
prisma/migrations/for version control.
import { prisma } from './lib/prisma.js';
// Example: Get all users
const users = await prisma.user.findMany();
// Example: Create a user
const newUser = await prisma.user.create({
data: {
email: 'user@example.com',
name: 'John Doe',
},
});The API is organized by resource:
/api/users- User management/api/appointments- Appointment management/api/documents- Document management
-
Start the database (if not already running):
npm run docker:up
-
Start the development server:
npm run dev
-
Make changes to your code
-
Test your changes:
npm test -
Format your code before committing:
npm run format
Create branches off of dev using the format: <name>/type-title-of-this-branch
Valid types:
feat: New featurefix: Bug fixrefact: Refactordocs: Documentationchore: Maintenance task
- Create a branch from
dev - Make your changes
- Run tests:
npm test - Format code:
npm run format - Open a pull request to
dev
dev- Development branch (where contributions are made)qa- Quality assurance branch (functional version for testing)prod- Production branch (production-ready code)
If you can't connect to the database:
-
Check if the container is running:
docker-compose ps
-
View database logs:
npm run docker:logs
-
Restart the database:
npm run docker:down npm run docker:up
If you get errors about Prisma Client:
npm run db:generateIf port 3000 is already in use, change the PORT in your .env file.
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Required |
PORT |
Server port | 3000 |
NODE_ENV |
Environment (development/production) | development |
ISC