JSPM

  • Created
  • Published
  • Downloads 828
  • Score
    100M100P100Q92497F
  • License MIT

Alepha is a convention-driven TypeScript framework for building robust, end-to-end type-safe applications, from serverless APIs to full-stack React apps.

Package Exports

  • alepha
  • alepha/api/files
  • alepha/api/jobs
  • alepha/api/notifications
  • alepha/api/users
  • alepha/api/verifications
  • alepha/batch
  • alepha/bucket
  • alepha/cache
  • alepha/cache/redis
  • alepha/command
  • alepha/core
  • alepha/datetime
  • alepha/devtools
  • alepha/email
  • alepha/fake
  • alepha/file
  • alepha/lock
  • alepha/lock/redis
  • alepha/logger
  • alepha/postgres
  • alepha/queue
  • alepha/queue/redis
  • alepha/react
  • alepha/react/auth
  • alepha/react/form
  • alepha/react/head
  • alepha/react/i18n
  • alepha/redis
  • alepha/retry
  • alepha/router
  • alepha/scheduler
  • alepha/security
  • alepha/server
  • 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/security
  • alepha/server/static
  • alepha/server/swagger
  • alepha/topic
  • alepha/topic/redis
  • alepha/ui
  • alepha/vite

Readme

Logo Alepha

npm npm npm npm GitHub stars

A convention-driven TypeScript framework for building type-safe full-stack applications.

Quick Start

npx @alepha/cli create my-app

Or manually:

npm install alepha

What is this?

Alepha is an opinionated framework that handles everything from database to frontend.

It uses a descriptor-based architecture ($action, $page, $repository, etc.) and enforces type safety across the entire stack.

For more information, please visit the documentation.

Examples

Type-safe API endpoint

Write type-safe API endpoints with automatic OpenAPI documentation and more.

// app.ts
import { run, t } from "alepha";
import { $action } from "alepha/server";
import { $swagger } from "alepha/server/swagger";

class Api {
  docs = $swagger({
    info: {
      title: "My API",
      version: "1.0.0",
    }
  })

  sayHello = $action({
    path: "/hello/:name",
    schema: {
      params: t.object({
        name: t.text()
      }),
      response: t.object({
        message: t.text(),
      })
    },
    handler: async ({ params }) => {
      return { message: `Hello ${params.name} !` };
    }
  });
}

run(Api);
node app.ts

Database with Drizzle ORM

Drizzle ORM is a type-safe ORM for TypeScript, bundled inside Alepha.

You need drizzle-kit CLI as dev dependencies:

npm install -D drizzle-kit
// app.ts
import { $hook, run, t } from "alepha";
import { $entity, $repository, pg } from "alepha/postgres";
import { $logger } from "alepha/logger";

export const users = $entity({
  name: "users",
  schema: t.object({
    id: pg.primaryKey(),
    name: t.text(),
  }),
});


class Db {
  log = $logger();
  users = $repository(users);

  ready = $hook({
    on: "ready",
    handler: async () => {
      await this.users.create({
        name: "John Doe",
      });
      this.log.info("Users:", await this.users.find());
    }
  })
}

run(Db)
node app.ts

React Application

Build full-stack React applications, with server-side rendering (SSR) and client-side rendering (CSR).

React is required as a dependency:

npm install react react-dom
npm install -D @types/react
// app.tsx
import { 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 HomePage {
  index = $page({
    schema: {
      query: t.object({
        start: t.number({ default: 0 }),
      })
    },
    component: Hello,
    resolve: (req) => {
      return { count: req.query.start };
    },
  });
}

run(HomePage);

Vite is required as a devDependencies:

npm install -D vite

Add the Alepha Vite plugin to your Vite config:

// vite.config.ts
import { viteAlepha } from "alepha/vite";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    viteAlepha()
  ]
});

Create an index.html file:

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>App</title>
</head>
<body>
<script type="module" src="app.tsx"></script>
</body>
</html>

Then run Vite:

npx vite

License

MIT