cerber-core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cerber-example/BIBLE.md +132 -0
- package/.cerber-example/CERBER_LAW.md +200 -0
- package/.cerber-example/connections/contracts/booking-to-pricing.json +44 -0
- package/.cerber-example/connections/contracts/pricing-to-booking.json +37 -0
- package/.cerber-example/modules/booking-calendar/MODULE.md +225 -0
- package/.cerber-example/modules/booking-calendar/contract.json +106 -0
- package/.cerber-example/modules/booking-calendar/dependencies.json +8 -0
- package/.cerber-example/modules/pricing-engine/MODULE.md +160 -0
- package/.cerber-example/modules/pricing-engine/contract.json +64 -0
- package/.cerber-example/modules/pricing-engine/dependencies.json +8 -0
- package/CHANGELOG.md +68 -0
- package/LICENSE +21 -0
- package/README.md +1379 -0
- package/bin/cerber +105 -0
- package/bin/cerber-focus +31 -0
- package/bin/cerber-guardian +90 -0
- package/bin/cerber-health +113 -0
- package/bin/cerber-morning +19 -0
- package/bin/cerber-repair +21 -0
- package/dist/cerber/index.d.ts +47 -0
- package/dist/cerber/index.d.ts.map +1 -0
- package/dist/cerber/index.js +154 -0
- package/dist/cerber/index.js.map +1 -0
- package/dist/guardian/index.d.ts +70 -0
- package/dist/guardian/index.d.ts.map +1 -0
- package/dist/guardian/index.js +271 -0
- package/dist/guardian/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/examples/backend-schema.ts +72 -0
- package/examples/frontend-schema.ts +67 -0
- package/examples/health-checks.ts +196 -0
- package/examples/solo-integration/README.md +457 -0
- package/examples/solo-integration/package.json +47 -0
- package/examples/team-integration/README.md +347 -0
- package/examples/team-integration/package.json +23 -0
- package/package.json +104 -0
- package/solo/README.md +258 -0
- package/solo/config/performance-budget.json +53 -0
- package/solo/config/solo-contract.json +71 -0
- package/solo/lib/feature-flags.ts +177 -0
- package/solo/scripts/cerber-auto-repair.js +260 -0
- package/solo/scripts/cerber-daily-check.js +282 -0
- package/solo/scripts/cerber-dashboard.js +191 -0
- package/solo/scripts/cerber-deps-health.js +247 -0
- package/solo/scripts/cerber-docs-sync.js +304 -0
- package/solo/scripts/cerber-flags-check.js +229 -0
- package/solo/scripts/cerber-performance-budget.js +271 -0
- package/solo/scripts/cerber-rollback.js +229 -0
- package/solo/scripts/cerber-snapshot.js +319 -0
- package/team/README.md +327 -0
- package/team/config/team-contract.json +27 -0
- package/team/lib/module-system.ts +157 -0
- package/team/scripts/cerber-add-module.sh +195 -0
- package/team/scripts/cerber-connections-check.sh +186 -0
- package/team/scripts/cerber-focus.sh +170 -0
- package/team/scripts/cerber-module-check.sh +165 -0
- package/team/scripts/cerber-team-morning.sh +210 -0
- package/team/templates/BIBLE_TEMPLATE.md +52 -0
- package/team/templates/CONNECTION_TEMPLATE.json +20 -0
- package/team/templates/MODULE_TEMPLATE.md +60 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# PROJECT BIBLE - Master Map
|
|
2
|
+
|
|
3
|
+
**Project:** Hotel Booking System Example
|
|
4
|
+
**Owner:** Stefan Pitek
|
|
5
|
+
**Last Updated:** 2026-01-02
|
|
6
|
+
|
|
7
|
+
## Architecture Overview
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
┌─────────────────────────────────────────┐
|
|
11
|
+
│ Frontend (React/Next.js) │
|
|
12
|
+
│ - Booking UI │
|
|
13
|
+
│ - Price Calculator │
|
|
14
|
+
└─────────────────┬───────────────────────┘
|
|
15
|
+
│
|
|
16
|
+
▼
|
|
17
|
+
┌─────────────────────────────────────────┐
|
|
18
|
+
│ API Layer (Express) │
|
|
19
|
+
│ /api/bookings │
|
|
20
|
+
│ /api/pricing │
|
|
21
|
+
└─────────────────┬───────────────────────┘
|
|
22
|
+
│
|
|
23
|
+
┌─────────┼─────────┐
|
|
24
|
+
▼ ▼
|
|
25
|
+
pricing-engine booking-calendar
|
|
26
|
+
│ │
|
|
27
|
+
└─────────┬─────────┘
|
|
28
|
+
▼
|
|
29
|
+
PostgreSQL Database
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Modules Index
|
|
33
|
+
|
|
34
|
+
### Core Modules
|
|
35
|
+
|
|
36
|
+
1. **pricing-engine** - Dynamic pricing calculation
|
|
37
|
+
- Owner: Stefan Pitek
|
|
38
|
+
- Status: Active
|
|
39
|
+
- Files: `src/modules/pricing-engine/`
|
|
40
|
+
- Purpose: Calculate room prices based on date, occupancy, season
|
|
41
|
+
|
|
42
|
+
2. **booking-calendar** - Room availability and reservations
|
|
43
|
+
- Owner: Stefan Pitek
|
|
44
|
+
- Status: Active
|
|
45
|
+
- Files: `src/modules/booking-calendar/`
|
|
46
|
+
- Purpose: Manage room bookings and availability
|
|
47
|
+
|
|
48
|
+
## Connections Map
|
|
49
|
+
|
|
50
|
+
- `pricing-engine` → `booking-calendar`: checkAvailability()
|
|
51
|
+
- `booking-calendar` → `pricing-engine`: calculatePrice()
|
|
52
|
+
|
|
53
|
+
## Team Responsibilities
|
|
54
|
+
|
|
55
|
+
- **Stefan Pitek**: pricing-engine, booking-calendar
|
|
56
|
+
- **Backend Team**: API layer, database schema
|
|
57
|
+
- **Frontend Team**: Booking UI, integration
|
|
58
|
+
|
|
59
|
+
## Module Dependencies
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
booking-calendar
|
|
63
|
+
↓
|
|
64
|
+
pricing-engine
|
|
65
|
+
↓
|
|
66
|
+
database
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Tech Stack
|
|
70
|
+
|
|
71
|
+
- **Backend**: Node.js, Express, TypeScript
|
|
72
|
+
- **Database**: PostgreSQL, Prisma ORM
|
|
73
|
+
- **Testing**: Jest, Supertest
|
|
74
|
+
- **Validation**: Cerber TEAM module system
|
|
75
|
+
|
|
76
|
+
## Development Workflow
|
|
77
|
+
|
|
78
|
+
1. **Focus Mode**: `bash team/scripts/cerber-focus.sh pricing-engine`
|
|
79
|
+
2. **Validate**: `bash team/scripts/cerber-module-check.sh pricing-engine`
|
|
80
|
+
3. **Check Connections**: `bash team/scripts/cerber-connections-check.sh`
|
|
81
|
+
4. **Commit**: Guardian validates architecture
|
|
82
|
+
5. **Deploy**: Cerber 2.1 validates health
|
|
83
|
+
|
|
84
|
+
## API Endpoints
|
|
85
|
+
|
|
86
|
+
### Pricing
|
|
87
|
+
- `GET /api/pricing/calculate` - Calculate room price
|
|
88
|
+
- Query: `roomType`, `checkIn`, `checkOut`, `guests`
|
|
89
|
+
- Returns: `{ price: number, breakdown: {...} }`
|
|
90
|
+
|
|
91
|
+
### Booking
|
|
92
|
+
- `POST /api/bookings` - Create reservation
|
|
93
|
+
- Body: `{ roomId, checkIn, checkOut, guestInfo }`
|
|
94
|
+
- Returns: `{ bookingId, confirmationCode }`
|
|
95
|
+
|
|
96
|
+
- `GET /api/bookings/:id` - Get booking details
|
|
97
|
+
- `DELETE /api/bookings/:id` - Cancel booking
|
|
98
|
+
|
|
99
|
+
## Database Schema
|
|
100
|
+
|
|
101
|
+
```sql
|
|
102
|
+
-- Rooms
|
|
103
|
+
CREATE TABLE rooms (
|
|
104
|
+
id SERIAL PRIMARY KEY,
|
|
105
|
+
room_number VARCHAR(10) UNIQUE,
|
|
106
|
+
room_type VARCHAR(50),
|
|
107
|
+
base_price DECIMAL(10,2)
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
-- Bookings
|
|
111
|
+
CREATE TABLE bookings (
|
|
112
|
+
id SERIAL PRIMARY KEY,
|
|
113
|
+
room_id INTEGER REFERENCES rooms(id),
|
|
114
|
+
check_in DATE,
|
|
115
|
+
check_out DATE,
|
|
116
|
+
guest_name VARCHAR(255),
|
|
117
|
+
total_price DECIMAL(10,2),
|
|
118
|
+
status VARCHAR(20)
|
|
119
|
+
);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Notes
|
|
123
|
+
|
|
124
|
+
- Pricing engine uses dynamic pricing algorithm based on:
|
|
125
|
+
- Seasonal multipliers (high/low season)
|
|
126
|
+
- Day of week (weekends +20%)
|
|
127
|
+
- Advance booking discount
|
|
128
|
+
- Length of stay discount
|
|
129
|
+
|
|
130
|
+
- Booking calendar ensures no double-bookings
|
|
131
|
+
- All changes validated by Guardian pre-commit
|
|
132
|
+
- Production health monitored by Cerber 2.1
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# CERBER LAW - Team Rules
|
|
2
|
+
|
|
3
|
+
**Project:** Hotel Booking System
|
|
4
|
+
**Version:** 2.0-team
|
|
5
|
+
**Last Updated:** 2026-01-02
|
|
6
|
+
|
|
7
|
+
## Core Principles
|
|
8
|
+
|
|
9
|
+
1. **Module Boundaries Are Sacred**
|
|
10
|
+
- Modules communicate only through declared contracts
|
|
11
|
+
- No direct imports between modules (use public interface)
|
|
12
|
+
- All connections must have documented contracts
|
|
13
|
+
|
|
14
|
+
2. **Focus Mode First**
|
|
15
|
+
- Always use `cerber-focus.sh` before working on a module
|
|
16
|
+
- Share FOCUS_CONTEXT.md with AI instead of entire codebase
|
|
17
|
+
- Keep context small and focused
|
|
18
|
+
|
|
19
|
+
3. **Documentation Is Code**
|
|
20
|
+
- MODULE.md must be updated with every public interface change
|
|
21
|
+
- Connection contracts are versioned
|
|
22
|
+
- Breaking changes must be documented
|
|
23
|
+
|
|
24
|
+
## Module Rules
|
|
25
|
+
|
|
26
|
+
### Creating Modules
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Always use the official script
|
|
30
|
+
bash team/scripts/cerber-add-module.sh <module-name>
|
|
31
|
+
|
|
32
|
+
# Never create modules manually
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Module Structure
|
|
36
|
+
|
|
37
|
+
Each module MUST have:
|
|
38
|
+
- `MODULE.md` - Complete documentation
|
|
39
|
+
- `contract.json` - Public interface definition
|
|
40
|
+
- `dependencies.json` - List of dependencies
|
|
41
|
+
|
|
42
|
+
### Naming Conventions
|
|
43
|
+
|
|
44
|
+
- Module names: `kebab-case` (e.g., `pricing-engine`)
|
|
45
|
+
- File names: `camelCase.ts` or `kebab-case.ts`
|
|
46
|
+
- Exports: Named exports only (no default exports)
|
|
47
|
+
|
|
48
|
+
## Connection Rules
|
|
49
|
+
|
|
50
|
+
### Creating Connections
|
|
51
|
+
|
|
52
|
+
1. Define interface in both modules
|
|
53
|
+
2. Create connection contract in `.cerber/connections/contracts/`
|
|
54
|
+
3. Version the contract (semver)
|
|
55
|
+
4. Document breaking changes
|
|
56
|
+
|
|
57
|
+
### Connection Contract Template
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"id": "module-a-to-module-b",
|
|
62
|
+
"from": "module-a",
|
|
63
|
+
"to": "module-b",
|
|
64
|
+
"type": "function-call",
|
|
65
|
+
"interface": { ... },
|
|
66
|
+
"version": "1.0.0",
|
|
67
|
+
"breaking_changes": []
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Breaking Changes
|
|
72
|
+
|
|
73
|
+
When making breaking changes:
|
|
74
|
+
1. Increment major version
|
|
75
|
+
2. Add to `breaking_changes` array
|
|
76
|
+
3. Update both modules
|
|
77
|
+
4. Notify team in PR description
|
|
78
|
+
|
|
79
|
+
## Validation Rules
|
|
80
|
+
|
|
81
|
+
### Before Commit
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Validate module
|
|
85
|
+
bash team/scripts/cerber-module-check.sh <module-name>
|
|
86
|
+
|
|
87
|
+
# Validate all connections
|
|
88
|
+
bash team/scripts/cerber-connections-check.sh
|
|
89
|
+
|
|
90
|
+
# Guardian validates architecture
|
|
91
|
+
git commit
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Before PR
|
|
95
|
+
|
|
96
|
+
1. All modules pass validation
|
|
97
|
+
2. All connections valid
|
|
98
|
+
3. BIBLE.md updated
|
|
99
|
+
4. FOCUS_CONTEXT.md generated
|
|
100
|
+
5. Tests pass
|
|
101
|
+
6. Guardian pre-commit passed
|
|
102
|
+
|
|
103
|
+
## Workflow
|
|
104
|
+
|
|
105
|
+
### Daily Start
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm run cerber:morning
|
|
109
|
+
# or
|
|
110
|
+
bash team/scripts/cerber-team-morning.sh
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Working on Module
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# 1. Enter focus mode
|
|
117
|
+
bash team/scripts/cerber-focus.sh pricing-engine
|
|
118
|
+
|
|
119
|
+
# 2. Work on module (share FOCUS_CONTEXT.md with AI)
|
|
120
|
+
|
|
121
|
+
# 3. Validate changes
|
|
122
|
+
bash team/scripts/cerber-module-check.sh pricing-engine
|
|
123
|
+
|
|
124
|
+
# 4. Commit (Guardian validates)
|
|
125
|
+
git commit -m "feat(pricing-engine): add seasonal pricing"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Adding Module
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# 1. Create module
|
|
132
|
+
bash team/scripts/cerber-add-module.sh payment-gateway
|
|
133
|
+
|
|
134
|
+
# 2. Edit MODULE.md, contract.json, dependencies.json
|
|
135
|
+
|
|
136
|
+
# 3. Enter focus mode
|
|
137
|
+
bash team/scripts/cerber-focus.sh payment-gateway
|
|
138
|
+
|
|
139
|
+
# 4. Implement module
|
|
140
|
+
|
|
141
|
+
# 5. Validate
|
|
142
|
+
bash team/scripts/cerber-module-check.sh payment-gateway
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Forbidden Practices
|
|
146
|
+
|
|
147
|
+
❌ **DO NOT:**
|
|
148
|
+
- Import directly from another module's internals
|
|
149
|
+
- Skip module validation before committing
|
|
150
|
+
- Modify MODULE.md without updating contract.json
|
|
151
|
+
- Create modules without using `cerber-add-module.sh`
|
|
152
|
+
- Make breaking changes without versioning
|
|
153
|
+
- Work on entire codebase when you could use focus mode
|
|
154
|
+
|
|
155
|
+
✅ **DO:**
|
|
156
|
+
- Use focus mode for every module
|
|
157
|
+
- Validate before committing
|
|
158
|
+
- Document all public interfaces
|
|
159
|
+
- Version connection contracts
|
|
160
|
+
- Update BIBLE.md with changes
|
|
161
|
+
- Follow module boundaries strictly
|
|
162
|
+
|
|
163
|
+
## Integration with Guardian + Cerber
|
|
164
|
+
|
|
165
|
+
Cerber TEAM works alongside existing tools:
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
Morning:
|
|
169
|
+
bash team/scripts/cerber-team-morning.sh (TEAM)
|
|
170
|
+
|
|
171
|
+
Development:
|
|
172
|
+
bash team/scripts/cerber-focus.sh <module> (TEAM)
|
|
173
|
+
git commit (Guardian validates)
|
|
174
|
+
|
|
175
|
+
Pre-push:
|
|
176
|
+
npm run cerber:pre-push (SOLO checks)
|
|
177
|
+
|
|
178
|
+
Deploy:
|
|
179
|
+
curl /api/health (Cerber 2.1 validates)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Enforcement
|
|
183
|
+
|
|
184
|
+
- **Guardian**: Pre-commit validation of architecture
|
|
185
|
+
- **Module Check**: Validates module compliance
|
|
186
|
+
- **Connection Check**: Validates contracts
|
|
187
|
+
- **Code Review**: Human review of module boundaries
|
|
188
|
+
- **CI/CD**: Automated validation on PR
|
|
189
|
+
|
|
190
|
+
## Exceptions
|
|
191
|
+
|
|
192
|
+
When you need to break the rules:
|
|
193
|
+
1. Document reason in MODULE.md
|
|
194
|
+
2. Add `ARCHITECT_APPROVED:` comment in code
|
|
195
|
+
3. Create issue to fix properly
|
|
196
|
+
4. Notify team in PR
|
|
197
|
+
|
|
198
|
+
## Contact
|
|
199
|
+
|
|
200
|
+
Questions? Contact Stefan Pitek or see [docs/TEAM.md](../../docs/TEAM.md)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "booking-to-pricing",
|
|
3
|
+
"from": "booking-calendar",
|
|
4
|
+
"to": "pricing-engine",
|
|
5
|
+
"type": "function-call",
|
|
6
|
+
"interface": {
|
|
7
|
+
"function": "calculatePrice",
|
|
8
|
+
"description": "Booking calendar calls pricing engine when modifying bookings to recalculate total price",
|
|
9
|
+
"input": {
|
|
10
|
+
"type": "PriceParams",
|
|
11
|
+
"fields": {
|
|
12
|
+
"roomType": "string",
|
|
13
|
+
"checkIn": "Date",
|
|
14
|
+
"checkOut": "Date",
|
|
15
|
+
"guests": "number",
|
|
16
|
+
"promoCode": "string | undefined"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"output": {
|
|
20
|
+
"type": "PriceResult",
|
|
21
|
+
"fields": {
|
|
22
|
+
"totalPrice": "number",
|
|
23
|
+
"basePrice": "number",
|
|
24
|
+
"breakdown": "PriceBreakdown"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"version": "2.0.0",
|
|
29
|
+
"breaking_changes": [
|
|
30
|
+
{
|
|
31
|
+
"version": "2.0.0",
|
|
32
|
+
"date": "2026-01-02",
|
|
33
|
+
"description": "Added detailed breakdown to return type",
|
|
34
|
+
"migration": "Update booking-calendar to handle new breakdown field"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"version": "2.0.0",
|
|
38
|
+
"date": "2026-01-02",
|
|
39
|
+
"description": "Made promoCode parameter optional",
|
|
40
|
+
"migration": "Can now omit promoCode parameter"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"notes": "This connection is used during booking modifications. The booking calendar must recalculate prices with current rates when guests modify their dates."
|
|
44
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "pricing-to-booking",
|
|
3
|
+
"from": "pricing-engine",
|
|
4
|
+
"to": "booking-calendar",
|
|
5
|
+
"type": "function-call",
|
|
6
|
+
"interface": {
|
|
7
|
+
"function": "checkAvailability",
|
|
8
|
+
"description": "Pricing engine calls booking calendar to verify room availability before calculating prices",
|
|
9
|
+
"input": {
|
|
10
|
+
"type": "AvailabilityParams",
|
|
11
|
+
"fields": {
|
|
12
|
+
"roomType": "string",
|
|
13
|
+
"checkIn": "Date",
|
|
14
|
+
"checkOut": "Date",
|
|
15
|
+
"quantity": "number"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"output": {
|
|
19
|
+
"type": "AvailabilityResult",
|
|
20
|
+
"fields": {
|
|
21
|
+
"available": "boolean",
|
|
22
|
+
"availableCount": "number",
|
|
23
|
+
"conflictingBookings": "string[]"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"version": "2.0.0",
|
|
28
|
+
"breaking_changes": [
|
|
29
|
+
{
|
|
30
|
+
"version": "2.0.0",
|
|
31
|
+
"date": "2026-01-02",
|
|
32
|
+
"description": "Added 'availableCount' to return type",
|
|
33
|
+
"migration": "Update pricing-engine to handle new field"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"notes": "This connection ensures that quoted prices are only for available rooms. Pricing engine must handle the case where availability changes between price quote and booking."
|
|
37
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Module: booking-calendar
|
|
2
|
+
|
|
3
|
+
**Owner:** Stefan Pitek
|
|
4
|
+
**Status:** Active
|
|
5
|
+
**Last Updated:** 2026-01-02
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
Manages room availability, bookings, and calendar operations. Ensures no double-bookings and provides real-time availability information.
|
|
10
|
+
|
|
11
|
+
## Responsibilities
|
|
12
|
+
|
|
13
|
+
- Track room availability by date
|
|
14
|
+
- Create and manage bookings
|
|
15
|
+
- Prevent double-bookings (conflict detection)
|
|
16
|
+
- Calculate available rooms for date ranges
|
|
17
|
+
- Handle booking cancellations and modifications
|
|
18
|
+
- Generate availability calendars
|
|
19
|
+
|
|
20
|
+
## Public Interface
|
|
21
|
+
|
|
22
|
+
Functions/classes that other modules can use:
|
|
23
|
+
|
|
24
|
+
### `checkAvailability(params: AvailabilityParams): AvailabilityResult`
|
|
25
|
+
|
|
26
|
+
Checks if rooms are available for the specified dates.
|
|
27
|
+
|
|
28
|
+
**Parameters:**
|
|
29
|
+
- `roomType` (string) - Type of room to check
|
|
30
|
+
- `checkIn` (Date) - Check-in date
|
|
31
|
+
- `checkOut` (Date) - Check-out date
|
|
32
|
+
- `quantity` (number) - Number of rooms needed
|
|
33
|
+
|
|
34
|
+
**Returns:**
|
|
35
|
+
- `available` (boolean) - Whether rooms are available
|
|
36
|
+
- `availableCount` (number) - How many rooms available
|
|
37
|
+
- `conflictingBookings` (string[]) - IDs of conflicting bookings (if any)
|
|
38
|
+
|
|
39
|
+
**Example:**
|
|
40
|
+
```typescript
|
|
41
|
+
import { checkAvailability } from './modules/booking-calendar';
|
|
42
|
+
|
|
43
|
+
const result = checkAvailability({
|
|
44
|
+
roomType: 'deluxe',
|
|
45
|
+
checkIn: new Date('2026-07-15'),
|
|
46
|
+
checkOut: new Date('2026-07-20'),
|
|
47
|
+
quantity: 2
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (result.available) {
|
|
51
|
+
console.log(`${result.availableCount} rooms available`);
|
|
52
|
+
} else {
|
|
53
|
+
console.log('Rooms not available for these dates');
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### `createBooking(params: BookingParams): BookingResult`
|
|
58
|
+
|
|
59
|
+
Creates a new booking reservation.
|
|
60
|
+
|
|
61
|
+
**Parameters:**
|
|
62
|
+
- `roomId` (string) - ID of the room to book
|
|
63
|
+
- `checkIn` (Date) - Check-in date
|
|
64
|
+
- `checkOut` (Date) - Check-out date
|
|
65
|
+
- `guestInfo` (GuestInfo) - Guest details
|
|
66
|
+
- `totalPrice` (number) - Total booking price
|
|
67
|
+
|
|
68
|
+
**Returns:**
|
|
69
|
+
- `bookingId` (string) - Unique booking identifier
|
|
70
|
+
- `confirmationCode` (string) - Human-readable confirmation code
|
|
71
|
+
- `status` (string) - Booking status ('confirmed', 'pending', 'cancelled')
|
|
72
|
+
|
|
73
|
+
**Example:**
|
|
74
|
+
```typescript
|
|
75
|
+
const booking = createBooking({
|
|
76
|
+
roomId: 'room-101',
|
|
77
|
+
checkIn: new Date('2026-07-15'),
|
|
78
|
+
checkOut: new Date('2026-07-20'),
|
|
79
|
+
guestInfo: {
|
|
80
|
+
name: 'John Doe',
|
|
81
|
+
email: 'john@example.com',
|
|
82
|
+
phone: '+1234567890'
|
|
83
|
+
},
|
|
84
|
+
totalPrice: 850.00
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
console.log(`Booking confirmed: ${booking.confirmationCode}`);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `cancelBooking(bookingId: string): CancellationResult`
|
|
91
|
+
|
|
92
|
+
Cancels an existing booking.
|
|
93
|
+
|
|
94
|
+
**Parameters:**
|
|
95
|
+
- `bookingId` (string) - ID of booking to cancel
|
|
96
|
+
|
|
97
|
+
**Returns:**
|
|
98
|
+
- `success` (boolean) - Whether cancellation succeeded
|
|
99
|
+
- `refundAmount` (number) - Amount to be refunded
|
|
100
|
+
- `cancellationFee` (number) - Fee charged for cancellation
|
|
101
|
+
|
|
102
|
+
### `getBooking(bookingId: string): Booking`
|
|
103
|
+
|
|
104
|
+
Retrieves booking details.
|
|
105
|
+
|
|
106
|
+
**Parameters:**
|
|
107
|
+
- `bookingId` (string) - Booking ID or confirmation code
|
|
108
|
+
|
|
109
|
+
**Returns:**
|
|
110
|
+
- Complete booking object with all details
|
|
111
|
+
|
|
112
|
+
### `modifyBooking(bookingId: string, changes: BookingChanges): BookingResult`
|
|
113
|
+
|
|
114
|
+
Modifies an existing booking (dates, room type, etc.).
|
|
115
|
+
|
|
116
|
+
**Parameters:**
|
|
117
|
+
- `bookingId` (string) - Booking to modify
|
|
118
|
+
- `changes` (BookingChanges) - Fields to update
|
|
119
|
+
|
|
120
|
+
**Returns:**
|
|
121
|
+
- Updated booking with new confirmation code
|
|
122
|
+
|
|
123
|
+
## Dependencies
|
|
124
|
+
|
|
125
|
+
Modules this module uses:
|
|
126
|
+
- `pricing-engine` - To recalculate prices when modifying bookings
|
|
127
|
+
- `database` - To persist bookings and check availability
|
|
128
|
+
|
|
129
|
+
## File Structure
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
src/modules/booking-calendar/
|
|
133
|
+
├── index.ts - Public interface
|
|
134
|
+
├── availability.ts - Availability checking logic
|
|
135
|
+
├── booking-manager.ts - Create/modify/cancel bookings
|
|
136
|
+
├── conflict-detector.ts - Double-booking prevention
|
|
137
|
+
├── types.ts - Type definitions
|
|
138
|
+
└── validators.ts - Input validation
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Testing
|
|
142
|
+
|
|
143
|
+
How to test this module:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm test -- booking-calendar
|
|
147
|
+
|
|
148
|
+
# Or specific test suites
|
|
149
|
+
npm test -- booking-calendar.availability
|
|
150
|
+
npm test -- booking-calendar.conflicts
|
|
151
|
+
npm test -- booking-calendar.bookings
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Test coverage: 98%
|
|
155
|
+
|
|
156
|
+
## Performance
|
|
157
|
+
|
|
158
|
+
- Availability check: 10-20ms (with database query)
|
|
159
|
+
- Create booking: 50-100ms (includes conflict check + database write)
|
|
160
|
+
- Conflict detection: < 5ms (optimized query with indexes)
|
|
161
|
+
|
|
162
|
+
## Database Schema
|
|
163
|
+
|
|
164
|
+
```sql
|
|
165
|
+
CREATE TABLE bookings (
|
|
166
|
+
id UUID PRIMARY KEY,
|
|
167
|
+
room_id VARCHAR(50) NOT NULL,
|
|
168
|
+
check_in DATE NOT NULL,
|
|
169
|
+
check_out DATE NOT NULL,
|
|
170
|
+
guest_name VARCHAR(255),
|
|
171
|
+
guest_email VARCHAR(255),
|
|
172
|
+
guest_phone VARCHAR(50),
|
|
173
|
+
total_price DECIMAL(10,2),
|
|
174
|
+
status VARCHAR(20),
|
|
175
|
+
confirmation_code VARCHAR(10) UNIQUE,
|
|
176
|
+
created_at TIMESTAMP DEFAULT NOW(),
|
|
177
|
+
updated_at TIMESTAMP DEFAULT NOW()
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
CREATE INDEX idx_bookings_dates ON bookings(room_id, check_in, check_out);
|
|
181
|
+
CREATE INDEX idx_bookings_status ON bookings(status);
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Conflict Detection Rules
|
|
185
|
+
|
|
186
|
+
- Check-in date must be before check-out date
|
|
187
|
+
- Cannot book if ANY overlap exists with confirmed bookings
|
|
188
|
+
- Overlap includes:
|
|
189
|
+
- Booking A starts before Booking B ends
|
|
190
|
+
- Booking B starts before Booking A ends
|
|
191
|
+
- Cancelled bookings are ignored in conflict detection
|
|
192
|
+
- Pending bookings held for 15 minutes before release
|
|
193
|
+
|
|
194
|
+
## Breaking Changes
|
|
195
|
+
|
|
196
|
+
### v2.0.0 (2026-01-02)
|
|
197
|
+
- `createBooking` now requires `totalPrice` parameter
|
|
198
|
+
- Changed `status` enum values ('active' → 'confirmed')
|
|
199
|
+
- Removed deprecated `bookRoom()` function
|
|
200
|
+
|
|
201
|
+
### v1.8.0 (2025-11-15)
|
|
202
|
+
- Added `modifyBooking()` function
|
|
203
|
+
- Changed return type of `checkAvailability` to include count
|
|
204
|
+
|
|
205
|
+
## Notes
|
|
206
|
+
|
|
207
|
+
- All dates are stored in UTC, converted to local time for display
|
|
208
|
+
- Confirmation codes are 10-character alphanumeric (e.g., "XY9K4P2M1Q")
|
|
209
|
+
- Bookings automatically cancelled if not paid within 24 hours
|
|
210
|
+
- Same-day bookings require phone confirmation
|
|
211
|
+
- Check-in time: 3:00 PM, Check-out time: 11:00 AM
|
|
212
|
+
|
|
213
|
+
## Integration Notes
|
|
214
|
+
|
|
215
|
+
- Pricing engine calls `checkAvailability` before calculating prices
|
|
216
|
+
- Payment gateway triggers `createBooking` after payment success
|
|
217
|
+
- Email service notified on booking creation/cancellation
|
|
218
|
+
- Housekeeping service receives next-day check-in list
|
|
219
|
+
|
|
220
|
+
## Future Plans
|
|
221
|
+
|
|
222
|
+
- [ ] Add waitlist functionality for fully booked dates
|
|
223
|
+
- [ ] Implement automatic overbooking prevention with buffer
|
|
224
|
+
- [ ] Add recurring booking support (e.g., weekly stays)
|
|
225
|
+
- [ ] Integration with external booking platforms (Booking.com, Airbnb)
|