Notes about I'd architecture a new long-life project.
- Monolith first, split when needed.
- Folder structure by feature, component, or service. Avoid layers, file category, or same class.
- Place tests along code. Don't use a separate folder
- Avoid long nested paths for endpoints. Context should be in the JWT
- Composition over inheritance
- Promote dependency injection
- Use docker for development at least
- Use built-in tools first, avoid third party tools (e.g. test runners, linters, formatters, etc.)
- Use middleware based web framework
- Use middlewares as core of your req/res processing, not just for pre/post hooks
- Avoid build steps when possible
- Take advantage of the power of SQL and RDBM, when needed use JSON type for dynamic content
- Use libs that promotes Unix and Web standards
- Use HTTP2/gRPC
- Do not silent errors, log them at least
- Avoid ORMs; queries become suboptimal pretty quickly. SQL is a standard, ORM APIs aren't
- Use early returns pattern
- Tests must be idempotent. They should not depend on previous tests, assertions should not depend if DB was emptied or not.
- Use gRPC for private APIS, use REST for public APIS
- For tests, use a library to create fake random data.
- Ready to run in local
- Do not remove database and shutdown containers after tests. Do it in setup.
- Place OpenAPI definition along endpoint handlers
- Code monolith, deploy microservices when needed. Developing, maintaining and debugging microservices is hard but k8s is great.
- ENV variables must default to values ready for Production. Overwrite them for other envs (CI, test, developemnt, etc..)
- Write tests in the same programming language than your project.
- Apply emergent architecture of your application rather than using MVC by default. MVC leads to anemic domain model.
- Program to interfaces not implementations
- Do not expose model details in your public endpoints. For instance, hide model details such as
/book/isbn10/:id&/book/isbn13/:isbn, use/book/:isbninstead. - Do not code tests as set of use cases within arrays or sets. They need to run in a loop, that's the test runner job.
- If you are developing a web service with a modern framework, do not pursue code coverage with unit tests. Execise your service trough available endpoints.
TBD