|
| 1 | +# ADR-001: Modularizing the Badging API Architecture |
| 2 | + |
| 3 | +## Status |
| 4 | +Accepted |
| 5 | + |
| 6 | +## Date |
| 7 | +2026-01-16 |
| 8 | + |
| 9 | +## Context |
| 10 | + |
| 11 | +The CHAOSS Badging API currently supports two distinct badging processes under the same badging program: |
| 12 | + |
| 13 | +- Event Badging |
| 14 | +- Project Badging |
| 15 | + |
| 16 | +While both processes share a common website and some infrastructure (authentication, GitHub/GitLab integrations), they represent different workflows, data flows, and responsibilities. |
| 17 | + |
| 18 | +The current API codebase has several issues that affect that affect maintainability and clarity of process flow: |
| 19 | + |
| 20 | +- Event Badging and Project Badging logic are tightly coupled and co-located. |
| 21 | +- There is no clear separation of concerns between HTTP handling, business logic, and data access. |
| 22 | +- Contributors cannot easily determine which part of the system they are modifying. |
| 23 | +- Code is duplicated. |
| 24 | +- Names of files and modules are ambiguous. |
| 25 | +- Files and functions are not clearly attributable to a specific process. |
| 26 | +- Database operations, business logic, and HTTP handling are intermixed. |
| 27 | +- Checklist generation and parsing logic is fragile and difficult to trace. |
| 28 | +- Refactoring or adding features risks unintended side effects across processes. |
| 29 | +Logic flow is hard to trace, making debugging and feature addition difficult. |
| 30 | + |
| 31 | + |
| 32 | +These issues increase cognitive load, slow onboarding, slow and ineffective contributions, and make safe parallel development difficult. |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Decision |
| 37 | + |
| 38 | +We will refactor the Badging API to adopt a modular, layered architecture with explicit separation of concerns. This is necessary to improve the stability, clarity, and maintainability of the Badging System |
| 39 | + |
| 40 | +### 1. Modular Separation by Process |
| 41 | + |
| 42 | +The API will be structured around two top-level domains: |
| 43 | + |
| 44 | +- `event-badging` |
| 45 | +- `project-badging` |
| 46 | + |
| 47 | +Each domain will encapsulate its own: |
| 48 | +- Routes |
| 49 | +- Controllers |
| 50 | +- Services |
| 51 | +- Data access logic |
| 52 | +- Domain-specific models (where applicable) |
| 53 | + |
| 54 | +Shared infrastructure and cross-cutting concerns will live in a `shared` directory. |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +### 2. Layered Architecture Within Each Module |
| 59 | + |
| 60 | +Each module will follow a consistent internal structure: |
| 61 | + |
| 62 | +``` |
| 63 | +
|
| 64 | +/<domain> |
| 65 | +/routes → HTTP route definitions |
| 66 | +/controllers → Request/response orchestration |
| 67 | +/services → Business logic and workflows |
| 68 | +/data-access → Database read/write operations |
| 69 | +/models → ORM models and associations |
| 70 | +
|
| 71 | +``` |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +### 3. Introduction of a Dedicated Data Access Layer |
| 76 | + |
| 77 | +A dedicated Data Access Layer (DAL) will be introduced and named: |
| 78 | + |
| 79 | +``` |
| 80 | +
|
| 81 | +data-access |
| 82 | +
|
| 83 | +``` |
| 84 | + |
| 85 | +#### Rationale for Naming |
| 86 | + |
| 87 | +- Avoids confusion with GitHub/GitLab “repositories” |
| 88 | +- Clearly communicates responsibility |
| 89 | +- Aligns with standard backend architecture terminology |
| 90 | +- Improves contributor understanding and onboarding |
| 91 | + |
| 92 | +#### Responsibilities of `data-access` |
| 93 | + |
| 94 | +- Perform database reads and writes |
| 95 | +- Interact directly with ORM models |
| 96 | +- Contain no business logic |
| 97 | +- Contain no HTTP or framework-specific code |
| 98 | + |
| 99 | +Services must not interact with ORM models directly. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +### 4. Strict Responsibility Boundaries |
| 104 | + |
| 105 | +| Layer | Responsibility | |
| 106 | +|-------------|----------------| |
| 107 | +| Routes | Map URLs to controllers | |
| 108 | +| Controllers | Handle HTTP concerns (req/res, status codes) | |
| 109 | +| Services | Business rules, workflows, decisions | |
| 110 | +| Data Access | Database persistence and queries | |
| 111 | +| Models | Schema definitions and associations | |
| 112 | + |
| 113 | +Business logic resides only in services. |
| 114 | + |
| 115 | +Models remain declarative and must not contain: |
| 116 | +- Workflow logic |
| 117 | +- Formatting logic |
| 118 | +- External API calls |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +### 5. Shared Infrastructure |
| 123 | + |
| 124 | +Common components used by both domains will live under: |
| 125 | + |
| 126 | +``` |
| 127 | +
|
| 128 | +/shared |
| 129 | +
|
| 130 | +``` |
| 131 | + |
| 132 | +Including: |
| 133 | +- Authentication providers |
| 134 | +- External API clients (GitHub/GitLab) |
| 135 | +- Shared models |
| 136 | +- Shared data-access modules |
| 137 | +- Common utilities |
| 138 | + |
| 139 | +Any change to shared code requires explicit review due to its cross-domain impact. |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +## Consequences |
| 144 | + |
| 145 | +### Positive Outcomes |
| 146 | + |
| 147 | +- Clear ownership of Event Badging vs Project Badging code |
| 148 | +- Safer parallel development by multiple contributors |
| 149 | +- Improved testability through isolation of business logic |
| 150 | +- Easier onboarding for new contributors |
| 151 | +- Reduced risk of regressions during refactors |
| 152 | +- Architecture that scales with new badging processes |
| 153 | + |
| 154 | +### Trade-offs |
| 155 | + |
| 156 | +- Initial refactor requires significant upfront time investment |
| 157 | +- Requires contributors to follow stricter conventions |
| 158 | +- Some boilerplate increases due to additional layers |
| 159 | + |
| 160 | +These trade-offs are accepted in favor of long-term maintainability and contributor clarity. |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +## Implementation Plan |
| 165 | + |
| 166 | +1. Modularise the project to improve maintainability |
| 167 | +2. Separate concerns between project badging and event badging by determining which scopes to have. |
| 168 | +3. Write proper tests for the api |
| 169 | +4. Improve security of the api and badging app by attending to the vulnerabilities of the packages |
| 170 | +5. Resolve the issue of checkbox on ticking on event-diversity-and-inclusion repo |
| 171 | +6. Deploy version 2.0 |
| 172 | +--- |
| 173 | + |
| 174 | + |
| 175 | +## Notes |
| 176 | + |
| 177 | +- Refactoring will be done incrementally to avoid breaking behavior. |
| 178 | +- Files will be moved in small, verifiable steps with frequent commits. |
| 179 | +- External integrations (GitHub/GitLab) will be mocked where possible during refactor. |
| 180 | +- End-to-end integration testing will be performed after modularization. |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +## Related Documents |
| 185 | + |
| 186 | +- Badging Data Flow Documentation |
| 187 | +- Contributor Architecture Guide (planned) |
| 188 | +- Refactoring Checklist (planned) |
| 189 | + |
| 190 | +--- |
| 191 | + |
| 192 | +## Decision Drivers |
| 193 | + |
| 194 | +- Maintainability |
| 195 | +- Contributor clarity |
| 196 | +- Safe parallel development |
| 197 | +- Separation of concerns |
| 198 | +- Long-term scalability of the badging program |
| 199 | + |
0 commit comments