diff --git a/sources/architecture-briefing.html b/sources/architecture-briefing.html new file mode 100644 index 00000000..d4deab8c --- /dev/null +++ b/sources/architecture-briefing.html @@ -0,0 +1,366 @@ +
NearBeach is one Django app with three HTTP surfaces on top of a shared ORM. Django owns routing, auth, permissions and persistence. The UI is a set of Vue components mounted inside Django templates, and they talk mainly to undocumented internal JSON endpoints, not to the public REST API.
+path() routes in NearBeach/urls.py (pages + AJAX)/api/v0/models.pyis_deleted=False filters written by handtransaction.atomic or select_related callsCounts come from grep over NearBeach/, excluding migrations, tests and vendored static files.
Every request, whatever its surface, goes through the same stack: route, auth decorator, NearBeach's own permission decorator, a view function, then the ORM. The interesting part is that the two API-style surfaces duplicate the same business logic.
+The dashed arrow is the thin path: only 5 frontend files call /api/v0/. The rest of the roughly 140 axios-using files call internal routes such as project_information/<id>/save/.
The function view computes context, encodes it as JSON strings and renders a template. The template does little more than mount Vue.
+This is the real application API. Vue sends FormData, a Django Form validates it, and the view writes to models and returns serialized JSON or a URL string.
DRF viewsets with drf-spectacular docs. This re-implements creates and updates for the same objects, including side effects such as transfer_new_object_uploads.
This means a rule change, such as "a project needs at least one group", has to be made in two places: views/project_views.py with forms.py, and views/api/project_api_view.py with serializers/project_serializer.py. Nothing keeps them in sync except tests.
project_information/<int:project_id>/ route resolves to a plain function view.project_permissions in FUNCTION_DICT. It intersects the user's UserGroup rows with the project's ObjectAssignment groups, then takes Max("permission_set__project"). The result (0–4) is passed into the view as kwargs["user_level"]. Superusers skip all of this and get 4..values() / serializers.serialize() queries and turns each result into a JSON string.v-bind:project-results="{{project_results}}". Django HTML-escapes it, the browser unescapes it, and Vue evaluates it as a JS expression.#app and registers every component globally. Each component then fetches its sub-modules (notes, documents, links) over internal AJAX.// Vue component (ProjectInformation.vue) +const data_to_send = new FormData(); +data_to_send.set("project_name", this.projectNameModel); +this.axios.post(`${this.rootUrl}project_information/${id}/save/`, data_to_send) // X-CSRFTOKEN from cookie + +# Django view +form = ProjectForm(request.POST) # validation only, never rendered +if not form.is_valid(): return HttpResponseBadRequest(form.errors) +project.project_name = form.cleaned_data["project_name"]; project.save() +# ...then ObjectAssignment rows, upload transfers, kanban card sync: separate saves, no transaction+
Notes, tags, links, groups, users, documents and sprints attach to any object type through string-dispatched routes such as object_data/<destination>/<location_id>/add_link/ and documentation/<destination>/<location_id>/…. The destination segment selects a model from one of several OBJECT_DICT tables. It's also used directly as an ORM keyword, as in ObjectAssignment.objects.filter(**{destination: location_id}). That's how one view serves ten object types.
ScheduledObject and ObjectTemplate, then creates Tasks, Projects or Kanban cards from templates.ObjectAssignment answers "can this group see this object". It's one table with about ten nullable foreign keys (project, task, requirement, kanban board…) instead of a GenericForeignKey. PermissionSet answers "what can members of this group do", with a 0–4 level per object type.Group / UserGroup models replace django.contrib.auth groups and permissions. has_perm isn't used anywhere. Child objects (change task, kanban card, requirement item) inherit permission from their parent through _fetch_parent_details.is_deleted, and there's no custom manager. Each query has to remember the filter, which is why there are 440 of them.date_created, date_modified, change_user and creation_user are copied into each one with no abstract base.OVERRIDE_AUTH_USER_MODEL sets AUTH_USER_MODEL. Models resolve it through getattr(settings, "AUTH_USER_MODEL", User).| Decision | Pros | Cons |
|---|---|---|
| Single installable Django app | Easy to self-host or pip-install, with one migration history and one deploy unit. | No internal module boundaries. models.py, forms.py and urls.py are each over 1,000 lines, and every view can import every model. |
| Django templates mounting Vue | Server-side auth and routing come for free. There's no SPA router, and each page ships its data with it, so first paint needs no extra request. | The data contract is a template string. Props are JS expressions built from escaped JSON. One global bundle registers every component on every page. |
| Internal AJAX alongside the REST API | The UI can change endpoints freely without versioning. | Business rules are duplicated between Form-based views and DRF serializers, and the UI's real API is undocumented. |
| Function views + decorators | Very explicit and easy to grep. The permission check is visible on every handler. | Boilerplate is repeated, and decorator order matters. Injecting user_level through kwargs couples every view signature to the decorator. |
| Custom group/permission-set model | Matches the product's domain (teams and object-level access) and can be managed in the UI. | Bypasses Django's auth tooling. Every check is several queries, computed on every request with no caching. |
String-dispatched destination routes | One implementation of notes, tags and links serves all object types. | Stringly-typed polymorphism spread across several OBJECT_DICT copies. URL input reaches ORM keyword names. |
| Hand-written soft delete and audit fields | No hidden manager magic, and recovery is easy. | One missed filter leaks deleted rows. There are hundreds of chances to miss one. |
| Cron + management commands | No broker or worker infrastructure to run. | Jobs only run at cron granularity, with no retries or visibility. Event hooks run inline. |
No transactions anywhere. new_project_save saves the project, then N ObjectAssignment rows, then moves uploads. A failure partway through leaves a project with no groups, which also means nobody but superusers can see it.
URL segments become ORM lookups. <destination> is an unconstrained str converter, and it reaches filter(**{object_lookup: location_id}) in generic_permissions.py. I haven't checked whether a crafted lookup like a__b__startswith can be exploited. Either way, the input should be checked against an allow-list before it reaches the ORM.
N+1 queries are likely. There are no select_related or prefetch_related calls. len(queryset) is used where .exists() would do, and permission checks run several queries on every request.
Two write paths per object. Form views and DRF viewsets drift. Moving the UI onto /api/v0/, or pulling shared logic into a service layer, would remove one of them.
Packaging drift. pyproject.toml declares Django>=3.1 and leaves out DRF, knox and two-factor, while requirements.txt pins 4.2.17+ with them. The local/ settings hardcode SECRET_KEY and DEBUG=True, which is acceptable only because it's test-only.
local/settings.py: installed apps, middleware order, DRF and knox configuration, storage switches.NearBeach/urls.py and urls_api_v0.py: the full route surface.decorators/check_user_permissions/object_permissions.py and partials/: the permission model in code.models.py around ObjectAssignment (line 989) and PermissionSet (line 1239).views/project_views.py next to views/api/project_api_view.py: the duplication, side by side.views/object_data_views.py: the generic destination pattern, 1,500 lines.