Skip to content

Commit 7bb3307

Browse files
authored
Feature: Add BE docs (#864)
1 parent a0c355c commit 7bb3307

File tree

7 files changed

+4390
-0
lines changed

7 files changed

+4390
-0
lines changed

backend/docs/README.md

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# Hi.Events Backend Documentation
2+
3+
Welcome to the Hi.Events backend documentation. This directory contains comprehensive guides on the architecture, patterns, and best practices used throughout the backend codebase.
4+
5+
**🚨 These docs are AI generated and are not 100% accurate. Always verify anything important by looking at the actual code.**
6+
7+
## Documentation Index
8+
9+
### [Architecture Overview](architecture-overview.md)
10+
**Start here** - High-level overview of the entire backend architecture.
11+
12+
**Contents**:
13+
- Architectural layers (HTTP, Application, Domain, Infrastructure)
14+
- Core components (Domain Objects, DTOs, Repositories, Events)
15+
- Request flow and data flow
16+
- Key design patterns
17+
- Multi-tenancy architecture
18+
- Best practices summary
19+
20+
**Who should read**: Everyone working on the backend
21+
22+
---
23+
24+
### [Domain-Driven Design](domain-driven-design.md)
25+
Deep dive into the DDD patterns used in Hi.Events.
26+
27+
**Contents**:
28+
- Application Layer (Handlers)
29+
- Domain Services Layer
30+
- Data Transfer Objects (DTOs)
31+
- Domain Objects (auto-generated)
32+
- Enums and constants
33+
- DTO flow patterns
34+
- Transaction management
35+
- Service composition
36+
- Validation patterns
37+
38+
**Who should read**: Backend developers implementing new features
39+
40+
---
41+
42+
### [Database Schema](database-schema.md)
43+
Complete database schema architecture and entity relationships.
44+
45+
**Contents**:
46+
- Core entity hierarchy
47+
- Multi-tenancy architecture
48+
- All database entities (Account, Event, Order, Attendee, etc.)
49+
- Entity relationships and diagrams
50+
- Architectural patterns (soft deletes, JSONB, indexes)
51+
- PostgreSQL-specific features
52+
53+
**Who should read**: Backend developers, database administrators
54+
55+
---
56+
57+
### [Repository Pattern](repository-pattern.md)
58+
Guide to the repository pattern implementation.
59+
60+
**Contents**:
61+
- Base repository interface (40+ methods)
62+
- Creating new repositories
63+
- Usage in handlers
64+
- Best practices (favor base methods, eager loading)
65+
- Common patterns (pagination, filters, bulk operations)
66+
- Testing with mocks
67+
68+
**Who should read**: Backend developers working with data access
69+
70+
---
71+
72+
### [Events and Background Jobs](events-and-jobs.md)
73+
Event-driven architecture and asynchronous processing.
74+
75+
**Contents**:
76+
- Application Events vs Infrastructure Events
77+
- Event listeners
78+
- Background jobs
79+
- Event flow examples
80+
- Retry strategies
81+
- Transaction boundaries
82+
- Queue separation
83+
84+
**Who should read**: Backend developers implementing workflows and integrations
85+
86+
---
87+
88+
### [API Patterns and HTTP Layer](api-patterns.md)
89+
HTTP layer patterns and API design.
90+
91+
**Contents**:
92+
- BaseAction pattern
93+
- Response methods
94+
- Authorization patterns
95+
- JSON API resources
96+
- Routing patterns
97+
- Request validation
98+
- Exception handling
99+
100+
**Who should read**: Backend developers building API endpoints
101+
102+
---
103+
104+
## Quick Reference
105+
106+
### Common Tasks
107+
108+
#### Creating a New Feature
109+
110+
1. **Read**: [Architecture Overview](architecture-overview.md) - Understand the layers
111+
2. **Read**: [Domain-Driven Design](domain-driven-design.md) - Understand DTOs, Handlers, Services
112+
3. **Reference**: Existing feature in `/prompts` directory
113+
4. **Implement**: Following the established patterns
114+
115+
#### Adding a New Entity
116+
117+
1. **Create migration**: `php artisan make:migration create_xxx_table`
118+
2. **Run migration**: `php artisan migrate`
119+
3. **Generate domain objects**: `php artisan generate-domain-objects`
120+
4. **Create repository interface and implementation**: See [Repository Pattern](repository-pattern.md)
121+
5. **Register repository**: Add to `RepositoryServiceProvider`
122+
6. **Update database docs**: Reference [Database Schema](database-schema.md)
123+
124+
#### Adding a New API Endpoint
125+
126+
1. **Create FormRequest**: See [API Patterns](api-patterns.md#request-validation)
127+
2. **Create Action**: Extend `BaseAction`, see [API Patterns](api-patterns.md#baseaction-pattern)
128+
3. **Create DTO**: Extend `BaseDataObject`, see [DDD](domain-driven-design.md#dtos)
129+
4. **Create Handler**: See [DDD](domain-driven-design.md#application-layer)
130+
5. **Create Domain Service** (if needed): See [DDD](domain-driven-design.md#domain-services-layer)
131+
6. **Create JSON Resource**: See [API Patterns](api-patterns.md#json-api-resources)
132+
7. **Add route**: `routes/api.php`
133+
134+
#### Adding Background Processing
135+
136+
1. **Create Event**: See [Events and Jobs](events-and-jobs.md#application-events)
137+
2. **Create Job**: See [Events and Jobs](events-and-jobs.md#background-jobs)
138+
3. **Create Listener**: See [Events and Jobs](events-and-jobs.md#event-listeners)
139+
4. **Register** (if needed): See [Events and Jobs](events-and-jobs.md#event-registration)
140+
141+
### Key Commands
142+
143+
```bash
144+
# Backend (run in Docker container)
145+
cd docker/development
146+
docker compose -f docker-compose.dev.yml exec backend bash
147+
148+
# Generate domain objects
149+
php artisan generate-domain-objects
150+
151+
# Run migrations
152+
php artisan migrate
153+
154+
# Run unit tests
155+
php artisan test --testsuite=Unit
156+
157+
# Run specific test
158+
php artisan test --filter=TestName
159+
```
160+
161+
### File Locations
162+
163+
```
164+
backend/
165+
├── app/
166+
│ ├── DomainObjects/ # Auto-generated domain objects
167+
│ │ ├── Generated/ # Don't edit these
168+
│ │ ├── Enums/ # General enums
169+
│ │ └── Status/ # Status enums
170+
│ ├── Events/ # Application events
171+
│ ├── Http/
172+
│ │ ├── Actions/ # HTTP actions (controllers)
173+
│ │ ├── Request/ # Form requests
174+
│ │ └── Resources/ # JSON API resources
175+
│ ├── Jobs/ # Background jobs
176+
│ ├── Listeners/ # Event listeners
177+
│ ├── Models/ # Eloquent models
178+
│ ├── Repository/
179+
│ │ ├── Interfaces/ # Repository contracts
180+
│ │ └── Eloquent/ # Implementations
181+
│ └── Services/
182+
│ ├── Application/ # Application handlers
183+
│ │ └── Handlers/ # Use case handlers
184+
│ ├── Domain/ # Domain services
185+
│ └── Infrastructure/ # External services
186+
├── database/
187+
│ └── migrations/ # Database migrations
188+
└── routes/
189+
└── api.php # API routes
190+
```
191+
192+
## Architecture Principles
193+
194+
### Core Principles
195+
196+
1. **Domain-Driven Design**: Clear separation between domain, application, and infrastructure
197+
2. **Repository Pattern**: All data access through interfaces
198+
3. **DTO Pattern**: Immutable data transfer between layers
199+
4. **Event-Driven**: Decoupled communication via events
200+
5. **Type Safety**: Strong typing with domain objects and DTOs
201+
202+
### Best Practices
203+
204+
1. **Always extend `BaseDataObject`** for new DTOs (not `BaseDTO`)
205+
2. **Use domain object constants** for field names
206+
3. **Favor base repository methods** over custom methods
207+
4. **Extend `BaseAction`** for all HTTP actions
208+
5. **Use enums** for domain constants
209+
210+
### Code Quality
211+
212+
- Follow PSR-12 coding standards
213+
- Wrap all translatable strings in `__()` helper
214+
- Create unit tests for new features
215+
- Don't add comments unless absolutely necessary
216+
- Refactor complex code instead of documenting it
217+
218+
## External Resources
219+
220+
- [CLAUDE.md](../../CLAUDE.md) - Project guidelines for AI assistants
221+
- [Laravel Documentation](https://laravel.com/docs)
222+
- [Spatie Laravel Data](https://spatie.be/docs/laravel-data)
223+
- [PostgreSQL Documentation](https://www.postgresql.org/docs/)
224+
225+
## Contributing
226+
227+
When adding new features or making significant changes:
228+
229+
1. Follow the patterns documented here
230+
2. Update relevant documentation if patterns change
231+
3. Add examples to `/prompts` for reference
232+
4. Ensure tests pass: `php artisan test --testsuite=Unit`
233+
234+
## Getting Help
235+
236+
1. **Start with**: [Architecture Overview](architecture-overview.md)
237+
2. **Look at examples**: `/prompts` directory contains feature documentation
238+
3. **Check CLAUDE.md**: Project-specific guidelines and patterns
239+
4. **Reference specific guides**: Use the documentation index above
240+
241+
---
242+
243+
**Last Updated**: 2025-10-29
244+
245+
**Documentation Version**: 1.0

0 commit comments

Comments
 (0)