Skip to content

Latest commit

 

History

History
187 lines (130 loc) · 5.83 KB

README.md

File metadata and controls

187 lines (130 loc) · 5.83 KB

Here’s a structured README.md template you can use for your project to provide an overview and describe the modules, setup, and usage:


Typescript API with NestJS, PostgreSQL, and Prisma

Project Overview

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.

Features

  • 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).

Project Structure

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

API Endpoints

User Endpoints

  • [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

Profile Endpoints

  • [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

Database Schema

The project uses two main tables: User and Profile.

User Table:

Field Type Description
id int Primary key
username string Unique username
phone string User's phone number

Profile Table:

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

Technologies Used

  • 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.

Installation & Setup

  1. Clone the repository:

    git clone https://github.com/abhishek2k21/Typscript-Api.git
    cd Typscript-Api
  2. Install dependencies:

    npm install
  3. 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"
  4. Run Prisma migrations:

    npx prisma migrate dev
  5. Run the NestJS server:

    npm run start:dev

Usage

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"
}

Testing

To run the tests, execute:

npm run test

Contribution

Feel free to fork the repository and submit pull requests. If you encounter issues, please report them via the issue tracker.


License

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.