Giter Club home page Giter Club logo

charitify's Introduction

Charitify - app for helping those in need.

Table of contents generated with markdown-toc

๐Ÿ—ƒ Server structure

Server executing sarts with src/server.js file. Here we launch express and initialize all needed utils. The rest 'trinkets' are inside /src/server folder. Directories there are structured in this way:

๐Ÿ›ค Routes

Here are stored routes of the app that may use middlewares to validate session, or payload and controllers to process request.

๐Ÿ–‡ Middlewares

Here express middlewares take their place. They are used to process the incoming requests before handling them down to the controllers. Usually they use passport, joi as a payload validators.

๐Ÿ•น๏ธ Controllers

Think of controllers as "orchestrators". They call the services, which contain more "pure" business logic. But by themselves,controllers don't really contain any logic other than handling the request and calling services. The services do most of the work, while the controllers orchestrate the service calls and decide what to do with the data returned.

โš™๏ธ Services

Services should contain the majority of your business logic: - logic that encapsulates your business requirements, calls your data access layer or models, calls API's external to the Node application. And in general, contains most of your algorithmic code. Each service is created per entity. One service should operate only with user or campaign data etc. Try to keep them as lose coupled as possible.

๐Ÿ—„๏ธ Models

Mongoose schemes are described in this folder. Since we rely on Mongo db in future and probably wount use any other db, we can afford to work with models directly. Describe any new db entity here.

๐Ÿ“‹ Config

Heer we usually locate some enums, and othe simple static configs that may be reused across the server.

๐Ÿ›  Utils

The last type of logic we'll cover is that of common logic functions that are not necessarily specific to your business logic or domain, or even a REST API in general. A good example of a utility function would be a function that converts milliseconds to minutes and/or seconds, or one that checks two arrays to see if they contain similar items. These are general enough - and reusable enough - that they deserve to go in their own folder.

๐Ÿงฐ Project installation

  1. Clone project using
	git clone https://github.com/Charitify/Charitify.git
  1. Go to the root directory
	cd Charitify
  1. Make sure you are running right version of node.js and npm. View required version inside .nvmrc. Install nvm to manage your node.js versions.
	nvm use <version of node.js>
  1. Install dependencies
	npm install -g sapper && npm install
  1. Create an environments folder and put inside .env ord .env.prod files in order to run an app. Ask project contributors to share this files.
	mkdir environments

NOTE โš ๏ธ : In the current setup local development do not require a local db, app uses a remote one. URI to it is specified in .env files.

  1. That's all for now!

๐Ÿƒ Run the project

Since this app is a monolith it includes both frontend and backend. Therefore running an app means compiling both frontend, service-workers and backend. Please read more about sapper before starting developing here.

Run app in a dev mode

    npm run dev

This command will use ./environments/.env config and run sapper. Briefly, it would build all necessary files into __sapper__/dev folder, and run it from there.

๐Ÿ’ก Every time you save a file sapper would rebuild dev project and refresh the page.

Run an app with production config

    npm run prod

This command will use ./environments/.env.prod

Build app ready for production

    npm run build

This command would add folder __sapper__/build. Inside is a production-ready server, client and service-worker code.

Run production build

    npm start

โ— This build do not any of the .env files! It has all variables inserted inside the code.


๐Ÿ“ค Deployment

Charitify app is deployed via travis-ci. Deploy is triggered every time you push code to master branch. This can be configured in .travis.yml. Primary deploy steps happen on VPS that is hosting the project. Travis just ssh to machine and run the deploy.sh script on it.

Simplified deploy steps

  1. New commit was pushed to master.
  2. Travis CI is triggered to start build pipeline.
  3. Travis extracts secured key that was added to it`s servers.
  4. Travis ssh to remote VPS using the extracted key.
  5. Travis executes deploy.sh on VPS server.
  6. Build is finished successfully if deploy.sh is executed with exit code 1

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

App is running on VPS using pm2. It is connected to pm2 plus therefore we can monitor the state of app here. PM2 starting options can be updated inside deploy.sh script. Read more about app starting modes here

๐Ÿ›ก Security

Never share and never comit any of these files:

  • SSH keys to the VPS
  • .env files
  • __sapper__/build folder (it contains precompiled env variables)

charitify's People

Contributors

bublikus avatar harazdovskiy avatar vitalii-m avatar

Stargazers

 avatar

Watchers

 avatar  avatar

charitify's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.