Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ezhivitsa committed Jun 16, 2018
1 parent 37a3ab7 commit 14a7ce4
Show file tree
Hide file tree
Showing 6 changed files with 1,396 additions and 1,502 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
"code",
"ideas"
]
},
{
"login": "KuhArt",
"name": "KuhArt",
"avatar_url": "https://avatars3.githubusercontent.com/u/14125982?v=4",
"profile": "https://github.com/KuhArt",
"contributions": [
"code"
]
}
]
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v2.0.0 (2018-06-16)

* Change approach for using validators
* Add start script
* Update npm dependencies

## v1.6.1 (2018-05-13)

* Update README
Expand Down
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Stack](https://raw.githubusercontent.com/paralect/stack/master/stack-component-template/stack.png)](https://github.com/paralect/stack)

[![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Build Status](http://product-stack-ci.paralect.com/api/badges/paralect/koa-api-starter/status.svg)](http://product-stack-ci.paralect.com/paralect/koa-api-starter)
Expand All @@ -29,26 +29,33 @@ Out of the box support following features:
9. JWT based authentication.
10. Tests for endpoints.

### Starting api
## Start

To start the project just run: `npm run development`. This command will start application on port `3001` and will automatically restart whenever you change any file in `./src` directory.
In order to start server in the docker container you can use bash file `./bin/start.sh`:
```bash
$ ./bin/start.sh
```

To start the project not in the docker container just run: `npm run development`. This command will start the application on port `3001` and will automatically restart whenever you change any file in `./src` directory.

### Explanations of the files structure

We try to keep things as simple as possible, so you can focus on building product instead of learning concepts.

There are two main directories within project:

1. [src/config](./src/config) - consist of configuration for the [environment](./src/config/index.js), [koa server](./src/config/koa.js) and [API routes](./src/config/routes).
2. [src/config/routes](./src/config/routes) - consist of [public](./src/config/routes/public.js) (don't require jwt token) and [authenticated](./src/config/routes/authenticated.js) (require jwt token) routes and [middlewares](./src/config/routes/middlewares).
- [middlewares](./src/config/routes/middlewares) - koa middlewares which we use on every request (for example, get current user data from the database)
2. [src/config/routes](./src/config/routes) - consist of [public](./src/config/routes/public.js) (don't require jwt token) and [authenticated](./src/config/routes/authenticated.js) (require jwt token) routes and [middlewares](./src/config/routes/middlewares).
- [middlewares](./src/config/routes/middlewares) - koa middlewares which we use on every request (for example, get current user data from the database)

3. [src/resources](./src/resources) - REST api resources and everything related to the resource:
- [database service](./src/resources/user/user.service.js) - resource service to work with database (MongoDB or other database)
- [database schema](./src/resources/user/user.schema.js) - database schema for the resource entity.
- [validators](./src/resources/account/validators/signup.validator.js) - request validation logic.
- [controllers](./src/resources/account/account.controller.js) - the central place for the request handling and data manipulation.
- [builders](./src/resource/user/user.builder.js) - creating database documents for testing.
- [factory](./src/resource/user/user.factory.js) - predefined types of database documents for testing.
- [tests](./src/resource/user/user.spec.js) - mocha tests for the endpoint.
- [database service](./src/resources/user/user.service.js) - resource service to work with database (MongoDB or other database)
- [database schema](./src/resources/user/user.schema.js) - database schema for the resource entity.
- [validators](./src/resources/account/validators/signup.validator.js) - request validation logic. You can use this validators inside of the validation middleware ([example in ./src/resources/account/public.js](./src/resources/account/public.js)) or you can use this validators inside of the controller ([example in ./src/resources/user/user.controller.js](./src/resources/user/user.controller.js))
- [controllers](./src/resources/account/account.controller.js) - the central place for the request handling and data manipulation.
- [builders](./src/resource/user/user.builder.js) - creating database documents for testing.
- [factory](./src/resource/user/user.factory.js) - predefined types of database documents for testing.
- [tests](./src/resource/user/user.spec.js) - mocha tests for the endpoint.

All other files, that does not fit that structure should be placed straight in the `src` folder. We can always introduce more folders as we need them. Currently root folder consist following:

Expand Down Expand Up @@ -80,8 +87,8 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars2.githubusercontent.com/u/6461311?v=4" width="100px;"/><br /><sub><b>Evgeny Zhivitsa</b></sub>](https://github.com/ezhivitsa)<br />[💻](https://github.com/paralect/koa-api-starter/commits?author=ezhivitsa "Code") [📖](https://github.com/paralect/koa-api-starter/commits?author=ezhivitsa "Documentation") [🤔](#ideas-ezhivitsa "Ideas, Planning, & Feedback") [👀](#review-ezhivitsa "Reviewed Pull Requests") [⚠️](https://github.com/paralect/koa-api-starter/commits?author=ezhivitsa "Tests") | [<img src="https://avatars3.githubusercontent.com/u/681396?v=4" width="100px;"/><br /><sub><b>Andrew Orsich</b></sub>](http://paralect.com)<br />[📖](https://github.com/paralect/koa-api-starter/commits?author=anorsich "Documentation") [🤔](#ideas-anorsich "Ideas, Planning, & Feedback") [👀](#review-anorsich "Reviewed Pull Requests") | [<img src="https://avatars3.githubusercontent.com/u/2302873?v=4" width="100px;"/><br /><sub><b>Ihar</b></sub>](https://github.com/IharKrasnik)<br />[💻](https://github.com/paralect/koa-api-starter/commits?author=IharKrasnik "Code") [🤔](#ideas-IharKrasnik "Ideas, Planning, & Feedback") |
| :---: | :---: | :---: |
| [<img src="https://avatars2.githubusercontent.com/u/6461311?v=4" width="100px;"/><br /><sub><b>Evgeny Zhivitsa</b></sub>](https://github.com/ezhivitsa)<br />[💻](https://github.com/paralect/koa-api-starter/commits?author=ezhivitsa "Code") [📖](https://github.com/paralect/koa-api-starter/commits?author=ezhivitsa "Documentation") [🤔](#ideas-ezhivitsa "Ideas, Planning, & Feedback") [👀](#review-ezhivitsa "Reviewed Pull Requests") [⚠️](https://github.com/paralect/koa-api-starter/commits?author=ezhivitsa "Tests") | [<img src="https://avatars3.githubusercontent.com/u/681396?v=4" width="100px;"/><br /><sub><b>Andrew Orsich</b></sub>](http://paralect.com)<br />[📖](https://github.com/paralect/koa-api-starter/commits?author=anorsich "Documentation") [🤔](#ideas-anorsich "Ideas, Planning, & Feedback") [👀](#review-anorsich "Reviewed Pull Requests") | [<img src="https://avatars3.githubusercontent.com/u/2302873?v=4" width="100px;"/><br /><sub><b>Ihar</b></sub>](https://github.com/IharKrasnik)<br />[💻](https://github.com/paralect/koa-api-starter/commits?author=IharKrasnik "Code") [🤔](#ideas-IharKrasnik "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/14125982?v=4" width="100px;"/><br /><sub><b>KuhArt</b></sub>](https://github.com/KuhArt)<br />[💻](https://github.com/paralect/koa-api-starter/commits?author=KuhArt "Code") |
| :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
43 changes: 26 additions & 17 deletions SHIP_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,41 @@ Out of the box support following features:

### Starting api

To start the project just run: `npm run development`. This command will start application on port `3001` and will automatically restart whenever you change any file in `./src` directory.
In order to start server in the docker container you can use bash file `./bin/start.sh`:
```bash
$ ./bin/start.sh
```

To start the project not in the docker container just run: `npm run development`. This command will start the application on port `3001` and will automatically restart whenever you change any file in `./src` directory.

### Explanations of the files structure

We try to keep things as simple as possible, so you can focus on building product instead of learning concepts.

There are two main directories within project:
1. [src/config](./src/config) - consist of configuration for the [environment](./src/config/index.js), [koa server](./src/config/koa.js) and [API routes](./src/config/routes.js).
2. [src/resources](./src/resources) - REST api resources and everything related to the resource:
- [database service](./src/resources/user/user.service.js) - resource service to work with database (MongoDB or other database)
- [database schema](./src/resources/user/user.schema.js) - database schema for the resource entity.
- [validators](./src/resources/account/validators/signup.validator.js) - request validation logic.
- [controllers](./src/resources/account/account.controller.js) - the central place for the request handling and data manipulation.
- [builders](./src/resource/user/user.builder.js) - creating database documents for testing.
- [factory](./src/resource/user/user.factory.js) - predefined types of database documents for testing.
- [tests](./src/resource/account/account.test.js) - mocha tests for the endpoint.

1. [src/config](./src/config) - consist of configuration for the [environment](./src/config/index.js), [koa server](./src/config/koa.js) and [API routes](./src/config/routes).
2. [src/config/routes](./src/config/routes) - consist of [public](./src/config/routes/public.js) (don't require jwt token) and [authenticated](./src/config/routes/authenticated.js) (require jwt token) routes and [middlewares](./src/config/routes/middlewares).
- [middlewares](./src/config/routes/middlewares) - koa middlewares which we use on every request (for example, get current user data from the database)

3. [src/resources](./src/resources) - REST api resources and everything related to the resource:
- [database service](./src/resources/user/user.service.js) - resource service to work with database (MongoDB or other database)
- [database schema](./src/resources/user/user.schema.js) - database schema for the resource entity.
- [validators](./src/resources/account/validators/signup.validator.js) - request validation logic. You can use this validators inside of the validation middleware ([example in ./src/resources/account/public.js](./src/resources/account/public.js)) or you can use this validators inside of the controller ([example in ./src/resources/user/user.controller.js](./src/resources/user/user.controller.js))
- [controllers](./src/resources/account/account.controller.js) - the central place for the request handling and data manipulation.
- [builders](./src/resource/user/user.builder.js) - creating database documents for testing.
- [factory](./src/resource/user/user.factory.js) - predefined types of database documents for testing.
- [tests](./src/resource/user/user.spec.js) - mocha tests for the endpoint.

All other files, that does not fit that structure should be placed straight in the `src` folder. We can always introduce more folders as we need them. Currently root folder consist following:

1. [src/app.js](./src/app.js) - starting point of the node.js application. It combine application configuration and start Koa http listener.
2. [src/auth.service.js](./src/auth.service.js) - JWT based authentication helper. Consist logic of JWT token encryption/decryption. Can consist other authentication related functions.
3. [src/db.js](./src/db.js) - handles connection to the MongoDB.
4. [src/email.service.js](./src/email.service.js) - fake service for sending application emails.
5. [src/logger.js](./src/logger.js) - application logger.
6. [src/security.util.js](./src/security.util.js) - number of methods for generating secure tokens and comparing passwords with password hash.
7. [src/tests/app.spect.js](./src/tests/app.spec.js) - starting point for tests.
1. [src/app.constants.js](./src/app.constants.js) - constant variables that are used in the application
2. [src/app.js](./src/app.js) - starting point of the node.js application. It combine application configuration and start Koa http listener.
3. [src/auth.service.js](./src/auth.service.js) - JWT based authentication helper. Consist logic of JWT token encryption/decryption. Can consist other authentication related functions.
4. [src/db.js](./src/db.js) - handles connection to the MongoDB.
5. [src/email.service.js](./src/email.service.js) - fake service for sending application emails.
6. [src/logger.js](./src/logger.js) - application logger.
7. [src/security.util.js](./src/security.util.js) - number of methods for generating secure tokens and comparing passwords with password hash.

### List of improvements

Expand Down
Loading

0 comments on commit 14a7ce4

Please sign in to comment.