Skip to content

Commit ef28c17

Browse files
Add backend API development documentation for authentication and inventory management modules
1 parent 169abff commit ef28c17

2 files changed

Lines changed: 188 additions & 0 deletions

File tree

D5 Backend & API.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Backend API Development Details (Day 5 - Day 6)
2+
3+
This document outlines the requirements and specifications for implementing the **Authentication Module** and **Inventory Management APIs** in the backend of the project.
4+
5+
---
6+
7+
## **Project Context**
8+
The project aims to create a web application for local shopkeepers to manage their inventory, customers, purchases, sales, and billing efficiently. The backend plays a critical role in securely managing data and providing reliable APIs for the frontend.
9+
10+
This phase focuses on implementing:
11+
1. **Authentication Module**: Ensures that only authorized users can access the system.
12+
2. **Inventory Management APIs**: Provides functionality for shopkeepers to manage their inventory.
13+
14+
---
15+
16+
## **Feature Specifications**
17+
18+
### **1. Authentication Module**
19+
#### Overview
20+
The authentication module ensures secure access to the application by implementing:
21+
- **User Registration**: New users can sign up.
22+
- **User Login**: Existing users can log in with their credentials.
23+
- **JWT Authentication**: Protects routes by issuing JSON Web Tokens to authenticated users.
24+
25+
#### Details
26+
- **Endpoints to Implement**:
27+
- `POST /auth/register`
28+
- Accepts user details (e.g., `name`, `email`, `password`).
29+
- Encrypts the password using `bcrypt`.
30+
- Saves the user in the database.
31+
- `POST /auth/login`
32+
- Verifies user credentials.
33+
- Issues a JWT token if credentials are valid.
34+
- **Middleware**: `authMiddleware`
35+
- Protects API routes by verifying the JWT token.
36+
37+
#### Key Requirements
38+
- Use `bcrypt` for password hashing.
39+
- Use `jsonwebtoken` to issue and verify JWT tokens.
40+
- Include validation for all input fields (e.g., email format, password strength).
41+
- Store only the hashed password in the database.
42+
- JWT tokens should have an expiration time (e.g., 1 day).
43+
44+
#### Database Tables
45+
- **Users Table**:
46+
- `id`: Primary key.
47+
- `name`: Full name of the user.
48+
- `email`: Unique email of the user.
49+
- `password`: Encrypted password.
50+
- `created_at`: Timestamp of user registration.
51+
52+
---
53+
54+
### **2. Inventory Management APIs**
55+
#### Overview
56+
The inventory management module allows shopkeepers to:
57+
- Add new products to their inventory.
58+
- Edit product details.
59+
- Delete products.
60+
- Retrieve a list of all products.
61+
62+
#### Details
63+
- **Endpoints to Implement**:
64+
- `POST /products`
65+
- Adds a new product to the inventory.
66+
- Fields: `name`, `quantity`, `price`, `supplier`, `description` (optional).
67+
- `GET /products`
68+
- Retrieves all products in the inventory.
69+
- `PUT /products/:id`
70+
- Updates details of an existing product.
71+
- Fields: `name`, `quantity`, `price`, `supplier`, `description`.
72+
- `DELETE /products/:id`
73+
- Deletes a product from the inventory.
74+
75+
#### Key Requirements
76+
- Use input validation to ensure correct data types and mandatory fields.
77+
- Handle errors such as invalid product IDs or duplicate product names.
78+
- Ensure secure operations by protecting endpoints with `authMiddleware`.
79+
80+
#### Database Tables
81+
- **Products Table**:
82+
- `id`: Primary key.
83+
- `name`: Name of the product.
84+
- `quantity`: Quantity available.
85+
- `price`: Price per unit.
86+
- `supplier`: Supplier name or ID.
87+
- `description`: Optional field for product details.
88+
- `created_at`: Timestamp of product creation.
89+
- `updated_at`: Timestamp of the last update.
90+
91+
---
92+
93+
## **Development Steps**
94+
95+
### **Step 1: Set Up Middleware and Utilities**
96+
- Create `authMiddleware` to verify JWT tokens for protected routes.
97+
- Create utility functions for password hashing (`bcrypt.hash`) and token generation (`jsonwebtoken.sign`).
98+
99+
### **Step 2: Implement Authentication Endpoints**
100+
- Develop the `POST /auth/register` and `POST /auth/login` endpoints.
101+
- Test user registration and login flows using `Postman`.
102+
103+
### **Step 3: Implement Inventory APIs**
104+
- Develop CRUD operations for the `/products` endpoint.
105+
- Test each endpoint for different scenarios (e.g., successful addition, invalid data).
106+
107+
### **Step 4: Testing and Debugging**
108+
- Test all API endpoints using `Postman` or `Swagger`.
109+
- Add unit tests for key functions and integration tests for endpoints.
110+
111+
---
112+
113+
## **Deliverables**
114+
1. Functional authentication module (register, login, JWT-based protection).
115+
2. Functional inventory management APIs (add, edit, delete, retrieve products).
116+
3. API documentation for all implemented endpoints (using Swagger/OpenAPI).
117+
4. Unit and integration tests for critical features.
118+
119+
---
120+
121+
## **Notes**
122+
- Ensure code readability and maintainability by adhering to best practices.
123+
- Log errors and critical events for easier debugging.
124+
- Update the `Product Feature Tracker.md` after completing each feature.

