Skip to content

Commit 087c712

Browse files
committed
Merge remote-tracking branch 'upstream/main' into feature/components-and-pages
2 parents 00f5b1c + bcbbbf2 commit 087c712

43 files changed

Lines changed: 9677 additions & 9200 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ temp
77

88
translations/tests/
99
translations/examples/
10-
translations/metta_queries/
10+
translations/metta_queries/
11+
12+
api/target

.github/pr-template.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Description
2+
3+
A clear and concise description of the changes.
4+
5+
## Related Issue
6+
7+
Closes #[issue_number]
8+
9+
## Type of Change
10+
11+
- [ ] Bug fix (non-breaking change which fixes an issue)
12+
- [ ] New feature (non-breaking change which adds functionality)
13+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
14+
- [ ] This change requires a documentation update
15+
16+
## Checklist
17+
18+
- [ ] I have read the [**Contributing Guidelines**](./CONTRIBUTING.md).
19+
- [ ] I have performed a self-review of my own code.
20+
- [ ] I have commented my code, particularly in hard-to-understand areas.
21+
- [ ] I have made corresponding changes to the documentation.
22+
- [ ] My changes generate no new warnings.
23+
- [ ] I have added tests that prove my fix is effective or that my feature works.
24+
- [ ] New and existing unit tests pass locally with my changes.
25+
- [ ] Any dependent changes have been merged and published in downstream modules.

.github/workflows/pre-pr.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Pre PR CI
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
build-test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Setup Node
13+
uses: actions/setup-node@v4
14+
with:
15+
node-version: 20
16+
cache: pnpm
17+
- name: Setup Rust
18+
uses: actions-rs/toolchain@v1
19+
with:
20+
toolchain: stable
21+
components: rustfmt, clippy
22+
- name: Install frontend deps
23+
run: cd frontend && pnpm ci
24+
- name: Lint frontend
25+
run: cd frontend && pnpm run lint && pnpm run prettier:check
26+
- name: Test frontend
27+
run: cd frontend && pnpm test -- --ci --watchAll=false
28+
29+
- name: Lint backend
30+
run: cd backend && cargo clippy -- -D warnings
31+
- name: Format backend
32+
run: cd backend && cargo fmt -- --check
33+
- name: Test backend
34+
run: cd backend && cargo test --all

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ FROM rust:1.86 AS rust-builder
33

44
WORKDIR /mettakg
55

6-
COPY api api
7-
86
RUN apt-get update && apt-get install -y --no-install-recommends \
97
musl-dev \
108
g++ \
@@ -21,6 +19,8 @@ ENV OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu
2119

2220
ENV LIBPQ_STATIC=1
2321

22+
COPY api api
23+
2424
RUN cd api/ && cargo build --release --target x86_64-unknown-linux-musl
2525

2626
# STAGE 2: build and install translation sub-project

Dockerfile.mork

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM rust:1.89
2+
3+
RUN apt-get update && apt-get install -y git cmake
4+
5+
RUN git clone https://github.com/trueagi-io/MORK.git /app
6+
7+
WORKDIR /app
8+
9+
RUN git checkout server
10+
11+
# Clone the PathMap dependency to the absolute path expected by the manifest
12+
RUN git clone --branch master https://github.com/Adam-Vandervorst/PathMap.git /PathMap
13+
14+
RUN cargo build --release -p mork-server --bin mork-server
15+
16+
EXPOSE 8001
17+
18+
CMD ["./target/release/mork-server"]

README.md

Lines changed: 108 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,71 @@ https://deepfunding.ai/proposal/scalable-metta-knowledge-graphs/
44

55
This README is WIP and is subject to change.
66

