Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Database
DATABASE_URL="postgresql://healthcare_user:healthcare_password@localhost:5432/healthcare_db?schema=public"

# Server
PORT=3000
NODE_ENV=development
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ temp/
# package-lock.json
# yarn.lock
# pnpm-lock.yaml

/src/generated/prisma
295 changes: 254 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,293 @@
# PROJECT NAME
# 25-HealthCare Backend

below are common sections that you may like to populate or leave empty to populate later. refer to the template repo `WesternDeveloperSociety/project-spec-template` for the default.
Backend API for WDS Healthcare project 2025, built with Express.js, TypeScript, and PostgreSQL.

## Purpose
## Tech Stack

_what and who is this project for?_
- **Runtime**: Node.js
- **Framework**: Express.js 5
- **Language**: TypeScript
- **Database**: PostgreSQL (via Docker)
- **ORM**: Prisma
- **Testing**: Vitest
- **Code Formatting**: Prettier

## Contribution
## Prerequisites

_add instructions on how to contribute to this repository, below is an example_
Before you begin, ensure you have the following installed:

1. Create a branch off of `dev` branch named in the format `<name>/type-title-of-this-branch`.
- valid types include:
- feat: feature
- fix: bug fix
- refact: refactor
- docs: documentation
- chore: a chore
- **Node.js** (v20 or higher recommended)
- **Docker** and **Docker Compose** (for local PostgreSQL database)
- **npm** (comes with Node.js)

2. Once development is concluded, open a pull request from your branch back to the `dev` branch.
## Quick Start

## Branches
### 1. Install Dependencies

```bash
npm install
```

### 2. Set Up Environment Variables

- `dev`: where contributions are made
- `qa`: contains a functional version of code to be tested
- `prod`: production ready code to be released
Copy the example environment file:

## Development
```bash
cp .env.example .env
```

The `.env` file contains:

_add instructions on how to start the dev environment, below is an example_
- `DATABASE_URL` - PostgreSQL connection string
- `PORT` - Server port (default: 3000)
- `NODE_ENV` - Environment (development/production)

1. Install dependencies
### 3. Start the Database

Start PostgreSQL using Docker Compose:

```bash
npm i
npm run docker:up
```

2. Start development server
This 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`

### 4. Set Up the Database Schema

Push the Prisma schema to create tables:

```bash
npm run dev
npm run db:push
```

## Deployment
Or create a migration (recommended for production):

```bash
npm run db:migrate
```

_add instructions on how to deploy this project (in applicable), below is an example_
### 5. Generate Prisma Client

1. Ensure `NODE_ENV=production`
Generate the Prisma Client (usually done automatically, but can be run manually):

```bash
echo "NODE_ENV=production" > .env
npm run db:generate
```

2. Install production dependencies
### 6. Start the Development Server

```bash
npm run dev
```

The server will start on `http://localhost:3000` (or the port specified in `.env`).

## Available Scripts

### Development

- `npm run dev` - Start development server with hot reload
- `npm run build` - Build TypeScript to JavaScript
- `npm start` - Start production server (requires build first)

### Database

- `npm run db:generate` - Generate Prisma Client
- `npm run db:push` - Push schema changes to database (development)
- `npm run db:migrate` - Create and apply a migration
- `npm run db:migrate:deploy` - Deploy migrations (production)
- `npm run db:studio` - Open Prisma Studio (database GUI)
- `npm run db:seed` - Run database seed script

### Docker

- `npm run docker:up` - Start PostgreSQL container
- `npm run docker:down` - Stop PostgreSQL container
- `npm run docker:logs` - View PostgreSQL logs

### Testing

- `npm test` - Run tests once
- `npm run test:watch` - Run tests in watch mode
- `npm run test:coverage` - Run tests with coverage report

### Code Quality

- `npm run format` - Format all code with Prettier
- `npm run format:check` - Check code formatting without changes

## Project Structure

```
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
```

## Database Management

### Using Prisma Studio

Prisma Studio provides a visual interface to view and edit your database:

```bash
npm i
npm run db:studio
```

3. Start production server
This opens a web interface at `http://localhost:5555`.

### Making Schema Changes

1. **Edit** `prisma/schema.prisma`
2. **Push changes** (development):
```bash
npm run db:push
```
3. **Or create a migration** (recommended):
```bash
npm run db:migrate
```
This creates a migration file in `prisma/migrations/` for version control.

### Using Prisma in Your Code

```typescript
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',
},
});
```

## API Routes

The API is organized by resource:

- `/api/users` - User management
- `/api/appointments` - Appointment management
- `/api/documents` - Document management

## Development Workflow

1. **Start the database** (if not already running):

```bash
npm run docker:up
```

2. **Start the development server**:

```bash
npm run dev
```

3. **Make changes** to your code

4. **Test your changes**:

```bash
npm test
```

5. **Format your code** before committing:
```bash
npm run format
```

## Contributing

### Branch Naming

Create branches off of `dev` using the format: `<name>/type-title-of-this-branch`

Valid types:

- `feat`: New feature
- `fix`: Bug fix
- `refact`: Refactor
- `docs`: Documentation
- `chore`: Maintenance task

### Pull Request Process

1. Create a branch from `dev`
2. Make your changes
3. Run tests: `npm test`
4. Format code: `npm run format`
5. Open a pull request to `dev`

## Branches

- `dev` - Development branch (where contributions are made)
- `qa` - Quality assurance branch (functional version for testing)
- `prod` - Production branch (production-ready code)

## Troubleshooting

### Database Connection Issues

If you can't connect to the database:

1. **Check if the container is running**:

```bash
docker-compose ps
```

2. **View database logs**:

```bash
npm run docker:logs
```

3. **Restart the database**:
```bash
npm run docker:down
npm run docker:up
```

### Prisma Client Not Found

If you get errors about Prisma Client:

```bash
npm run start
npm run db:generate
```

## Contributors
### Port Already in Use

_give yourself some credit_
If port 3000 is already in use, change the `PORT` in your `.env` file.

Team Leads:
## Environment Variables

- Bob
- His friends
| Variable | Description | Default |
| -------------- | ------------------------------------ | ----------- |
| `DATABASE_URL` | PostgreSQL connection string | Required |
| `PORT` | Server port | 3000 |
| `NODE_ENV` | Environment (development/production) | development |

Developers:
## License

- Robert
- John
- A few more friends
ISC
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
postgres:
image: postgres:16-alpine
container_name: healthcare-postgres
restart: unless-stopped
environment:
POSTGRES_USER: healthcare_user
POSTGRES_PASSWORD: healthcare_password
POSTGRES_DB: healthcare_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U healthcare_user -d healthcare_db']
interval: 10s
timeout: 5s
retries: 5

volumes:
postgres_data:

Loading