/find-a-friend-back-end

๐Ÿฑ Pet adoptions back-end API REST. Built with Node.js, Fastify and Vitest.

Primary LanguageTypeScript

๐Ÿพ Find a Friend (Back-End)

Find a Friend (back-end), is a crucial part of the practical challenge aimed at reinforcing concepts of API development, SOLID principles, and testing. The project consists of an API designed to facilitate the adoption of animals by connecting individuals interested in adopting pets with organizations that offer animals for adoption.

๐Ÿ’ก About

Application Rules

  • It must be possible to register a pet.
  • It must be possible to list all pets available for adoption in a city.
  • It must be possible to filter pets by their characteristics.
  • It must be possible to view details of a pet available for adoption.
  • It must be possible to register as an organization (ORG).
  • It must be possible to log in as an organization (ORG).

Business Rules

  • To list pets, it is mandatory to provide the city.
  • An ORG needs to have an address and a WhatsApp number.
  • A pet must be associated with an ORG.
  • Users who want to adopt a pet will contact the ORG via WhatsApp.
  • All filters, other than the city, are optional.
  • For an ORG to access the application as an admin, they must be logged in.

๐Ÿš€ How to Run

To run the application, follow these steps:

  1. Start Docker Compose:

    docker-compose up
  2. Set Environment Variables:

    Create a .env file or configure environment variables with the following values:

    NODE_ENV=dev
    PORT=3333
    DATABASE_URL=postgresql://docker:docker@localhost:5432/find-a-friend-db?schema=public
    JWT_SECRET=henrique
    
  3. Install Dependencies:

    pnpm install
  4. Generate Prisma Client:

    npx prisma generate
  5. Run Prisma Migrations:

    npx prisma migrate dev
  6. Start the Server in Development Mode:

    pnpm run start:dev

The application should now be running and accessible at the specified port. You can interact with the API according to your requirements.

๐Ÿ› ๏ธ How to Build

  1. Compile TypeScript to JavaScript:

    pnpm run build
  2. Start the Compiled Server:

    pnpm start

๐Ÿงช How to Test

To run tests, follow these steps:

  1. Execute Unit Tests:

    pnpm run test
  2. Execute Integration Tests:

    pnpm run test:e2e
  3. Generate Test Coverage Report:

    pnpm run test:coverage

The tests will ensure the functionality and reliability of the project.

๐Ÿ“ฆ Dependencies

  • @fastify/cors, fastify: Framework for Node.js API development.
  • @prisma/client: Prisma client for interacting with the database.
  • bcryptjs: Library for password hashing.
  • dotenv: Environment variable loading.
  • supertest: Library for integration testing.
  • tsup: TypeScript compiler.
  • vitest: Testing framework.
  • zod: Data validation library. ๐Ÿถ

If you're interested in deploying the application, you can learn how to do it here. It's quick and easy! ๐Ÿš€

๐Ÿ‘จโ€๐Ÿ’ป Author

Luiz Henrique - Software Developer

Linkedin | E-mail