7-
## Spaces
7+
## Installation
8+
9+
### Prerequisites
10+
11+
- Docker and Docker Compose
12+
- Node.js 22
13+
14+
### Setup
15+
16+
1. Clone the repository:
17+
```bash
18+
git clone https://github.com/your-repo/MeTTa-KG.git
19+
cd MeTTa-KG
20+
```
21+
22+
2. Copy environment variables (if needed):
23+
- Create a `.env` file based on required variables (see docker-compose.yml for reference)
24+
25+
3. Build and run with Docker Compose:
26+
```bash
27+
docker-compose up --build
28+
```
29+
30+
This will start the API, database, Mork server, and Adminer for database management.
31+
32+
## Running Locally
33+
34+
### Using Docker Compose (Recommended)
35+
36+
```bash
37+
docker-compose up
38+
```
39+
40+
- API: http://localhost:8000 (or configured port)
41+
- Frontend: Served via Vite dev server (run separately if needed)
42+
- Adminer: http://localhost:8080
43+
- Mork: http://localhost:8001
44+
45+
### Manual Setup
46+
47+
1. **Database**: Start PostgreSQL
48+
2. **Mork**: Build and run the Mork server (see Dockerfile.mork). you can also run it from the official Mork repo (https://github.com/trueagi-io/MORK)
49+
3. **Backend**:
50+
```bash
51+
cd api
52+
cargo run
53+
```
54+
4. **Frontend**:
55+
```bash
56+
cd frontend
57+
npm install
58+
npm run dev
59+
```
60+
61+
## Usage
62+
63+
### Spaces
864

965
A Knowledge Graph (KG) corresponds to a hierarchy of spaces. Each space has a name, which we refer to as its namespace. The root space is identified by the "/" namespace, while its direct subspaces (spaces on the second level of the hierachy) are identified by namespaces such as "/subspace1/", and so on.
1066

1167
Namespaces are similar to filesystem paths, especially when viewed as a tree. In this view, the difference is that for namespaces, interior nodes play the same role as leaf nodes, while their roles differ in the case of a filesystem path. In particular, every namespace in the hierachy identifies a space. Moreover, namespaces are never "terminal", meaning that it is always possible to embed subspaces further.
1268

1369
Spaces support two operations, read and write. As the name suggests, a read operation on a space provides a read-only view of that space. A write operation works by applying some transformations to the space, creating a new space in the process and preserving the original space. The newly created space is embedded into the space the write operation was used on.
1470

15-
### Namespace Rules
71+
#### Namespace Rules
1672

1773
A namespace should:
1874

@@ -23,7 +79,7 @@ A namespace should:
2379
- start with an alphanumeric character
2480
- end with an alphanumeric character
2581

26-
## Tokens
82+
### Tokens
2783

2884
Tokens give access to spaces in the KG by linking to their namespaces. A token has a number of associated permissions:
2985

@@ -46,16 +102,61 @@ It is currently not possible to modify an existing token's namespace, descriptio
46102

47103
Tokens are managed on the `/tokens` page ([Demo](https://metta-kg.vercel.app/tokens)).
48104

49-
## Editor
105+
### Editor
50106

51107
The editor allows you to interact with the contents of the KG using the [MeTTa](https://metta-lang.dev/) language.
52108

53109
The editor can be found on the `/` page ([Demo](https://metta-kg.vercel.app/)).
54110

55-
## Translations
111+
### Translations
56112

57113
Documentation on translations can be found [here](./translations/README.md).
58114

59-
## Demo
115+
## Development
116+
117+
### Frontend
118+
119+
- `npm run dev`: Start development server
120+
- `npm run build`: Build for production
121+
- `npm run lint`: Run ESLint
122+
- `npm run prettier`: Format code
123+
124+
### Backend
125+
126+
- `cargo run`: Start the API server
127+
- `cargo test`: Run tests
128+
129+
130+
## Contributing
131+
132+
### Database Workflow
133+
134+
#### Prerequisites
135+
- Install the Diesel CLI: `cargo install diesel_cli --no-default-features --features postgres`.
136+
137+
#### Schema Changes
138+
- **Generate Migration**: `cd api && diesel migration generate <migration_name>` (e.g., `add_user_table`).
139+
- **Edit Migration Files**: Modify `up.sql` (forward changes) and `down.sql` (rollback) in the new `api/migrations/<timestamp>_<name>/` folder.
140+
- **Apply Migration**: Run the app (`cargo run` or `docker-compose up`); migrations execute automatically on startup.
141+
- **Verify**: Check app logs for migration success. Use Adminer (http://localhost:8080) to inspect the DB.
142+
- **Rollback**: `diesel migration revert` (reverts the last migration), then restart the app.
143+
144+
#### Seeding Data
145+
- Edit the existing seed migration (`api/migrations/2024-08-13-154617_seed/up.sql`) or generate a new migration for additional data.
146+
- Add `INSERT` statements in `up.sql`.
147+
- Restart the app to apply seeds.
148+
149+
#### Testing DB Changes
150+
- **Unit Tests**: `cargo test` (runs with embedded migrations).
151+
- **Integration Tests**: `cargo test --features integration-tests` (requires a running DB instance).
152+
- **Docker Tests**: `docker-compose up --build` for full-stack testing.
153+
154+
#### Production Deployment
155+
- Migrations are embedded in the release binary (`cargo build --release`).
156+
- On deployment, the app runs migrations automatically—no manual steps needed.
60157

61-
A live version of MeTTa-KG can be found at: https://metta-kg.vercel.app.
158+
#### Best Practices
159+
- Always use migrations for schema changes to maintain version control.
160+
- Commit migration files to Git; never modify existing migrations directly.
161+
- Backup the DB before applying major changes.
162+
- Use Adminer for DB inspection and manual queries during development.

docker-compose.yml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,51 @@ services:
33
build: .
44
ports:
55
- "${METTA_KG_PORT}:${METTA_KG_PORT}"
6+
depends_on:
7+
mork:
8+
condition: service_started
9+
db:
10+
condition: service_healthy
611
environment:
7-
METTA_KG_DATABASE_URL: ${METTA_KG_DATABASE_URL}
12+
POSTGRES_USER: ${POSTGRES_USER}
13+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
14+
POSTGRES_DB: ${POSTGRES_DB}
815
METTA_KG_SECRET: ${METTA_KG_SECRET}
916
METTA_KG_MORK_URL: ${METTA_KG_MORK_URL}
10-
METTA_KG_ORIGIN_URL: ${METTA_KG_ORIGIN_URL}
17+
METTA_KG_ORIGIN_URL: ${METTA_KG_ORIGIN_URL}
1118
ROCKET_ADDRESS: ${METTA_KG_ADDRESS}
1219
ROCKET_PORT: ${METTA_KG_PORT}
13-
db:
20+
db:
1421
image: "postgres"
1522
restart: always
16-
ports:
23+
ports:
1724
- "5432:5432"
1825
environment:
1926
POSTGRES_USER: ${POSTGRES_USER}
2027
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
2128
POSTGRES_DB: ${POSTGRES_DB}
29+
healthcheck:
30+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
31+
interval: 10s
32+
timeout: 5s
33+
retries: 5
2234
adminer:
2335
image: adminer
2436
restart: always
2537
ports:
2638
- "8080:8080"
39+
depends_on:
40+
- db
2741
environment:
2842
ADMINER_DEFAULT_DB_DRIVER: pgsql
2943
ADMINER_DEFAULT_DB_HOST: db
3044
ADMINER_DEFAULT_DB_NAME: ${POSTGRES_DB}
3145
mork:
32-
image: mork_server
33-
restart: always
46+
build:
47+
context: .
48+
dockerfile: Dockerfile.mork
3449
ports:
3550
- "${MORK_SERVER_PORT}:${MORK_SERVER_PORT}"
3651
environment:
3752
MORK_SERVER_ADDR: ${MORK_SERVER_ADDR}
3853
MORK_SERVER_PORT: ${MORK_SERVER_PORT}
39-

frontend/.husky/pre-commit

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# # frontend
2+
# cd ./frontend
3+
# pnpm prettier:check
4+
# pnpm lint
5+
#
6+
#
7+
# # rust api
8+
# cd ../api
9+
#
10+
# cargo fmt --all -- --check
11+
# cargo clippy --all-targets --all-features -- -D warnings
12+
# cargo test --all

frontend/.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ignore build artifacts
2+
dist/
3+
build/
4+
5+
# Ignore lockfiles
6+
package-lock.json
7+
yarn.lock

frontend/.prettierrc.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
{
2-
"trailingComma": "es5",
3-
"tabWidth": 4,
4-
"semi": false,
5-
"singleQuote": true
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": false,
7+
"quoteProps": "as-needed",
8+
"jsxSingleQuote": false,
9+
"trailingComma": "es5",
10+
"bracketSpacing": true,
11+
"bracketSameLine": false,
12+
"arrowParens": "always",
13+
"proseWrap": "preserve",
14+
"htmlWhitespaceSensitivity": "css",
15+
"vueIndentScriptAndStyle": false,
16+
"endOfLine": "lf",
17+
"embeddedLanguageFormatting": "auto",
18+
"singleAttributePerLine": false
619
}

0 commit comments

Comments
 (0)