This application is a RESTful API developed with NestJS, using PostgreSQL as the database and Prisma as the ORM. The API includes JWT authentication, role-based permission control (user and admin), a logging system (Winston), and interactive documentation via Swagger.
- User CRUD:
- Each user has a role (
USERorADMIN). - Only an
ADMINcan delete users and create products.
- Each user has a role (
- Product CRUD:
- Any user can view products.
- Only users with the
ADMINrole can create, update, or delete products.
- Authentication and Authorization:
- Registration of new users.
- Login of existing users to obtain JWT token.
- Route protection based on user role.
- Payment System:
- Creates a session with Stripe for payments.
- Logging System:
- Activity and error logging using Winston.
- API Documentation:
- Interactive documentation available via Swagger.
- NestJS, PostgreSQL, Prisma, JWT, Winston, Zod, Swagger, Stripe.
- Clone the repository:
git clone https://github.com/Lucalopezz/api-loja-nestjs.git cd api-loja-nestjs - Install dependencies:
npm install
- Configure the database:
- Create a PostgreSQL database.
- Add to the
.envfile:DATABASE_URL=postgresql://user:password@localhost:5432/database_name
- Run migrations:
npx prisma migrate dev
- Start the server:
npm run start:dev
The application will be available at http://localhost:3000.
- Registration:
POST /auth/register{ "email": "user@example.com", "password": "password123", "name": "User Name" } - Login:
POST /auth/loginResponse:{ "email": "user@example.com", "password": "password123" }{ "access_token": "jwt_token" } - Swagger: Access
http://localhost:3000/docs.
- src/:
- auth/: Authentication module.
- payment/: Payment module with Stripe.
- users/: User CRUD.
- products/: Product CRUD.
- common/: Guards, interceptors, and utils.
- main.ts: Main entry point.