FILE SERVER
Uploading files is a common task on a website; it will be implemented in different ways, such as storage in a file system, or database, consuming a web service, etc. This project uses Mongo Database and the functionality of GridFS; this specification allows the storage of files larger than 16 MB. This project also uses reactive features in Spring Boot, like Spring WebFlux and Reactive MongoDB.
Prerequisites
- Spring Boot: this is the framework used to develop the app.
- Spring WebFlux: this is library to manage reactive projects in Java.
- MongoDB: this is the non-SQL database to store the files in this app.
- Clean Architecture: the project follows the pieces of advice that Martin Fowler gives in the book "Clean Architecture."
Use Cases
The project has five use
cases
- Upload file: The user has to upload a file, and the app can upload any file; The name of the file will be unique;
- Download file: If the user wants to download a file, he will download the file.
- List files: If the user wants to show the list of files that he uploads, the app can display the list of storage files
- Delete file: If the user wants to delete a file, he can choose and delete it.
- Play Video: If the user wants to show a video, he can choose and watch it. In this step, this feature will be limited to getting a URL to get the video streaming.
Architecture
The project is a monolith; it
tries to use the principle of screaming architecture; therefore, it is split
into two layers.
- Domain layer: in this layer, the application has the use cases and the entities; the domain represents the business core for the application. The dependency inversion principle (DIP) is used to develop the use cases; all of them in the constructor receive interfaces; therefore, the implementations are hidden from the business logic. In this area, we put the five use cases to manage the files; however, the responsibility to manage the streams of files was delegated to the infrastructure layer, so the use cases only receive type DTO (Data transfer object) objects and return models(Domain Objects).
- Infrastructure layer: this layer has adapters, controllers, and other kinds of specific implementation for the interfaces. it has the responsibility to transform the answer of use cases to a more suitable response to the entries point (For this application, it is a JSON format); to do it, it goes to the database and gets or puts the data from use-cases after of that fit the response to a JSON format. (gateways).
Packaging (Ports and adapters)
This is the packaging structure for the project.
- The services for storing files in GridFS are helpers that are used in the controller; the use case only manages information about the metadata of files.
- To configure some features for the Spring Boot app, you must use other folders like configurations or exceptions, but this kind of data is outside the package model to port and adapters.
Deploy app
To deploy the
app, you can use the docker-compose command “docker-compose up -d “this command
does the compilation to backend and the frontend of the project, this takes a
time because it uses multistep compilation for docker. When the process ends up
you can check if it is running with the command “docker ps” and you will see
the next list.
Conclusion
This app use
reactive programming to do a file server, Could be possible add a login and sign
Up option? Yes but, we choose only to develop the main uses cases associate to
manage files this is the repo of the app file-server-app.git, in the next port we explore the UI of
the project bye.



Comments
Post a Comment