Git Product home page Git Product logo

kitesjs / kites Goto Github PK

View Code? Open in Web Editor NEW
54.0 2.0 6.0 1.65 MB

Template-based Web Application Framework

Home Page: https://kitesjs.github.io/kites

License: MIT License

TypeScript 97.13% JavaScript 1.94% HTML 0.93%
template-based lightweight-framework kites-templates extensions-manager autodiscover web-application-framework typescript-framework javascript-framework websockets nodejs-framework

kites's Introduction

kites

Template-based Web Application Framework

Join the chat at https://gitter.im/nodevn/kites npm version npm downloads Travis

Kites is a framework providing dynamic applications assembling and Template-based extracting. Namely it contains a lot of templates and extensions to help building a new application quickly.

Features

  • Extension as a feature
  • Autodiscover extensions
  • Rich decorators system
  • Event-driven programming
  • Reactive programming
  • Storage mutiple providers
  • Micro frontends development

Installation

# install kites cli
$ npm install -g @kites/cli

# init a project
kites init my-project

# move to project workspace
cd my-project

# install dependencies
npm install

# start development
npm start

To change environment use cmd set NODE_ENV=development or use options your IDE provides. If you don't specify node environment kites assumes development as default.

Example

The application below simply prints out a greeting: Hello World!

TypeScript version:

import {engine} from '@kites/core';

async function bootstrap() {
  const app = await engine().init();
  app.logger.info('Hello World!');
}

bootstrap();

JavaScript version:

const kites = require('@kites/core');

kites.engine().init().then((app) => {
  app.logger.info('Hello World!');
});

Extensions

Kites is an eco-system and has many modules which can be assembled into a larger application. You are welcome to write your own extension or even publish it to the community.

Auto discovery

Kites has an option to allow the application auto discover extensions in the directory tree. This means kites will searches for files kites.config.js which describes the extensions and applies all the extensions that are found automatically.

This is fundamental principle for allowing extensions as plugins to be automatically plugged into the system. The application completed with minimalist lines of code, but very powerful!

import {engine} from '@kites/core';

async function bootstrap() {
  // let kites autodiscover the extensions
  const app = await engine({ discover: true }).init();
  app.logger.info('A new kites started!');
}

bootstrap();

Kites extensions auto discovery might slows down the startup and can be explicitly override by using use function. The following code has a slightly complicated configuration for each extension which we want to use.

import {engine} from '@kites/core';
import express from '@kites/express';

async function bootstrap() {
  const app = await engine({
      discover: false,
    })
    .use(express())
    .on('express:config', app => {
      app.get('/hi', (req, res) => res.send('hello!'));
    })
    .init();

  app.logger.info(`Let's browse http://localhost:3000/hi`);
}

// let kites fly!
bootstrap();

Templates

Here is the list of built-in templates and their implementation status:

  • starter: Kites Project Starter with Typescript (default)
  • docsify: Template webserver for documentation site generator
  • chatbot: Template for generating an AI Chatbot

More templates, checkout issue #1.

Documentation

License

MIT License

Copyright (c) 2018 Nhữ Bảo Vũ

The MIT License

kites's People

Contributors

dependabot[bot] avatar vunb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kites's Issues

Add BaseApiController

  • Allow a new controller definition extends from BaseApiController

Example:

@Controller("/")
class ExampleController extends BaseApiController {
    @Get("/")
    public async info() {
        return this.ok("foo");
    }

Implement http action results

List action results.

  • OkResult
  • OkNegotiatedContentResult
  • RedirectResult
  • ResponseMessageResult
  • StatusCodeResult
  • BadRequestErrorMessageResult
  • BadRequestResult
  • ConflictResult
  • CreatedNegotiatedContentResult
  • ExceptionResult
  • InternalServerError
  • NotFoundResult
  • JsonResult

Example:

@Controller("/todo")
class ToDoController extends BaseApiController {
    @Get("/:task")
    public async info() {
        return this.ok("foo");
    }

    @Get("/")
    public async list() {
        const content = { foo: "bar" };
        const statusCode = 403;

        return this.json(content, statusCode);
    }

Add HttpContext

The HttpContext property allow us to access the current request, response and user with ease.

  • Access HttpContext in controllers derived from BaseHttpController or @Inject decorator.

Todo - Kites Extensions/Templates

Wanted the list of cli tools:

