diff --git a/.cursor/commands/create-pr.md b/.cursor/commands/create-pr.md index 2ff323fb..2c2c7c91 100644 --- a/.cursor/commands/create-pr.md +++ b/.cursor/commands/create-pr.md @@ -21,8 +21,8 @@ ## ルール -- 日本語での回答・作成を基本とする -- 文体は常体で回答・作成すること +- タイトルは英語で作成し、descriptionは日本語での回答・作成を基本とする +- 文体は常体で作成すること ## 手順 @@ -37,7 +37,7 @@ - このIssueが何をするものでどのような変更を行うものかを確認する - このIssueのラベルを確認する - `gh issue` コマンドを使用してIssueを確認すること - - 対象のIssueがない場合はユーザーに確認する + - 対象のIssueがない場合やIssueの内容とbranch名がおおよそ一致しない場合はユーザーに確認する 3. **変更点を確認する** @@ -55,6 +55,7 @@ - PRのタイトルはIssueのタイトルや内容、Branchでの変更点をを詳しくかつ内容を簡潔に反映したものにする。 - Titleの形式は `(): ` であり、この形式で作成すること。 + - 英語で作成すること 6. **Descriptionを作成する** - テンプレートは`.github/pull_request_template.md`を利用すること diff --git a/.github/act/README.md b/.github/act/README.md new file mode 100644 index 00000000..f0672d01 --- /dev/null +++ b/.github/act/README.md @@ -0,0 +1,27 @@ +# Act Debug + +Run CI performed by Github Action in a local environment + +Install [`act`](https://github.com/nektos/act) and Start `Docker` for local environment. + +## Setup + +1. add .env file in the root directory ref .env.example +2. add .secrets file in the root directory ref .secrets.example + +## Run + +```sh +# run all workflows +act --container-architecture linux/amd64\ + --secret-file ./.github/act/.secrets\ + --env-file ./.github/act/.env\ + --defaultbranch main + +# run specific workflow +act --container-architecture linux/amd64\ + --secret-file ./.github/act/.secrets\ + --env-file ./.github/act/.env\ + --defaultbranch main\ + -W "target-flow" +``` diff --git a/README.md b/README.md index 46002270..3f67d1d2 100644 --- a/README.md +++ b/README.md @@ -116,18 +116,3 @@ bun run test # Other # See `scripts` field in `package.json` ``` - -## CI in the local environment - -Perform CI performed by Github Action in a local environment - -Install [`act`](https://github.com/nektos/act) and Start `Docker` - -```sh -act --container-architecture linux/amd64 --secret-file ./.github/act/.secrets --env-file ./.github/act/.env --defaultbranch main -W "target-flow" -``` - -## Note - -> [!NOTE] -> Since Biome's VSCode extension does not support workspaces, all settings are rolled up and configured in root's `biome.json`. diff --git a/apps/api/README.md b/apps/api/README.md index 0943da2c..93edfd81 100644 --- a/apps/api/README.md +++ b/apps/api/README.md @@ -1,90 +1,242 @@ # mona-ca Backend API Server -## What's this ? +Backend API server for mona-ca. -This is the code for the Server-Side API of mona-ca. +## 📖 Table of Contents + +- [Overview](#overview) +- [Tech Stack](#tech-stack) +- [Architecture](#architecture) +- [Setup](#setup) +- [Development](#development) +- [Testing](#testing) +- [Database](#database) +- [Deployment](#deployment) + +## Overview + +mona-ca Backend API is a serverless API server running on Cloudflare Workers. +Built with Clean Architecture principles to ensure high maintainability and extensibility. + +## Tech Stack It is made by these: -* __Bun__ 🥟: All-in-one JavaScript runtime -* __Wrangler__ ☁️: The Cloudflare Developer Platform -* __ElysiaJS__ 🦊: Ergonomic web framework -* __Drizzle ORM__ 🌦️: Headless TypeScript ORM -* __Lucia__ 🔐: Auth library -* __Oslo__ 🔒: Many auth utilities -* __Arctic__ 🔏: Collection of OAuth 2.0 clients -* __Resend__ ✉️: Library for the Resend API. +__Bun__ 🥟: All-in-one JavaScript runtime + +__Wrangler__ ☁️: The Cloudflare Developer Platform + +__ElysiaJS__ 🦊: Ergonomic web framework + +__Drizzle ORM__ 🌦️: Headless TypeScript ORM + +__Lucia__ 🔐: Auth library + +__Oslo__ 🔒: Many auth utilities + +__Arctic__ 🔏: Collection of OAuth 2.0 clients + +__Resend__ ✉️: Library for the Resend API. + +## Architecture + +Built on Clean Architecture, DDD, and Onion Architecture with a layered architecture pattern. -Project Architecture: +### Architecture Principles -* __Clean Architecture__ 📚: to ensure independence -* __Repository Pattern__ 🗄️: Abstraction of data access -* __SOLID Principles__ 🔄: Programming Principles +- **Clean Architecture**: Keep business logic independent from frameworks and infrastructure +- **DDD**: Domain-Driven Design +- **Onion Architecture**: Onion Architecture +- **Repository Pattern**: Abstract data access logic +- **SOLID Principles**: Design principles for maintainability and extensibility +- **Dependency Injection**: Improve testability +- **Feature-based Organization**: Organize code by domain features -## Start Development Server +### Layer Structure -To start the development server run: +```text +┌─────────────────────────────────────┐ +│ Presentation Layer │ routes/ +│ (ElysiaJS Routes) │ +├─────────────────────────────────────┤ +│ Adapter Layer │ features/*/adapters/ +│ (Presenters, Repositories, │ +│ Gateways) │ +├─────────────────────────────────────┤ +│ Application Layer │ features/*/application/ +│ (Use Cases, Ports) │ +├─────────────────────────────────────┤ +│ Domain Layer │ features/*/domain/ +│ (Entities, Value Objects) │ +├─────────────────────────────────────┤ +│ Infrastructure Layer │ core/infra/ +│ (Drizzle, Crypto, Config) │ +└─────────────────────────────────────┘ +``` + +See [Architecture Documentation](./docs/architecture.md) for details. + +### Directory Structure + +```text +apps/api/ +├── src/ +│ ├── core/ # Common infrastructure & libraries +│ │ ├── adapters/ # Common adapter implementations +│ │ ├── di/ # DI container +│ │ ├── domain/ # Common domain objects +│ │ ├── infra/ # Infrastructure implementations +│ │ ├── lib/ # Common libraries +│ │ ├── ports/ # Common interfaces +│ │ └── testing/ # Testing support +│ ├── features/ # Feature modules +│ │ └── [feature]/ # Each feature +│ │ ├── adapters/ # Adapter layer +│ │ ├── application/ # Application layer +│ │ ├── di/ # Feature DI container +│ │ ├── domain/ # Domain layer +│ │ └── testing/ # Testing support +│ ├── plugins/ # Elysia plugins +│ ├── routes/ # Route definitions +│ └── index.ts # Entry point +├── tests/ # E2E tests +├── drizzle/ # DB migrations +├── docs/ # Documentation +├── types/ # Type definitions +├── package.json # Package configuration +├── tsconfig.json +├── vitest.config.ts +├── wrangler.jsonc # Cloudflare configuration +└── drizzle.config.ts # Drizzle configuration +``` + +## Setup + +### Installation ```sh -# install -bun i +# Install dependencies +bun install +``` + +### Environment Variables + +Create a `.dev.vars` file and set the required environment variables. + +### Database Setup + +```sh +# Generate migration files +bun run db:gen + +# Apply migrations (local) +bun run db:mig +``` -# dev server start -bun dev +## Development + +### Start Development Server + +```sh +bun run dev ``` -## OpenAPI +The development server starts at `http://localhost:8787`. + +### OpenAPI/Swagger + +API documentation is available at: ```sh open http://localhost:8787/swagger ``` -## Development Tool Commands +### Code Quality Checks -### Check +#### Static Code Analysis -static code check about syntax, format, import +Check syntax, format, and import order. ```sh -# not fixed -bun check +# Check only +bun run check -# force fix -bun check:fix +# Auto-fix +bun run check:fix ``` -### Test +#### Type Checking ```sh -# run test -bun run test # not `bun test` +bun run typecheck +``` + +### Coding Guidelines -# run test (watch mode) -bun run test:watch +See [Implementation Guide](./docs/guides.md) for detailed implementation guidelines. + +## Testing + +### Run Tests + +```sh +# Run all tests +bun run test + +# Watch mode +bun run test:w ``` -### Type Check +### Testing Strategy + +- **Unit Test**: Test Use Cases and Repositories +- **Integration Test**: Test Plugins and Routes + +Tests use Vitest and Cloudflare Workers Simulator. + +See [Implementation Guide - Testing Strategy](./docs/guides.md#テスト戦略) for details. + +## Database + +### Migrations ```sh -bun type-check +# Generate migration files +bun run db:gen + +# Apply migrations (local) +bun run db:mig ``` -### Database +### Drizzle Studio + +GUI tool for database management. ```sh -# generate migration files -db:gen +# Open local DB +bun run db:std -# migration -db:mig +# Open remote DB (production) +bun run db:std:remote +``` -# start Drizzle studio(local) -db:std +Opens `https://local.drizzle.studio` in your browser. -# start Drizzle studio(remote) -db:std:remote +## Deployment + +### Build + +```sh +# Build (dry-run) +bun run build ``` -### Other +### Deploy -See `scripts` field in [`package.json`](https://github.com/koutyuke/mona-ca/blob/main/apps/api/package.json) +```sh +# Deploy to Cloudflare Workers +wrangler deploy + +# Deploy to production +wrangler deploy --env production +``` diff --git a/apps/api/docs/architecture.md b/apps/api/docs/architecture.md index f5074c7c..8b3cf5a9 100644 --- a/apps/api/docs/architecture.md +++ b/apps/api/docs/architecture.md @@ -32,7 +32,7 @@ mona-ca Backend APIは、Clean Architectureをベースとした多層アーキ ## 技術スタック | カテゴリ | 技術 | 用途 | -|---------|------|------| +| --- | --- | --- | | Runtime | Bun | JavaScript/TypeScriptランタイム | | Platform | Cloudflare Workers | エッジコンピューティング環境 | | Framework | ElysiaJS | Web API Framework | @@ -62,7 +62,7 @@ mona-ca Backend APIは、Clean Architectureをベースとした多層アーキ │ Gateways) │ ├─────────────────────────────────────┤ │ Application Layer │ features/*/application/ -│ (Use Cases, Contracts, Ports) │ +│ (Use Cases, Ports) │ ├─────────────────────────────────────┤ │ Domain Layer │ features/*/domain/ │ (Entities, Value Objects) │ @@ -122,12 +122,12 @@ mona-ca Backend APIは、Clean Architectureをベースとした多層アーキ - エラーハンドリング - Result型(`ok()`, `err()`)での結果返却 -**Contracts** (`contracts/`): +**Inbound Ports** (`ports/in/`): - UseCaseのInterface定義 - 入力/出力型の定義 -**Ports** (`ports/`): +**Outbound Ports** (`ports/out/`): - Repository Interfaceの定義 - Gateway Interfaceの定義 @@ -166,19 +166,11 @@ apps/api/ │ ├── core/ # 共通インフラ・ライブラリ │ │ ├── adapters/ # 共通ゲートウェイ実装 │ │ │ └── gateways/ -│ │ │ ├── email/ -│ │ │ └── turnstile/ │ │ ├── di/ # コアDIコンテナ -│ │ │ └── container.ts │ │ ├── domain/ # 共通ドメインオブジェクト │ │ │ └── value-objects/ -│ │ ├── infra/ # インフラ実装 -│ │ │ ├── config/ # 環境変数管理 -│ │ │ ├── crypto/ # 暗号化関連 -│ │ │ ├── drizzle/ # DB・スキーマ定義 -│ │ │ └── elysia/ # Elysia拡張 +│ │ ├── infra/ # 共通インフラ実装 │ │ ├── lib/ # 共通ライブラリ -│ │ │ └── ... │ │ ├── ports/ # 共通ポート(インターフェース) │ │ │ ├── gateways/ │ │ │ └── system/ @@ -193,13 +185,12 @@ apps/api/ │ │ │ ├── presenters/ │ │ │ └── repositories/ │ │ ├── application/ # アプリケーション層 -│ │ │ ├── contracts/ # UseCaseインターフェース │ │ │ ├── infra/ # Feature固有のインフラ -│ │ │ ├── ports/ # Repository/Gatewayインターフェース +│ │ │ ├── ports/ +│ │ │ │ ├── in/ # UseCase Interface +│ │ │ │ └── out/ # Repository/Gateway Interface │ │ │ └── use-cases/ # UseCaseの実装 │ │ ├── di/ # Feature固有のDIコンテナ -│ │ │ ├── container.interface.ts -│ │ │ └── container.ts │ │ ├── domain/ # ドメイン層 │ │ │ ├── entities/ │ │ │ └── value-objects/ @@ -211,12 +202,6 @@ apps/api/ │ │ └── index.ts # Feature公開API │ │ │ ├── plugins/ # Elysiaプラグイン -│ │ ├── auth/ # 認証プラグイン -│ │ ├── captcha/ # CAPTCHA検証 -│ │ ├── container/ # DI Plugin -│ │ ├── openapi/ # OpenAPI/Swagger -│ │ ├── ratelimit/ # レート制限プラグイン -│ │ └── client-type/ # クライアントタイププラグイン │ │ │ ├── routes/ # ルート定義 │ │ ├── [Slug]/ # 各スライス @@ -253,14 +238,10 @@ features/[feature-name]/ │ ├── find-by-id.test.ts │ └── ... ├── application/ -│ ├── contracts/ # UseCaseのInterface定義 -│ │ └── [domain]/ -│ │ └── [action].usecase.interface.ts │ ├── infra/ # Feature固有のインフラ実装 -│ ├── ports/ # Repository/GatewayのInterface -│ │ ├── gateways/ -│ │ ├── repositories/ -│ │ └── infra/ +│ ├── ports/ # PortsのInterface +│ │ ├── in/ # UseCase Interface +│ │ └── out/ # Repository/Gateway Interface │ └── use-cases/ # UseCaseの実装 │ └── [domain]/ │ ├── [action].usecase.ts @@ -328,8 +309,6 @@ plugins core/infra core/lib 1. UseCase内でエラー発生 ↓ Result型で`err()`を返す 2. Route層でResult型を判定 - ↓ エラー時は例外をthrow -3. Error Plugin - ↓ 適切なHTTPステータスとメッセージを返す -4. Error Response + ↓ エラー時は`error(code, context)`を返す +3. Error Responseを返す ``` diff --git a/apps/catalog/README.md b/apps/catalog/README.md index 784f0b84..688606df 100644 --- a/apps/catalog/README.md +++ b/apps/catalog/README.md @@ -1 +1,117 @@ -# `catalog` \ No newline at end of file +# mona-ca Component Catalog + +Component catalog and design system for mona-ca using Storybook. + +## 📖 Table of Contents + +- [Overview](#overview) +- [Tech Stack](#tech-stack) +- [Setup](#setup) +- [Development](#development) +- [Building](#building) + +## Overview + +mona-ca Component Catalog is a Storybook-based UI component library showcase. +This catalog provides interactive documentation and testing environment for all UI components used in mona-ca applications. + +It supports both web and mobile (React Native) environments, allowing developers to browse and test components in isolation. + +## Tech Stack + +It is made by these: + +__Storybook__ 📚: Frontend workshop for UI development + +__Expo__ 📱: The fastest way to build an app + +__React Native__ ⚛️: Framework for building native apps + +__NativeWind__ 🎨: Tailwind CSS for React Native + +__React Native Web__ 🌐: React Native for Web + +## Setup + +### Installation + +```sh +# Install dependencies +bun install +``` + +### Prebuild + +Generate native projects for iOS and Android. + +```sh +bun run prebuild +``` + +## Development + +### Start Storybook (Web) + +Start Storybook server for web browsers. + +```sh +bun run sb +``` + +The Storybook UI will be available at `http://localhost:6006`. + +### Start Storybook (Mobile) + +Start Expo development server with Storybook enabled. + +```sh +# Start with development build +bun run sb:mobile + +# Start iOS +bun run sb:ios +``` + +### Generate Storybook Stories + +Generate story list for React Native Storybook. + +```sh +bun run sb:gen +``` + +### Code Quality Checks + +#### Static Code Analysis + +Check syntax, format, and import order. + +```sh +# Check only +bun run check + +# Auto-fix +bun run check:fix +``` + +## Building + +### Build Storybook (Web) + +Build static Storybook site for deployment. + +```sh +bun run sb:build +``` + +The static site will be generated in `./.storybook/static`. + +### Build Native Apps + +```sh +# Build iOS +bun run ios + +# Build Android +bun run android +``` diff --git a/apps/mobile/README.md b/apps/mobile/README.md new file mode 100644 index 00000000..631716fc --- /dev/null +++ b/apps/mobile/README.md @@ -0,0 +1,169 @@ +# mona-ca Mobile Application + +Mobile application for mona-ca. + +## 📖 Table of Contents + +- [Overview](#overview) +- [Tech Stack](#tech-stack) +- [Architecture](#architecture) +- [Setup](#setup) +- [Development](#development) +- [Building](#building) + +## Overview + +mona-ca Mobile Application is a cross-platform mobile app built with React Native and Expo. +This app allows users to manage their menstrual cycles and share information with their partners. + +## Tech Stack + +It is made by these: + +__Expo__ 📱: The fastest way to build an app + +__React Native__ ⚛️: Framework for building native apps + +__NativeWind__ 🎨: Tailwind CSS for React Native + +__Jotai__ ⚛️: Primitive and flexible state management + +__TanStack Query__ 🔄: Powerful data synchronization + +__React Hook Form__ 📝: Performant forms with validation + +__Valibot__ ✅: Schema validation + +## Architecture + +Built on **Feature-Sliced Design (FSD)** with Presenter/Container Pattern. + +### Architecture Principles + +- **Feature-Sliced Design**: Structure code by business domains and technical purpose +- **Presenter/Container Pattern**: Separate UI logic from business logic +- **Composition Pattern**: Inject handlers and components into Presenter +- **SOLID Principles**: Design principles for maintainability and extensibility +- **Dependency Injection**: Improve testability + +### Layer Structure + +```text +┌─────────────────────────────────────┐ +│ App Layer │ app/ +│ (Expo Router) │ +├─────────────────────────────────────┤ +│ Layers │ +│ ┌───────────────────────────────┐ │ +│ │ Pages (Routes) │ │ layers/pages/ +│ ├───────────────────────────────┤ │ +│ │ Widgets (Complex UI) │ │ layers/widgets/ +│ ├───────────────────────────────┤ │ +│ │ Features (Business Logic) │ │ layers/features/ +│ ├───────────────────────────────┤ │ +│ │ Entities (Business Models) │ │ layers/entities/ +│ ├───────────────────────────────┤ │ +│ │ Shared (Common Code) │ │ layers/shared/ +│ └───────────────────────────────┘ │ +└─────────────────────────────────────┘ +``` + +See [Architecture Documentation](./docs/architecture.md) for details. + +### Directory Structure + +```text +apps/mobile/ +├── src/ +│ ├── app/ # Expo Router routes +│ └── layers/ # FSD layers +│ ├── pages/ # Page components +│ ├── widgets/ # Complex UI components +│ ├── features/ # Business logic features +│ ├── entities/ # Business entities +│ └── shared/ # Shared utilities +├── assets/ # Static assets +├── docs/ # Documentation +├── types/ # Type definitions +├── ios/ # iOS native code +├── android/ # Android native code +├── package.json +├── tsconfig.json +├── app.json # Expo configuration +├── babel.config.js +└── metro.config.js +``` + +## Setup + +### Installation + +```sh +# Install dependencies +bun install +``` + +### Environment Variables + +Create environment variables as needed. + +### Prebuild + +Generate native projects for iOS and Android. + +```sh +bun run prebuild +``` + +## Development + +### Start Development Server + +```sh +# Start with development build +bun run dev + +# Start iOS +bun run dev:ios + +# Start Android +bun run dev:android +``` + +### Code Quality Checks + +#### Static Code Analysis + +Check syntax, format, and import order. + +```sh +# Check only +bun run check + +# Auto-fix +bun run check:fix +``` + +#### Type Checking + +```sh +bun run typecheck +``` + +### Coding Guidelines + +See [Implementation Guide](./docs/guides.md) for detailed implementation guidelines. + +## Building + +### Build for iOS + +```sh +bun run ios +``` + +### Build for Android + +```sh +bun run android +```