Library API to facilitate book borrowing system.
- Installing the depedencies
yarn
- Run the apps
yarn dev
├── src
| ├── @types # 3rd party d.ts files and for extending types
| | ├── custom-env.d.ts
| | ├── express.d.ts
| ├── helper
| | ├── crud
| | | ├── crud.constant.ts
| | | ├── crud.controller.ts
| | | ├── crud.DAL.ts # depedency inversion to mongoose
| | | ├── index.ts
| | ├── activeStatus.ts
| ├── lib
| | ├── errorManagement
| | | ├── appError.ts # error class, to string
| | | ├── commonErrors.ts # extends AppError
| | | ├── error.type.ts
| | | ├── handler.ts # if error logs, if not operational (programmer error) to avoid unpredictable behaviour
| | | ├── index.ts
| | | ├── operationalErrorDecider.ts # decide error is operational or not
| | ├── logger
| | | ├── index.ts
| | | ├── logger.config.ts
| | | ├── logger.constants.ts
| | ├── auth
| | | ├── index.ts
| | | ├── auth.constant.ts
| | | ├── auth.controller.ts
| | | ├── auth.route.ts
| | | ├── auth.validation.ts
| | ├── db.ts
| ├── resources # resource to support routes, every route has constant, controller, model, route, and types
| | ├── author
| | | ├── author.constant.ts # languages etc
| | | ├── author.controller.ts
| | | ├── author.model.ts
| | | ├── author.route.ts
| | | ├── author.type.ts
| | ├── book
| | ├── bookTransactions
| | ├── fine
| | ├── genre
| | ├── publisher
| | ├── user
| ├── app.ts # api declaration
| ├── config.ts
| ├── server.ts # networking concern (start server, connecting to db)
├── .env.development
├── .env.production
├── .env.staging
├── .eslintrc
├── .gitignore
├── .gitignore
├── package.json
├── tsconfig.json
├── yarn.lock
There are 3 types of logged-in users: SUPERADMIN, ADMIN, MEMBER.
_id (ObjectId, Autogenerate) | password (hashed) | firstname | lastname | gender (0=male, 1=female) | settings | role | is_active | |
---|---|---|---|---|---|---|---|---|
1 | [email protected] | admin | Admin | LastA | 0 | { theme, notification, compactMode } | admin | true |
2 | [email protected] | admin | Super | LastS | 1 | { theme, notification, compactMode } | super_admin | true |
3 | [email protected] | member | Member | LastM | 0 | { theme, notification, compactMode } | user | true |
_id | name | created_by | created_at | updated_by | updated_at |
---|---|---|---|---|---|
1 | Fiction | _userid | 2020-01-31 | _userid | 2020-01-31 |
2 | Action | _userid | 2020-01-31 | _userid | 2020-01-31 |
_id | first_name | last_name | created_by | created_at | updated_by | updated_at | date_of_birth | date_of_death |
---|---|---|---|---|---|---|---|---|
1 | Samudra | tikus | _userid | 2020-01-31 | _userid | 2020-01-31 | 2018-01-31 | |
2 | Whitey | bravery | _userid | 2020-01-31 | _userid | 2020-01-31 | 2019-05-05 | |
3 | Bob C | Martin | _userid | 2020-01-31 | _userid | 2020-01-31 | 1950-01-31 | 2021-01-31 |
_id | name | created_by | created_at | updated_by | updated_at |
---|---|---|---|---|---|
1 | Whiley | _userid | 2020-01-31 | _userid | 2020-01-31 |
2 | Penerbit Pureo | _userid | 2020-01-31 | _userid | 2020-01-31 |
_id | Title | created_by | created_at | updated_by | updated_at | authors | genres | pubsliher | year | edition |
---|---|---|---|---|---|---|---|---|---|---|
1 | Clean Code | _userid | 2020-01-31 | _userid | 2020-01-31 | _authorid | _genreid[] | _publisherid | 2020 | 10 |
2 | Penerbit Pureo | _userid | 2020-01-31 | _userid | 2020-01-31 | _authorid | _genreid[] | _publisherid | 2020 | 10 |
_id | book | is_rented | is_active | created_by | created_at | updated_by | updated_at |
---|---|---|---|---|---|---|---|
1 | _bookid | true | true | _userid | 2020-01-31 | _userid | 2020-01-31 |
2 | _bookid | false | false | _userid | 2020-01-31 | _userid | 2020-01-31 |
_id | book | user | start_date | end_date | return_date | fine_paid | is_active |
---|---|---|---|---|---|---|---|
1 | _bookinstanceid | _userid | 2020-01-31 | 2020-10-31 | 2020-10-31 | 0 | |
2 | _bookinstanceid | _userid | 2020-01-31 | 2020-10-31 | 2020-11-31 | 750000 |
category | _books |
---|---|
weekly | _booksid[] |
monthly | _booksid[] |
yearly | _booksid[] |
category | _books |
---|---|
_genreid | _booksid[] |
Tables | Create | Read | Update | Delete |
---|---|---|---|---|
User | v | self | self | x |
Genre | x | v | x | x |
Author | x | v | x | x |
Book | x | v | x | x |
BookInstance | x | v | v | x |
BookTransaction | v | v | v | x |
BookRanking | x | v | x | x |
BookLatest | x | v | x | x |
Tables | Create | Read | Update | Delete |
---|---|---|---|---|
User | v | v | v | x |
Genre | v | v | v | v |
Author | v | v | v | v |
Book | v | v | v | v |
BookInstance | v | v | v | v |
BookTransaction | v | v | v | x |
BookRanking | x | v | x | x |
BookLatest | x | v | x | x |
Tables | Create | Read | Update | Delete |
---|---|---|---|---|
User | v | v | v | v |
Genre | v | v | v | v |
Author | v | v | v | v |
Book | v | v | v | v |
BookInstance | v | v | v | v |
BookTransaction | v | v | v | v |
BookRanking | v | v | v | v |
BookLatest | v | v | v | v |
- Node
- Yarn
- installing depedencies
yarn
- make 3 env
- .env.development
- .env.staging
- .env.development
APP_name=development udra library
PORT=3000
SALT_ROUND=10
DB_name=<<your db name>>
DB_PASSWORD=<<your db password name>>
- start development
yarn dev
- Error
- Logging
- Authorization
- Authentication
- User Input Validation
- Deploy
- Testing
- Cron
- Cache
- Socket
- Message broker
- Document API using swagger
- Folder Structure
- Structure by components?
Ensure each unit keep small and simple
- separate layer
For clean separation and ease mocking
- route
- controller
- model
- constant
- type
- validation
- separate app & server To separate concern between API declaration and networking concern
- Error Handling Distinguish Programmer and operational error. Exit if programmer error to avoid unpredictable behaviour. Handling error centrally to avoid wrong duplication
- Validate with both express-validator and mongoose?
They compliment each other.
Express validator to ensure clients sends is valid
and mongoose schema to ensure our data is in right shape.
Also validating the client data as soon as possible is good for security and performance before hitting the database.
- Testing with jest source