- Pokédex is a simple SPA that integrates PokéAPI and a custom API for complementar services, like removing unwanted pokémons
- This repo contains two main folders:
backend
andfrontend
, which defines independent applications
- Backend was developed using NodeJS and Typescript
- It uses ExpressJS as http server provider
- It was developed following SOLID principles
- Postgres is used as the main database and uses migrations to setup its tables
- Prettier, Eslint and Editorconfig are being used to keep the code following a good pattern
- PM2 is used to serve files in production mode
- Docker is used to create database container
- The project is splitted into two main folders:
Modules
: each folder inside holds files attached to an entity of the project. In this case, just the RemovedPokemon entity. They have the following structure:Infra
: all files related to external services, like database and http serverHttp
: stores controllers and routes using Express as external dependencyTypeORM
: stores entities and repositories using TypeORM as external dependencyInjections
: assign an external dependency to a ADT (Abstract Data Type). So a service will automatically use it when instantiated by usingcontainer.resolve(Service)
. If we want to replace the dabatase, for example, we just need to create a new repository following the same ADT and register it on the injections folder
Repositories
: ADTs for accessing entity repositoryServices
: the functional part of the code. Services are all functions we may want to access through the REST API
Shared
: common files for all modules
- Whenever the client sends a request, the main flux consists on:
- Route -> Controller -> Service, which can use repositories and other stuff to execute the desired functionality
-
Go to the
backend
folder -
Install project dependencies by running
npm install
oryarn install
-
Copy
docker-compose.yml
to a newdocker-compose.override.yml
file and fill it with the credentials that you want to create the containers. You may want to let with the same credentials of the example file for testing purposes. -
Create and run docker containers by running
docker-compose -f docker-compose.override.yml up -d
-
Copy
ormconfig.example.json
to a newormconfig.json
file and fill it with the same credentials that you have set up when creating the containers. If you have not changed your composer file, you don't have to change this one as well. -
Create database tables by running
npm run typeorm migration:run
oryarn typeorm migration:run
-
Copy
.env.example
to a new.env
file and fill it with the credentials that you want to. -
Start backend on development mode by running
npm run dev
oryarn dev
-
Go to the
backend
folder -
Generate
dist
folder by runningnpm run build
oryarn build
-
Change your
ormconfig.json
file to use the files located on thedist
folder:- Just replace
src
bydist
and.ts
by.js
on theormconfig.json
entries.
- Just replace
-
Copy
ecosystem.config.json.example
to a newecosystem.config.json
file -
Start backend on production mode by running
yarn prod
- Frontend was developed using ReactJS 18 and Typescript
- It uses ChakraUI as the main component provider
- It was developed following Atomic Design principles
- PokéAPI is integrated to provide Pokémon info
- The backend is integrade as a custom API to provide complementar services
- React Context API is used instead of Redux to setup hooks and shared components
- Prettier, Eslint and Editorconfig are being used to keep the code following a good pattern
public
: public HTML filessrc
@Types
: data transfer objects and types in generalComponents
: splitted intoAtoms
,Molecules
andOrganisms
as it follows Atomic Design principles. Organisms stores completely functional components. Molecules and Atoms components are focused to deliver just the UI strucuture, but oftenly implements simple functionalities as wellHooks
: custom hooks created using React Context API. Each one integrates functions and/or states that can be shared between all componentsPages
: stores all the project pages, in this case, just the homeServices
: setup all external APIsStyles
: setup ChakraUI style theme
-
Go to the
frontend
folder -
Install project dependencies by running
npm install
oryarn install
-
Start frontend on development mode by running
npm run start
oryarn start
- Development mode will use backend on development mode as well, so you need backend running on
https://localhost:3000
to use its services - If you want to run frontend locally but using the production API, you can do it by running
NODE_ENV=production yarn start
instead
- Development mode will use backend on development mode as well, so you need backend running on
-
Go to the
frontend
folder -
Generate
build
folder by runningnpm run build
oryarn build
-
Serve static files using any server you want to