@ripla/godd-mcp 0.1.2-beta-20260312091403

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/README.md +412 -0
  2. package/dist/godd.cjs +465 -0
  3. package/dist/godd.js +34845 -0
  4. package/dist/index.js +224 -0
  5. package/notes-api/.env.example +29 -0
  6. package/notes-api/README.md +65 -0
  7. package/notes-api/alembic/README +1 -0
  8. package/notes-api/alembic/env.py +62 -0
  9. package/notes-api/alembic/script.py.mako +28 -0
  10. package/notes-api/alembic/versions/001_initial_notes_tables.py +71 -0
  11. package/notes-api/alembic.ini +149 -0
  12. package/notes-api/app/__init__.py +1 -0
  13. package/notes-api/app/config.py +90 -0
  14. package/notes-api/app/database.py +31 -0
  15. package/notes-api/app/main.py +55 -0
  16. package/notes-api/app/models/__init__.py +17 -0
  17. package/notes-api/app/models/audit.py +38 -0
  18. package/notes-api/app/models/base.py +38 -0
  19. package/notes-api/app/models/session.py +32 -0
  20. package/notes-api/app/models/setting.py +16 -0
  21. package/notes-api/app/models/user.py +38 -0
  22. package/notes-api/app/routers/__init__.py +1 -0
  23. package/notes-api/app/routers/auth.py +205 -0
  24. package/notes-api/app/routers/files.py +76 -0
  25. package/notes-api/app/routers/pr.py +92 -0
  26. package/notes-api/app/routers/settings.py +44 -0
  27. package/notes-api/app/routers/tree.py +22 -0
  28. package/notes-api/app/routers/users.py +145 -0
  29. package/notes-api/app/schemas/__init__.py +1 -0
  30. package/notes-api/app/schemas/auth.py +45 -0
  31. package/notes-api/app/schemas/user.py +41 -0
  32. package/notes-api/app/security.py +94 -0
  33. package/notes-api/app/services/__init__.py +1 -0
  34. package/notes-api/app/services/audit.py +25 -0
  35. package/notes-api/app/services/business_date.py +38 -0
  36. package/notes-api/app/services/github.py +140 -0
  37. package/notes-api/app/services/github_pr.py +120 -0
  38. package/notes-api/app/services/pr_chain.py +225 -0
  39. package/notes-api/app/startup.py +66 -0
  40. package/notes-api/docker/Dockerfile +14 -0
  41. package/notes-api/docker/Dockerfile.test +14 -0
  42. package/notes-api/pyproject.toml +53 -0
  43. package/notes-api/tests/conftest.py +21 -0
  44. package/notes-api/tests/test_business_date.py +32 -0
  45. package/notes-api/tests/test_health.py +11 -0
  46. package/notes-api/uv.lock +1012 -0
  47. package/notes-app/README.md +30 -0
  48. package/notes-app/docker/Dockerfile.prod +12 -0
  49. package/notes-app/docker/Dockerfile.test +12 -0
  50. package/notes-app/eslint.config.js +23 -0
  51. package/notes-app/index.html +12 -0
  52. package/notes-app/nginx.conf +23 -0
  53. package/notes-app/package.json +37 -0
  54. package/notes-app/pnpm-lock.yaml +3124 -0
  55. package/notes-app/src/App.tsx +13 -0
  56. package/notes-app/src/main.tsx +13 -0
  57. package/notes-app/src/pages/LoginPage.test.tsx +15 -0
  58. package/notes-app/src/pages/LoginPage.tsx +10 -0
  59. package/notes-app/src/pages/MainPage.tsx +14 -0
  60. package/notes-app/src/styles/globals.css +1 -0
  61. package/notes-app/src/vite-env.d.ts +1 -0
  62. package/notes-app/tsconfig.json +24 -0
  63. package/notes-app/tsconfig.node.json +10 -0
  64. package/notes-app/vite.config.js +21 -0
  65. package/notes-app/vite.config.ts +22 -0
  66. package/notes-app/vitest.config.ts +16 -0
  67. package/package.json +58 -0
  68. package/stacks/django-vue.yaml +33 -0
  69. package/stacks/fastapi-react.yaml +160 -0
  70. package/stacks/flutter-firebase.yaml +58 -0
  71. package/stacks/nextjs-prisma.yaml +33 -0
  72. package/stacks/schema.json +144 -0
  73. package/templates/agents/architect.hbs +183 -0
  74. package/templates/agents/auto-documenter.hbs +36 -0
  75. package/templates/agents/backend-developer.hbs +175 -0
  76. package/templates/agents/code-reviewer.hbs +29 -0
  77. package/templates/agents/database-developer.hbs +52 -0
  78. package/templates/agents/debug-specialist.hbs +39 -0
  79. package/templates/agents/environment-setup.hbs +41 -0
  80. package/templates/agents/frontend-developer.hbs +45 -0
  81. package/templates/agents/integration-qa.hbs +26 -0
  82. package/templates/agents/performance-qa.hbs +24 -0
  83. package/templates/agents/pr-writer.hbs +53 -0
  84. package/templates/agents/quality-lead.hbs +26 -0
  85. package/templates/agents/requirements-analyst.hbs +26 -0
  86. package/templates/agents/security-analyst.hbs +21 -0
  87. package/templates/agents/security-reviewer.hbs +20 -0
  88. package/templates/agents/ssot-updater.hbs +45 -0
  89. package/templates/agents/technical-writer.hbs +28 -0
  90. package/templates/agents/unit-test-engineer.hbs +19 -0
  91. package/templates/agents/user-clone.hbs +43 -0
  92. package/templates/github-actions/aws/deploy-notes.yml.hbs +118 -0
  93. package/templates/github-actions/azure/deploy-notes.yml.hbs +78 -0
  94. package/templates/github-actions/gcp/deploy-notes.yml.hbs +76 -0
  95. package/templates/github-actions/vercel-railway/deploy-notes.yml.hbs +49 -0
  96. package/templates/mindsets/agent-stdio.hbs +51 -0
  97. package/templates/mindsets/dart.hbs +39 -0
  98. package/templates/mindsets/ddd-clean-architecture.hbs +52 -0
  99. package/templates/mindsets/electron.hbs +41 -0
  100. package/templates/mindsets/fastapi.hbs +40 -0
  101. package/templates/mindsets/flutter.hbs +56 -0
  102. package/templates/mindsets/kotlin.hbs +46 -0
  103. package/templates/mindsets/postgresql.hbs +39 -0
  104. package/templates/mindsets/python.hbs +39 -0
  105. package/templates/mindsets/react.hbs +51 -0
  106. package/templates/mindsets/swift.hbs +46 -0
  107. package/templates/mindsets/terraform.hbs +53 -0
  108. package/templates/mindsets/typescript.hbs +34 -0
  109. package/templates/mindsets/vite.hbs +37 -0
  110. package/templates/notes-compose.yml +79 -0
  111. package/templates/partials/cogito-geo.hbs +84 -0
  112. package/templates/partials/cogito-godd.hbs +22 -0
  113. package/templates/partials/cogito-grammar.hbs +105 -0
  114. package/templates/partials/cogito-particle.hbs +76 -0
  115. package/templates/partials/cogito-root-ai.hbs +79 -0
  116. package/templates/partials/cogito-root-arch.hbs +75 -0
  117. package/templates/partials/cogito-root-core.hbs +75 -0
  118. package/templates/partials/cogito-root-daily.hbs +58 -0
  119. package/templates/partials/cogito-root-dev.hbs +71 -0
  120. package/templates/partials/cogito-root-devops.hbs +71 -0
  121. package/templates/partials/cogito-root-framework.hbs +80 -0
  122. package/templates/partials/cogito-root-lang.hbs +74 -0
  123. package/templates/partials/godd-core.hbs +50 -0
  124. package/templates/partials/project-context.hbs +52 -0
  125. package/templates/partials/ssot-header.hbs +40 -0
  126. package/templates/partials/ssot-rules.hbs +30 -0
  127. package/templates/prompts/adr.hbs +39 -0
  128. package/templates/prompts/agent-dev-workflow.hbs +34 -0
  129. package/templates/prompts/analyze-report.hbs +36 -0
  130. package/templates/prompts/auto-documentation.hbs +37 -0
  131. package/templates/prompts/check.hbs +52 -0
  132. package/templates/prompts/commit.hbs +96 -0
  133. package/templates/prompts/dev.hbs +127 -0
  134. package/templates/prompts/docs-init.hbs +95 -0
  135. package/templates/prompts/docs-update.hbs +51 -0
  136. package/templates/prompts/git-workflow.hbs +125 -0
  137. package/templates/prompts/impact-analysis.hbs +43 -0
  138. package/templates/prompts/install.hbs +40 -0
  139. package/templates/prompts/new-branch.hbs +61 -0
  140. package/templates/prompts/notes-deploy.hbs +72 -0
  141. package/templates/prompts/pr-analyze.hbs +44 -0
  142. package/templates/prompts/pr-create.hbs +125 -0
  143. package/templates/prompts/push-execute.hbs +83 -0
  144. package/templates/prompts/push.hbs +24 -0
  145. package/templates/prompts/release-notes.hbs +38 -0
  146. package/templates/prompts/requirements-to-business-flow.hbs +29 -0
  147. package/templates/prompts/requirements-to-tickets.hbs +26 -0
  148. package/templates/prompts/review.hbs +126 -0
  149. package/templates/prompts/setup.hbs +247 -0
  150. package/templates/prompts/spec.hbs +35 -0
  151. package/templates/prompts/specification-to-tickets.hbs +24 -0
  152. package/templates/prompts/submit.hbs +143 -0
  153. package/templates/prompts/sync.hbs +63 -0
  154. package/templates/prompts/test-plan.hbs +56 -0
  155. package/templates/terraform/aws/alb.tf.hbs +58 -0
  156. package/templates/terraform/aws/backend.tf.hbs +10 -0
  157. package/templates/terraform/aws/cloudfront.tf.hbs +96 -0
  158. package/templates/terraform/aws/ecr.tf.hbs +30 -0
  159. package/templates/terraform/aws/ecs.tf.hbs +136 -0
  160. package/templates/terraform/aws/iam.tf.hbs +88 -0
  161. package/templates/terraform/aws/local.tf.hbs +34 -0
  162. package/templates/terraform/aws/output.tf.hbs +49 -0
  163. package/templates/terraform/aws/provider.tf.hbs +26 -0
  164. package/templates/terraform/aws/rds.tf.hbs +38 -0
  165. package/templates/terraform/aws/s3.tf.hbs +34 -0
  166. package/templates/terraform/aws/secrets.tf.hbs +38 -0
  167. package/templates/terraform/aws/security_groups.tf.hbs +72 -0
  168. package/templates/terraform/aws/vpc.tf.hbs +63 -0
  169. package/templates/terraform/azure/backend.tf.hbs +8 -0
  170. package/templates/terraform/azure/iam.tf.hbs +36 -0
  171. package/templates/terraform/azure/main.tf.hbs +199 -0
  172. package/templates/terraform/azure/output.tf.hbs +19 -0
  173. package/templates/terraform/azure/provider.tf.hbs +19 -0
  174. package/templates/terraform/gcp/backend.tf.hbs +6 -0
  175. package/templates/terraform/gcp/iam.tf.hbs +47 -0
  176. package/templates/terraform/gcp/main.tf.hbs +171 -0
  177. package/templates/terraform/gcp/output.tf.hbs +15 -0
  178. package/templates/terraform/gcp/provider.tf.hbs +19 -0
  179. package/templates/terraform/vercel-railway/main.tf.hbs +64 -0
  180. package/templates/terraform/vercel-railway/output.tf.hbs +11 -0
