In this chapter we're gonna talk about the conventions used in X-way. They are enforced by the client generator, and if you want to get the full benefits and autocompletion, you must respect them.
When we're creating a module. We advise against using default exports:
export default XXX. Rather use named exports: `export
The reasons for this are:
- Easy refactoring of your models (especially when using a smart IDE like VSCode)
- More accurate autocompletion and auto imports as you use them
When naming files, always use capital case for classes, lower-case for sets. For example if a file exports a class make the file uppercase (
FileUtilitary.ts), if it exports a set of functions you can have it lower-case (
If we have a special element such as Collection, Event, Exception, Listener, Service, etc, we also want to suffix the name with the file's speciality in the following pattern:
Another way would have been
PostService.ts however we made the choice above for easier search reasons.
The exported value for special element should be suffixed by the name, for example
Post.service.ts exports a constant:
- Easy to find the files without looking at folders. You can just search for
Post.and you may find collections, services, events and you can either put
.sfor service and it takes you to the right file.
- You know the file's responsability not only based on the folder it is in.
- The cli generator can autocomplete those kind of files (For example when linking collections, it can easily find all collections from your microservice)
Use types when you have no choice. That's the rule. Always prefix the interfaces with
I for easier searchability and to avoid confusion with models.
- Interfaces from other modules can be extended:
Now you can use everywhere in your bundle the interface from "my-module" and it will be extended as described.
This folder structure is thought through to support modern-web development with microservices in mind.