Skip to content

Commit 5fb3295

Browse files
Merge pull request #2167 from markscott-ms/issues/2051-calm-server
Copy `calm server` to a separate package `calm-server`.
2 parents 8eb1fa7 + bd0bb1b commit 5fb3295

29 files changed

+1668
-2
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
/calm-hub/ @jpgough-ms @rocketstack-matt @grahampacker-ms @Thels @markscott-ms
66

7+
/calm-server/ @rocketstack-matt @markscott-ms
8+
79
/cli/ @aidanm3341 @lbulanti-ms @willosborne @grahampacker-ms @jpgough-ms @rocketstack-matt @Thels @LeighFinegold @markscott-ms
810

911
/shared/ @aidanm3341 @lbulanti-ms @willosborne @grahampacker-ms @jpgough-ms @rocketstack-matt @Thels @LeighFinegold @markscott-ms

.github/pull_request_template.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
## Affected Components
1717
<!-- Check all that apply -->
1818
- [ ] CLI (`cli/`)
19-
- [ ] Shared (`shared/`)
20-
- [ ] CALM Widgets (`calm-widgets/`)
19+
- [ ] Schema (`calm/`)
20+
- [ ] CALM AI (`calm-ai/`)
2121
- [ ] CALM Hub (`calm-hub/`)
2222
- [ ] CALM Hub UI (`calm-hub-ui/`)
23+
- [ ] CALM Server (`calm-server/`)
24+
- [ ] CALM Widgets (`calm-widgets/`)
2325
- [ ] Documentation (`docs/`)
26+
- [ ] Shared (`shared/`)
2427
- [ ] VS Code Extension (`calm-plugins/vscode/`)
2528
- [ ] Dependencies
2629
- [ ] CI/CD
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build CALM Server
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- 'main'
10+
- 'release*'
11+
push:
12+
branches:
13+
- 'main'
14+
- 'release*'
15+
16+
jobs:
17+
calm-server:
18+
name: Build, Test, and Lint CALM Server Module
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout PR Branch
23+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6
27+
with:
28+
node-version: v22
29+
30+
- name: Install workspace
31+
run: npm ci
32+
33+
- name: Lint CALM Server Module
34+
run: npm run lint --workspace=calm-server
35+
36+
- name: Build workspace
37+
run: npm run build:calm-server
38+
39+
- name: Run tests with coverage for CALM Server
40+
run: npm run test:calm-server

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Ready to get started? Check out the [CALM tutorials](https://calm.finos.org/tuto
3434
| [CALM AI](./calm-ai) | [@rocketstack-matt](https://github.com/rocketstack-matt) | No build, prompt tools only, managed separately to CLI for easier maintenance and broader reuse. |
3535
| [CALM Hub](./calm-hub) | [@jpgough-ms](https://github.com/jpgough-ms), [@grahampacker-ms](https://github.com/grahampacker-ms) | [![Build Calm Hub](https://github.com/finos/architecture-as-code/actions/workflows/build-calm-hub.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/build-calm-hub.yml) |
3636
| [CALM Hub UI](./calm-hub-ui) | [@aidanm3341](https://github.com/aidanm3341), [@aamanrebello](https://github.com/aamanrebello), [@yoofitt96](https://github.com/YoofiTT96) | [![Build CALM Hub UI](https://github.com/finos/architecture-as-code/actions/workflows/build-calm-hub-ui.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/build-calm-hub-ui.yml) |
37+
| [CALM-Server](./calm-server) | [@rocketstack-matt](https://github.com/rocketstack-matt), [@markscott-ms](https://github.com/markscott-ms) | [![Build CALM Server](https://github.com/finos/architecture-as-code/actions/workflows/build-calm-server.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/build-calm-server.yml) |
3738
| [Docs](./docs) | [@rocketstack-matt](https://github.com/rocketstack-matt) | [![Sync Docs to S3](https://github.com/finos/architecture-as-code/actions/workflows/s3-docs-sync.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/s3-docs-sync.yml) [![Build Docs](https://github.com/finos/architecture-as-code/actions/workflows/build-docs.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/build-docs.yml) |
3839
| [CALM VSCode Plugin](./calm-plugins/vscode) | [@LeighFinegold](https://github.com/LeighFinegold), [@rocketstack-matt](https://github.com/rocketstack-matt), [@markscott-ms](https://github.com/markscott-ms) | ![Build VS Code Extension](https://github.com/finos/architecture-as-code/workflows/Build%20VS%20Code%20Extension/badge.svg) |
3940

calm-server/AGENTS.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# @finos/calm-server
2+
3+
The `calm-server` executable provides a standalone HTTP server implementation of CALM validation functionality.
4+
5+
## Architecture
6+
7+
The calm-server provides:
8+
9+
- **Bundled CALM Schemas** - All CALM schemas (release and draft) are bundled during build
10+
- **Health Check Endpoint** (`/health`) - Status endpoint for monitoring
11+
- **Validation Endpoint** (`/calm/validate`) - POST endpoint for validating CALM architectures
12+
- **Rate Limiting** - Protects against abuse with 100 requests per 15 minutes per IP
13+
14+
## Project Structure
15+
16+
```
17+
calm-server/
18+
├── src/
19+
│ ├── index.ts # Entry point, CLI argument parsing
20+
│ ├── server/
21+
│ │ ├── cli-server.ts # Express server startup
22+
│ │ └── routes/
23+
│ │ ├── routes.ts # Router setup
24+
│ │ ├── health-route.ts # Health check endpoint
25+
│ │ └── validation-route.ts # Architecture validation endpoint
26+
│ └── *.spec.ts # Unit tests
27+
├── dist/
28+
│ ├── index.js # Compiled executable
29+
│ └── calm/ # Bundled CALM schemas
30+
│ ├── release/ # Released schema versions
31+
│ └── draft/ # Draft schema versions
32+
├── package.json
33+
├── tsconfig.json
34+
├── tsconfig.build.json
35+
├── tsup.config.ts # Build configuration
36+
├── vitest.config.ts # Test configuration
37+
└── eslint.config.mjs # Linting configuration
38+
```
39+
40+
## Building & Running
41+
42+
### Build the package
43+
```bash
44+
npm run build:calm-server
45+
```
46+
47+
This builds the TypeScript code and copies all CALM schemas from `calm/release` and `calm/draft` into `dist/calm/`.
48+
49+
### Run the server locally
50+
```bash
51+
# Using bundled schemas (default)
52+
./calm-server/dist/index.js --port 3000 --verbose
53+
54+
# Or with custom schemas
55+
./calm-server/dist/index.js -s ../calm/release --port 3000 --verbose
56+
57+
# Or using npm
58+
npm run build:calm-server
59+
node calm-server/dist/index.js --port 3000
60+
```
61+
62+
### Global installation (for development)
63+
```bash
64+
npm run link:calm-server
65+
66+
# Use bundled schemas (default)
67+
calm-server --port 3000
68+
69+
# Or provide custom schemas
70+
calm-server -s /path/to/schemas --port 3000
71+
```
72+
73+
## Command-Line Options
74+
75+
```
76+
Usage: calm-server [options]
77+
78+
CALM Server - A server implementation for the Common Architecture Language Model
79+
80+
Options:
81+
-V, --version output the version number
82+
--port <port> Port to run the server on (default: "3000")
83+
--host <host> Host to bind the server to (default: "127.0.0.1")
84+
-s, --schema-directory <path> Path to the directory containing the meta schemas to use.
85+
(default: bundled schemas in dist/calm)
86+
-v, --verbose Enable verbose logging (default: false)
87+
-c, --calm-hub-url <url> URL to CALMHub instance
88+
--rate-limit-window <ms> Rate limit window in milliseconds (default: 900000 = 15 minutes)
89+
--rate-limit-max <requests> Max requests per IP within the rate limit window (default: 100)
90+
-h, --help display help for command
91+
```
92+
93+
### Security Notes
94+
95+
- **Default Host**: The server binds to `127.0.0.1` (localhost) by default
96+
- **No Authentication**: The server has **NO authentication or authorization controls**
97+
- **Network Exposure Warning**: If you bind to a non-localhost host (e.g., `0.0.0.0`, `::`, public IP), a warning will be logged. Only do this in trusted network environments
98+
99+
## Testing
100+
101+
### Run tests
102+
```bash
103+
npm run test:calm-server
104+
```
105+
106+
### Test the health endpoint
107+
```bash
108+
# Start the server (uses bundled schemas)
109+
node calm-server/dist/index.js &
110+
SERVER_PID=$!
111+
112+
# Test health
113+
curl http://localhost:3000/health
114+
115+
# Clean up
116+
kill $SERVER_PID
117+
```
118+
119+
### Test the validation endpoint
120+
```bash
121+
# With a CALM architecture JSON
122+
curl -X POST http://localhost:3000/calm/validate \
123+
-H "Content-Type: application/json" \
124+
-d '{"architecture": "{\"$schema\": \"https://...\"...}"}'
125+
```
126+
127+
## Dependencies
128+
129+
- `@finos/calm-shared` - Shared utilities, validation logic, schema handling
130+
- `express` - HTTP server framework
131+
- `express-rate-limit` - Rate limiting middleware
132+
- `commander` - CLI argument parsing
133+
134+
## Development Notes
135+
136+
### Copying from CLI
137+
138+
The calm-server implementation mirrors the server functionality from the CLI package (`cli/src/server/`):
139+
140+
- `src/server/cli-server.ts` - Express server setup
141+
- `src/server/routes/routes.ts` - Route configuration
142+
- `src/server/routes/health-route.ts` - Health check
143+
- `src/server/routes/validation-route.ts` - Architecture validation
144+
145+
Both implementations share the same core logic for validation and schema handling through the `@finos/calm-shared` package.
146+
147+
### Build Configuration
148+
149+
The tsup configuration:
150+
- Bundles shared packages (`@finos/calm-shared`, `@finos/calm-models`, `@finos/calm-widgets`)
151+
- Adds Node.js shebang via banner for executable
152+
- Outputs CommonJS format with tree-shaking enabled
153+
- Marks external `node_modules` as external (not bundled)
154+
155+
## Linking for Development
156+
157+
After building, you can link the executable globally:
158+
159+
```bash
160+
npm run link:calm-server
161+
calm-server --help
162+
```
163+
164+
This allows testing the executable without needing to build or reference the dist directory.
165+
166+
## License
167+
168+
Apache-2.0

calm-server/README.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# @finos/calm-server
2+
3+
A standalone HTTP server for the Common Architecture Language Model (CALM) validation functionality.
4+
5+
The `calm-server` executable provides HTTP endpoints for CALM architecture validation.
6+
7+
## Features
8+
9+
- **Bundled CALM Schemas** - All CALM schemas (release and draft) are bundled with the executable
10+
- **Health Check Endpoint** (`GET /health`) - Status endpoint for monitoring
11+
- **Validation Endpoint** (`POST /calm/validate`) - Validate CALM architectures against schemas
12+
13+
## Usage
14+
15+
### Starting the Server
16+
17+
```bash
18+
# Basic usage (uses bundled schemas by default)
19+
calm-server
20+
21+
# With custom port
22+
calm-server --port 8080
23+
24+
# With verbose logging
25+
calm-server --port 3000 --verbose
26+
27+
# Or provide a custom schema directory
28+
calm-server -s /path/to/calm/schemas --port 3000
29+
```
30+
31+
### Command-Line Options
32+
33+
```
34+
Usage: calm-server [options]
35+
36+
Options:
37+
-V, --version output the version number
38+
--port <port> Port to run the server on (default: "3000")
39+
--host <host> Host to bind the server to (default: "127.0.0.1")
40+
-s, --schema-directory <path> Path to the directory containing the meta schemas
41+
(default: bundled schemas in dist/calm)
42+
-v, --verbose Enable verbose logging (default: false)
43+
-c, --calm-hub-url <url> URL to CALMHub instance
44+
--rate-limit-window <ms> Rate limit window in milliseconds (default: 900000 = 15 minutes)
45+
--rate-limit-max <requests> Max requests per IP within the rate limit window (default: 100)
46+
-h, --help display help for command
47+
```
48+
49+
### Security Considerations
50+
51+
- **Default Host is Localhost**: By default, the server binds to `127.0.0.1` for security
52+
- **No Built-in Authentication**: This server has no authentication or authorization controls
53+
- **Network Exposure**: When binding to non-localhost addresses, a security warning is logged. Only expose to the network in trusted environments
54+
55+
## API Endpoints
56+
57+
### Health Check
58+
59+
Check if the server is running:
60+
61+
```bash
62+
curl http://localhost:3000/health
63+
```
64+
65+
Response:
66+
```json
67+
{
68+
"status": "OK"
69+
}
70+
```
71+
72+
### Validate Architecture
73+
74+
Validate a CALM architecture document:
75+
76+
```bash
77+
curl -X POST http://localhost:3000/calm/validate \
78+
-H "Content-Type: application/json" \
79+
-d '{
80+
"architecture": "{\"$schema\":\"https://calm.finos.org/release/1.2/meta/calm.json\",\"nodes\":[]}"
81+
}'
82+
```
83+
84+
Response (success):
85+
```json
86+
{
87+
"jsonSchemaValidationOutputs":[],
88+
"spectralSchemaValidationOutputs":[],
89+
"hasErrors":false,
90+
"hasWarnings":false
91+
}
92+
```
93+
94+
Response (validation errors):
95+
```json
96+
{
97+
"jsonSchemaValidationOutputs":[],
98+
"spectralSchemaValidationOutputs":[...],
99+
"hasErrors":true,
100+
"hasWarnings":false
101+
}
102+
```
103+
104+
## Development
105+
106+
### Building
107+
108+
```bash
109+
# From repository root
110+
npm run build:calm-server
111+
112+
# Or from calm-server directory
113+
cd calm-server
114+
npm run build
115+
```
116+
117+
### Testing
118+
119+
```bash
120+
# From repository root
121+
npm run test:calm-server
122+
123+
# Or from calm-server directory
124+
cd calm-server
125+
npm test
126+
127+
# With coverage
128+
npm test -- --coverage
129+
```
130+
131+
### Linting
132+
133+
```bash
134+
# From calm-server directory
135+
npm run lint
136+
npm run lint-fix
137+
```
138+
139+
## License
140+
141+
Apache-2.0
142+

0 commit comments

Comments
 (0)