diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9d83a16..cc1d049 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -28,7 +28,8 @@ "dotenv.dotenvx-vscode", "ms-vsliveshare.vsliveshare", "corschenzi.mermaid-graphical-editor", - "anthropic.claude-code" + "anthropic.claude-code", + "ms-python.mypy-type-checker" ], "settings": { "[python]": { diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh index 0dbdd9a..67b709a 100755 --- a/.devcontainer/postCreateCommand.sh +++ b/.devcontainer/postCreateCommand.sh @@ -31,7 +31,7 @@ fi # --- アプリケーションのセットアップ --- # アプリケーション固有のセットアップ(依存関係のインストール、マイグレーションなど)を実行する echo "🚀 Starting application setup..." -./scripts/setup.sh +sh ./scripts/setup_application.sh # --- データベースのセットアップ --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a261bbc..70ebcc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,6 @@ on: push: branches: [main, develop] pull_request: - branches: [main, develop] workflow_dispatch: jobs: @@ -18,7 +17,7 @@ jobs: uses: ./.github/actions/setup-node-deps - name: Format check - run: npm run format:check + run: npm run format:check:front lint-check: runs-on: ubuntu-latest @@ -30,7 +29,7 @@ jobs: uses: ./.github/actions/setup-node-deps - name: Lint check - run: npm run lint:check + run: npm run lint:check:front build: runs-on: ubuntu-latest @@ -43,4 +42,4 @@ jobs: uses: ./.github/actions/setup-node-deps - name: Build - run: npm run build + run: npm run build:front diff --git a/.github/workflows/ci_server.yml b/.github/workflows/ci_server.yml index 4c11c7f..9c7966a 100644 --- a/.github/workflows/ci_server.yml +++ b/.github/workflows/ci_server.yml @@ -4,7 +4,7 @@ on: push: branches: [main, develop] pull_request: - branches: [main, develop] + workflow_dispatch: env: PYTHON_VERSION: '3.13' @@ -89,6 +89,18 @@ jobs: working-directory: ./server run: uv sync + - name: Run Ruff check (Linter) + working-directory: ./server + run: uv run ruff check . + + - name: Run Ruff format check (Formatter) + working-directory: ./server + run: uv run ruff format --check . + + - name: Run mypy (Type check) + working-directory: ./server + run: uv run mypy . + - name: Run Alembic migrations working-directory: ./server run: dotenvx run --env-file ../.env -- uv run alembic -n testdb upgrade head diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml index aca7570..b0e210d 100644 --- a/.github/workflows/firebase-hosting-merge.yml +++ b/.github/workflows/firebase-hosting-merge.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: npm run install:all && npm run build + - run: npm run install:all && npm run build:front - uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml index 7f614b3..93c2de7 100644 --- a/.github/workflows/firebase-hosting-pull-request.yml +++ b/.github/workflows/firebase-hosting-pull-request.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: npm run install:all && npm run build + - run: npm run install:all && npm run build:front - uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.vscode/settings.json b/.vscode/settings.json index fa38051..b8223d4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,7 +34,9 @@ "editor.defaultFormatter": "vscode.html-language-features" }, "[markdown]": { - "editor.defaultFormatter": "vscode.markdown-language-features" + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.defaultFormatter": "DavidAnson.vscode-markdownlint" }, "biome.lsp.bin": "frontend/node_modules/@biomejs/biome/bin/biome", "tailwindCSS.experimental.classRegex": [ @@ -53,5 +55,12 @@ "python.testing.pytestEnabled": true, "python.testing.pytestArgs": ["./server/tests", "-svvv"], "python.testing.autoTestDiscoverOnSaveEnabled": true, - "python.defaultInterpreterPath": "${workspaceFolder}/server/.venv/bin/python" + "python.defaultInterpreterPath": "${workspaceFolder}/server/.venv/bin/python", + "mypy-type-checker.reportingScope": "workspace", + "mypy-type-checker.importStrategy": "fromEnvironment", + "mypy-type-checker.args": [ + "--ignore-missing-imports", + "--follow-imports=silent" + ], + "python.analysis.typeCheckingMode": "off" } diff --git a/cspell.json b/cspell.json index ac9c202..c261480 100644 --- a/cspell.json +++ b/cspell.json @@ -2,18 +2,28 @@ "version": "0.2", "language": "en,ja", "words": [ - "Tabishare", - "devcontainers", - "itsmechlark", "anthropics", - "pylance", - "dbaeumer", + "autodocs", "bradlc", + "dbaeumer", + "devcontainers", + "devdb", + "dotenvx", "eamodio", - "uvicorn", + "fastapi", + "itsmechlark", + "mypy", "Nonoctal", + "NOPASSWD", + "psql", + "pylance", + "pytest", + "rolname", "Tabi", - "autodocs" + "Tabishare", + "tablename", + "testdb", + "uvicorn" ], "ignoreWords": [], "import": [] diff --git a/package.json b/package.json index 0edd3ba..df8beca 100644 --- a/package.json +++ b/package.json @@ -3,18 +3,34 @@ "private": true, "version": "0.0.0", "scripts": { - "dev": "concurrently --names \"FRONT,SERVER,STORYBOOK\" --prefix-colors \"cyan,yellow\" \"npm run dev:front\" \"npm run dev:server\" \"npm run dev:storybook\"", + "// --- ALL --- //": "", + "dev": "concurrently --names \"FRONT,SERVER,STORYBOOK\" --prefix-colors \"cyan,yellow,magenta\" \"npm run dev:front\" \"npm run dev:server\" \"npm run dev:storybook\"", + "install:all": "npm ci && cd frontend && npm ci", + + "// --- FRONTEND --- //": "", "dev:front": "cd frontend && npm run dev", - "dev:server": "cd server && python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload", "dev:storybook": "cd frontend && npm run storybook", - "install:all": "npm ci && cd frontend && npm ci", - "build": "cd frontend && npm run build", - "lint:check": "cd frontend && npm run lint:check", - "lint:fix": "cd frontend && npm run lint:fix", - "format:check": "cd frontend && npm run format:check", - "format:fix": "cd frontend && npm run format:fix", - "preview": "cd frontend && npm run preview", - "db:connect": "npx dotenvx run -- sh -c 'psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB'" + "build:front": "cd frontend && npm run build", + "lint:check:front": "cd frontend && npm run lint:check", + "lint:fix:front": "cd frontend && npm run lint:fix", + "format:check:front": "cd frontend && npm run format:check", + "format:fix:front": "cd frontend && npm run format:fix", + "preview:front": "cd frontend && npm run preview", + + "// --- SERVER --- //": "", + "dev:server": "cd server && npx dotenvx run --env-file ../.env -- uv run uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload", + "test:server": "cd server && npx dotenvx run --env-file ../.env -- uv run pytest", + "type-check:server": "cd server && uv run mypy .", + "lint:check:server": "cd server && uv run ruff check .", + "lint:fix:server": "cd server && uv run ruff check --fix .", + "format:check:server": "cd server && uv run ruff format --check .", + "format:fix:server": "cd server && uv run ruff format .", + + "// --- DATABASE --- //": "", + "connect:db": "npx dotenvx run -- sh -c 'psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB'", + "migrate:db": "cd server && npx dotenvx run --env-file ../.env -- alembic -n devdb upgrade head", + "status:db": "cd server && npx dotenvx run --env-file ../.env -- alembic -n devdb current", + "rollback:db": "cd server && npx dotenvx run --env-file ../.env -- alembic -n devdb downgrade -1" }, "devDependencies": { "@dotenvx/dotenvx": "^1.48.4", diff --git a/scripts/setup.sh b/scripts/setup_application.sh similarity index 100% rename from scripts/setup.sh rename to scripts/setup_application.sh diff --git a/server/README.md b/server/README.md index 7fca2f5..0e8114b 100644 --- a/server/README.md +++ b/server/README.md @@ -5,12 +5,14 @@ FastAPI + PostgreSQL + Alembicを使用したバックエンドAPI ## 開発環境手順 ### 前提条件 + - Docker Desktopがインストールされている - VS Code + Dev Containers拡張機能がインストールされている ### devcontainer環境でのセットアップ 1. **devcontainer起動** + ```bash cd tabi-share # VS Codeでプロジェクトを開く @@ -18,6 +20,7 @@ FastAPI + PostgreSQL + Alembicを使用したバックエンドAPI ``` 2. **データベースマイグレーション** + ```bash cd server @@ -26,22 +29,24 @@ FastAPI + PostgreSQL + Alembicを使用したバックエンドAPI ``` 3. **開発サーバー起動** + ```bash npm run dev ``` - ### アクセス先 -- フロントエンド: http://localhost:3000 (または5173) -- バックエンドAPI: http://localhost:8000 -- API自動ドキュメント: http://localhost:8000/docs -- 代替ドキュメント: http://localhost:8000/redoc + +- フロントエンド: (または5173) +- バックエンドAPI: +- API自動ドキュメント: +- 代替ドキュメント: ## 開発ワークフロー(devcontainer環境) ### 環境変数の変更手順 1. **環境変数の復号化** + ```bash cd tabi-share @@ -51,11 +56,13 @@ FastAPI + PostgreSQL + Alembicを使用したバックエンドAPI 2. **.envファイルをIDEで編集する** 3. **環境変数の暗号化** + ```bash - npx detenvx encrypt + npx dotenvx encrypt ``` ### パッケージの追加手順 + ```bash cd server @@ -71,12 +78,14 @@ uv add --dev pytest 1. **server/app/models.pyにモデルを追加する** 2. **マイグレーションファイルを生成する** + ```bash cd server npx dotenvx run --env-file ../.env -- alembic -n devdb revision --autogenerate -m "file_name" ``` 3. **マイグレーションファイルをDBに適用する** + ```bash # 現在のバージョンを確認する npx dotenvx run --env-file ../.env -- alembic -n devdb current @@ -98,13 +107,17 @@ uv add --dev pytest ``` ### DBに直接アクセスする方法 + - 環境変数の値を使ってアクセスする + ```bash cd tabi-share npx dotenvx run -- sh -c 'psql -U $POSTGRES_USER -h $POSTGRES_HOST -d $POSTGRES_DB' ``` + - よく使用するコマンド + ```bash \l # List Databases \dt # List Tables @@ -114,12 +127,15 @@ uv add --dev pytest ``` ### 新機能開発 + 1. **機能ブランチ作成** + ```bash git switch -c feature/your-feature-name ``` 2. **モデル定義** (`app/models.py`) + ```python class YourModel(Base): __tablename__ = "your_table" @@ -128,6 +144,7 @@ uv add --dev pytest ``` 3. **マイグレーション生成・適用** + ```bash cd server npx dotenvx run --env-file ../.env -- alembic -n devdb revision --autogenerate -m "file_name" @@ -135,6 +152,7 @@ uv add --dev pytest ``` 4. **スキーマ定義** (`app/schemas.py`) + ```python class YourModelCreate(BaseModel): # 作成用スキーマ @@ -146,12 +164,14 @@ uv add --dev pytest ``` 5. **CRUD操作実装** (`app/cruds/your_model.py`) + ```python async def create_your_model(db: Session, model_data: YourModelCreate): # CRUD実装 ``` 6. **APIルーター実装** (`app/routers/your_model.py`) + ```python @router.post("/", response_model=YourModelResponse) async def create_endpoint( @@ -162,9 +182,12 @@ uv add --dev pytest ``` ### テスト実行 + #### VScodeのテスト機能を使った実行方法 + - アクティビティバーのテストを押し、対象のテストファイルを実行する場合 - Terminalから実行する場合 + ```bash cd server # 全テスト実行 @@ -192,11 +215,11 @@ uv add --dev pytest ## よく使用するコマンド(devcontainer環境) - ## API設計パターン ### 標準的なCRUDエンドポイント -``` + +```text GET /api/v1/users/ # ユーザー一覧取得 POST /api/v1/users/ # ユーザー作成 GET /api/v1/users/{id} # 特定ユーザー取得 @@ -205,6 +228,7 @@ DELETE /api/v1/users/{id} # ユーザー削除 ``` ### レスポンス形式 + ```json { "data": {...}, @@ -222,6 +246,7 @@ DELETE /api/v1/users/{id} # ユーザー削除 ## 開発ツール設定 ### mypy設定 + - 設定内容を整理して記述する プロジェクトルートに`mypy.ini`または`pyproject.toml`で型チェック設定: @@ -244,6 +269,7 @@ ignore_errors = true ``` --> ### pytest設定 + - 設定内容を整理して記述する