Here’s a structured README.md
template you can use for your project to provide an overview and describe the modules, setup, and usage:
This project is a simple API built using NestJS and Prisma ORM with a PostgreSQL database. It implements basic CRUD operations for two main entities: User and Profile.
The application demonstrates the following features:
- Creation, retrieval, updating, and deletion of user data.
- Each user is associated with a profile that includes additional information such as email, address, and location details.
- The API is structured with modern TypeScript patterns, leveraging NestJS decorators and Prisma as the ORM for PostgreSQL.
- RESTful API for managing users and their profiles.
- PostgreSQL database integration with Prisma ORM for data modeling and migrations.
- Modular structure with separation of concerns across the controller, service, and DTO layers.
- Validation and error handling for invalid requests (e.g., missing user or profile data).
backend/
├── prisma/ # Prisma schema and migrations
├── src/
│ ├── user/ # User module
│ │ ├── dto/ # Data Transfer Objects (DTOs) for user
│ │ ├── user.controller.ts # Handles HTTP requests for User
│ │ ├── user.module.ts # User module definition
│ │ ├── user.service.ts # Business logic for User
│ ├── profile/ # Profile module
│ │ ├── dto/ # Data Transfer Objects (DTOs) for profile
│ │ ├── profile.controller.ts # Handles HTTP requests for Profile
│ │ ├── profile.module.ts # Profile module definition
│ │ ├── profile.service.ts # Business logic for Profile
│ ├── app.module.ts # Root module
│ ├── main.ts # Entry point of the application
├── .env # Environment variables
├── .eslintrc.js # ESLint configuration
├── .prettierrc # Prettier configuration
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
- [GET] /api/users - Retrieve all users
- [POST] /api/users - Create a new user
- [GET] /api/users/:id - Retrieve a user by ID
- [PATCH] /api/users/:id - Update user details
- [DELETE] /api/users/:id - Delete a user by ID
- [GET] /api/profiles - Retrieve all profiles
- [POST] /api/profiles - Create a new profile
- [GET] /api/profiles/:id - Retrieve a profile by ID
- [PATCH] /api/profiles/:id - Update profile details
- [DELETE] /api/profiles/:id - Delete a profile by ID
The project uses two main tables: User
and Profile
.
Field | Type | Description |
---|---|---|
id |
int |
Primary key |
username |
string |
Unique username |
phone |
string |
User's phone number |
Field | Type | Description |
---|---|---|
id |
int |
Primary key |
userId |
int |
Foreign key to User |
email |
string |
User's email address |
gender |
string |
User's gender |
address |
string |
User's address |
pincode |
string |
Postal code |
city |
string |
City |
state |
string |
State |
country |
string |
Country |
- NestJS: A progressive Node.js framework for building efficient and scalable server-side applications.
- TypeScript: Superset of JavaScript that adds static types.
- PostgreSQL: An open-source relational database system.
- Prisma ORM: A next-generation ORM for database modeling and migrations.
- Docker (optional): To run the PostgreSQL database in a container.
-
Clone the repository:
git clone https://github.com/abhishek2k21/Typscript-Api.git cd Typscript-Api
-
Install dependencies:
npm install
-
Set up PostgreSQL:
You can either run a local PostgreSQL instance or use Docker. Update your
.env
file with the correct database connection string.DATABASE_URL="postgresql://USER:PASSWORD@localhost:5432/bezt_assignment_db?schema=public"
-
Run Prisma migrations:
npx prisma migrate dev
-
Run the NestJS server:
npm run start:dev
After the setup, the API will be running on http://localhost:3000
. You can test the endpoints using Postman, Curl, or any HTTP client of your choice.
Example request:
POST http://localhost:3000/api/users
Content-Type: application/json
{
"username": "johndoe",
"phone": "1234567890"
}
To run the tests, execute:
npm run test
Feel free to fork the repository and submit pull requests. If you encounter issues, please report them via the issue tracker.
This project is licensed under the MIT License - see the LICENSE file for details.
This README.md
gives a detailed overview of your project, from its purpose to its structure and usage instructions. You can adjust it as needed depending on your final implementation.