This repository is Backend API part of Truthy CMS written in NestJS. For Frontend please visit https://github.com/gobeam/truthy-react-frontend. This project includes API for Authentication, User Management, Role Management, Permission Management, Email Module, Account Settings, OTP, RBAC support, Localization, and many more.
Created by Roshan Ranabhat (gobeam) and maintained with ❤️ by an amazing team of awesome developers.
Check Live code deployed here: Backend API Docs: Swagger Docs Frontend: Truthy CMS
- Getting Started
- Prerequisites
- Available Scripts
- Setup
- Docker Setup
- File Structure
- Application Security
- Contributing
- Sponsors
- License
- Acknowledgement
This project was created to help developers by bootstrapping basic modules that need to be present while creating a standard CMS. The main motto of this project was to save precious time while developing CMS and focus more on the core part. This project is trying to follow the best possible standard to make it optimized and production-ready. Hope you like it.
If you love it don't forget to share your experience. If you want to contribute to the Truthy CMS in any way like API, Frontend, Design, Logo you're more than welcome to do so. Our plan is to make this no. 1 CMS maintained by opensource community.
NodeJS https://nodejs.org/en/
Typescript https://www.typescriptlang.org/
PostgresQL https://www.postgresql.org/
Redis https://redis.io/
This commands downloads the latest version of truthy i.e NestJS Truthy CMS backend API.
In the project directory, you can run:
Runs the app in the development & watch mode.
Open http://localhost:7777/api-docs to view swagger API docs in browser (only available in development mode).
You will also see any lint errors in the console.
Builds the app for production to the build
folder.
Lints all the files inside src,apps,libs,test folders and shows the results.
Formats all the files inside src using prettier with config provided in .prettierrc
Runs coverage test command and creates coverage folder with detail report which can be checked with:
yarn coveralls
Uses Type ORM to create a migration file. migration_file_name
is Migration file name to be created.
This command is used to migrate existing migration file.
This command is used to rollback migration.
This command is used to run existing seeders.
First, you need to install the project using npx command
npx truthy-api
or clone it using
git clone https://github.com/gobeam/truthy.git
You also need to run PostgresQL for database and Redis for key-val storage which will be used for queue and throttling. After cloning the make changes in configuration file that exists in config folder which exists in root of project. File names are named in accordance with environment you run project with. For example if you're running project in development environment you should make change in configuration of development.yml file. Please keep in mind environment variables always overrides the config.
If you want to run locally,
yarn start
If you want to view swagger docs on development open http://localhost:7777/api-docs (assuming you are running application on 7777 port)
Run Migration
yarn migrate
Run Seeders
yarn seed
Rollback Migration
yarn migration:rollback
If you want to run project without docker you will not need to create .env file
If you want to use Docker to deploy it on production or development stage First create a .env file copying from .env.example and add environment for below parameters only since it will be used for building container using docker-compose
SERVER_PORT=7777
DB_PASSWORD=root
DB_USERNAME=postgres
DB_DATABASE_NAME=truthy
DB_PORT=5488
REDIS_PORT=6399
After creating env file make changes in configuration in accordance with you development environment. Follow setup guide in case you missed it.
Now to run containers do
docker-compose build .
docker-compose up -d
These commands will run 3 containers for PostgresQL, Redis and Main API.
To run migration on docker container
docker exec -it <container_id_or_name> yarn migrate
To run seeder on docker container
docker exec -it <container_id_or_name> yarn seed
This project follows the following file structure:
truthy
├── config * Contains all configuration files
│ └── default.yml * Default configuration file.
│ └── development.yml * Configuration file for development environment.
│ └── production.yml * Configuration file for production environment.
│ └── test.yml * Configuration file for test environment.
├── coverage * Coverage reports after running `yarn coverage` command.
├── dist * Optimized code for production after `yarn build` is run.
├── images * this folder is where uploaded profile images are stored. This folder is git ignored.
├── src
│ └── <module> * Folder where specific modules all files are stored
│ └── dto * Data Transfer Objects.
│ └── entity * Models for module.
│ └── pipes * Includes validation pipes for NestJS modules.
│ └── serializer * Includes serializer for model data.
│ └── <module>.controller.ts * Controller file.
│ └── <module>.module.ts * root module file for module.
│ └── <module>.service.ts * Service file for <module>.
│ └── <module>.service.spec.ts * Test file for service.
│ └── <module>.repository.ts * Repository file for <module>.
│ └── <module>.repository.spec.ts * Test file for repository.
│ └── common * Common helpers function, dto, entity, exception, decorators etc.
│ └── config * Configuration variables files.
│ └── database * Database folders that includes migration and seeders file
│ └── migrations * Migration folder includes all migration files.
│ └── seeds * Seeds folder includes all seeders files.
│ └── exception * Exception folder includes custom exceptions.
│ └── app.module.ts * Root module of the application.
│ └── main.ts * The entry file of the application which uses the core function NestFactory to create a Nest application instance.
├── test * Contains E2E tests
Some important root files
.
├── .editorconfig * Coding styles (also by programming language).
├── .env * Environment variables for docker.
├── .prettierrc.js * Formatting Prettier options.
├── .eslintrc.js * ESLint configuration and rules.
├── .docker-compose.yml * Docker compose configuration.
├── Dockerfile * Docker file for prod environment.
├── Dockerfile.dev * Docker file for dev environment.
├── tsconfig.json * Typescript configuration for application.
By default Throttle has been implemented for all API's. Redis is default driver to record throttle state data. You can easily change configuration from config files.
User Will have 2FA authentication option available to be turned on or off. For 2FA time-based one-time password is used. A time-based one-time password (TOTP) application automatically generates an authentication code that changes after a certain period of time. Applications like Authenticator, 1Password, Authy etc. can be used to generate TOTP. When you enable 2FA, you will be sent a QR code in your email which should be scanned from above mentioned application and TOTP will be generated by those applications.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate. - see CONTRIBUTING.md
for details.
If you want to be featured in contributors list on our home page please add PR on https://github.com/gobeam/truthy-contributors to provide your details.
Released under the MIT License - see LICENSE.md
for details.
truthy's People
Forkers
nksmkj7 wantedsystem tonydspaniard harrytran998 windward-hive detectiveosint csyangpeng maisnamraju hoanghungict linecode grahamcrackers manishpaudel ryan2018-js cavewebs agoulziprod canh7antt8a oluwashane louiscklaw aryaw spotlesscoder kodlix luigigil planczero mannydiera leductanh nikhil-shrestha andreirk jc-coder mnguyen081002 devguy221 thiefjim mjmaix rajeet laskydev leohangrai nuoku vinhprs dk-khoado moatasimv devstojko jacksond882 hongquandev devlorvn amanix007 michaelgobz wooodhead ahrary wladimirguerra ngocson092 dorucioclea lilwayne470 tanbiranjum kimchan7415 tangcuyu rachmadideni buiduong094 chrisaandes ohrimenkosv53 neolanders cantuares dansasser walosha kiethuynhsl xiaoqiujun harry-88 nhuttranm elanetanu felipealbuquerq vnijat emircem sajjadkhoshnoudi mhtbhavsar neelbamroliya bizen299-mdhr hashmat2526 jamessmith7030 saadoundhirat mrtousif develop084 hocit4dev mohammed-sada vivafoxdirector santhoshpkumar ruban-s febrysw javier1234559 gittakisnani complicated2018 amainooti mdasad3617 marcions anubhavjain786 grimmkin rlodhiya2502 mdasifj625 acanon1 sangkyunyoon atharvdalaltruthy's Issues
Could you please tell me the version of Node.js used in this project and whether it supports using package-lock.json? I cannot run this project now.
error TS2688: Cannot find type definition file for 'ioredis'.
The file is in the program because:
Entry point for implicit type library 'ioredis'
node_modules/@nestjs/typeorm/dist/common/typeorm.decorators.d.ts:2:10 - error TS2305: Module '"typeorm"' has no exported member 'DataSource'.
Fix: Add try/catch to limitConsumerPromiseHandler for error handling
Can You please add MySQL ?
Can you please also add mysql for database option?
First issue
This is first issue
How to generate:
Expected
Please update documentation
We want to use Truthy for a simple project (crud), so I clone it to my local machine to test.
After running commands migrate/seed. Go to login screen, login and got relation user not found
=> need to set synchronize: true
login => wrong password (might be not Truthy@123 with jwt secret = example@123)
=> Register to manually set admin
=> got QueryFailedError: null value in column "address" of relation "user" violates not-null constraint
.
I really like this project and want to apply it to my company project but it seems lack of documentation and has some bugs. It's not about login/register bug I've got, it's about I don't feel safe applying Truthy to my company production project
Thanks,
Add a json data field that can be used to update any sort of meta data
Is your feature request related to a problem? Please describe.
Looking at whats out there now, it will be very useful to have another column that would be a json field where we can store details like user tenancy data or external details that fall outside the context of authentication.
Example of such a thing was I wanted to some user data that would be available using the /profile
api like external API keys.
Bug PostSQL
hi, I have an error with the database, QueryFailedError: NULL value violates NOT NULL constraint of column "address" in relation "user"
thank you
env variable not being called in ormconfig.ts
In ormconfig.ts, env variables are returned as undefined. While debugging, I found that ormconfig.ts executes before app.module.ts, hence ormconfig.ts doesn't have an idea about process.env.
How did I fix it?
- Installed @nestjs/config
- In ormconfig.ts,
import { ConfigModule } from '@nestjs/config';
ConfigModule.forRoot();
JwtTwoFactorGuard Issue
How to generate JwtTwoFactorGuard QRcode?
separate unit test directory and convert relative import to absolute
Is your feature request related to a problem? Please describe.
Make separate unit test directory and convert relative import to absolute
Ability to assign multiple roles to a user
Is your feature request related to a problem? Please describe.
It would be nice to be able to assign multiple roles to a user.
For example role 1 has x permissions, and role 2 has y permissions.
It would be nice to not have to create a third role with x and y permissions to cover both roles.
seed doesn't working
Describe the bug
I get the following error when running npm run seed
✖ Could not import seeders!
Error: Cannot find module 'src/config/email-template-data'
Require stack:
- /usr/src/app/src/database/seeds/create-email-template.seed.ts
- /usr/src/app/node_modules/typeorm-seeding/dist/importer.js
- /usr/src/app/node_modules/typeorm-seeding/dist/commands/seed.command.js
- /usr/src/app/node_modules/typeorm-seeding/dist/cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/usr/src/app/node_modules/@cspotcode/source-map-support/source-map-support.js:679:30)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:101:18)
at Object. (/usr/src/app/src/database/seeds/create-email-template.seed.ts:4:1)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Module.m._compile (/usr/src/app/node_modules/ts-node/src/index.ts:1455:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Object.require.extensions. [as .ts] (/usr/src/app/node_modules/ts-node/src/index.ts:1458:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/usr/src/app/src/database/seeds/create-email-template.seed.ts',
'/usr/src/app/node_modules/typeorm-seeding/dist/importer.js',
'/usr/src/app/node_modules/typeorm-seeding/dist/commands/seed.command.js',
'/usr/src/app/node_modules/typeorm-seeding/dist/cli.js'
]
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
(base)
To Reproduce
Steps to reproduce the behavior:
- setup docker-compose up
- run
npm run migrate
inside the container (also tried using docker exec) - npm run seed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.