@@ -4,9 +4,14 @@ A Function as a Service (FaaS) platform. Users submit source code, it compiles t
44
55> ** Note:** ` projectNIL/scope/ ` is the canonical specification. This doc summarizes the system and focuses on operational context.
66
7- ## Architecture
7+ ## Quick Links
8+
9+ - ** [ Getting Started Guide] ( ./guides/getting-started.md ) ** - Set up and run your first function
10+ - ** [ Writing Functions Guide] ( ./guides/writing-functions.md ) ** - Learn how to write AssemblyScript functions
11+ - ** [ API Reference] ( ./api.md ) ** - Complete endpoint documentation
12+ - ** [ Canonical Contracts] ( ../scope/contracts.md ) ** - Authoritative API and queue contracts
813
9- Canonical, end-to-end architecture lives in ` projectNIL/scope/architecture.md ` .
14+ ## Architecture
1015
1116``` mermaid
1217flowchart LR
@@ -21,29 +26,30 @@ flowchart LR
2126 API -->|JPA| Tables
2227 API -->|pgmq send| Jobs
2328
24- Compiler[Compiler Service\n(assemblyscript, future langs) ] -->|pgmq read| Jobs
29+ Compiler[Compiler Service] -->|pgmq read| Jobs
2530 Compiler -->|pgmq send| Results
2631
2732 API -->|pgmq read| Results
28- API -->|execute WASM| Wasm[WASM Runtime (Chicory) ]
33+ API -->|execute WASM| Wasm[WASM Runtime]
2934```
3035
36+ See [ scope/architecture.md] ( ../scope/architecture.md ) for the canonical architecture specification.
37+
3138## Services
3239
3340| Service | Tech | Port | Purpose |
3441| ---------| ------| ------| ---------|
35- | api | Spring Boot 4.x / Java 25 | 8080 | REST API, DB, WASM execution |
36- | compiler | Java 25 / Node.js | 8081 | Compile AS → WASM (see [ compiler.md ] ( ./compiler.md ) ) |
42+ | api | Spring Boot 4.0 / Java 25 | 8080 | REST API, DB, WASM execution |
43+ | compiler | Java 25 / Node.js | 8081 | Compile AssemblyScript to WASM |
3744| postgres | PostgreSQL 18 + pgmq | 5432 | Persistence + message queue |
3845
39- See [ infrastructure.md] ( ./infrastructure.md ) for deployment details.
40-
4146## Local Development
4247
4348### Prerequisites
4449
4550- [ Podman] ( https://podman.io/ ) (or Docker)
4651- [ Podman Compose] ( https://github.com/containers/podman-compose ) (or Docker Compose)
52+ - Java 25+ (for running services locally)
4753
4854### Quick Start
4955
@@ -62,40 +68,19 @@ podman exec projectnil-db psql -U projectnil -d projectnil -c "\dt"
6268
6369### Running the Full Stack
6470
65- To run the complete stack including the compiler service:
66-
6771``` bash
6872cd projectNIL/infra
6973
70- # Start postgres and run migrations first
74+ # Start postgres and run migrations
7175podman compose up -d postgres
7276podman compose --profile migrate up liquibase
7377
74- # Build and start compiler service (first build takes a few minutes)
78+ # Build and start compiler service
7579podman compose --profile full up -d compiler
7680
77- # Verify services are running
78- podman compose ps
79-
80- # Check compiler logs
81- podman compose logs -f compiler
82- ```
83-
84- ### Testing Compilation End-to-End
85-
86- ``` bash
87- # Send a test compilation job
88- podman exec projectnil-db psql -U projectnil -d projectnil -c \
89- " SELECT pgmq.send('compilation_jobs', '{
90- \" functionId\" : \" 12345678-1234-1234-1234-123456789abc\" ,
91- \" language\" : \" assemblyscript\" ,
92- \" source\" : \" export function add(a: i32, b: i32): i32 { return a + b; }\"
93- }'::jsonb);"
94-
95- # Check for compilation result (wait a few seconds)
96- podman exec projectnil-db psql -U projectnil -d projectnil -c \
97- " SELECT message->>'functionId', message->>'success', message->>'error'
98- FROM pgmq.read('compilation_results', 30, 10);"
81+ # Start API service (from projectNIL root)
82+ cd ..
83+ ./gradlew :services:api:bootRun
9984```
10085
10186### Common Commands
@@ -114,199 +99,89 @@ podman compose --profile full down -v
11499# Connect to database
115100podman exec -it projectnil-db psql -U projectnil -d projectnil
116101
117- # Rebuild compiler after code changes
118- podman compose --profile full build compiler
119- podman compose --profile full up -d compiler
120- ```
121-
122- ### Manual Setup (Alternative)
123-
124- If you prefer to run PostgreSQL manually:
125-
126- ``` bash
127- podman run -d --name pgmq-postgres \
128- -e POSTGRES_PASSWORD=postgres \
129- -p 5432:5432 \
130- ghcr.io/pgmq/pg18-pgmq:v1.8.0
131- ```
132-
133- Connect and enable pgmq:
134-
135- ``` bash
136- psql postgres://postgres:postgres@localhost:5432/postgres
137- ```
138-
139- ``` sql
140- CREATE EXTENSION pgmq;
141-
142- -- Create queues
143- SELECT pgmq .create (' compilation_jobs' );
144- SELECT pgmq .create (' compilation_results' );
145- ```
146-
147- ### pgmq Quick Reference
148-
149- ``` sql
150- -- Send message
151- SELECT pgmq .send (' compilation_jobs' , ' {"functionId": "...", "language": "assemblyscript", "source": "..."}' );
152-
153- -- Read message (invisible for 30s)
154- SELECT * FROM pgmq .read (' compilation_jobs' , 30 , 1 );
155-
156- -- Delete after processing
157- SELECT pgmq .delete (' compilation_jobs' , 1 );
158-
159- -- Or archive for retention
160- SELECT pgmq .archive (' compilation_jobs' , 1 );
102+ # Run tests
103+ ./gradlew test # All tests
104+ ./gradlew :services:api:test # API tests only
105+ ./gradlew :services:compiler:test # Compiler tests only
161106```
162107
163108## Tech Stack
164109
165- | Component | Technology | Version | ADR / Details |
166- | -----------| ------------| ---------| ---------------|
167- | Language | Java | 25 | - |
168- | Framework | Spring Boot | 4.0.0 (Spring 7) | - |
169- | Database | PostgreSQL | 18 | - |
170- | Message Queue | pgmq | 1.8.0 | [ ADR-002] ( ./decisions/002-message-queue-pgmq.md ) |
171- | WASM Runtime | Chicory | 0.0.1 | [ ADR-001] ( ./decisions/001-wasm-runtime.md ) |
172- | Migrations | Liquibase | 4.30 | - |
173- | Compiler | AssemblyScript | Latest | - |
174- | Containers | Podman Compose | - | - |
175-
176- See [ stack.md] ( ./stack.md ) for full rationale and library versions.
110+ | Component | Technology | Version |
111+ | -----------| ------------| ---------|
112+ | Language | Java | 25 |
113+ | Framework | Spring Boot | 4.0.0 |
114+ | Database | PostgreSQL | 18 |
115+ | Message Queue | pgmq | 1.8.0 |
116+ | WASM Runtime | Chicory | 1.6.1 |
117+ | Migrations | Liquibase | 4.30 |
118+ | Compiler | AssemblyScript | Latest |
119+ | Containers | Podman Compose | - |
177120
178- ## Function Lifecycle
179-
180- Canonical state machines and flows live in:
181- - ` projectNIL/scope/entities.md `
182- - ` projectNIL/scope/flows.md `
183-
184- ``` mermaid
185- stateDiagram-v2
186- [*] --> PENDING
187- PENDING --> COMPILING
188- COMPILING --> READY
189- COMPILING --> FAILED
190- ```
191-
192- ## Database Schema
193-
194- Managed via Liquibase migrations in ` infra/migrations/ ` .
195-
196- ``` sql
197- -- Status enums
198- CREATE TYPE function_status AS ENUM (' PENDING' , ' COMPILING' , ' READY' , ' FAILED' );
199- CREATE TYPE execution_status AS ENUM (' PENDING' , ' RUNNING' , ' COMPLETED' , ' FAILED' );
200-
201- CREATE TABLE functions (
202- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
203- name VARCHAR (255 ) NOT NULL ,
204- description TEXT ,
205- language VARCHAR (50 ) NOT NULL ,
206- source TEXT NOT NULL ,
207- wasm_binary BYTEA ,
208- status function_status NOT NULL DEFAULT ' PENDING' ,
209- compile_error TEXT ,
210- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
211- updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
212- );
213-
214- CREATE TABLE executions (
215- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
216- function_id UUID REFERENCES functions(id) ON DELETE CASCADE ,
217- input JSONB,
218- output JSONB,
219- status execution_status NOT NULL DEFAULT ' PENDING' ,
220- error_message TEXT ,
221- started_at TIMESTAMPTZ ,
222- completed_at TIMESTAMPTZ ,
223- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
224- );
225-
226- -- Indexes
227- CREATE INDEX idx_functions_name ON functions(name);
228- CREATE INDEX idx_functions_status ON functions(status);
229- CREATE INDEX idx_executions_function_id ON executions(function_id);
230- CREATE INDEX idx_executions_status ON executions(status);
231- CREATE INDEX idx_executions_created_at ON executions(created_at DESC );
232- ```
233-
234- ## Message Formats
235-
236- Canonical queue and HTTP contracts are captured in ` projectNIL/scope/contracts.md ` .
237-
238- ** Compilation Request** (API → Compiler):
239- ``` json
240- {
241- "functionId" : " 550e8400-e29b-41d4-a716-446655440000" ,
242- "language" : " assemblyscript" ,
243- "source" : " export function add(a: i32, b: i32): i32 { return a + b; }"
244- }
245- ```
246-
247- ** Compilation Result** (Compiler → API):
248- ``` json
249- {
250- "functionId" : " 550e8400-e29b-41d4-a716-446655440000" ,
251- "success" : true ,
252- "wasmBinary" : " AGFzbQEAAAA..." ,
253- "error" : null
254- }
255- ```
256-
257- ## CI Operational Notes
258- - Gradle caching (` actions/cache@v4 ` ) now persists ` ~/.gradle/caches ` and ` ~/.gradle/wrapper ` during the “CI - dev & feature branches” workflow.
259- - Cold run (commit ` b0145a7 ` , cache miss) executed ` ./gradlew build --build-cache ` in ~ 80 s and uploaded a ~ 276 MB cache.
260- - Warm run (empty commit ` ci: trigger cache verification ` , SHA ` 441010f ` ) restored that cache (log shows ` Cache hit ` and multiple ` FROM-CACHE ` tasks) and completed in ~ 22 s.
261- - Use empty commits when you need to validate cache health without changing code.
121+ See [ stack.md] ( ./stack.md ) for rationale and [ decisions/] ( ./decisions/ ) for ADRs.
262122
263123## Project Structure
264124
265125```
266126projectNIL/
267- ├── common/ # Shared domain objects and queue DTOs
127+ ├── common/ # Shared domain objects
268128│ └── src/main/java/.../domain/
269- │ ├── Function.java, Execution.java, ...
270- │ └── queue/ # CompilationJob, CompilationResult
129+ │ ├── Function.java
130+ │ ├── Execution.java
131+ │ └── queue/ # CompilationJob, CompilationResult
271132│
272133├── services/
273- │ ├── api/ # Spring Boot API service
274- │ │ └── build.gradle.kts
134+ │ ├── api/ # Spring Boot API service
135+ │ │ └── src/main/java/.../
136+ │ │ ├── web/ # Controllers, DTOs
137+ │ │ ├── service/ # Business logic
138+ │ │ ├── repository/ # JPA repositories
139+ │ │ ├── runtime/ # WASM execution
140+ │ │ └── messaging/ # PGMQ integration
275141│ │
276- │ └── compiler/ # AssemblyScript compiler service
277- │ ├ ── build.gradle.kts
278- │ ├── scripts/run-with-podman.sh # helper for local Podman tests
279- │ └── src / # see docs/compiler.md for structure
142+ │ └── compiler/ # AssemblyScript compiler
143+ │ └ ── src/main/java/.../
144+ │ ├── core/ # Compilation logic
145+ │ └── messaging / # PGMQ integration
280146│
281- ├── infra/ # Infrastructure configuration
282- │ ├── compose.yml # Podman/Docker Compose
283- │ └── migrations/ # Liquibase database migrations
284- │ ├── db.changelog-master.yaml
285- │ └── changelog/
286- │ ├── 001-create-functions-table.yaml
287- │ ├── 002-create-executions-table.yaml
288- │ └── 003-setup-pgmq-queues.yaml
147+ ├── infra/ # Infrastructure
148+ │ ├── compose.yml # Local development
149+ │ └── migrations/ # Liquibase changelogs
289150│
290- ├── docs/
291- │ ├── README.md # This file
292- │ ├── api.md # API reference
293- │ ├── roadmap.md # Future phases
294- │ ├── stack.md # Technology stack
295- │ └── decisions/ # ADRs
151+ ├── docs/ # Documentation
152+ │ ├── guides/ # User guides
153+ │ ├── api.md # API reference
154+ │ └── decisions/ # ADRs
296155│
297- ├── gradle/libs.versions.toml
298- ├── build.gradle.kts
299- └── settings.gradle.kts
156+ └── scope/ # Canonical specifications
157+ ├── contracts.md # API & queue contracts
158+ ├── entities.md # Domain entities
159+ └── flows.md # Sequence diagrams
300160```
301161
302- ## Related Docs
303-
304- - [ API Reference] ( ./api.md )
305- - [ Infrastructure] ( ./infrastructure.md )
306- - [ Compiler Service] ( ./compiler.md )
307- - [ WASM Runtime] ( ./wasm-runtime.md )
308- - [ Session Handoff] ( ./session-handoff.md )
309- - [ Roadmap] ( ./roadmap.md )
310- - [ Tech Stack] ( ./stack.md )
311- - [ ADR-001: WASM Runtime] ( ./decisions/001-wasm-runtime.md )
312- - [ ADR-002: Message Queue] ( ./decisions/002-message-queue-pgmq.md )
162+ ## Documentation Index
163+
164+ ### User Guides
165+ - [ Getting Started] ( ./guides/getting-started.md ) - First function in 5 minutes
166+ - [ Writing Functions] ( ./guides/writing-functions.md ) - AssemblyScript function guide
167+
168+ ### Reference
169+ - [ API Reference] ( ./api.md ) - Complete endpoint documentation
170+ - [ WASM Runtime] ( ./wasm-runtime.md ) - Chicory runtime details
171+ - [ Compiler Service] ( ./compiler.md ) - Compilation pipeline
172+ - [ Infrastructure] ( ./infrastructure.md ) - Deployment and ops
173+
174+ ### Specifications
175+ - [ Canonical Contracts] ( ../scope/contracts.md ) - Source of truth for APIs
176+ - [ Domain Entities] ( ../scope/entities.md ) - Entity definitions and state machines
177+ - [ System Flows] ( ../scope/flows.md ) - End-to-end sequences
178+
179+ ### Project
180+ - [ Roadmap] ( ./roadmap.md ) - Phase 0/1/2 plans
181+ - [ Session Handoff] ( ./session-handoff.md ) - Current implementation status
182+ - [ Design: API Service] ( ./design-api-service.md ) - Implementation blueprint
183+ - [ AGENTS.md] ( ../AGENTS.md ) - Coding conventions
184+
185+ ### Architecture Decisions
186+ - [ ADR-001: WASM Runtime] ( ./decisions/001-wasm-runtime.md ) - Why Chicory
187+ - [ ADR-002: Message Queue] ( ./decisions/002-message-queue-pgmq.md ) - Why pgmq
0 commit comments