Plann.er_Back-End

Back-end da aplicação Plann.er, um planejador de viagens!

Stars
0
Committers
1

English

Plann.er - Back-End is a Node.js application developed to serve as the backend for the plann.er travel planner application.

Summary

Technologies Used

  • Node.js: JavaScript runtime built on Chrome's V8 JavaScript engine.
  • Prisma: Next-generation ORM for Node.js and Typescript.
  • Fastify: Fast and low overhead web framework for Node.js
  • @fastify/cors: Fastify plugin for enabling CORS.
  • @fastify/static: Fastify plugin for serving static files.
  • @scalar/fastify-api-reference: Fastify plugin for API documentation.
  • dayjs: Fast and lightweight JavaScript date library.
  • Zod: TypeScript-first schema declaration and validation library.
  • Nodemailer: Node.js module for sending emails.

Structure of the project

The project structure is as follows:

 src: directory containing application source files

    documentation: directory containing API documentation files (Insomnia and Swagger).

    erros: directory containing exported ClientError class.

    lib: directory containing Prisma, Mail, and Day.js configurations.

    routes: directory containing application route files.

|    error-handler.ts: handler to check if the error is client-side or server-side.

|    env.ts: environment validation with Zod.

    server.js: file that initializes the application.

 .env.example: example file for environment variables.

 prisma: directory containing schema and migrations.

Installation

  1. Clone the repository or download and extract the ZIP file from the repository.
git clone https://github.com/Vitinho163/Plann.er_Back-End.git
  1. Install dependencies:
npm install
  1. Rename the .env.example file to .env and fill in the information:
DATABASE_URL="file:./dev.db"
API_BASE_URL="http://localhost:3333"
WEB_BASE_URL="http://localhost:3000"
PORT=3333
  1. Start the server:
npm run dev

deploy

This API was hosted directly on Render.

The deployment can be accessed at the address:

https://plann-er-back-end.onrender.com

Note: As it is hosted on a free service, the application 'hibernates' after 15 minutes of inactivity. If you are trying to access the site and the BackEnd does not respond, just wait, as it will be 'initializing' the services.

Route Documentation

The documentation for all routes is available at:

http://localhost:{port}/reference

Make sure to replace {port} with the port defined in the .env file. If not defined, try accessing it with the default port 3333.

Note: This application was developed using Node.js version v20.15. In case of issues, try updating Node.js to the latest version.


Portugus

Plann.er - Back-End uma aplicao Node.js desenvolvida para se comunicar com o aplicativo de planejamento de viagens Plann.er.

Sumrio

Tecnologias Utilizadas

  • Node.js: Ambiente de execuo JavaScript construdo no motor JavaScript V8 do Chrome.
  • Prisma: ORM de prxima gerao para Node.js e TypeScript.
  • Fastify: Framework web rpido e de baixa sobrecarga para Node.js.
  • @fastify/cors: Plugin Fastify para habilitar CORS.
  • @fastify/static: Plugin Fastify para servir arquivos estticos.
    -@scalar/fastify-api-reference: Plugin Fastify para documentao de API.
    -dayjs: Biblioteca de data JavaScript rpida e leve.
    -Zod: Biblioteca de declarao e validao de schemas em TypeScript.
    -Nodemailer: Mdulo Node.js para envio de e-mails.

Estrutura do Projeto

A estrutura do projeto a seguinte:

 src: diretrio contendo os arquivos de origem da aplicao

  documentation: diretrio contendo arquivos de documentao da API (Insomnia e Swagger).

  errors: diretrio contendo a classe ClientError exportada.

  lib: diretrio contendo configuraes do Prisma, Mail e Day.js.

  routes: diretrio contendo arquivos de rotas da aplicao.

  error-handler.ts: handler para verificar se o erro  do lado do cliente ou do servidor.

  env.ts: verificao das variaveis de ambiente com Zod.

  server.js: arquivo que inicializa a aplicao.

 prisma: diretrio contendo schemas e migrations.

| .env.example: arquivo de exemplo para variveis de ambiente.

Instalao

  1. Clone o repositrio ou faa o download e extraia o arquivo ZIP do repositrio.
git clone https://github.com/Vitinho163/Plann.er_Back-End.git
  1. Instale as dependncias:
npm install
  1. Renomeie o arquivo .env.example para .env e preencha as informaes:
DATABASE_URL="file:./dev.db"
API_BASE_URL="http://localhost:3333"
WEB_BASE_URL="http://localhost:3000"
PORT=3333
  1. Inicie o servidor:
npm run dev

Deploy

Esta API foi hospedada diretamente no Render.

O deployment pode ser acessado no seguinte endereo:

https://plann-er-back-end.onrender.com

Nota: Como est hospedado em um servio gratuito, a aplicao 'hiberna' aps 15 minutos de inatividade. Se voc estiver tentando acessar o site e o BackEnd no responder, basta aguardar, pois ele estar 'inicializando' os servios.

Documentao das Rotas

A documentao de todas as rotas est disponvel em:

https://plann-er-back-end.onrender.com/reference

ou caso esteja hospedado em seu desktop:

http://localhost:{port}/reference

Certifique-se de substituir {port} pela porta definida no arquivo .env. Se no estiver definido, tente acessar com a porta padro 3333.

Nota: Esta aplicao foi desenvolvida usando a verso Node.js v20.15. Em caso de problemas, tente atualizar o Node.js para a verso mais recente.