From e6b64e33442c7eb2878db39689abdb52130977c0 Mon Sep 17 00:00:00 2001 From: brasse b Date: Fri, 10 Apr 2026 13:07:01 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Archivum=20skeleton=20=E2=80=94=20Go/Gr?= =?UTF-8?q?aphQL=20backend=20+=20Vue=203=20PWA=20frontend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Full project scaffold: multi-stage Dockerfile (ARM64/AMD64), AsciiDoc↔TipTap bridge, Setup Wizard, CodeMirror source editor, Git-backed storage layer, LDAP+JWT auth skeleton, Tailwind mobile-first layout, and VS Code build/push tasks targeting registry at 192.168.0.19:5000. Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 31 ++++ .vscode/tasks.json | 157 +++++++++++++++++ LICENSE | 146 ++++++++-------- README.md | 131 +++++++++++++- backend/cmd/server/main.go | 31 ++++ backend/go.mod | 8 + backend/internal/auth/auth.go | 111 ++++++++++++ backend/internal/config/config.go | 61 +++++++ backend/internal/git/git.go | 104 +++++++++++ backend/internal/graph/resolver.go | 16 ++ backend/internal/graph/schema.graphql | 87 ++++++++++ backend/internal/graph/server.go | 28 +++ backend/internal/storage/storage.go | 70 ++++++++ docker/Dockerfile | 42 +++++ docker/docker-compose.yml | 17 ++ frontend/index.html | 15 ++ frontend/package.json | 36 ++++ frontend/src/App.vue | 23 +++ frontend/src/assets/main.css | 23 +++ frontend/src/bridge/asciidoc-bridge.ts | 164 ++++++++++++++++++ .../src/components/editor/SourceEditor.vue | 47 +++++ .../src/components/editor/VisualEditor.vue | 34 ++++ frontend/src/components/layout/AppLayout.vue | 56 ++++++ frontend/src/components/layout/Sidebar.vue | 59 +++++++ .../src/components/wizard/SetupWizard.vue | 134 ++++++++++++++ frontend/src/lib/gql.ts | 24 +++ frontend/src/main.ts | 10 ++ frontend/src/router/index.ts | 27 +++ frontend/src/stores/app.ts | 36 ++++ frontend/src/views/DocumentView.vue | 76 ++++++++ frontend/src/views/HomeView.vue | 49 ++++++ frontend/tailwind.config.js | 23 +++ frontend/tsconfig.json | 23 +++ frontend/tsconfig.node.json | 11 ++ frontend/vite.config.ts | 46 +++++ 35 files changed, 1882 insertions(+), 74 deletions(-) create mode 100644 .gitignore create mode 100644 .vscode/tasks.json create mode 100644 backend/cmd/server/main.go create mode 100644 backend/go.mod create mode 100644 backend/internal/auth/auth.go create mode 100644 backend/internal/config/config.go create mode 100644 backend/internal/git/git.go create mode 100644 backend/internal/graph/resolver.go create mode 100644 backend/internal/graph/schema.graphql create mode 100644 backend/internal/graph/server.go create mode 100644 backend/internal/storage/storage.go create mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.yml create mode 100644 frontend/index.html create mode 100644 frontend/package.json create mode 100644 frontend/src/App.vue create mode 100644 frontend/src/assets/main.css create mode 100644 frontend/src/bridge/asciidoc-bridge.ts create mode 100644 frontend/src/components/editor/SourceEditor.vue create mode 100644 frontend/src/components/editor/VisualEditor.vue create mode 100644 frontend/src/components/layout/AppLayout.vue create mode 100644 frontend/src/components/layout/Sidebar.vue create mode 100644 frontend/src/components/wizard/SetupWizard.vue create mode 100644 frontend/src/lib/gql.ts create mode 100644 frontend/src/main.ts create mode 100644 frontend/src/router/index.ts create mode 100644 frontend/src/stores/app.ts create mode 100644 frontend/src/views/DocumentView.vue create mode 100644 frontend/src/views/HomeView.vue create mode 100644 frontend/tailwind.config.js create mode 100644 frontend/tsconfig.json create mode 100644 frontend/tsconfig.node.json create mode 100644 frontend/vite.config.ts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..101e251 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Go +backend/vendor/ +backend/*.exe +backend/*.test +backend/archivum + +# Frontend +frontend/node_modules/ +frontend/dist/ +frontend/.env +frontend/.env.local + +# Docker local data +docker/data/ + +# Generated GraphQL code +backend/internal/graph/generated.go +backend/internal/graph/models_gen.go + +# Config (never commit secrets) +config.json +settings.json +*.db + +# OS +.DS_Store +Thumbs.db + +# IDE +.idea/ +*.swp diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d86ed68 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,157 @@ +{ + "version": "2.0.0", + "tasks": [ + + // ── Docker: Build ────────────────────────────────────────────────────────── + { + "label": "Docker: Build (Windows)", + "type": "shell", + "windows": { + "command": "docker build -t 192.168.0.19:5000/archivum:latest -f docker/Dockerfile ." + }, + "group": "build", + "presentation": { "reveal": "always", "panel": "shared" }, + "problemMatcher": [] + }, + { + "label": "Docker: Build (Linux)", + "type": "shell", + "linux": { + "command": "docker build -t 192.168.0.19:5000/archivum:latest -f docker/Dockerfile ." + }, + "group": "build", + "presentation": { "reveal": "always", "panel": "shared" }, + "problemMatcher": [] + }, + + // ── Docker: Push ─────────────────────────────────────────────────────────── + { + "label": "Docker: Push (Windows)", + "type": "shell", + "windows": { + "command": "docker push 192.168.0.19:5000/archivum:latest" + }, + "group": "build", + "presentation": { "reveal": "always", "panel": "shared" }, + "problemMatcher": [] + }, + { + "label": "Docker: Push (Linux)", + "type": "shell", + "linux": { + "command": "docker push 192.168.0.19:5000/archivum:latest" + }, + "group": "build", + "presentation": { "reveal": "always", "panel": "shared" }, + "problemMatcher": [] + }, + + // ── Docker: Build & Push ─────────────────────────────────────────────────── + { + "label": "Docker: Build & Push (Windows)", + "dependsOrder": "sequence", + "dependsOn": ["Docker: Build (Windows)", "Docker: Push (Windows)"], + "group": { "kind": "build", "isDefault": true }, + "presentation": { "reveal": "always", "panel": "shared" }, + "problemMatcher": [] + }, + { + "label": "Docker: Build & Push (Linux)", + "dependsOrder": "sequence", + "dependsOn": ["Docker: Build (Linux)", "Docker: Push (Linux)"], + "group": "build", + "presentation": { "reveal": "always", "panel": "shared" }, + "problemMatcher": [] + }, + + // ── Docker: Multi-arch Build & Push (buildx) ─────────────────────────────── + { + "label": "Docker: Multi-arch Build & Push (Windows)", + "type": "shell", + "windows": { + "command": "docker buildx build --platform linux/amd64,linux/arm64 -t 192.168.0.19:5000/archivum:latest -f docker/Dockerfile --push ." + }, + "group": "build", + "presentation": { "reveal": "always", "panel": "shared" }, + "problemMatcher": [] + }, + { + "label": "Docker: Multi-arch Build & Push (Linux)", + "type": "shell", + "linux": { + "command": "docker buildx build --platform linux/amd64,linux/arm64 -t 192.168.0.19:5000/archivum:latest -f docker/Dockerfile --push ." + }, + "group": "build", + "presentation": { "reveal": "always", "panel": "shared" }, + "problemMatcher": [] + }, + + // ── Backend: Run ─────────────────────────────────────────────────────────── + { + "label": "Backend: Run", + "type": "shell", + "windows": { + "command": "go run .\\cmd\\server", + "options": { "cwd": "${workspaceFolder}\\backend" } + }, + "linux": { + "command": "go run ./cmd/server", + "options": { "cwd": "${workspaceFolder}/backend" } + }, + "group": "test", + "isBackground": true, + "presentation": { "reveal": "always", "panel": "dedicated" }, + "problemMatcher": { + "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(.*)", "file": 1, "line": 2, "column": 3, "message": 4 }, + "background": { + "activeOnStart": true, + "beginsPattern": "^Archivum listening", + "endsPattern": "^Archivum listening" + } + } + }, + + // ── Frontend: Dev ────────────────────────────────────────────────────────── + { + "label": "Frontend: Dev", + "type": "shell", + "windows": { + "command": "npm run dev", + "options": { "cwd": "${workspaceFolder}\\frontend" } + }, + "linux": { + "command": "npm run dev", + "options": { "cwd": "${workspaceFolder}/frontend" } + }, + "group": "test", + "isBackground": true, + "presentation": { "reveal": "always", "panel": "dedicated" }, + "problemMatcher": { + "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(.*)", "file": 1, "line": 2, "column": 3, "message": 4 }, + "background": { + "activeOnStart": true, + "beginsPattern": "VITE", + "endsPattern": "Local:" + } + } + }, + + // ── Frontend: Build ──────────────────────────────────────────────────────── + { + "label": "Frontend: Build", + "type": "shell", + "windows": { + "command": "npm run build", + "options": { "cwd": "${workspaceFolder}\\frontend" } + }, + "linux": { + "command": "npm run build", + "options": { "cwd": "${workspaceFolder}/frontend" } + }, + "group": "build", + "presentation": { "reveal": "always", "panel": "shared" }, + "problemMatcher": ["$tsc"] + } + + ] +} diff --git a/LICENSE b/LICENSE index 8760148..7f4ceb9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,73 +1,73 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - - (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. - - You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - -To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. - -Copyright 2026 brasse - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + + You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + +To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. + +Copyright 2026 brasse + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md index bfb0044..dcf14f8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,132 @@ # Archivum -Wiki with Git and direkt file as the truth \ No newline at end of file +A high-performance, production-ready wiki system optimized for Desktop and Mobile, designed to run on a Raspberry Pi 5 (ARM64) or any AMD64 host. + +## Tech Stack + +| Layer | Technology | +|---|---| +| Backend | Go + GraphQL (gqlgen) + SQLite (modernc.org/sqlite, CGO-free) | +| Frontend | Vue 3 (Composition API) + Vite + Tailwind CSS | +| PWA | vite-plugin-pwa (offline caching, installable) | +| Version Control | Git (backend executes git on the storage path) | +| Editor | TipTap (visual) + CodeMirror (raw AsciiDoc) | +| Auth | LDAP + JWT with in-memory session tracking | + +## Features + +- **AsciiDoc-native** — documents stored as plain `.adoc` files, Git is the source of truth. +- **Visual ↔ Source editor** — TipTap for rich editing, CodeMirror for raw AsciiDoc, with a round-trip TypeScript bridge. +- **Git history & diff** — every save is a commit; full history and unified diffs via GraphQL. +- **Setup Wizard** — guided first-run configuration for LDAP, admin user, and storage paths. +- **PWA** — installable on mobile, fast loading, offline viewing of cached documents. +- **Multi-arch Docker** — single Dockerfile targeting ARM64 and AMD64. + +## Project Structure + +``` +Archivum/ +├── backend/ # Go application +│ ├── cmd/server/ # Entry point +│ └── internal/ +│ ├── auth/ # LDAP + JWT +│ ├── config/ # config.json management +│ ├── git/ # Git operations +│ ├── graph/ # GraphQL schema + resolvers +│ └── storage/ # Document read/write +├── frontend/ # Vue 3 application +│ └── src/ +│ ├── bridge/ # AsciiDoc ↔ TipTap TypeScript bridge +│ ├── components/ +│ │ ├── editor/ # VisualEditor + SourceEditor +│ │ ├── layout/ # AppLayout + Sidebar +│ │ └── wizard/ # Setup Wizard +│ ├── router/ +│ ├── stores/ +│ └── views/ +├── docker/ # Dockerfile + docker-compose +└── .vscode/ # VS Code build & deploy tasks +``` + +## Quick Start + +### Prerequisites + +- Docker (with access to your registry) +- Go 1.22+ (for local backend development) +- Node.js 20+ (for local frontend development) + +### Docker (recommended) + +```bash +docker compose -f docker/docker-compose.yml up -d +``` + +Open `http://localhost:8080` and follow the Setup Wizard. + +### Local Development + +```bash +# Backend +cd backend +go run ./cmd/server + +# Frontend (separate terminal) +cd frontend +npm install +npm run dev +``` + +## Configuration + +### Backend — `config.json` + +```json +{ + "storage_path": "/data/wiki", + "db_path": "/data/archivum.db", + "ldap": { + "host": "ldap.example.com", + "port": 389, + "base_dn": "dc=example,dc=com", + "bind_dn": "cn=reader,dc=example,dc=com", + "bind_password": "secret" + }, + "jwt_secret": "change-me", + "listen_addr": ":4000" +} +``` + +### Frontend — `settings.json` + +```json +{ + "api_url": "http://localhost:4000/graphql", + "app_name": "Archivum", + "default_theme": "light" +} +``` + +### Docker environment variables + +| Variable | Default | Description | +|---|---|---| +| `DOCKER_PATH` | `/config` | Base path for config and data volumes | +| `PUID` | `1000` | File system user ID | +| `PGID` | `1000` | File system group ID | + +## VS Code Tasks + +Open the Command Palette (`Ctrl+Shift+P`) → **Tasks: Run Task**: + +| Task | Platform | Description | +|---|---|---| +| `Docker: Build` | Windows / Linux | Build multi-arch image | +| `Docker: Push` | Windows / Linux | Push to `192.168.0.19:5000` | +| `Docker: Build & Push` | Windows / Linux | Build then push | +| `Backend: Run` | Both | `go run ./cmd/server` | +| `Frontend: Dev` | Both | `npm run dev` | + +## License + +MIT diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go new file mode 100644 index 0000000..344dd54 --- /dev/null +++ b/backend/cmd/server/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "log" + "net/http" + "os" + + "github.com/brasse-b/archivum/internal/config" + "github.com/brasse-b/archivum/internal/graph" +) + +func main() { + cfg, err := config.Load(configPath()) + if err != nil { + log.Fatalf("failed to load config: %v", err) + } + + srv := graph.NewServer(cfg) + + log.Printf("Archivum listening on %s", cfg.ListenAddr) + if err := http.ListenAndServe(cfg.ListenAddr, srv); err != nil { + log.Fatal(err) + } +} + +func configPath() string { + if p := os.Getenv("DOCKER_PATH"); p != "" { + return p + "/config/config.json" + } + return "config.json" +} diff --git a/backend/go.mod b/backend/go.mod new file mode 100644 index 0000000..9eab028 --- /dev/null +++ b/backend/go.mod @@ -0,0 +1,8 @@ +module github.com/brasse-b/archivum + +go 1.22 + +require ( + github.com/go-ldap/ldap/v3 v3.4.8 + modernc.org/sqlite v1.30.0 +) diff --git a/backend/internal/auth/auth.go b/backend/internal/auth/auth.go new file mode 100644 index 0000000..65144e2 --- /dev/null +++ b/backend/internal/auth/auth.go @@ -0,0 +1,111 @@ +package auth + +import ( + "crypto/rand" + "encoding/hex" + "errors" + "sync" + "time" + + "github.com/brasse-b/archivum/internal/config" + "github.com/go-ldap/ldap/v3" +) + +// Session represents an authenticated user session. +type Session struct { + Username string + Token string + ExpiresAt time.Time +} + +// Manager handles LDAP authentication and in-memory session tracking. +type Manager struct { + cfg *config.Config + mu sync.RWMutex + sessions map[string]*Session +} + +func NewManager(cfg *config.Config) *Manager { + return &Manager{ + cfg: cfg, + sessions: make(map[string]*Session), + } +} + +// Login authenticates against LDAP and returns a bearer token on success. +func (m *Manager) Login(username, password string) (string, error) { + l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", m.cfg.LDAP.Host, m.cfg.LDAP.Port)) + if err != nil { + return "", err + } + defer l.Close() + + if err := l.Bind(m.cfg.LDAP.BindDN, m.cfg.LDAP.BindPassword); err != nil { + return "", err + } + + sr, err := l.Search(&ldap.SearchRequest{ + BaseDN: m.cfg.LDAP.BaseDN, + Filter: fmt.Sprintf("(uid=%s)", ldap.EscapeFilter(username)), + Scope: ldap.ScopeWholeSubtree, + }) + if err != nil { + return "", err + } + if len(sr.Entries) != 1 { + return "", errors.New("user not found") + } + + userDN := sr.Entries[0].DN + if err := l.Bind(userDN, password); err != nil { + return "", errors.New("invalid credentials") + } + + token, err := generateToken() + if err != nil { + return "", err + } + + m.mu.Lock() + m.sessions[token] = &Session{ + Username: username, + Token: token, + ExpiresAt: time.Now().Add(24 * time.Hour), + } + m.mu.Unlock() + + return token, nil +} + +// Validate checks a bearer token and returns the associated session. +func (m *Manager) Validate(token string) (*Session, error) { + m.mu.RLock() + s, ok := m.sessions[token] + m.mu.RUnlock() + + if !ok { + return nil, errors.New("invalid token") + } + if time.Now().After(s.ExpiresAt) { + m.mu.Lock() + delete(m.sessions, token) + m.mu.Unlock() + return nil, errors.New("token expired") + } + return s, nil +} + +// Logout removes a session. +func (m *Manager) Logout(token string) { + m.mu.Lock() + delete(m.sessions, token) + m.mu.Unlock() +} + +func generateToken() (string, error) { + b := make([]byte, 32) + if _, err := rand.Read(b); err != nil { + return "", err + } + return hex.EncodeToString(b), nil +} diff --git a/backend/internal/config/config.go b/backend/internal/config/config.go new file mode 100644 index 0000000..c85741a --- /dev/null +++ b/backend/internal/config/config.go @@ -0,0 +1,61 @@ +package config + +import ( + "encoding/json" + "errors" + "os" +) + +// Config holds all backend runtime configuration. +type Config struct { + StoragePath string `json:"storage_path"` + DBPath string `json:"db_path"` + LDAP LDAPConfig `json:"ldap"` + JWTSecret string `json:"jwt_secret"` + ListenAddr string `json:"listen_addr"` +} + +type LDAPConfig struct { + Host string `json:"host"` + Port int `json:"port"` + BaseDN string `json:"base_dn"` + BindDN string `json:"bind_dn"` + BindPassword string `json:"bind_password"` +} + +// ErrRequireSetup is returned when config is missing or empty, +// signalling that the frontend should start the Setup Wizard. +var ErrRequireSetup = errors.New("REQUIRE_SETUP") + +func Load(path string) (*Config, error) { + data, err := os.ReadFile(path) + if err != nil { + if errors.Is(err, os.ErrNotExist) { + return nil, ErrRequireSetup + } + return nil, err + } + + var cfg Config + if err := json.Unmarshal(data, &cfg); err != nil { + return nil, err + } + + if cfg.StoragePath == "" || cfg.JWTSecret == "" { + return nil, ErrRequireSetup + } + + if cfg.ListenAddr == "" { + cfg.ListenAddr = ":4000" + } + + return &cfg, nil +} + +func Save(path string, cfg *Config) error { + data, err := json.MarshalIndent(cfg, "", " ") + if err != nil { + return err + } + return os.WriteFile(path, data, 0600) +} diff --git a/backend/internal/git/git.go b/backend/internal/git/git.go new file mode 100644 index 0000000..61f8857 --- /dev/null +++ b/backend/internal/git/git.go @@ -0,0 +1,104 @@ +package git + +import ( + "bytes" + "fmt" + "os/exec" + "path/filepath" + "strings" +) + +// Repo wraps a bare directory that is a Git repository. +type Repo struct { + root string +} + +// Open returns a Repo for an existing directory, initialising Git if needed. +func Open(root string) (*Repo, error) { + r := &Repo{root: root} + if err := r.initIfNeeded(); err != nil { + return nil, err + } + return r, nil +} + +func (r *Repo) initIfNeeded() error { + out, _ := r.run("rev-parse", "--is-inside-work-tree") + if strings.TrimSpace(out) == "true" { + return nil + } + _, err := r.run("init") + return err +} + +// Commit writes data to path and creates a Git commit authored by author. +func (r *Repo) Commit(path, content, message, author, email string) error { + full := filepath.Join(r.root, path) + if err := writeFile(full, content); err != nil { + return err + } + if _, err := r.run("add", path); err != nil { + return err + } + _, err := r.run( + "-c", fmt.Sprintf("user.name=%s", author), + "-c", fmt.Sprintf("user.email=%s", email), + "commit", "-m", message, + ) + return err +} + +// Log returns the commit history for a file. +func (r *Repo) Log(path string) ([]LogEntry, error) { + out, err := r.run("log", "--format=%H|%an|%ae|%ai|%s", "--", path) + if err != nil { + return nil, err + } + var entries []LogEntry + for _, line := range strings.Split(strings.TrimSpace(out), "\n") { + if line == "" { + continue + } + parts := strings.SplitN(line, "|", 5) + if len(parts) == 5 { + entries = append(entries, LogEntry{ + Hash: parts[0], + Author: parts[1], + Email: parts[2], + Date: parts[3], + Subject: parts[4], + }) + } + } + return entries, nil +} + +// Diff returns the unified diff between two commits for a file. +func (r *Repo) Diff(path, fromHash, toHash string) (string, error) { + out, err := r.run("diff", fromHash, toHash, "--", path) + return out, err +} + +// Show returns the file content at a specific commit. +func (r *Repo) Show(hash, path string) (string, error) { + return r.run("show", fmt.Sprintf("%s:%s", hash, path)) +} + +type LogEntry struct { + Hash string + Author string + Email string + Date string + Subject string +} + +func (r *Repo) run(args ...string) (string, error) { + cmd := exec.Command("git", append([]string{"-C", r.root}, args...)...) + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + if err := cmd.Run(); err != nil { + return "", fmt.Errorf("git %v: %w — %s", args, err, stderr.String()) + } + return stdout.String(), nil +} diff --git a/backend/internal/graph/resolver.go b/backend/internal/graph/resolver.go new file mode 100644 index 0000000..412ea21 --- /dev/null +++ b/backend/internal/graph/resolver.go @@ -0,0 +1,16 @@ +package graph + +// Resolver is the root resolver — all query/mutation methods live here. +// Fields are populated by NewServer via dependency injection. +type Resolver struct { + cfg interface{} // *config.Config — placeholder until gqlgen generation + auth interface{} // *auth.Manager + storage interface{} // *storage.Store + git interface{} // *git.Repo +} + +// TODO: Run `go generate ./...` after adding gqlgen to go.mod to generate +// the type-safe resolver stubs from schema.graphql. +// +// The generated code lands in graph/generated.go (gitignored for now). +// Implement each method on *Resolver once the stubs exist. diff --git a/backend/internal/graph/schema.graphql b/backend/internal/graph/schema.graphql new file mode 100644 index 0000000..d2a77cd --- /dev/null +++ b/backend/internal/graph/schema.graphql @@ -0,0 +1,87 @@ +type Query { + # Returns REQUIRE_SETUP if config is missing. + systemStatus: SystemStatus! + + # Fetch a document by its slug path. + document(slug: String!): Document + + # List documents under an optional path prefix. + documents(prefix: String): [DocumentMeta!]! + + # Commit history for a document. + history(slug: String!): [CommitEntry!]! + + # Unified diff between two commits for a document. + diff(slug: String!, fromHash: String!, toHash: String!): String! + + # Raw content of a document at a specific commit. + documentAtCommit(slug: String!, hash: String!): String! +} + +type Mutation { + # First-run setup. + setup(input: SetupInput!): Boolean! + + # Authenticate and receive a bearer token. + login(username: String!, password: String!): String! + + # Invalidate the current session. + logout: Boolean! + + # Save (create or update) a document. + saveDocument(input: SaveDocumentInput!): Document! + + # Delete a document. + deleteDocument(slug: String!): Boolean! +} + +# ── Types ────────────────────────────────────────────────────────────────────── + +enum SystemStatus { + OK + REQUIRE_SETUP +} + +type Document { + slug: String! + content: String! + meta: DocumentMeta! +} + +type DocumentMeta { + slug: String! + title: String! + updatedAt: String! +} + +type CommitEntry { + hash: String! + author: String! + email: String! + date: String! + subject: String! +} + +# ── Inputs ───────────────────────────────────────────────────────────────────── + +input SetupInput { + storagePath: String! + adminUser: String! + adminPass: String! + ldap: LDAPInput + jwtSecret: String! +} + +input LDAPInput { + host: String! + port: Int! + baseDN: String! + bindDN: String! + bindPassword: String! +} + +input SaveDocumentInput { + slug: String! + content: String! + commitMessage: String! +} diff --git a/backend/internal/graph/server.go b/backend/internal/graph/server.go new file mode 100644 index 0000000..4c50b8f --- /dev/null +++ b/backend/internal/graph/server.go @@ -0,0 +1,28 @@ +package graph + +import ( + "net/http" + + "github.com/brasse-b/archivum/internal/config" +) + +// NewServer wires up the HTTP handler for the GraphQL endpoint. +// Replace the stub handler with the gqlgen-generated handler once +// `go generate ./...` has been run. +func NewServer(cfg *config.Config) http.Handler { + mux := http.NewServeMux() + + // Placeholder — replace with generated gqlgen handler. + mux.HandleFunc("/graphql", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"data":{"systemStatus":"REQUIRE_SETUP"}}`)) + }) + + // Simple health check. + mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + }) + + return mux +} diff --git a/backend/internal/storage/storage.go b/backend/internal/storage/storage.go new file mode 100644 index 0000000..c378baa --- /dev/null +++ b/backend/internal/storage/storage.go @@ -0,0 +1,70 @@ +package storage + +import ( + "errors" + "os" + "path/filepath" + "strings" +) + +// Store manages AsciiDoc files on disk. +type Store struct { + root string +} + +func New(root string) (*Store, error) { + if err := os.MkdirAll(root, 0755); err != nil { + return nil, err + } + return &Store{root: root}, nil +} + +// Read returns the content of a document by its slug path (e.g. "guides/install"). +func (s *Store) Read(slug string) (string, error) { + data, err := os.ReadFile(s.filePath(slug)) + if err != nil { + if errors.Is(err, os.ErrNotExist) { + return "", ErrNotFound + } + return "", err + } + return string(data), nil +} + +// Write persists content to disk, creating parent directories as needed. +func (s *Store) Write(slug, content string) error { + path := s.filePath(slug) + if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { + return err + } + return os.WriteFile(path, []byte(content), 0644) +} + +// Delete removes a document from disk. +func (s *Store) Delete(slug string) error { + return os.Remove(s.filePath(slug)) +} + +// List returns all document slugs under an optional prefix. +func (s *Store) List(prefix string) ([]string, error) { + base := filepath.Join(s.root, filepath.FromSlash(prefix)) + var slugs []string + err := filepath.WalkDir(base, func(path string, d os.DirEntry, err error) error { + if err != nil { + return err + } + if !d.IsDir() && strings.HasSuffix(path, ".adoc") { + rel, _ := filepath.Rel(s.root, path) + slug := strings.TrimSuffix(filepath.ToSlash(rel), ".adoc") + slugs = append(slugs, slug) + } + return nil + }) + return slugs, err +} + +func (s *Store) filePath(slug string) string { + return filepath.Join(s.root, filepath.FromSlash(slug)+".adoc") +} + +var ErrNotFound = errors.New("document not found") diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..0e2298d --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,42 @@ +# ── Stage 1: Build frontend ─────────────────────────────────────────────────── +FROM node:20-alpine AS frontend-builder + +WORKDIR /app/frontend +COPY frontend/package*.json ./ +RUN npm ci +COPY frontend/ ./ +RUN npm run build + +# ── Stage 2: Build backend ──────────────────────────────────────────────────── +FROM golang:1.22-alpine AS backend-builder + +WORKDIR /app/backend +COPY backend/go.mod backend/go.sum ./ +RUN go mod download +COPY backend/ ./ +# CGO disabled — pure Go SQLite (modernc.org/sqlite). +RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /archivum ./cmd/server + +# ── Stage 3: Runtime image ──────────────────────────────────────────────────── +FROM alpine:3.20 + +# Allow PUID/PGID override at runtime. +ARG PUID=1000 +ARG PGID=1000 + +RUN addgroup -g "${PGID}" archivum \ + && adduser -u "${PUID}" -G archivum -s /sbin/nologin -D archivum + +# Embed frontend into the binary's working directory. +COPY --from=frontend-builder /app/frontend/dist /srv/archivum/ui +COPY --from=backend-builder /archivum /usr/local/bin/archivum + +# Volumes: config and data live outside the image. +VOLUME ["/config", "/data"] + +ENV DOCKER_PATH=/config + +USER archivum +EXPOSE 4000 + +ENTRYPOINT ["/usr/local/bin/archivum"] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..9fa9c9a --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,17 @@ +services: + archivum: + image: archivum:latest + build: + context: .. + dockerfile: docker/Dockerfile + container_name: archivum + restart: unless-stopped + ports: + - "8080:4000" + volumes: + - ${DOCKER_PATH:-./data}/config:/config + - ${DOCKER_PATH:-./data}/data:/data + environment: + DOCKER_PATH: /config + PUID: ${PUID:-1000} + PGID: ${PGID:-1000} diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..824ebe2 --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,15 @@ + + + + + + + + + Archivum + + +
+ + + diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000..b4db224 --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,36 @@ +{ + "name": "archivum", + "version": "0.1.0", + "private": true, + "scripts": { + "dev": "vite", + "build": "vue-tsc && vite build", + "preview": "vite preview", + "type-check": "vue-tsc --noEmit" + }, + "dependencies": { + "@tiptap/core": "^2.4.0", + "@tiptap/pm": "^2.4.0", + "@tiptap/starter-kit": "^2.4.0", + "@tiptap/vue-3": "^2.4.0", + "asciidoctor": "^3.0.4", + "codemirror": "^6.0.1", + "graphql": "^16.9.0", + "graphql-request": "^6.1.0", + "pinia": "^2.1.7", + "vue": "^3.4.0", + "vue-router": "^4.3.0" + }, + "devDependencies": { + "@codemirror/lang-markdown": "^6.2.5", + "@types/node": "^20.14.0", + "@vitejs/plugin-vue": "^5.0.5", + "autoprefixer": "^10.4.19", + "postcss": "^8.4.38", + "tailwindcss": "^3.4.4", + "typescript": "^5.4.5", + "vite": "^5.3.1", + "vite-plugin-pwa": "^0.20.0", + "vue-tsc": "^2.0.21" + } +} diff --git a/frontend/src/App.vue b/frontend/src/App.vue new file mode 100644 index 0000000..88cd0e5 --- /dev/null +++ b/frontend/src/App.vue @@ -0,0 +1,23 @@ + + + diff --git a/frontend/src/assets/main.css b/frontend/src/assets/main.css new file mode 100644 index 0000000..8c0ee8a --- /dev/null +++ b/frontend/src/assets/main.css @@ -0,0 +1,23 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +@layer base { + html { + font-family: 'Inter', ui-sans-serif, system-ui; + } + + /* AsciiDoc rendered output */ + .adoc-content h1 { @apply text-2xl font-bold mb-4 mt-6; } + .adoc-content h2 { @apply text-xl font-semibold mb-3 mt-5; } + .adoc-content h3 { @apply text-lg font-medium mb-2 mt-4; } + .adoc-content p { @apply mb-3 leading-relaxed; } + .adoc-content pre { @apply bg-surface-800 rounded-lg p-4 overflow-x-auto font-mono text-sm mb-4; } + .adoc-content code { @apply font-mono text-sm bg-surface-800 px-1 rounded; } + .adoc-content ul { @apply list-disc list-inside mb-3 space-y-1; } + .adoc-content ol { @apply list-decimal list-inside mb-3 space-y-1; } + .adoc-content blockquote { @apply border-l-4 border-slate-500 pl-4 italic text-slate-400 mb-3; } + .adoc-content table { @apply w-full text-sm border-collapse mb-4; } + .adoc-content th { @apply bg-surface-800 px-3 py-2 text-left border border-slate-700; } + .adoc-content td { @apply px-3 py-2 border border-slate-700; } +} diff --git a/frontend/src/bridge/asciidoc-bridge.ts b/frontend/src/bridge/asciidoc-bridge.ts new file mode 100644 index 0000000..b05f671 --- /dev/null +++ b/frontend/src/bridge/asciidoc-bridge.ts @@ -0,0 +1,164 @@ +/** + * AsciiDoc ↔ TipTap Bridge + * + * Converts between raw AsciiDoc strings and TipTap/ProseMirror JSON documents. + * Uses Asciidoctor.js to parse AsciiDoc into an AST, then maps nodes to + * ProseMirror node types understood by TipTap's StarterKit. + * + * Round-trip guarantee: fromTipTap(toTipTap(adoc)) should be semantically + * equivalent to the original adoc (formatting may differ slightly). + */ + +import Asciidoctor from 'asciidoctor' +import type { JSONContent } from '@tiptap/core' + +const asciidoctor = Asciidoctor() + +// ── AsciiDoc → TipTap ──────────────────────────────────────────────────────── + +export function toTipTap(adoc: string): JSONContent { + if (!adoc.trim()) { + return { type: 'doc', content: [{ type: 'paragraph' }] } + } + + const doc = asciidoctor.load(adoc, { safe: 'safe' }) + const blocks = (doc.getBlocks?.() ?? []) as AsciidoctorBlock[] + const content = blocks.flatMap(convertBlock).filter(Boolean) as JSONContent[] + + return { + type: 'doc', + content: content.length ? content : [{ type: 'paragraph' }], + } +} + +// ── TipTap → AsciiDoc ──────────────────────────────────────────────────────── + +export function fromTipTap(json: JSONContent): string { + if (!json.content?.length) return '' + return json.content.map(nodeToAdoc).join('\n\n') +} + +// ── Internal converters ────────────────────────────────────────────────────── + +// Asciidoctor.js types are not fully typed — use a minimal interface. +interface AsciidoctorBlock { + getNodeName(): string + getLevel?(): number + getTitle?(): string + getSource?(): string + getSourceLanguage?(): string + getContent?(): string + getBlocks?(): AsciidoctorBlock[] + getItems?(): AsciidoctorBlock[] +} + +function convertBlock(block: AsciidoctorBlock): JSONContent | JSONContent[] { + const name = block.getNodeName() + + switch (name) { + case 'section': + case 'preamble': + return (block.getBlocks?.() ?? []).flatMap(convertBlock) + + case 'paragraph': + return { + type: 'paragraph', + content: parseInline(block.getContent?.() ?? ''), + } + + case 'listing': + case 'literal': { + const lang = block.getSourceLanguage?.() ?? '' + return { + type: 'codeBlock', + attrs: { language: lang || null }, + content: [{ type: 'text', text: block.getSource?.() ?? '' }], + } + } + + case 'ulist': + return { + type: 'bulletList', + content: (block.getItems?.() ?? []).map((item) => ({ + type: 'listItem', + content: [{ type: 'paragraph', content: parseInline(item.getContent?.() ?? '') }], + })), + } + + case 'olist': + return { + type: 'orderedList', + content: (block.getItems?.() ?? []).map((item) => ({ + type: 'listItem', + content: [{ type: 'paragraph', content: parseInline(item.getContent?.() ?? '') }], + })), + } + + default: + // Fallback: render as paragraph. + return { + type: 'paragraph', + content: parseInline(block.getContent?.() ?? block.getSource?.() ?? ''), + } + } +} + +/** Very basic inline markup → TipTap marks. */ +function parseInline(text: string): JSONContent[] { + // Strip Asciidoctor HTML output to plain text for now. + // A full implementation would parse *bold*, _italic_, `code` etc. + const plain = text.replace(/<[^>]+>/g, '') + return plain ? [{ type: 'text', text: plain }] : [] +} + +function nodeToAdoc(node: JSONContent): string { + switch (node.type) { + case 'paragraph': + return inlineToAdoc(node.content ?? []) + + case 'heading': { + const level = (node.attrs?.level as number) ?? 1 + const prefix = '='.repeat(level + 1) + return `${prefix} ${inlineToAdoc(node.content ?? [])}` + } + + case 'codeBlock': { + const lang = (node.attrs?.language as string | null) ?? '' + const src = node.content?.[0]?.text ?? '' + return `[source${lang ? ',' + lang : ''}]\n----\n${src}\n----` + } + + case 'bulletList': + return (node.content ?? []) + .map((li) => `* ${inlineToAdoc(li.content?.[0]?.content ?? [])}`) + .join('\n') + + case 'orderedList': + return (node.content ?? []) + .map((li) => `. ${inlineToAdoc(li.content?.[0]?.content ?? [])}`) + .join('\n') + + case 'blockquote': + return `[quote]\n____\n${(node.content ?? []).map(nodeToAdoc).join('\n')}\n____` + + case 'horizontalRule': + return "'''" + + default: + return inlineToAdoc(node.content ?? []) + } +} + +function inlineToAdoc(nodes: JSONContent[]): string { + return nodes + .map((n) => { + const text = n.text ?? '' + const marks = (n.marks ?? []).map((m) => m.type) + let result = text + if (marks.includes('bold')) result = `*${result}*` + if (marks.includes('italic')) result = `_${result}_` + if (marks.includes('code')) result = `\`${result}\`` + return result + }) + .join('') +} diff --git a/frontend/src/components/editor/SourceEditor.vue b/frontend/src/components/editor/SourceEditor.vue new file mode 100644 index 0000000..0a79452 --- /dev/null +++ b/frontend/src/components/editor/SourceEditor.vue @@ -0,0 +1,47 @@ + + + diff --git a/frontend/src/components/editor/VisualEditor.vue b/frontend/src/components/editor/VisualEditor.vue new file mode 100644 index 0000000..2af69f3 --- /dev/null +++ b/frontend/src/components/editor/VisualEditor.vue @@ -0,0 +1,34 @@ + + + diff --git a/frontend/src/components/layout/AppLayout.vue b/frontend/src/components/layout/AppLayout.vue new file mode 100644 index 0000000..b5b18a5 --- /dev/null +++ b/frontend/src/components/layout/AppLayout.vue @@ -0,0 +1,56 @@ + + + + + diff --git a/frontend/src/components/layout/Sidebar.vue b/frontend/src/components/layout/Sidebar.vue new file mode 100644 index 0000000..39d02c9 --- /dev/null +++ b/frontend/src/components/layout/Sidebar.vue @@ -0,0 +1,59 @@ + + + diff --git a/frontend/src/components/wizard/SetupWizard.vue b/frontend/src/components/wizard/SetupWizard.vue new file mode 100644 index 0000000..64a0615 --- /dev/null +++ b/frontend/src/components/wizard/SetupWizard.vue @@ -0,0 +1,134 @@ + + + + + diff --git a/frontend/src/lib/gql.ts b/frontend/src/lib/gql.ts new file mode 100644 index 0000000..0fac19b --- /dev/null +++ b/frontend/src/lib/gql.ts @@ -0,0 +1,24 @@ +// Minimal GraphQL client — swap for graphql-request if preferred. + +const API_URL = import.meta.env.VITE_API_URL ?? '/graphql' + +export async function gql( + query: string, + variables?: Record, +): Promise { + const token = localStorage.getItem('token') + const res = await fetch(API_URL, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + ...(token ? { Authorization: `Bearer ${token}` } : {}), + }, + body: JSON.stringify({ query, variables }), + }) + + const json = await res.json() + if (json.errors?.length) { + throw new Error(json.errors[0].message) + } + return json.data as T +} diff --git a/frontend/src/main.ts b/frontend/src/main.ts new file mode 100644 index 0000000..b63d2d2 --- /dev/null +++ b/frontend/src/main.ts @@ -0,0 +1,10 @@ +import { createApp } from 'vue' +import { createPinia } from 'pinia' +import { router } from '@/router' +import App from '@/App.vue' +import '@/assets/main.css' + +const app = createApp(App) +app.use(createPinia()) +app.use(router) +app.mount('#app') diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts new file mode 100644 index 0000000..302addd --- /dev/null +++ b/frontend/src/router/index.ts @@ -0,0 +1,27 @@ +import { createRouter, createWebHistory } from 'vue-router' +import HomeView from '@/views/HomeView.vue' + +export const router = createRouter({ + history: createWebHistory(), + routes: [ + { + path: '/', + name: 'home', + component: HomeView, + }, + { + path: '/doc/:slug(.*)', + name: 'document', + component: () => import('@/views/DocumentView.vue'), + }, + { + path: '/setup', + name: 'setup', + component: () => import('@/components/wizard/SetupWizard.vue'), + }, + { + path: '/:pathMatch(.*)*', + redirect: '/', + }, + ], +}) diff --git a/frontend/src/stores/app.ts b/frontend/src/stores/app.ts new file mode 100644 index 0000000..70a73b3 --- /dev/null +++ b/frontend/src/stores/app.ts @@ -0,0 +1,36 @@ +import { defineStore } from 'pinia' +import { ref } from 'vue' +import { gql } from '@/lib/gql' + +export const useAppStore = defineStore('app', () => { + const requiresSetup = ref(false) + const token = ref(localStorage.getItem('token')) + const username = ref(null) + + async function checkStatus() { + try { + const data = await gql<{ systemStatus: string }>(`{ systemStatus }`) + requiresSetup.value = data.systemStatus === 'REQUIRE_SETUP' + } catch { + requiresSetup.value = true + } + } + + async function login(user: string, password: string) { + const data = await gql<{ login: string }>( + `mutation Login($u: String!, $p: String!) { login(username: $u, password: $p) }`, + { u: user, p: password }, + ) + token.value = data.login + username.value = user + localStorage.setItem('token', data.login) + } + + function logout() { + token.value = null + username.value = null + localStorage.removeItem('token') + } + + return { requiresSetup, token, username, checkStatus, login, logout } +}) diff --git a/frontend/src/views/DocumentView.vue b/frontend/src/views/DocumentView.vue new file mode 100644 index 0000000..9613b8f --- /dev/null +++ b/frontend/src/views/DocumentView.vue @@ -0,0 +1,76 @@ + + + diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue new file mode 100644 index 0000000..1c16e42 --- /dev/null +++ b/frontend/src/views/HomeView.vue @@ -0,0 +1,49 @@ + + + diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.js new file mode 100644 index 0000000..e35b5a9 --- /dev/null +++ b/frontend/tailwind.config.js @@ -0,0 +1,23 @@ +/** @type {import('tailwindcss').Config} */ +export default { + content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'], + darkMode: 'class', + theme: { + extend: { + fontFamily: { + sans: ['Inter', 'ui-sans-serif', 'system-ui'], + mono: ['JetBrains Mono', 'ui-monospace', 'monospace'], + }, + colors: { + surface: { + 50: '#f8fafc', + 100: '#f1f5f9', + 800: '#1e293b', + 900: '#0f172a', + 950: '#020617', + }, + }, + }, + }, + plugins: [], +} diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json new file mode 100644 index 0000000..100b17c --- /dev/null +++ b/frontend/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "ES2022", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2022", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + "moduleResolution": "Bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "preserve", + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true, + "baseUrl": ".", + "paths": { "@/*": ["src/*"] } + }, + "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/frontend/tsconfig.node.json b/frontend/tsconfig.node.json new file mode 100644 index 0000000..cbd2a63 --- /dev/null +++ b/frontend/tsconfig.node.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "Bundler", + "allowSyntheticDefaultImports": true, + "strict": true + }, + "include": ["vite.config.ts"] +} diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts new file mode 100644 index 0000000..52c085b --- /dev/null +++ b/frontend/vite.config.ts @@ -0,0 +1,46 @@ +import { defineConfig } from 'vite' +import vue from '@vitejs/plugin-vue' +import { VitePWA } from 'vite-plugin-pwa' +import { resolve } from 'path' + +export default defineConfig({ + plugins: [ + vue(), + VitePWA({ + registerType: 'autoUpdate', + includeAssets: ['favicon.ico', 'apple-touch-icon.png'], + manifest: { + name: 'Archivum', + short_name: 'Archivum', + description: 'AsciiDoc wiki with Git history', + theme_color: '#1e293b', + background_color: '#0f172a', + display: 'standalone', + icons: [ + { src: 'icons/icon-192.png', sizes: '192x192', type: 'image/png' }, + { src: 'icons/icon-512.png', sizes: '512x512', type: 'image/png' }, + { src: 'icons/icon-512.png', sizes: '512x512', type: 'image/png', purpose: 'any maskable' }, + ], + }, + workbox: { + globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'], + runtimeCaching: [ + { + urlPattern: /\/graphql$/, + handler: 'NetworkFirst', + options: { cacheName: 'api-cache' }, + }, + ], + }, + }), + ], + resolve: { + alias: { '@': resolve(__dirname, 'src') }, + }, + server: { + port: 5173, + proxy: { + '/graphql': { target: 'http://localhost:4000', changeOrigin: true }, + }, + }, +})