|
1 | | -# Parkly — Gate Operations Monorepo |
| 1 | +# Parkly — Parking Operations Command Center |
2 | 2 |
|
3 | | -Monorepo này đã được cutover từ legacy gate-events flow sang operations console đầy đủ hơn: session orchestration, decision engine, entry/exit workflow, review queue, SSE health feeds, outbox monitor và evidence pack. |
| 3 | +Parkly là hệ thống điều hành bãi giữ xe cho nhân viên cổng, giám sát và admin. Nó tập trung vào xe vào/ra, duyệt biển số (ALPR), trạng thái làn/camera, xe đang trong bãi, audit trail, và đồng bộ sự kiện bền vững qua outbox. |
| 4 | + |
| 5 | +Parkly is a parking operations command center for gate operators, supervisors, and admins. It manages entry/exit sessions, ALPR-assisted review, live lane health, active occupancy, audit trails, and resilient outbox delivery. |
| 6 | + |
| 7 | +## What It Does |
| 8 | + |
| 9 | +``` |
| 10 | +Guard scans plate → System creates session → High confidence: auto-open barrier |
| 11 | + → Low confidence: review queue → Supervisor approves → Barrier opens |
| 12 | +Vehicle exits → Session resolved → Audit + outbox events delivered |
| 13 | +``` |
| 14 | + |
| 15 | +## Core Workflows |
| 16 | + |
| 17 | +| Workflow | Description | |
| 18 | +|----------|-------------| |
| 19 | +| **Run Lane** | Primary workspace: select site/gate/lane, submit entry or exit capture | |
| 20 | +| **Review Queue** | Supervisor reviews low-confidence captures, approves/rejects in seconds | |
| 21 | +| **Session History** | Full audit trail with timeline, media, and decision context | |
| 22 | +| **Device Health** | Live camera/lane status with heartbeat monitoring | |
| 23 | +| **Outbox Monitor** | B2B webhook delivery status, DLQ failures, retry backlog | |
| 24 | + |
| 25 | +## Architecture |
| 26 | + |
| 27 | +``` |
| 28 | +[Guard Console / Mobile] ──HTTPS──> [Express API] |
| 29 | + │ |
| 30 | + ┌─────────────┼─────────────┐ |
| 31 | + │ │ │ |
| 32 | + MySQL Redis BullMQ |
| 33 | + (Prisma) (Redlock) (Outbox) |
| 34 | + │ │ │ |
| 35 | + └─────────────┼─────────────┘ |
| 36 | + │ |
| 37 | + [SSE Streams] |
| 38 | + │ |
| 39 | + [React SPA Console] |
| 40 | +``` |
| 41 | + |
| 42 | +Key patterns: outbox pattern for resilient external delivery, snapshot REST + SSE delta for real-time state, Redis Redlock for lane coordination, three auth planes (user JWT, device HMAC, service secrets). |
| 43 | + |
| 44 | +## Tech Stack |
| 45 | + |
| 46 | +| Layer | Technology | |
| 47 | +|-------|-----------| |
| 48 | +| Backend | Node.js 22 LTS, Express 4, TypeScript (Strict) | |
| 49 | +| Database | Prisma 7 ORM, MySQL 8.x | |
| 50 | +| Cache/Queue | Redis 7, BullMQ | |
| 51 | +| Frontend | React 18, Vite, TanStack Query, Zustand, React Router v6 | |
| 52 | +| Shared | `@parkly/contracts` (Zod schemas), `@parkly/gate-core` | |
| 53 | +| E2E | Playwright | |
4 | 54 |
|
5 | 55 | ## Structure |
6 | 56 |
|
7 | | -- `apps/api` — Express API, worker, Flyway, Prisma, operational scripts |
| 57 | +- `apps/api` — Express API, worker, Flyway migrations, Prisma schema |
8 | 58 | - `apps/web` — React/Vite operations console |
9 | | -- `packages/contracts` — shared Zod contracts/types |
| 59 | +- `packages/contracts` — shared Zod transport contracts (single source of truth) |
10 | 60 | - `packages/gate-core` — shared gate decision / domain helpers |
11 | | -- `docs` — runbook, API surface, evidence pack, archive patch notes |
| 61 | +- `docs` — API contract, ADRs, runbook, evidence requirements |
12 | 62 |
|
13 | 63 | ## Quickstart |
14 | 64 |
|
15 | 65 | ```bash |
| 66 | +# 1. Copy env |
16 | 67 | cp apps/api/.env.example apps/api/.env |
17 | 68 | cp apps/web/.env.example apps/web/.env |
| 69 | + |
| 70 | +# 2. Install |
18 | 71 | pnpm install |
19 | | -cd apps/api |
20 | | -pnpm db:migrate |
21 | | -pnpm prisma:pull |
22 | | -pnpm db:grant:app |
23 | | -pnpm db:seed:min |
24 | | -pnpm dev |
25 | | -``` |
26 | 72 |
|
27 | | -Terminal khác: |
| 73 | +# 3. Start infrastructure |
| 74 | +docker compose -f infra/docker/docker-compose.local.yml up -d mysql redis |
28 | 75 |
|
29 | | -```bash |
30 | | -cd apps/api |
31 | | -pnpm worker:dev |
| 76 | +# 4. Setup database |
| 77 | +pnpm --dir apps/api db:migrate |
| 78 | +pnpm --dir apps/api db:grant:app |
| 79 | +pnpm --dir apps/api db:seed:min |
| 80 | + |
| 81 | +# 5. Run |
| 82 | +pnpm dev:api # Terminal 1: API on :3000 |
| 83 | +pnpm --dir apps/api worker:dev # Terminal 2: BullMQ worker |
| 84 | +pnpm dev:web # Terminal 3: Web console on :5173 |
32 | 85 | ``` |
33 | 86 |
|
34 | | -Terminal khác nữa: |
| 87 | +## Entry Points |
| 88 | + |
| 89 | +| URL | Purpose | |
| 90 | +|-----|---------| |
| 91 | +| `http://127.0.0.1:5173/` | Web console | |
| 92 | +| `http://127.0.0.1:3000/docs` | Swagger API docs | |
| 93 | +| `http://127.0.0.1:3000/openapi.json` | OpenAPI spec | |
| 94 | +| `http://127.0.0.1:3000/metrics` | Prometheus metrics | |
| 95 | + |
| 96 | +## Demo Accounts |
| 97 | + |
| 98 | +| Role | Username | Password | Default Route | |
| 99 | +|------|----------|----------|---------------| |
| 100 | +| SUPER_ADMIN | `admin` | `Parkly@123` | /overview | |
| 101 | +| MANAGER | `manager` | `Parkly@123` | /review-queue | |
| 102 | +| OPERATOR | `ops` | `Parkly@123` | /run-lane | |
| 103 | +| GUARD | `guard` | `Parkly@123` | /run-lane | |
| 104 | + |
| 105 | +## Quality Gates |
35 | 106 |
|
36 | 107 | ```bash |
37 | | -cd apps/web |
38 | | -pnpm dev |
| 108 | +pnpm test:full # Canonical release gate: typecheck + unit + e2e + i18n |
| 109 | +pnpm typecheck:api # API TypeScript strict |
| 110 | +pnpm typecheck:web # Web TypeScript strict |
| 111 | +pnpm --dir apps/web build:web # Production bundle (must pass before release) |
39 | 112 | ``` |
40 | 113 |
|
41 | | -## Main entry points |
| 114 | +CI runs: quality gate, Flyway migration validation, npm audit, dependency review, CodeQL. |
| 115 | + |
| 116 | +## Evidence & Docs |
| 117 | + |
| 118 | +- `docs/PARKLY_GOLDEN_PATH.md` — 3-min + 10-min demo walkthrough |
| 119 | +- `docs/API.md` — API contract, envelopes, auth planes, SSE hydration rules |
| 120 | +- `docs/ADR.md` — Architecture decision records |
| 121 | +- `docs/EVIDENCE.md` — Release evidence requirements |
| 122 | +- `.planning/` — GSD project planning (roadmap, requirements, audit) |
42 | 123 |
|
43 | | -- API docs: `http://127.0.0.1:3000/docs` |
44 | | -- OpenAPI JSON: `http://127.0.0.1:3000/openapi.json` |
45 | | -- Metrics: `http://127.0.0.1:3000/metrics` |
46 | | -- Web console: `http://127.0.0.1:5173/` |
| 124 | +## Roadmap |
47 | 125 |
|
48 | | -## Operator docs |
| 126 | +7 phases: Truth Alignment → Golden Path → IA/Role Workflow → Industrial Ops UI → Contract Hardening → Playwright Evidence → Portfolio Packaging. |
49 | 127 |
|
50 | | -- `docs/RUNBOOK.md` |
51 | | -- `docs/API.md` |
52 | | -- `docs/EVIDENCE.md` |
53 | | -- `docs/README.md` |
| 128 | +See `.planning/ROADMAP.md` for full phase details. |
0 commit comments