  • mvc: Assembling all into complete ship (default), document
  • basic: Template for building from scratch
  • apidoc: Template for API Documentation, nodevn/kites-apidoc
  • express: Template for Express Application
  • restful: Template for generating a RESTful API Server
  • spa: Template for generating a Single Page Application (kites/spa)
  • cms: Template for generating a Content Management System (CMS)
  • chat: Template for generating a Chat application
  • chatbot: Template for generating an AI Chatbot application, vntk/chatbot, document
  • videocall: Template for generating a Video Call application
  • electron: Template for creating a desktop application with native_modules
  • gateway: Template for creating a microservices API Gateway
  • oauth|oauth2: Template for creating an OAuth2 Server
  • crawler: Template for crawl news, products, ...

Syntax:

kites init [my_app_name] --template chatbot

Example:

kites init my_kute_chatbot --template chatbot

Then a new project will be generated at the current directory.

Kites Micro Frontend

Build admin panel as an extension of kites. #kites-admin

First implement will use React?

Extensions have own their controllers and views for micro frontend.

Example:

Extension({
  prefix: 'api/v1',   // api route prefix
  controllers: [
    `./controllers/todo.controller`,
    `./controllers/user.controller`,
  ],
  views: [
    `./pages/user`,
    `./pages/dashboard`
  ]
})
class TodoExtension {}

Output:

  • The application publish the API controllers.
  • The client can access two generated pages: User and Dashboard

fs discover permission not allowed

Stat file folder without permission then we got an error:

2019-10-01T00:04:26.461Z [kites] info: Initializing [email protected] in mode "development", using configuration file kites.config.json
2019-10-01T00:04:26.470Z [kites] info: Searching for available extensions in E:\Projects\roomrtc\roomrtc-ce
2019-10-01T00:04:26.475Z [kites] info: Skipping extensions location cache when NODE_ENV=development or when option extensionsLocationCache === false, crawling now!
(node:8828) UnhandledPromiseRejectionWarning: Error: UNKNOWN: unknown error, stat 'E:\Projects\roomrtc\roomrtc-ce\node_modules\.bin\clang-apply-replacements'
    at Object.statSync (fs.js:855:3)
    at readFiles (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\fs.js:113:24)
    at readFiles (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\fs.js:115:38)
    at readFiles (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\fs.js:115:38)
    at Object.walkSyncLevel (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\fs.js:128:36)
    at Object.get (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\location-cache.js:22:21)
    at Object.discover (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\discover.js:26:35)
    at ExtensionsManager.init (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\extensions\extensions-manager.js:75:47)
    at KitesInstance.init (E:\Projects\roomrtc\roomrtc-ce\node_modules\@kites\core\engine\kites-instance.js:179:38)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:832:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Inject KITES_INSTANCE

  • Allow KITES_INSTANCE can be injected into Controllers, Services

Example:

import {Injectable, Inject} from '@kites/common';
import {KITES_INSTANCE, KitesInstance} from '@kites/core';

@Injectable()
class TodoService {
  constructor(
    @Inject(KITES_INSTANCE ) private kites: KitesInstance,
  ) {
    this.kites.logger.info('Injected kites instance!!');
  }
}

Add api close

  • add new api close to close kites application
  • may be use combine events with rxjs

Example:

// close application
await kites.close();

Support end to end testing

When the application grows, it is hard to manually test a behavior of each API endpoint. The end-to-end tests help us to make sure that everything is working correctly and fits project requirements.

TODO:

  • Add new module @kites/testing to support end to end testing
  • Help to init or close application properly
  • Support override kites providers and extensions usage

Example:

import { KitesInstance } from '@kites/core';
import { Test } from '@kites/testing';

import * as request from 'supertest';
import { TodoController } from './todo.controller';
import { TodoService } from './todo.service';

describe('Todo e2e', () => {
  let app: KitesInstance;
  let todoService = { findAll: () => ['list all tasks'] };

  beforeAll(async () => {
    app = await Test.createApp({
      providers: [TodoService],
    }).init();
  });

  it(`/GET list`, () => {
    return request(app.express.app)
      .get('/api/todo')
      .expect(200)
      .expect({
        data: todoService.findAll(),
      });
  });

  afterAll(async () => {
    await app.close();
  });
});

Add api discover

Add new api .discover(boolean | [{path, level, ...options}]) to discover extension in directory tree

Options:

  • boolean: turn on discover mode with default options, search in all folders has kites.config.js in kites.options.appPath
  • options: objects with multiple paths configuration
import {engine} from '@kites/core';

async function bootstrap() {
  // let kites autodiscover the extensions
  const app = await engine().discover(true).init();
  app.logger.info('A new kites started!');
}

bootstrap();

OR

import {engine} from '@kites/core';

async function bootstrap() {
  // let kites autodiscover the extensions
  const app = await engine().discover([true, 2, '/path1', '/path2']).init();
  app.logger.info('A new kites started!');
}

bootstrap();

Implement DI System

Trying to implement DI System for Kites.

Example:

Extension({
  controllers: [],
  views: []
})
class TodoExtension {
  constructor(@Inject(TodoService) svTodo: TodoService,) {
    // callable injected service here
    this.svTodo.begin(task);
  }
}

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.