12073 shaares
303 private links
303 private links
- The HTTP layer is straightforward: it turns HTTP requests into structures to be used by the service layer and vice versa.
- The service layer contains all the business logic of the service: data validation, business invariants, etc...
- The repository wraps the database queries
Then come some strategies:
- Cron jobs
- Caching is done at the service layer because the repository layer must stay dumb and the business rules often impact caching.
- logging with tracing
- Serving SPAs and static assets with a custom axum handler and a fallback URL for everything outside of the
/api. Static assets can be served with therust_embedcrate.
The project structure looks like:
cmd/
my-server/
migrations/
0001.sql
Cargo.toml
main.rs
server.rs
scheduler.rs
worker.rs
webapp.rs
libs/
mailer/
Cargo.toml
mailer.rs
queue/
Cargo.toml
queue.rs
stripe/
Cargo.toml
stripe.rs
services/
users/
repository/
users.rs
sessions.rs
service/
get_user.rs
get_session.rs
Cargo.toml
errors.rs
model.rs
repository.rs
service.rs
Cargo.toml <- Cargo.toml for the workspace
Dockerfile.my-server
Makefile
README.md