JSPM

  • Created
  • Published
  • Downloads 733
  • Score
    100M100P100Q92362F
  • License MIT

Easy-to-use modern TypeScript framework for building many kind of applications.

Package Exports

  • alepha
  • alepha/api/files
  • alepha/api/jobs
  • alepha/api/notifications
  • alepha/api/parameters
  • alepha/api/users
  • alepha/api/verifications
  • alepha/api/workflows
  • alepha/batch
  • alepha/bin
  • alepha/bucket
  • alepha/cache
  • alepha/cache/redis
  • alepha/cli
  • alepha/command
  • alepha/datetime
  • alepha/email
  • alepha/fake
  • alepha/file
  • alepha/lock
  • alepha/lock/redis
  • alepha/logger
  • alepha/orm
  • alepha/package.json
  • alepha/queue
  • alepha/queue/redis
  • alepha/redis
  • alepha/retry
  • alepha/router
  • alepha/scheduler
  • alepha/security
  • alepha/server
  • alepha/server/basic-auth
  • alepha/server/cache
  • alepha/server/compress
  • alepha/server/cookies
  • alepha/server/cors
  • alepha/server/health
  • alepha/server/helmet
  • alepha/server/links
  • alepha/server/metrics
  • alepha/server/multipart
  • alepha/server/proxy
  • alepha/server/rate-limit
  • alepha/server/security
  • alepha/server/static
  • alepha/server/swagger
  • alepha/sms
  • alepha/thread
  • alepha/topic
  • alepha/topic/redis
  • alepha/tsconfig
  • alepha/vite
  • alepha/websocket

Readme

Logo Alepha

Easy mode for building TypeScript applications.

npm npm npm npm GitHub stars

What is this?

Build API endpoints (Docker or Serverless), React applications (SSR, CSR or SSG), and more!

Relies only on very few runtime dependencies. No more bloated frameworks.

All-in-one tool that takes care of configuration, development, build, deployment, testing, etc. Convention over configuration.

Enterprise-grade framework designed for developer experience and scalability.

For more information, please visit the documentation.

Examples

We will show:

  • API endpoint with automatic OpenAPI documentation
  • Full-stack React application with server-side rendering

Requirements

API endpoint

Write API endpoints with automatic OpenAPI documentation.

# Add required config files in the current folder
$ npx alepha init

Create a new file src/main.ts:

import { run, t, Alepha } from "alepha";
import { $action } from "alepha/server";
import { $swagger } from "alepha/server/swagger";

class Api {

  // Functions starting with $ are "descriptors".
  // Like React hooks, they must be called inside Alepha context.
  docs = $swagger();

  sayHello = $action({
    path: "/hello/:name",
    // Every feature inside Alepha is strongly typed with runtime validation.
    // Schema is based on TypeBox library.
    schema: {
      params: t.object({
        // Alepha provides many built-in types.
        // For example `t.text()` = `t.string()` + specific maxLength, auto-trim, etc.
        name: t.text()
      }),
      response: t.object({
        message: t.text(),
      })
    },
    handler: async ({ params }) => {
      return { message: `Hello ${params.name} !` };
    }
  });
}

// Creating Alepha instance is like creating a new context.
const alepha = Alepha.create();

// And you add features by registering classes.
alepha.with(Api);

// `run` will take care of Alepha lifecycle (startup, graceful shutdown, etc.)
run(alepha);

Run the development server:

$ npx alepha dev
# alepha dev comes with hot-reload and full TypeScript support, but you can also run:
$ node ./src/main.ts

Then, open your browser at http://localhost:3000/docs/ and enjoy your automatically generated documentation.

Production build

Once you are done, build the application for production:

$ npx alepha build

Application will be built in the dist/ folder, ready to be deployed on any platform (Docker, Serverless, etc.). Bonus, no need to "npm install" on the server, Alepha bundles everything together.

React Application

Build full-stack React applications, with server-side rendering.

$ npx alepha init --react

Create a file src/main.tsx:

import { Alepha, run, t } from "alepha";
import { $page } from "@alepha/react";
import { useState } from "react";

const Hello = (props: { count: number }) => {
  const [ count, setCount ] = useState(props.count);
  return <button onClick={() => setCount(count + 1)}>Clicked: {count}</button>
}

class AppRouter {
  index = $page({
    schema: {
      query: t.object({
        start: t.number({ default: 0 }),
      })
    },
    component: Hello,
    resolve: (req) => {
      return { count: req.query.start };
    },
  });
}

const alepha = Alepha.create();

alepha.with(AppRouter);

run(alepha);

Run the development server:

$ npx alepha dev

Open your browser at http://localhost:5173/ and see your React application in action.

What's next?

  • Dive into the full docs for more advanced stuff
  • Browse the GitHub repo for examples and source code
  • Check out the individual packages to see what else you can build