Greetings, colleagues. Today we're going to talk about the kind of prep work you need to do before you start coding wildly. More specifically, about planning and creating an application architecture. But where to start? How to build this architecture? As with everything, you need to start from the beginning. Namely - with IDEA. The idea of our project was to create a useful telegram bot with basic functionality. Let us repeat exactly what: “I, as a user, want to be able to receive notifications when new articles are published in those groups on JavaRush that interest me.” Following the YAGNI principle, we will build our application. This means that we will only take what we need. We will not create functionality in advance and in reserve just because we want to and someday it might actually come in handy. Yes, we will create a readable and extensible application, but this does not mean that we will create a database schema “for growth”. In order not to support this “growth”, I decided that it would be better to abandon it altogether. This will help us avoid unnecessary support during development and unnecessary testing. Later, when our project goes into production (again an Anglicism, from the abbreviation prod - production), we will be able to do something more. Once you've decided on an idea, you need to get a little naughty and draw. What to draw? We will need the ability to save data on subscriptions to groups of different users. I know that you can use a user ID in the form of a chat ID in Telegram. And there is an idea of how the search for new articles will actually proceed: we will search in all groups that have subscriptions for new articles and send them to chats. Based on this, we get the following as a first approximation (here is the development without embellishment): I don’t hope that you will understand my handwriting: I want to show exactly how and where development begins. The first stage has been completed: we have somehow decided on what will happen. The models/tables in the database are described above. But this is a draft: it can and should be polished and brought into a more readable form. While I was polishing, I remembered that I also wanted to get statistics on the bot’s work. Added this. In this drawing it is more than clear what and how it will be arranged. That is, what tables and fields will be in them, what entity names will be for the tables. It was decided that there would be several of them:
- User - information about the telegram user who will use our bot. As you can see, we only save the chat ID and the flag whether the user is active or not. Why? Because our goal is not to collect information about users, but to benefit them;
- GroupSub - here will be information about the group to which you have a subscription and the latest article that was sent to subscribers;
- Statistics - I haven’t created a schema for it - we’ll do that later. This is not the main goal in the MVP of the project.
Create a repository for work
Finally, you can create a repository for working with a telegram bot.- We fill in the items that are already familiar to us - the name of the repository, its brief description.
- Add a license - Apache 2.0 (you can choose the license at your discretion).
- Our project is now available - here is the link to it: JavaRush Telegrambot .
Create a project in the repository
To work with the project, it would be good to use GitHub tools, such as project. What it is? This is a place where you can create tasks, track their completion, and save task status. Determine who will carry them out and more. To do this, in the created project we will find the Projects button , and there we will create a new one: As you can see, here I indicated the name of the project, described it and selected the template on which we will work - Automated Kanban. For us now it is not so important what this means. The main thing is that we will have a board with tasks, divided into columns, where each column will be the status of the task:- To do - all tasks that are planned to be done;
- In progress - tasks that are currently being worked on;
- Done - tasks that have already been completed within this project.
We write issues (issues) for the project
To understand what tasks to write, let’s decide what we will have in the project. We need an application that can be launched easily and quickly, so that we can access the database, so that we can manage and change the database schema, so that we can make REST requests in JavaRush to obtain data on articles. Based on this, you can choose the following technologies:- SpringBoot - as a framework for our application,
- Spring Data - for working with a database,
- Flyway - for working with database migrations,
- MySQL - as a database for the project,
- Telegrambot StringBoot starter - a library for working with a telegram bot,
- Unirest is a library for working with REST requests.
Task creation template
We will create tasks using the following template:- The task name will look like this: JRTB-{IssueNumber}:{IssueDescription} , where:
- {IssueNumber} is the serial number of the issue. Let's take it one more from the last problem;
- {IssueDescription} - a brief description of the issue.
- In the body of the task we will make a more detailed description of it (sometimes it may coincide with the description in the task name).
- Acceptance Criteria is a list of requirements, after which the task can be considered completed. So to speak, the criteria for accepting the task. Using them, a reviewer (from the English reviewer - reviewer - a person who looks at how a task is completed) can understand whether the task is completely completed or not.
- [FEATURE] JRTB-0: create Skeleton Spring boot project - everything is clear here: you need to do the first part of what we did in the previous article.
- [FEATURE] JRTB-2: add telegram bot to the project - add an empty bot that will simply respond and say that it is alive and well.
- [FEATURE] JRTB-3: Implement Command pattern for telegrambot - let's set up the correct approach to working with commands in a telegram bot. So far for several teams.
- [FEATURE] JRTB-1: Add repository layer - this is one of the biggest tasks - it combines everything that needs to be done to work with the database.
- [FEATURE] JRTB-5: As a user, I want to add the group to the subscription - this is already the first User Story in the Agile understanding. This will be a real benefit for our users: it will be possible to add group subscriptions to the bot.
- [FEATURE] JRTB-12: Implement scheduling for sending notification about new articles - here will be the implementation of searching for new articles if they are published for each of the groups and sent to all users who are subscribed to the groups.
- [FEATURE] JRTB-6: As a user, I want to see list of my group subscriptions - everything is simple here: we add a command that displays a list of all groups to which the user is subscribed.
- [FEATURE] JRTB-7: As a User, I want to remove group subscription from my subscriptions - here you need to implement removing the user’s subscription to updates in the group.
- [FEATURE] JRTB-8: As a User, I want to set inactive using bot - implement stopping the bot. That is, everything that needs to be done in our system for the work to stop. Add the /stop command to processing.
- [FEATURE] JRTB-9: As a User, I want to start working with bot OR set active if I used it before - add processing of the /start command. Exactly the way we want it.
- [FEATURE] JRTB-10: As an administrator, I want to see bot statistics - creating a collection of bot statistics. Adding administrator capabilities.
- [FEATURE] JRTB-11: As a user, I want to see documentation for this telegram bot - writing documentation. Yes, yes, friends, you can’t live without it, and the sooner you learn to do this, the better it will be for you))
Filling out the repository
What else needs to be done BEFORE we start coding? - Author, how many of these paragraphs can you add, are you pulling them out of the abyss?? — No, the quality of work is shown in the details. And they are the ones that make sense. So let's add one more detail. In order for the project to become popular and understandable for other developers, it needs to be filled out. What should I add? I described a complete list of what can be done in the article Optimizing work with your projects on GitHub: getting to know Github Template Repository . I highly recommend reading it. It is important for us to have clear versioning, a clear understanding of what we are doing. Therefore, I added a RELEASE_NOTES file in which changes to our project will be recorded. As an example, you can look at RELEASE_NOTES from my project (yes, why not show what I put my energy and creativity into). The changes for each new version are described there. I also added templates for creating new tasks, which have 4 options:- Bug Report is a task created by users/testers who find a bug in their work. This is a very important thing: it helps manage bug fixes;
- A feature request is a task to add new functionality. All the first tasks on the project are feature request tasks;
- Improvement request - a task to improve the operation of the application. For example, to change test answers when working with a bot. I'm not a technical writer and I can come up with not entirely correct answers. So if you have the desire and ability, offer it :)
- Question is a question for the developers about the operation of the application. A very useful thing. Let’s say there is no understanding of the work or there are doubts about some question - you can ask a question in this way and get an answer first-hand.
GO TO FULL VERSION