@@ -0,0 +1,29 @@
1
+ # GitHub API token (omitted for mock mode)
2
+ # GITHUB_TOKEN=
3
+
4
+ # Repository settings
5
+ GITHUB_OWNER=ripla
6
+ GITHUB_REPO=GoDD
7
+ GITHUB_BRANCH=main
8
+
9
+ # docs folder path (relative to repo root)
10
+ DOCS_PATH=docs
11
+
12
+ # Server
13
+ API_HOST=0.0.0.0
14
+ API_PORT=3100
15
+
16
+ # CORS
17
+ ALLOWED_ORIGINS=http://localhost:5175
18
+
19
+ # Database
20
+ DATABASE_URL=postgresql+asyncpg://app_user:password@localhost:5432/app_db
21
+
22
+ # JWT
23
+ JWT_SECRET=local-dev-secret-key-at-least-32-chars
24
+ JWT_ACCESS_EXPIRES_MIN=15
25
+ JWT_REFRESH_EXPIRES_DAYS=7
26
+
27
+ # Initial admin
28
+ NOTES_ADMIN_USERNAME=admin
29
+ NOTES_ADMIN_PASSWORD=admin123
@@ -0,0 +1,65 @@
1
+ # ripla Notes API
2
+
3
+ FastAPI バックエンド。docs/ のドキュメント閲覧・編集、GitHub Contents API 連携、PR チェーン管理を提供します。
4
+
5
+ ## 前提条件
6
+
7
+ - Python 3.12+
8
+ - uv
9
+ - PostgreSQL 16(GoDD Registry と共有)
10
+ - GitHub Token(モックモードなら不要)
11
+
12
+ ## セットアップ
13
+
14
+ ```bash
15
+ # 依存関係インストール
16
+ uv sync --all-extras
17
+
18
+ # 環境変数
19
+ cp .env.example .env
20
+ # .env を編集(DATABASE_URL, JWT_SECRET 等)
21
+
22
+ # マイグレーション(オプション、startup で create_all も実行)
23
+ uv run alembic upgrade head
24
+ ```
25
+
26
+ ## 起動
27
+
28
+ ```bash
29
+ uv run uvicorn app.main:app --host 0.0.0.0 --port 3100
30
+ ```
31
+
32
+ または:
33
+
34
+ ```bash
35
+ uv run python -m app.main
36
+ ```
37
+
38
+ ## 環境変数
39
+
40
+ | 変数 | 必須 | デフォルト | 説明 |
41
+ |------|------|-----------|------|
42
+ | GITHUB_TOKEN | - | (未設定=Mock) | GitHub API トークン |
43
+ | GITHUB_OWNER | - | ripla | リポジトリオーナー |
44
+ | GITHUB_REPO | - | GoDD | リポジトリ名 |
45
+ | GITHUB_BRANCH | - | main | ベースブランチ |
46
+ | DOCS_PATH | - | docs | docs フォルダパス |
47
+ | DATABASE_URL | Yes | - | PostgreSQL 接続 URL |
48
+ | JWT_SECRET | Yes | - | JWT 署名シークレット |
49
+ | NOTES_ADMIN_USERNAME | - | admin | 初期管理者 |
50
+ | NOTES_ADMIN_PASSWORD | - | admin123 | 初期管理者パスワード |
51
+
52
+ ## API
53
+
54
+ - `GET /api/health` - ヘルスチェック
55
+ - `POST /api/auth/login` - ログイン
56
+ - `GET /api/tree` - ファイルツリー
57
+ - `GET /api/files/{path}` - ファイル内容取得
58
+ - `PUT /api/files/{path}` - ファイル保存(PR chain)
59
+ - その他: `/docs` で OpenAPI を参照
60
+
61
+ ## テスト
62
+
63
+ ```bash
64
+ uv run pytest tests/ -v
65
+ ```
@@ -0,0 +1 @@
1
+ Generic single-database configuration.
@@ -0,0 +1,62 @@
1
+ """Alembic migration environment."""
2
+
3
+ from logging.config import fileConfig
4
+
5
+ from sqlalchemy import engine_from_config, pool
6
+
7
+ from alembic import context
8
+
9
+ from app.config import settings
10
+ from app.models import ( # noqa: F401 - needed for metadata
11
+ NotesAuditLog,
12
+ NotesEditingSession,
13
+ NotesSetting,
14
+ NotesUser,
15
+ )
16
+ from app.models.base import Base
17
+
18
+ config = context.config
19
+ config.set_main_option("sqlalchemy.url", settings.sync_database_url)
20
+
21
+ if config.config_file_name is not None:
22
+ fileConfig(config.config_file_name)
23
+
24
+ target_metadata = Base.metadata
25
+
26
+
27
+ def run_migrations_offline() -> None:
28
+ """Run migrations in 'offline' mode."""
29
+ url = config.get_main_option("sqlalchemy.url")
30
+ context.configure(
31
+ url=url,
32
+ target_metadata=target_metadata,
33
+ literal_binds=True,
34
+ dialect_opts={"paramstyle": "named"},
35
+ )
36
+
37
+ with context.begin_transaction():
38
+ context.run_migrations()
39
+
40
+
41
+ def run_migrations_online() -> None:
42
+ """Run migrations in 'online' mode."""
43
+ connectable = engine_from_config(
44
+ config.get_section(config.config_ini_section, {}),
45
+ prefix="sqlalchemy.",
46
+ poolclass=pool.NullPool,
47
+ )
48
+
49
+ with connectable.connect() as connection:
50
+ context.configure(
51
+ connection=connection,
52
+ target_metadata=target_metadata,
53
+ )
54
+
55
+ with context.begin_transaction():
56
+ context.run_migrations()
57
+
58
+
59
+ if context.is_offline_mode():
60
+ run_migrations_offline()
61
+ else:
62
+ run_migrations_online()
@@ -0,0 +1,28 @@
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ ${imports if imports else ""}
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = ${repr(up_revision)}
16
+ down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
17
+ branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18
+ depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19
+
20
+
21
+ def upgrade() -> None:
22
+ """Upgrade schema."""
23
+ ${upgrades if upgrades else "pass"}
24
+
25
+
26
+ def downgrade() -> None:
27
+ """Downgrade schema."""
28
+ ${downgrades if downgrades else "pass"}
@@ -0,0 +1,71 @@
1
+ """Initial notes tables.
2
+
3
+ Revision ID: 001_initial
4
+ Revises:
5
+ Create Date: 2026-02-27
6
+
7
+ """
8
+
9
+ import sqlalchemy as sa
10
+ from sqlalchemy.dialects.postgresql import JSONB, UUID
11
+
12
+ from alembic import op
13
+
14
+ revision = "001_initial"
15
+ down_revision = None
16
+ branch_labels = None
17
+ depends_on = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ op.create_table(
22
+ "notes_users",
23
+ sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
24
+ sa.Column("username", sa.String(100), nullable=False, unique=True),
25
+ sa.Column("display_name", sa.String(200), nullable=False),
26
+ sa.Column("password_hash", sa.String(255), nullable=False),
27
+ sa.Column("role", sa.String(20), nullable=False, server_default="viewer"),
28
+ sa.Column("refresh_token", sa.String(255), nullable=True),
29
+ sa.Column("failed_login_attempts", sa.Integer(), nullable=False, server_default="0"),
30
+ sa.Column("locked_until", sa.DateTime(timezone=True), nullable=True),
31
+ sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
32
+ sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
33
+ )
34
+
35
+ op.create_table(
36
+ "notes_editing_sessions",
37
+ sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
38
+ sa.Column("user_id", UUID(as_uuid=True), sa.ForeignKey("notes_users.id", ondelete="CASCADE"), nullable=False),
39
+ sa.Column("branch_name", sa.String(300), nullable=False),
40
+ sa.Column("pr_number", sa.Integer(), nullable=True),
41
+ sa.Column("pr_url", sa.String(500), nullable=True),
42
+ sa.Column("commit_count", sa.Integer(), nullable=False, server_default="0"),
43
+ sa.Column("business_date", sa.String(10), nullable=False),
44
+ sa.Column("status", sa.String(20), nullable=False, server_default="active"),
45
+ sa.Column("changed_files", JSONB(), nullable=False, server_default="[]"),
46
+ sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
47
+ sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
48
+ )
49
+
50
+ op.create_table(
51
+ "notes_audit_logs",
52
+ sa.Column("id", UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
53
+ sa.Column("user_id", UUID(as_uuid=True), sa.ForeignKey("notes_users.id", ondelete="SET NULL"), nullable=True),
54
+ sa.Column("action", sa.String(100), nullable=False),
55
+ sa.Column("ip_address", sa.String(45), nullable=True),
56
+ sa.Column("detail", JSONB(), nullable=True),
57
+ sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
58
+ )
59
+
60
+ op.create_table(
61
+ "notes_settings",
62
+ sa.Column("key", sa.String(100), primary_key=True),
63
+ sa.Column("value", JSONB(), nullable=False),
64
+ )
65
+
66
+
67
+ def downgrade() -> None:
68
+ op.drop_table("notes_settings")
69
+ op.drop_table("notes_audit_logs")
70
+ op.drop_table("notes_editing_sessions")
71
+ op.drop_table("notes_users")
@@ -0,0 +1,149 @@
1
+ # A generic, single database configuration.
2
+
3
+ [alembic]
4
+ # path to migration scripts.
5
+ # this is typically a path given in POSIX (e.g. forward slashes)
6
+ # format, relative to the token %(here)s which refers to the location of this
7
+ # ini file
8
+ script_location = %(here)s/alembic
9
+
10
+ # template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
11
+ # Uncomment the line below if you want the files to be prepended with date and time
12
+ # see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
13
+ # for all available tokens
14
+ # file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
15
+ # Or organize into date-based subdirectories (requires recursive_version_locations = true)
16
+ # file_template = %%(year)d/%%(month).2d/%%(day).2d_%%(hour).2d%%(minute).2d_%%(second).2d_%%(rev)s_%%(slug)s
17
+
18
+ # sys.path path, will be prepended to sys.path if present.
19
+ # defaults to the current working directory. for multiple paths, the path separator
20
+ # is defined by "path_separator" below.
21
+ prepend_sys_path = .
22
+
23
+
24
+ # timezone to use when rendering the date within the migration file
25
+ # as well as the filename.
26
+ # If specified, requires the tzdata library which can be installed by adding
27
+ # `alembic[tz]` to the pip requirements.
28
+ # string value is passed to ZoneInfo()
29
+ # leave blank for localtime
30
+ # timezone =
31
+
32
+ # max length of characters to apply to the "slug" field
33
+ # truncate_slug_length = 40
34
+
35
+ # set to 'true' to run the environment during
36
+ # the 'revision' command, regardless of autogenerate
37
+ # revision_environment = false
38
+
39
+ # set to 'true' to allow .pyc and .pyo files without
40
+ # a source .py file to be detected as revisions in the
41
+ # versions/ directory
42
+ # sourceless = false
43
+
44
+ # version location specification; This defaults
45
+ # to <script_location>/versions. When using multiple version
46
+ # directories, initial revisions must be specified with --version-path.
47
+ # The path separator used here should be the separator specified by "path_separator"
48
+ # below.
49
+ # version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
50
+
51
+ # path_separator; This indicates what character is used to split lists of file
52
+ # paths, including version_locations and prepend_sys_path within configparser
53
+ # files such as alembic.ini.
54
+ # The default rendered in new alembic.ini files is "os", which uses os.pathsep
55
+ # to provide os-dependent path splitting.
56
+ #
57
+ # Note that in order to support legacy alembic.ini files, this default does NOT
58
+ # take place if path_separator is not present in alembic.ini. If this
59
+ # option is omitted entirely, fallback logic is as follows:
60
+ #
61
+ # 1. Parsing of the version_locations option falls back to using the legacy
62
+ # "version_path_separator" key, which if absent then falls back to the legacy
63
+ # behavior of splitting on spaces and/or commas.
64
+ # 2. Parsing of the prepend_sys_path option falls back to the legacy
65
+ # behavior of splitting on spaces, commas, or colons.
66
+ #
67
+ # Valid values for path_separator are:
68
+ #
69
+ # path_separator = :
70
+ # path_separator = ;
71
+ # path_separator = space
72
+ # path_separator = newline
73
+ #
74
+ # Use os.pathsep. Default configuration used for new projects.
75
+ path_separator = os
76
+
77
+ # set to 'true' to search source files recursively
78
+ # in each "version_locations" directory
79
+ # new in Alembic version 1.10
80
+ # recursive_version_locations = false
81
+
82
+ # the output encoding used when revision files
83
+ # are written from script.py.mako
84
+ # output_encoding = utf-8
85
+
86
+ # database URL. This is consumed by the user-maintained env.py script only.
87
+ # other means of configuring database URLs may be customized within the env.py
88
+ # file.
89
+ sqlalchemy.url = driver://user:pass@localhost/dbname
90
+
91
+
92
+ [post_write_hooks]
93
+ # post_write_hooks defines scripts or Python functions that are run
94
+ # on newly generated revision scripts. See the documentation for further
95
+ # detail and examples
96
+
97
+ # format using "black" - use the console_scripts runner, against the "black" entrypoint
98
+ # hooks = black
99
+ # black.type = console_scripts
100
+ # black.entrypoint = black
101
+ # black.options = -l 79 REVISION_SCRIPT_FILENAME
102
+
103
+ # lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
104
+ # hooks = ruff
105
+ # ruff.type = module
106
+ # ruff.module = ruff
107
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
108
+
109
+ # Alternatively, use the exec runner to execute a binary found on your PATH
110
+ # hooks = ruff
111
+ # ruff.type = exec
112
+ # ruff.executable = ruff
113
+ # ruff.options = check --fix REVISION_SCRIPT_FILENAME
114
+
115
+ # Logging configuration. This is also consumed by the user-maintained
116
+ # env.py script only.
117
+ [loggers]
118
+ keys = root,sqlalchemy,alembic
119
+
120
+ [handlers]
121
+ keys = console
122
+
123
+ [formatters]
124
+ keys = generic
125
+
126
+ [logger_root]
127
+ level = WARNING
128
+ handlers = console
129
+ qualname =
130
+
131
+ [logger_sqlalchemy]
132
+ level = WARNING
133
+ handlers =
134
+ qualname = sqlalchemy.engine
135
+
136
+ [logger_alembic]
137
+ level = INFO
138
+ handlers =
139
+ qualname = alembic
140
+
141
+ [handler_console]
142
+ class = StreamHandler
143
+ args = (sys.stderr,)
144
+ level = NOTSET
145
+ formatter = generic
146
+
147
+ [formatter_generic]
148
+ format = %(levelname)-5.5s [%(name)s] %(message)s
149
+ datefmt = %H:%M:%S
@@ -0,0 +1 @@
1
+ """ripla Notes API - FastAPI application."""
@@ -0,0 +1,90 @@
1
+ """Application configuration via environment variables."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from pydantic_settings import BaseSettings
8
+
9
+
10
+ class Settings(BaseSettings):
11
+ """ripla Notes API settings."""
12
+
13
+ # Database — individual vars (local dev / Docker Compose)
14
+ db_host: str = "localhost"
15
+ db_port: int = 5432
16
+ db_user: str = "app_user"
17
+ db_password: str = "password"
18
+ db_name: str = "app_db"
19
+
20
+ # Database — full URL override
21
+ database_url: str | None = None
22
+
23
+ # API (PORT env used by Docker/Railway)
24
+ api_host: str = "0.0.0.0"
25
+ api_port: int = 3100
26
+ port: int | None = None # Override: PORT env
27
+
28
+ # CORS
29
+ allowed_origins: str = "http://localhost:5175"
30
+
31
+ # JWT
32
+ jwt_secret: str = "local-dev-secret-key-at-least-32-chars"
33
+ jwt_access_expires_min: int = 15
34
+ jwt_refresh_expires_days: int = 7
35
+
36
+ # GitHub
37
+ github_token: str | None = None
38
+ github_owner: str = "ripla"
39
+ github_repo: str = "GoDD"
40
+ github_branch: str = "main"
41
+ docs_path: str = "docs"
42
+
43
+ # Initial admin
44
+ notes_admin_username: str = "admin"
45
+ notes_admin_password: str = "admin123"
46
+
47
+ # Testing (skip DB seed when True)
48
+ testing: bool = False
49
+
50
+ @property
51
+ def async_database_url(self) -> str:
52
+ """Async DB URL for SQLAlchemy (asyncpg driver)."""
53
+ if self.database_url:
54
+ return re.sub(r"^postgres(ql)?://", "postgresql+asyncpg://", self.database_url)
55
+ return (
56
+ f"postgresql+asyncpg://{self.db_user}:{self.db_password}"
57
+ f"@{self.db_host}:{self.db_port}/{self.db_name}"
58
+ )
59
+
60
+ @property
61
+ def sync_database_url(self) -> str:
62
+ """Sync DB URL for Alembic migrations."""
63
+ if self.database_url:
64
+ url = re.sub(r"^postgres(ql)?(\+asyncpg)?://", "postgresql://", self.database_url)
65
+ return url
66
+ return (
67
+ f"postgresql://{self.db_user}:{self.db_password}"
68
+ f"@{self.db_host}:{self.db_port}/{self.db_name}"
69
+ )
70
+
71
+ @property
72
+ def cors_origins(self) -> list[str]:
73
+ """Parse allowed_origins into a list."""
74
+ if self.allowed_origins == "*":
75
+ return ["*"]
76
+ return [o.strip() for o in self.allowed_origins.split(",") if o.strip()]
77
+
78
+ @property
79
+ def effective_port(self) -> int:
80
+ """Port to use (PORT env or api_port)."""
81
+ return self.port if self.port is not None else self.api_port
82
+
83
+ def is_mock_mode(self) -> bool:
84
+ """True when GITHUB_TOKEN is not set (demo mode)."""
85
+ return not self.github_token
86
+
87
+ model_config = {"env_prefix": "", "case_sensitive": False}
88
+
89
+
90
+ settings = Settings()
@@ -0,0 +1,31 @@
1
+ """SQLAlchemy async engine and session factory."""
2
+
3
+ from collections.abc import AsyncGenerator
4
+
5
+ from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
6
+
7
+ from app.config import settings
8
+
9
+ engine = create_async_engine(
10
+ settings.async_database_url,
11
+ echo=False,
12
+ pool_size=10,
13
+ max_overflow=20,
14
+ )
15
+
16
+ async_session_factory = async_sessionmaker(
17
+ engine,
18
+ class_=AsyncSession,
19
+ expire_on_commit=False,
20
+ )
21
+
22
+
23
+ async def get_db() -> AsyncGenerator[AsyncSession, None]:
24
+ """FastAPI dependency: yield an async DB session."""
25
+ async with async_session_factory() as session:
26
+ try:
27
+ yield session
28
+ await session.commit()
29
+ except Exception:
30
+ await session.rollback()
31
+ raise
@@ -0,0 +1,55 @@
1
+ """ripla Notes API - FastAPI application entry point."""
2
+
3
+ from fastapi import FastAPI
4
+ from fastapi.middleware.cors import CORSMiddleware
5
+
6
+ from app.config import settings
7
+ from app.routers import auth, files, pr, settings as settings_router, tree, users
8
+ from app.startup import ensure_tables_and_seed
9
+
10
+ app = FastAPI(
11
+ title="ripla Notes API",
12
+ description="Docs viewing/editing API for ripla Notes (GitHub Contents + PR chain)",
13
+ version="0.1.0",
14
+ docs_url="/docs",
15
+ redoc_url="/redoc",
16
+ )
17
+
18
+ app.add_middleware(
19
+ CORSMiddleware,
20
+ allow_origins=settings.cors_origins,
21
+ allow_credentials=True,
22
+ allow_methods=["GET", "POST", "PUT", "DELETE"],
23
+ allow_headers=["Content-Type", "Authorization"],
24
+ )
25
+
26
+ app.include_router(auth.router)
27
+ app.include_router(users.router)
28
+ app.include_router(settings_router.router)
29
+ app.include_router(tree.router)
30
+ app.include_router(files.router)
31
+ app.include_router(pr.router)
32
+
33
+
34
+ @app.on_event("startup")
35
+ async def on_startup():
36
+ """Ensure tables and seed data on startup."""
37
+ if not settings.testing:
38
+ await ensure_tables_and_seed()
39
+
40
+
41
+ @app.get("/api/health")
42
+ async def health_check():
43
+ """Health check endpoint."""
44
+ return {"status": "ok"}
45
+
46
+
47
+ if __name__ == "__main__":
48
+ import uvicorn
49
+
50
+ uvicorn.run(
51
+ "app.main:app",
52
+ host=settings.api_host,
53
+ port=settings.effective_port,
54
+ reload=True,
55
+ )
@@ -0,0 +1,17 @@
1
+ """Notes ORM models."""
2
+
3
+ from app.models.audit import NotesAuditLog
4
+ from app.models.base import Base, TimestampMixin, UUIDMixin
5
+ from app.models.session import NotesEditingSession
6
+ from app.models.setting import NotesSetting
7
+ from app.models.user import NotesUser
8
+
9
+ __all__ = [
10
+ "Base",
11
+ "NotesAuditLog",
12
+ "NotesEditingSession",
13
+ "NotesSetting",
14
+ "NotesUser",
15
+ "TimestampMixin",
16
+ "UUIDMixin",
17
+ ]
@@ -0,0 +1,38 @@
1
+ """NotesAuditLog model."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import datetime
6
+
7
+ import uuid
8
+ from sqlalchemy import DateTime, ForeignKey, String, func
9
+ from sqlalchemy.dialects.postgresql import JSONB, UUID
10
+ from sqlalchemy.orm import Mapped, mapped_column, relationship
11
+
12
+ from app.models.base import Base, UUIDMixin
13
+
14
+
15
+ class NotesAuditLog(Base, UUIDMixin):
16
+ """Audit log for login/operations."""
17
+
18
+ __tablename__ = "notes_audit_logs"
19
+
20
+ user_id: Mapped[uuid.UUID | None] = mapped_column(
21
+ UUID(as_uuid=True),
22
+ ForeignKey("notes_users.id", ondelete="SET NULL"),
23
+ nullable=True,
24
+ )
25
+ action: Mapped[str] = mapped_column(String(100), nullable=False)
26
+ ip_address: Mapped[str | None] = mapped_column(String(45), nullable=True)
27
+ detail: Mapped[dict | None] = mapped_column(JSONB, nullable=True)
28
+ created_at: Mapped[datetime] = mapped_column(
29
+ DateTime(timezone=True),
30
+ nullable=False,
31
+ server_default=func.now(),
32
+ )
33
+
34
+ user: Mapped["NotesUser | None"] = relationship(
35
+ "NotesUser",
36
+ back_populates="audit_logs",
37
+ foreign_keys=[user_id],
38
+ )
@@ -0,0 +1,38 @@
1
+ """SQLAlchemy declarative base and common mixins."""
2
+
3
+ import uuid
4
+ from datetime import datetime
5
+
6
+ from sqlalchemy import DateTime, func
7
+ from sqlalchemy.dialects.postgresql import UUID
8
+ from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
9
+
10
+
11
+ class Base(DeclarativeBase):
12
+ """Base class for all ORM models."""
13
+
14
+ pass
15
+
16
+
17
+ class UUIDMixin:
18
+ """Provides a UUID primary key."""
19
+
20
+ id: Mapped[uuid.UUID] = mapped_column(
21
+ UUID(as_uuid=True),
22
+ primary_key=True,
23
+ default=uuid.uuid4,
24
+ )
25
+
26
+
27
+ class TimestampMixin:
28
+ """Provides created_at and updated_at columns."""
29
+
30
+ created_at: Mapped[datetime] = mapped_column(
31
+ DateTime(timezone=True),
32
+ server_default=func.now(),
33
+ )
34
+ updated_at: Mapped[datetime] = mapped_column(
35
+ DateTime(timezone=True),
36
+ server_default=func.now(),
37
+ onupdate=func.now(),
38
+ )