Skip to content

Commit

Permalink
[accella] update README
Browse files Browse the repository at this point in the history
  • Loading branch information
koyopro committed Dec 3, 2024
1 parent fbbb04b commit 6b7a31f
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-dodos-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"accella": minor
---

Documented the setup instructions in the README
81 changes: 81 additions & 0 deletions packages/accella/README-ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
Language: [English](https://github.com/koyopro/accella/blob/main/packages/accella/README.md) | [日本語](https://github.com/koyopro/accella/blob/main/packages/accella/README-ja.md)

# Accella

A web framework built with Astro and Accel Record.

## Installation

```bash
npm create accella@latest my-accella-app
```

## Getting Started

```bash
cd my-accella-app
npm run dev
open http://localhost:4321
```

## 構成

### Astro

Accellaは、WebフレームワークのAstroをベースに構築されています。AstroはServer-Firstなフレームワークで、ReactやVue.jsのようなフロントエンドコンポーネントと柔軟に連携することができます。

ページのルーティングは`src/pages`ディレクトリに配置されたAstroファイルによって行われます。Astroファイルは`.astro`拡張子を持ち、HTMLとJavaScriptを1つのファイルに記述することができます。

https://docs.astro.build/ja/getting-started/

### Accel Record

Accel Recordは、型安全で同期的な、TypeScript用のORMです。Active Recordパターンを採用しており、インターフェースはRuby on RailsのActiveRecordに強く影響を受けています。

Accellaでは最初からAccel Recordが組み込まれているため、すぐにデータベースを使った開発を始めることができます。初期設定ではSQLiteが使われていますが、設定を変更することでMySQLやPostgreSQLも利用可能です。

Accel Recordではマイグレーション管理にPrismaを利用しており、`db/schema/main.prisma` にデータベース設定やモデルの定義を記述します。

https://github.com/koyopro/accella/blob/main/packages/accel-record/README.md

### Accel Web

Accel Webは、AstroによるWebアプリケーション開発をサポートするライブラリで、こちらもAccellaに組み込まれています。セッション管理、リクエストパラメータのパース、フォーム作成などの機能を提供します。

https://github.com/koyopro/accella/blob/main/packages/accel-web/README.md

#### Request Parameters

Accellaではリクエストパラメータを扱うためのRequest ParametersオブジェクトをAstro.locals.paramsで提供します。

Request Parametersの利用方法は[Accel WebのREADME](https://github.com/koyopro/accella/blob/main/packages/accel-web/README.md#form-and-request-parameters)を参照してください。

#### Session

Accellaではセッション管理用オブジェクトをAstro.locals.sessionで提供します。

```astro
---
import { User } from '../models';
if (Astro.request.method === 'POST') {
Astro.locals.session.user = User.findBy({ email: 'test@example.com' });
}
const currentUser: User | undefined = Astro.locals.session.user;
---
{currentUser ? <p>Hello, {currentUser.name}!</p> : <p>Hello, Guest!</p>}
```

デフォルトではセッションから取り出した値はany型ですが、`src/config/session.ts`の型定義を変更することで型安全に利用することができます。

```typescript
import { type Session as BaseSession } from "accella/session";
import { User } from "../models";

// You can define the type of the session object here
export type SessionData = {
user: User; // Add here
};

export type Session = BaseSession & Partial<SessionData>;
```
78 changes: 78 additions & 0 deletions packages/accella/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,81 @@
Language: [English](https://github.com/koyopro/accella/blob/main/packages/accella/README.md) | [日本語](https://github.com/koyopro/accella/blob/main/packages/accella/README-ja.md)

# Accella

A web framework built with Astro and Accel Record.

## Installation

```bash
npm create accella@latest my-accella-app
```

## Getting Started

```bash
cd my-accella-app
npm run dev
open http://localhost:4321
```

## Structure

### Astro

Accella is built on top of the web framework Astro. Astro is a server-first framework that can flexibly integrate with frontend components like React and Vue.js.

Page routing is handled by Astro files located in the `src/pages` directory. Astro files have the `.astro` extension and can contain both HTML and JavaScript in a single file.

https://docs.astro.build/en/getting-started/

### Accel Record

Accel Record is a type-safe and synchronous ORM for TypeScript. It adopts the Active Record pattern and is heavily influenced by Ruby on Rails' Active Record.

Accel Record is integrated into Accella from the start, allowing you to begin database-driven development immediately. By default, SQLite is used, but you can configure it to use MySQL or PostgreSQL.

Accel Record uses Prisma for migration management, and you can define your database settings and models in `db/schema/main.prisma`.

https://github.com/koyopro/accella/blob/main/packages/accel-record/README.md

### Accel Web

Accel Web is a library that supports web application development with Astro, and it is also integrated into Accella. It provides features such as session management, request parameter parsing, and form creation.

https://github.com/koyopro/accella/blob/main/packages/accel-web/README.md

#### Request Parameters

Accella provides a Request Parameters object via `Astro.locals.params` to handle request parameters.

For usage details, refer to the [Accel Web README](https://github.com/koyopro/accella/blob/main/packages/accel-web/README.md#form-and-request-parameters).

#### Session

Accella provides a session management object via `Astro.locals.session`.

```astro
---
import { User } from '../models';
if (Astro.request.method === 'POST') {
Astro.locals.session.user = User.findBy({ email: 'test@example.com' });
}
const currentUser: User | undefined = Astro.locals.session.user;
---
{currentUser ? <p>Hello, {currentUser.name}!</p> : <p>Hello, Guest!</p>}
```

By default, values retrieved from the session are of type `any`, but you can use type definitions in `src/config/session.ts` to ensure type safety.

```typescript
import { type Session as BaseSession } from "accella/session";
import { User } from "../models";

// You can define the type of the session object here
export type SessionData = {
user: User; // Add here
};

export type Session = BaseSession & Partial<SessionData>;
```

0 comments on commit 6b7a31f

Please sign in to comment.