# Developing AcadeMix Backend

**URL:** <https://sef.discourse.group/t/developing-academix-backend/94>\
**Category:** Development\
**Created:** [May 23, 2020, 2:47pm UTC](https://sef.discourse.group/t/developing-academix-backend/94 "2020-05-23T14:47:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gravewalker](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/gravewalker/32/12_2.png) [@Gravewalker](https://sef.discourse.group/u/Gravewalker)\
**Post date:** [May 23, 2020, 2:47pm UTC](https://sef.discourse.group/t/developing-academix-backend/94/1 "2020-05-23T14:47:45Z")

</div>

We need to come up with a solid structure for the backend of the AcadeMix project.

As we have discussed in the weekly meeting first we are gonna come up with the structure, identify the database requirement. After that, we will identify the necessary endpoints and post it here so that we can proceed with the UI development simultaneously.

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [May 23, 2020, 8:33pm UTC](https://sef.discourse.group/t/developing-academix-backend/94/2 "2020-05-23T20:33:56Z")

</div>

Hi all,

Following are my suggestions for the database and API design.

**Database**

We have decided to implement 3 main entities named `category`, `sub_category`, and `item` I have included a design idea based around the above entities to implement a database.

Adding relational tables for each entity to map relations with a `language` entity.

 ![ERD](https://global.discourse-cdn.com/free1/uploads/sef/original/1X/4527ec54ca29ee0e107dcb64716c95cd59536aca.png)  
Above I have created a new table for the three main entities(\*\_translation). These tables will help to match language types with the data. Even though this approach is a bit complicated and requires a few more tables, I think this is better as if someday this project expands to an international level we can add support for more languages easily without breaking the code.  
Basically we get the ability to manage languages in the database.

**API**

For the first phase following are the APIs we are planning to develop.

- `/languages`

- `/categories`

- `/sub-categories`

- `/items`

These are just a few suggestions, your reviews will help a lot to reach a final conclusion. So feel free to comment 😊.

Thank you

---

<div class="post-metadata">

**Author:** ![akshika47](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/akshika47/32/993_2.png) [@akshika47](https://sef.discourse.group/u/akshika47)\
**Post date:** [May 23, 2020, 10:10pm UTC](https://sef.discourse.group/t/developing-academix-backend/94/3 "2020-05-23T22:10:40Z")

</div>

This is great progress @YohanAvishke! Love the attention to detail. One quick comment looking at the ER diagram. You might need another table to map items which falls under multiple categories. I would also have a variable in item table to have a description which can be used from us to add any additional information related to the content. What do you think?

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [May 24, 2020, 5:09am UTC](https://sef.discourse.group/t/developing-academix-backend/94/4 "2020-05-24T05:09:54Z")

</div>

Hi @akshika47 thanks a-lot for the response

> [@akshika47](#):
>
> You might need another table to map items which falls under multiple categories.

Good point @akshika47, in this case, it’s better to change relationships of entitiees as below

 ![image](https://global.discourse-cdn.com/free1/uploads/sef/original/1X/97c2ea83d80955ebeff9b52140022999fb15284c.png)  
Now it’s possible to,

1. Duplicate sub-categories among categories.
2. Duplicate items among sub-categories.

Which automatically results in items to be duplicated among categories.

* * *

> [@akshika47](#):
>
> I would also have a variable in item table to have a description which can be used from us to add any additional information related to the content. What do you think?

This is already included in the `item_translation` entity. As you can see below, we are persisting both name and description.  
By the end of the day, each item will have an id, name, description, and a link

![image](https://global.discourse-cdn.com/free1/uploads/sef/original/1X/61dfa0c0b4629cd02ff7588913f1c5d984cf0266.png)

A new normalized diagram with the above changes is attached below, Please note that I have done some variable type changes too.

 ![AcadeMix ERD](https://global.discourse-cdn.com/free1/uploads/sef/original/1X/47f5b3636b1d038c50c37b996283084ab761477f.png)

---

<div class="post-metadata">

**Author:** ![jaye](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/jaye/32/810_2.png) [@jaye](https://sef.discourse.group/u/jaye)\
**Post date:** [May 24, 2020, 7:16am UTC](https://sef.discourse.group/t/developing-academix-backend/94/5 "2020-05-24T07:16:13Z")

</div>

This is awesome @YohanAvishke!

1. Just a suggestion; Since we know we know this is gonna get translated only for 3 languages, can’t we add the translations inside the entity?

2. @akshika47 Are there any use cases in which a subcategory has multiple categories? 🤔

---

<div class="post-metadata">

**Author:** ![akshika47](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/akshika47/32/993_2.png) [@akshika47](https://sef.discourse.group/u/akshika47)\
**Post date:** [May 24, 2020, 10:01am UTC](https://sef.discourse.group/t/developing-academix-backend/94/6 "2020-05-24T10:01:52Z")

</div>

There is no use case for subcategory having multiple sub categories but there is a use case for an item being under more than 1 category or sub category. that needs to be represented.  
for example “Khan Academy” could be under students section and teachers section. Similarly it could fall under maths as well as some other sub category.

cc : @YohanAvishke

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [May 24, 2020, 10:22am UTC](https://sef.discourse.group/t/developing-academix-backend/94/7 "2020-05-24T10:22:14Z")

</div>

Thanks a-lot @jaye

> [@jaye](#):
>
> This is awesome @YohanAvishke!
> 
> 1. Just a suggestion; Since we know we know this is gonna get translated only for 3 languages, can’t we add the translations inside the entity?

I think this is a bad designing pattern due to the following reasons,

1. Tables will depend on language types.  
By creating a new table for translation we can pretty much have an independent table structure. Expanding the database further can be done without having to worry about changing already implemented tables.  
In conclusion we will have a more solid table structure.

2. We will have to worry about translating every bit of data(names and descriptions) if we follow the above design. Otherwise we will have to leave unnecessary null columns.  
But by having a new table for translations, we can do implementations on top of our APIs without worrying about multi-language support. Which can be added later, so the development process will be quicker.

3. Also I think in a nER scenario it makes more sense to create new relationships whenever possible instead of bulking all the data into a single table.

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [May 25, 2020, 2:05am UTC](https://sef.discourse.group/t/developing-academix-backend/94/8 "2020-05-25T02:05:17Z")

</div>

Hi all, after 2020-05-23T18:30:00Z's call. I have added the changes we discussed to the ERD.

 ![AcadeMix ERD (1)](https://global.discourse-cdn.com/free1/uploads/sef/original/1X/0c994a2d41e9292199473384656e8368f600bbd1.png)

---

<div class="post-metadata">

**Author:** ![jaye](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/jaye/32/810_2.png) [@jaye](https://sef.discourse.group/u/jaye)\
**Post date:** [May 25, 2020, 3:00am UTC](https://sef.discourse.group/t/developing-academix-backend/94/9 "2020-05-25T03:00:59Z")

</div>

@shyamal @DannyB Do you have any suggestions?

---

<div class="post-metadata">

**Author:** ![shyamal](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@shyamal](https://sef.discourse.group/u/shyamal)\
**Post date:** [May 25, 2020, 3:29am UTC](https://sef.discourse.group/t/developing-academix-backend/94/10 "2020-05-25T03:29:00Z")

</div>

Hi @jaye and team

This is looking neat assuming below.

Every item will follow the same hierarchy. Category, Sub Category, Item.

General comment, if you are uncertain about the possibility of adding more columns later with unpredictable relationship better to use NoSQL. But this seems like a relatively predictable requirement thus using SQL would be a good idea.

---

<div class="post-metadata">

**Author:** ![Gravewalker](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/gravewalker/32/12_2.png) [@Gravewalker](https://sef.discourse.group/u/Gravewalker)\
**Post date:** [May 28, 2020, 3:46am UTC](https://sef.discourse.group/t/developing-academix-backend/94/11 "2020-05-28T03:46:26Z")

</div>

**2nd Dev Meeting on Developing Backend**

Held on: 2020-05-27T15:30:00Z  
Attendees: @jaye @YohanAvishke @Gravewalker

**Meeting minutes:**

1. Reviewed the WIP PR on data retrieval endpoints.
2. Had a discussion on the structure of the payload.

**Conclusion**  
After a discussion on how the payload should structure and the best possible way to extract it in that form from the database, we came to a conclusion that we should continue using only Spring Jpa to extract data and should avoid using native or JPQL custom queries unless the particular query can’t be done with spring JPA repository. After extracting the data, to avoid JSON payload from going into a recursion we decided to use JSON ignore.

Here’s a sample payload of the `category`

```auto
[
    {
        id:1,
        translations: [
            {
                "id":1
                "language":{
                    id:1,
                    locale:"en-un"
                },
                name:"category1"
            },
            {
                "id":2
                "language":{
                    id:2,
                    locale:"si"
                },
                name:"කාණඩ 1"
            }
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![jaye](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/jaye/32/810_2.png) [@jaye](https://sef.discourse.group/u/jaye)\
**Post date:** [May 28, 2020, 4:31am UTC](https://sef.discourse.group/t/developing-academix-backend/94/12 "2020-05-28T04:31:38Z")

</div>

Thanks for the update @Gravewalker,

Btw, I think It’s better if we could generate the payload like this:

```json
[
    {
        id:1,
        translations: {
              "en-us" : {
                  "name": "Category 1"
               },
              "si-lk" : {
                  "name": "කාණ්ඩය 1"
               },
        }
    }
]

```

No need to include this for the initial PR. But it’s better to have a payload like this.  
cc: @YohanAvishke

Thanks.

---

<div class="post-metadata">

**Author:** ![Gravewalker](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/gravewalker/32/12_2.png) [@Gravewalker](https://sef.discourse.group/u/Gravewalker)\
**Post date:** [May 29, 2020, 1:57am UTC](https://sef.discourse.group/t/developing-academix-backend/94/13 "2020-05-29T01:57:42Z")

</div>

After the code review of the still open [PR](https://github.com/sef-global/sef-core/pull/39), we decided to move on from the current folder structure to a more project-oriented structure.

- Current structure.

```auto
src/
└── main
    ├── java
    │ └── org
    │ └── sefglobal
    │ └── core
    │ ├── AdminApplication.java
    │ ├── config
    │ │ └── SecurityConfig.java
    │ ├── controller
    │ │ ├── AcademixController.java
    │ │ ├── CertificateController.java
    │ │ ├── MultiverseController.java
    │ │ ├── MultiverseLinkController.java
    │ │ └── UserController.java
    │ ├── exception
    │ │ ├── APIException.java
    │ │ ├── BadRequestException.java
    │ │ ├── ResourceNotFoundException.java
    │ │ └── UnauthorisedException.java
    │ ├── model
    │ │ ├── Ambassador.java
    │ │ ├── AuditModel.java
    │ │ ├── Category.java
    │ │ ├── CategoryTranslation.java
    │ │ ├── Certificate.java
    │ │ ├── Engagement.java
    │ │ ├── Event.java
    │ │ ├── identity
    │ │ │ └── EngagementIdentity.java
    │ │ ├── Item.java
    │ │ ├── ItemTranslation.java
    │ │ ├── Language.java
    │ │ ├── Link.java
    │ │ ├── SubCategory.java
    │ │ ├── SubCategoryTranslation.java
    │ │ ├── University.java
    │ │ └── User.java
    │ ├── projections
    │ │ ├── CustomCategory.java
    │ │ ├── CustomItem.java
    │ │ ├── CustomLanguage.java
    │ │ ├── CustomSubCategory.java
    │ │ └── CustomTranslation.java
    │ ├── repository
    │ │ ├── AmbassadorRepository.java
    │ │ ├── CategoryRepository.java
    │ │ ├── CertificateRepository.java
    │ │ ├── EngagementRepository.java
    │ │ ├── EventRepository.java
    │ │ ├── ItemRepository.java
    │ │ ├── LanguageRepository.java
    │ │ ├── SubCategoryRepository.java
    │ │ ├── UniversityRepository.java
    │ │ └── UserRepository.java
    │ ├── service
    │ │ ├── AcademixService.java
    │ │ ├── AuthenticationService.java
    │ │ ├── CertificateService.java
    │ │ ├── DataLoader.java
    │ │ └── LanguageService.java
    │ └── util
    │ └── Status.java
    └── resources
        ├── application.properties
        └── application.properties.example

```

- Suggested changes: Create a package under org.sefglobal.core called academix and add necessary files.

---

<div class="post-metadata">

**Author:** ![shyamal](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@shyamal](https://sef.discourse.group/u/shyamal)\
**Post date:** [May 30, 2020, 1:22pm UTC](https://sef.discourse.group/t/developing-academix-backend/94/14 "2020-05-30T13:22:13Z")

</div>

Hi Team,  
If you don’t mind research little bit about “Clean Architecture”. Provide very flexible extensive approach to organize your code that may grow extensively yet can accommodate changes with less headache. 😁

Key. Only benefits If code base grows eventually with different perspectives such as domain or features, technology changes like db or api etc.

On a different note. How do you connect on the 7pm call?

---

<div class="post-metadata">

**Author:** ![Gravewalker](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/gravewalker/32/12_2.png) [@Gravewalker](https://sef.discourse.group/u/Gravewalker)\
**Post date:** [May 30, 2020, 1:48pm UTC](https://sef.discourse.group/t/developing-academix-backend/94/15 "2020-05-30T13:48:17Z")

</div>

@shyamal  
You can use this meet link to connect [https://meet.google.com/chs-konp-dst](https://meet.google.com/chs-konp-dst)

---

<div class="post-metadata">

**Author:** ![jaye](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/jaye/32/810_2.png) [@jaye](https://sef.discourse.group/u/jaye)\
**Post date:** [June 1, 2020, 3:25am UTC](https://sef.discourse.group/t/developing-academix-backend/94/16 "2020-06-01T03:25:05Z")

</div>

@Gravewalker @YohanAvishke  
Any updates from the data retrieval API?

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [June 1, 2020, 3:56am UTC](https://sef.discourse.group/t/developing-academix-backend/94/17 "2020-06-01T03:56:12Z")

</div>

@Gravewalker is still working on it. @Gravewalker can you please give an update. State if you’re facing any blockers.

---

<div class="post-metadata">

**Author:** ![Gravewalker](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/gravewalker/32/12_2.png) [@Gravewalker](https://sef.discourse.group/u/Gravewalker)\
**Post date:** [June 1, 2020, 7:09am UTC](https://sef.discourse.group/t/developing-academix-backend/94/18 "2020-06-01T07:09:19Z")

</div>

I updated the PR with the requested amendments.  
If no further amendments are needed data retrieval part of the API is completely implemented with this PR.

> <https://github.com/sef-global/sef-core/pull/39>

---

<div class="post-metadata">

**Author:** ![YohanAvishke](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/yohanavishke/32/106_2.png) [@YohanAvishke](https://sef.discourse.group/u/YohanAvishke)\
**Post date:** [June 1, 2020, 7:59am UTC](https://sef.discourse.group/t/developing-academix-backend/94/19 "2020-06-01T07:59:39Z")

</div>

@Gravewalker there are still a few unresolved discussion which seems to be outdated. Can you please add comments to them pointing to the commit that fixed them.

---

<div class="post-metadata">

**Author:** ![Gimhan\_minion](https://yyz2.discourse-cdn.com/free1/user_avatar/sef.discourse.group/gimhan_minion/32/109_2.png) [@Gimhan\_minion](https://sef.discourse.group/u/Gimhan_minion)\
**Post date:** [June 2, 2020, 3:34pm UTC](https://sef.discourse.group/t/developing-academix-backend/94/20 "2020-06-02T15:34:56Z")

</div>

@YohanAvishke Aiya Where are we up to now on “Creating API’s”? Do you need any help from my end? 🙂

[Next page](https://sef.discourse.group/t/developing-academix-backend/94.md?page=2)
