Skip to content
Open
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
129 changes: 1 addition & 128 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,21 @@ Includes Prisma ORM with SQLite, Swagger docs, linting, formatting, and Docker s
## Features

- Express server with basic folder structure
- Health check endpoint (`/health`)
- SQLite database (file-based)
- Prisma ORM integration
- Swagger API documentation (`/api-docs`)
- ESLint + Prettier setup
- Pre-commit hooks with Husky + lint-staged
- Nodemon for auto-reload
- Docker support

---

## 🛠 Tech Stack
## Tech Stack

- **Node.js**
- **Express**
- **Prisma ORM**
- **SQLite**
- **Swagger (swagger-ui-express, swagger-jsdoc)**
- **ESLint + Prettier**
- **Husky + lint-staged**
- **Docker**

---

## Project Structure

```

.
├── src/
│ ├── routes/
│ ├── controllers/
│ ├── services/
│ ├── middlewares/
│ └── app.js
├── prisma/
│ └── schema.prisma
├── .husky/
├── .eslintrc
├── .prettierrc
├── Dockerfile
├── package.json
└── README.md

```

---

Expand Down Expand Up @@ -98,20 +68,6 @@ npm run prisma:generate

---

## Prisma Model

```prisma
model Book {
id Int @id @default(autoincrement())
name String
author String
price Float
publisher String?
}
```

---

## Linting & Formatting

### Check lint
Expand Down Expand Up @@ -158,22 +114,6 @@ docker run -p 3000:3000 bookstore-api

---

## Scripts

```json
"scripts": {
"start": "node src/server.js",
"dev": "nodemon src/server.js",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
"prisma:migrate": "npx prisma migrate dev",
"prisma:generate": "npx prisma generate"
}
```

---

## Environment Variables

Create a `.env` file:
Expand All @@ -185,39 +125,6 @@ PORT=3000

---

## Status

- Core setup complete
- Database connected
- Tooling configured
- Dockerized

---

## Books API

```
POST /books ""Endpoint**
```

**Description:**
Creates a new book with multiple authors and stores it in the database.

---

### Request Body

```json
{
"name": "Atomic Habits",
"authors": ["Zain", "Chris"],
"price": 100,
"publisher": "Humdard Publisher"
}
```

---

### Validation Rules

- `name` → required (string)
Expand All @@ -227,43 +134,9 @@ Creates a new book with multiple authors and stores it in the database.

---

### Responses

#### 201 - Created

```json
{
"id": 1,
"name": "Atomic Habits",
"price": 100,
"publisher": "Humdard Publisher",
"authors": [{ "name": "Zain" }, { "name": "Chris" }]
}
```

---

#### 400 - Bad Request

```json
{
"error": "Validation failed",
"details": "Invalid input data"
}
```

---

## Testing the API

You can test the API using:

- Swagger UI → `http://localhost:3000/api-docs`
- Postman / Thunder Client

---

## Notes

- Ensure `express.json()` middleware is enabled
- Request body must match validation schema
Loading