Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up #1074

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

Clean up #1074

wants to merge 21 commits into from

Conversation

to-sta
Copy link
Collaborator

@to-sta to-sta commented Jan 5, 2025

Contributor checklist


Description

I worked on cleaning up the backend to make it leaner

Overview

  1. Renamed backend/backend to backend/core
  2. Script to analyze API calls in the frontend
  3. Streamline BASE_BACKEND_URL
  4. Remove unused API's that are just boilerplate anyways
  5. Improving DB field names
1. Renamed backend/backend to backend/core
The inner backend folder was renamed to core to provide more clarity and better reflect its purpose as the directory holding core Django settings.
├── frontend
|    ├── pages
|    ...
├── backend
     ├── core <- (previously backend)
2. Script to analyze API calls in the frontend
To better understand which API calls are actively used, I wrote a script that scans the frontend codebase for API patterns. Currently, it looks for three different base URLs: `localhost:8000`, `127.0.0.1:8000`, and `${BASE_BACKEND_URL}`.
API_PATTERNS = [
    re.compile(r"\$\{BASE_BACKEND_URL\}/\S+"),
    re.compile(r"localhost:8000/\S+"),
    re.compile(r"127.0.0.1:8000/\S+"),
]

Results:

API calls found in the frontend code:
-------------------------------------
Number of API calls: 8
Details:

[
    {'useAuth.ts': ['${BASE_BACKEND_URL}/auth/sign_in/`,']},
    {'create.vue': ['127.0.0.1:8000/v1/entities/organizations/",']},
    {'index.vue': ['${BASE_BACKEND_URL}/entities/groups/`,']},
    {'create.vue': ['127.0.0.1:8000/v1/content/resources/",']},
    {'index.vue': ['${BASE_BACKEND_URL}/content/resources/`,']},
    {'event.ts': ['${BASE_BACKEND_URL}/events/events/`,']},
    {'group.ts': ['${BASE_BACKEND_URL}/entities/groups/`,']},
    {'organization.ts': ['${BASE_BACKEND_URL}/entities/organizations/`,']},
]
3. Streamline BASE_BACKEND_URL
The use of `127.0.0.1`, `localhost`, and `${BASE_BACKEND_URL}`in the frontend was inconsistent. To simplify and prepare for production, all references now use the environment variable BASE_BACKEND_URL, which can be dynamically set (e.g.,` backend.activist.org` or `api.activist.org`).

Updated Results:

[   
    {'useAuth.ts': ['${BASE_BACKEND_URL}/auth/sign_in/`,']},
    {'create.vue': ['${BASE_BACKEND_URL}/v1/entities/organizations/`,']},
    {'index.vue': ['${BASE_BACKEND_URL}/entities/groups/`,']},
    {'create.vue': ['${BASE_BACKEND_URL}/v1/content/resources/`,']},
    {'index.vue': ['${BASE_BACKEND_URL}/content/resources/`,']},
    {'event.ts': ['${BASE_BACKEND_URL}/events/events/`,']},
    {'group.ts': ['${BASE_BACKEND_URL}/entities/groups/`,']},
    {'organization.ts': ['${BASE_BACKEND_URL}/entities/organizations/`,']}
]
4. Remove unused API's that are just boilerplate anyways
Here are the API that are currently exposed:

before (3)

Compared to the APIs currently in use, a significantly larger number are exposed, many of which are boilerplate viewsets.

Updated:

afterwards

5. Improving DB field names
Model field names within django add `_id` automatically to the column name, therefore if we are naming fields:
class GroupMember(models.Model):
    group_id = models.ForeignKey(Group, on_delete=models.CASCADE, related_name="group_members")
    ...

The SQL query would be:

SELECT * 
FROM entities.group_member
WHERE group_id_id = 'UUID'

What is a bit odd right? This change will needs to be adopted by the frontend.

example_id_id

Open

  • pytest tests
  • pinia stores
    @andrewtavis my assumption would be that the pinia stores might need to be updated to refelect the changes (e.g. groupId -> group)

Related issue

  • No related issue

Copy link

netlify bot commented Jan 5, 2025

Deploy Preview for activist-org canceled.

Name Link
🔨 Latest commit 4b2c31c
🔍 Latest deploy log https://app.netlify.com/sites/activist-org/deploys/677c142dcf50570008880fea

Copy link
Contributor

github-actions bot commented Jan 5, 2025

Thank you for the pull request!

The activist team will do our best to address your contribution as soon as we can. The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the General and Development rooms once you're in. Also consider joining our bi-weekly Saturday dev syncs. It'd be great to have you!

Maintainer checklist

  • The TypeScript and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The Playwright end to end and Zap penetration tests have been ran and are passing (if necessary)

  • The changelog has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

@to-sta to-sta requested a review from andrewtavis January 6, 2025 17:30
@andrewtavis
Copy link
Member

Are the i18n checks still failing for you, @to-sta? Just checking if your last commit used the ignore pre-commit functionality and the checks are still problematic...

@to-sta
Copy link
Collaborator Author

to-sta commented Jan 6, 2025

Are the i18n checks still failing for you, @to-sta? Just checking if your last commit used the ignore pre-commit functionality and the checks are still problematic...

There are no problems. I started working on this branch before we fixed the i18n check, so I initially commented out the pre-commit hook but have now reverted that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants