Technologies that I used to develop this MVC
- Node.js
- TypeScript
- Express
- TypeORM
- PostgreSQL
- Multer
- Helmet
- EJS
- Cors
- Express Async Errors
- ShellJs
- Rimraf
- Fs-extra
- NPM-run-all
- Bcrypt
- JWT
βββ src
β βββ config
β βββ controllers
β βββ database
β β βββ migrations
β βββ dtos
β βββ errors
β βββ middlewares
β βββ models
β βββ repositories
β βββ routes
β βββ server.ts
β βββ services
β βββ tools
β βββ @types
β βββ utils
β βββ views
βββ uploads
- User: Represents a contact
- Admin: Represents a user, who can create, update and delete contacts
- NODE_ENV: Defines the environment (Ex.: development / production)
- PORT: Defines the port on which the application runs (Ex.: 3333)
- APP_SECRET: Defines the secret of the application, which guarantees the uniqueness of the tokens (Ex.:asdybhq47qrdb)
- APP_TTL: Defines the time of validity of a token (Ex.: 1d)
- DB_TYPE: Defines the type of database (Ex.: postgres)
- DB_HOST: Defines the host of database (Ex.: localhost)
- DB_PORT: Defines the port of database (Ex.: 5432)
- DB_USERNAME: Defines the username of database (Ex.: admin)
- DB_PASSWORD: Defines the password of database (Ex.: admin123)
- DB_NAME: Defines the name of database (Ex.: softmakers-contatos)
- Node.js
- Yarn or npm
- One instance of PostgreSQL
Obs.: I recommend use docker
Clone the project and access the folder
$ git clone https://github.com/adoidadox2/SoftMakers-Contatos.git && cd SoftMakers-Contatos
Follow the steps below
# Install the dependencies
$ yarn
# Make a copy of '.env.example' to '.env'
# and set with YOUR environment variables.
$ cp .env.example .env
# Create the instance of postgreSQL using docker
$ docker run --name softmakers-contatos-postgres -e POSTGRES_USER=docker \
-e POSTGRES_DB=softmakers-contatos -e POSTGRES_PASSWORD=docker \
-p 5432:5432 -d -t postgres
# Once the services are running, run the migrations
$ yarn typeorm migration:run
To start the server in a development environment:
$ yarn dev:server
To start the server in a production environment (remember to put "production" at NODE_ENV):
#To transpile from Typescript to Javascript
$ yarn build
#To run the server already transpiled
$ yarn start
- All ID's are uuid
- Handled errors return their
HTTP status
and a specific error message. ** Ex ** .:{"status": "error", "message":" User not found "}
- Handled errors return their
- Unexpected errors are treated as
status 500 - Internal Server Error
Views -
#Create new admin
/admin
#Login
/session
#List all contacts, ( accepts pagination - 10 contacts per page Ex.: /user?page=1 )
/user
#Create new contact
/user/new
#Contact details
/user/:id
#Edit contact
/user/:id/edit
- First time creating MVC, as well as my first time dealing with HTML, I can say that I learned a lot in less than a week
- I've never used template engines before, I think it was a good experience, especially due to typescript, because I found some incredible packages (like ShellJs) needed to dynamically copy view's folder to the transpiled directory
- I believe that for a more scalable application, a functionality for creating and authenticating users of the system must be implemented, as well as preventing large flows of requests / DDoS and add sentry to monitor the application in production
- List users by address, using the address 1 - N user relation
This project is licensed under the MIT License - see the LICENSE file for details.
Made with β€οΈ by Augusto VinΓcius ππ» Get in touch!