How midnightntwrk/example-bboard works
Project Type and Purpose
• This is a full-stack decentralized application (DApp) composed of:
– A Compact smart contract (“contract” package) that enforces bulletin‐board rules on-chain.
– A shared API library (“api” package) for interacting with the contract.
– Two clients:
• bboard-cli – a Node.js CLI tool to deploy, post, and remove messages.
• bboard-ui – a React/Vite web UI for the same operations in the browser.
– External services: a Proof Server (local or remote) and a blockchain/testnet.
Break Out Top-Level Components
A. Contract
– Source files (contract/src/...).
– Compiler (Compact Compiler → generates on-chain bytecode / schema).
– Tests & simulator (contract/src/test).
B. API Library
– Entry point (api/src/index.ts).
– Common types and utility modules.
– Exposed methods for deploy(), postMessage(), takeDown().
C. CLI Client
– Launchers for various modes (standalone, testnet-local, testnet-remote).
– Configuration files (proof-server.yml).
– Uses the API library to orchestrate contract calls.
D. Web UI
– React app (bboard-ui/src).
– Contexts & hooks (DeployedBoardContext).
– Theming and layout components.
– Imports the API library in the browser bundle.
E. External Services
– Proof Server (verifies zero-knowledge proofs).
– Blockchain network (local standalone chain or remote testnet).
Relationships and Data Flows
– CLI/UI → API library → Proof Server → Blockchain.
– Blockchain → Contract bytecode + on-chain state → API library returns responses → CLI/UI.
– For standalone mode, show a “Local Proof Server + Local Blockchain” cluster.
– For testnet mode, show “Remote Proof Server” and “Testnet” as separate endpoints.
Architectural Patterns & Design Principles
– Monorepo modularity: four sibling packages (api, contract, bboard-cli, bboard-ui).
– Separation of concerns: contract logic vs. client interfaces vs. shared API.
– Reusability: both UI and CLI depend on the same API library.
– Pluggable deployment modes: standalone vs. testnet-local vs. testnet-remote.
Technologies, Frameworks & Libraries
– Smart-contract language: Compact (see badge in README).
– Language: TypeScript throughout (tsconfig.json in each package).
– Build tools: npm, vite (UI), vitest (CLI tests), ts-compiler.
– Linting/formatting: ESLint, Prettier configs.
– CI/CD: GitHub workflows (ci.yaml, checkmarx.yaml).