https://github.com/mkabdelrahman/bluelight
Demo REST API in Go using Domain-Driven Design
https://github.com/mkabdelrahman/bluelight
Last synced: 3 months ago
JSON representation
Demo REST API in Go using Domain-Driven Design
- Host: GitHub
- URL: https://github.com/mkabdelrahman/bluelight
- Owner: MKAbdElrahman
- Created: 2024-08-19T20:07:56.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-09-04T18:27:50.000Z (10 months ago)
- Last Synced: 2025-01-30T00:13:21.530Z (5 months ago)
- Language: Go
- Homepage:
- Size: 2.93 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bluelight
## Contract Based Architecture
```mermaid
graph LR
handler[HTTP handler] -- uses --> service[Service]service[Service] -- uses --> infrastructure[Other Infrastructure]
service -- uses --> db[Repositories]
db -- uses --> postgres[(PostgreQSL)]
handler -- uses --> request_contracts[Request Contracts]handler -- uses --> response_contracts[Response Contracts]
```- Contracts are explicit and put in their own layer.
- The Handlers will use the contracts layer to read http requests and validate they are not malformed and also for sending responses.
- To prepare responses, handlers talk to the application services layer which should be representative of the usecases.
- The domain objects should have no clue that they are bing used in a web application or stored using a sql database. I'm strongly againest putting annotaions on core domain entities.
## Features
- Sending JSON Respnses and Parsing JSON Requests
- Runtime app configutation
- Database setup and confguration
- SQL migrations
- CRUD operations
- Optimistic Concurrency Control
- Filtering, Sorting, and Pagination
- Rate limiting
- Sending Emails and Calling external APIs
- Graceful shutodown
- Authentication And Authorization
- Background operations
- CORS
- Metrics and Monitoring## Design Guidelines
### Context Usage
**Context is for Cancellation:** Use `context.Context` only for cancellation and timeouts, not for passing dependencies.**Avoid `context.Value` for Dependencies:** Passing loggers or other data via `context.Value` hides dependencies and risks runtime errors due to lack of type safety.
**Prefer Explicit Injection:** Always pass dependencies like loggers directly in constructors or function parameters for clarity and safety.
Read more at [Context is for cancelation
](https://dave.cheney.net/2017/01/26/context-is-for-cancelation)## Acknowledgments
- I learned alot from Alex Edwards books (I think its the best resource to learn Go).
- I also learned alot from Kent Beck books and his ideas about software design. I recommend alot reading his
recent Book Tidy First.- I also can't recommend more Mark Richards and Neals Ford writings about software architecture.
Thank you All
Mohamed Kamal