PFT.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
***Product Feature Tracking**
2+
# Product Feature Tracker
3+
4+
This document tracks the features added to the project over time to ensure clarity and progress visibility. Features are categorized based on modules and updated as development progresses.
5+
6+
---
7+
8+
## **Authentication Module**
9+
- [ ] **User Registration**: Allows new users to sign up.
10+
- [ ] **User Login**: Enables users to log in using credentials.
11+
- [ ] **JWT Authentication**: Secure token-based authentication.
12+
13+
## **Inventory Management Module**
14+
- [ ] **Add New Product**: Create a new product entry with details like name, quantity, and supplier.
15+
- [ ] **Edit Product**: Update existing product details.
16+
- [ ] **View Inventory**: Display all products in stock with real-time data.
17+
18+
## **Billing Module**
19+
- [ ] **Create Invoice**: Generate invoices for sales.
20+
- [ ] **View Invoices**: Display all generated invoices.
21+
- [ ] **Edit Invoice**: Update existing invoice details.
22+
23+
## **Database Configuration**
24+
- [x] **Design Database Schema**: Design the database schema based on the `DB Design.md` document.
25+
- [x] **Set Up Database**: Implement the database schema using Prisma and set up PostgreSQL locally.
26+
27+
## **Backend API Development**
28+
- [ ] **Authentication Module**: Implement user registration, login, and JWT-based authentication.
29+
- [ ] **Inventory Management APIs**: CRUD operations for products.
30+
31+
## **Frontend Development**
32+
- [ ] **Set up React Project**: Create the initial React project structure.
33+
- [ ] **Develop UI Components**: Create reusable components for managing inventory, sales, and purchases.
34+
35+
## **Testing and Deployment**
36+
- [ ] **Write Unit Tests**: Write unit tests for backend and frontend components.
37+
- [ ] **Write Integration Tests**: Write integration tests for backend and frontend components.
38+
- [ ] **Deploy Application**: Deploy the application to a production environment.
39+
40+
---
41+
42+
## **Progress Log**
43+
| Date | Module | Feature | Status |
44+
|------------|---------------------------|------------------------|--------------|
45+
| YYYY-MM-DD | Authentication | User Registration | In Progress |
46+
| YYYY-MM-DD | Inventory Management | Add New Product | Not Started |
47+
| YYYY-MM-DD | Billing | Generate Bills | Not Started |
48+
| YYYY-MM-DD | Reports | Sales Reports | Not Started |
49+
| YYYY-MM-DD | Database Configuration | Design Database Schema | Completed |
50+
| YYYY-MM-DD | Database Configuration | Set Up Database | Completed |
51+
| YYYY-MM-DD | Backend API Development | Authentication Module | Not Started |
52+
| YYYY-MM-DD | Backend API Development | Inventory Management | Not Started |
53+
| YYYY-MM-DD | Frontend Development | Set up React Project | Not Started |
54+
| YYYY-MM-DD | Frontend Development | Develop UI Components | Not Started |
55+
| YYYY-MM-DD | Testing and Deployment | Write Unit Tests | Not Started |
56+
| YYYY-MM-DD | Testing and Deployment | Write Integration Tests| Not Started |
57+
| YYYY-MM-DD | Testing and Deployment | Deploy Application | Not Started |
58+
59+
---
60+
61+
## **Notes**
62+
- Update this document after completing or initiating a feature.
63+
- Keep the progress log updated for accurate tracking.
64+

0 commit comments

Comments
 (0)