# koderkalash/teamops architecture

> Architecture diagram of the GitHub repository koderkalash/teamops, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/koderkalash/teamops
- Repository: https://github.com/koderkalash/teamops

## Overview

1. **Repository shape**
   - This is a two-app monorepo: `backend/` is a Node.js + Express API, and `frontend/` is a Next.js App Router client.
   - The top-level GitHub Actions workflow runs backend tests on push/PR, so CI is centered on API correctness rather than frontend build validation.

2. **End-to-end request path**
   - User interaction starts in the Next.js app.
   - Frontend pages call Next.js API routes under `frontend/app/api/*`, which proxy requests to the backend.
   - Those proxy routes forward auth and payloads to the Express API, which reads/writes MongoDB through Mongoose models.
   - This proxy layer keeps browser-to-backend traffic centralized and avoids direct cross-origin calls from the UI.

3. **Frontend boundary**
   - The frontend is organized around App Router pages: `login`, `signup`, and a protected `dashboard`.
   - `components/ProtectedRoute.js` and `lib/auth.js` indicate client-side route guarding and auth-state handling.
   - `lib/api.js` and the API route proxies form the network abstraction, so UI code does not hardcode backend access details.

4. **Backend application composition**
   - `backend/src/app.js` defines the Express application; `backend/src/server.js` starts the HTTP server.
   - `src/config/db.js` handles MongoDB connection setup.
   - The backend is layered in the conventional Express style: routes → middleware → controllers → models/utils.

5. **Domain subsystems**
   - The main backend domains are `auth`, `users`, `projects`, and `tasks`.
   - Each domain has its own controller, route file, and in most cases a model, which keeps resource-specific rules close to the relevant API surface.
   - `projectTask.route.js` suggests task operations nested under projects where membership and ownership matter.

6. **Data model and persistence**
   - MongoDB is the system of record, accessed via Mongoose schemas in `backend/src/models`.
   - The models likely encode the core entities: users, projects, and tasks, plus embedded or referenced relationships for membership and assignment.
   - Password hashing is handled in the user model layer via hooks, so credentials are never stored in plain text.

7. **Authentication flow**
   - `auth.controller.js`, `jwt.js`, and `auth.middleware.js` show a JWT-based login/signup system.
   - Public auth endpoints issue tokens after credential validation.
   - Protected routes read the token through middleware before controller logic executes.

8. **Authorization model**
   - Access control is multi-layered, not just “logged in vs not logged in.”
   - `role.middleware.js` enforces role-based access (`user`, `manager`, `admin`) at the route level.
   - Controllers also apply ownership and membership checks, especially for project and task mutations.
   - Some actions are field-restricted, meaning a user may update only specific fields such as task status.

9. **Reusable query and response behavior**
   - `utils/apiFeatures.js` provides shared list-query behavior such as filtering, searching, sorting, and pagination.
   - This reusable abstraction is used across list endpoints to keep API behavior consistent.
   - The project explicitly caps pagination at 50 items per page, which is an API-level performance guardrail.

10. **Cross-cutting middleware**
   - `globalLimiter.middleware.js` and `authLimiter.middleware.js` indicate request throttling exists in targeted form, especially around auth endpoints.
   - `error.middleware.js` centralizes error formatting, while `asyncHandler.js` reduces boilerplate around async controller failures.
   - `AppError.js` provides a standard application error type for predictable API responses.

11. **Testing and verification**
   - Backend integration tests live in `backend/tests`, with Jest and Supertest driving API-level verification.
   - `tests/setup.js` and `mongodb-memory-server` imply isolated test runs against an in-memory MongoDB, avoiding dependence on a shared dev database.
   - Current tests focus on authentication flows, and the GitHub Actions workflow enforces them in CI.

12. **Architectural boundaries to capture in a diagram**
   - Keep the frontend, proxy API routes, backend API, and MongoDB as separate boxes.
   - Show auth as a shared concern spanning frontend session handling, backend JWT issuance/verification, and route middleware.
   - Show projects/tasks/users as separate backend subsystems feeding a shared persistence layer.
   - Highlight that authorization is enforced in both middleware and controller logic, not only at the UI.

Main entry points: [`backend/src/app.js`](https://github.com/koderkalash/teamops/blob/main/backend/src/app.js) (Express App), [`backend/src/models`](https://github.com/koderkalash/teamops/tree/main/backend/src/models) (Models), [`frontend/app/api`](https://github.com/koderkalash/teamops/tree/main/frontend/app/api) (API Proxies), [`backend/src/controllers/auth.controller.js`](https://github.com/koderkalash/teamops/blob/main/backend/src/controllers/auth.controller.js) (Auth API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_ui_shell["App Router<br/>Next.js UI"]
  node_ui_auth["Auth Pages<br/>[page.js]"]
  node_ui_dashboard["Dashboard<br/>protected page<br/>[page.js]"]
  node_ui_guard["Route Guard<br/>client auth<br/>[ProtectedRoute.js]"]
  node_ui_auth_state["Auth State<br/>client session<br/>[auth.js]"]
  node_ui_api["API Client<br/>network lib<br/>[api.js]"]
  node_proxy_layer["API Proxies<br/>Next.js routes"]
  node_proxy_auth["Auth Proxy<br/>proxy routes<br/>[route.js]"]
  node_proxy_projects["Project Proxy<br/>proxy route<br/>[route.js]"]
end

subgraph group_backend["Backend"]
  node_backend_app["Express App<br/>HTTP app<br/>[app.js]"]
  node_backend_server["Server<br/>entrypoint<br/>[server.js]"]
  node_backend_db["DB Connect<br/>mongo setup<br/>[db.js]"]
  node_auth_domain["Auth API<br/>auth domain<br/>[auth.controller.js]"]
  node_user_domain["Users<br/>user domain<br/>[user.controller.js]"]
  node_project_domain["Projects<br/>project domain"]
  node_task_domain["Tasks<br/>task domain<br/>[task.controller.js]"]
  node_backend_mw["Middleware<br/>cross-cutting"]
  node_backend_models[("Models<br/>mongoose schemas")]
  node_query_utils["Query Utils<br/>api features<br/>[apiFeatures.js]"]
end

subgraph group_infra["Infra"]
  node_mongodb[("MongoDB<br/>database")]
  node_ci_tests["Backend Tests<br/>jest/supertest"]
end

node_ui_shell -->|"renders"| node_ui_auth
node_ui_shell -->|"renders"| node_ui_dashboard
node_ui_auth -->|"submits via"| node_ui_api
node_ui_dashboard -->|"protected by"| node_ui_guard
node_ui_guard -->|"reads"| node_ui_auth_state
node_ui_auth_state -->|"supplies auth"| node_ui_api
node_ui_api -->|"calls"| node_proxy_layer
node_proxy_layer -->|"includes"| node_proxy_auth
node_proxy_layer -->|"includes"| node_proxy_projects
node_proxy_layer -->|"forwards to"| node_backend_app
node_backend_server -->|"boots"| node_backend_app
node_backend_app -->|"uses"| node_backend_mw
node_backend_app -->|"routes to"| node_auth_domain
node_backend_app -->|"routes to"| node_user_domain
node_backend_app -->|"routes to"| node_project_domain
node_backend_app -->|"routes to"| node_task_domain
node_auth_domain -->|"writes/reads"| node_backend_models
node_user_domain -->|"writes/reads"| node_backend_models
node_project_domain -->|"writes/reads"| node_backend_models
node_task_domain -->|"writes/reads"| node_backend_models
node_backend_models -->|"persists in"| node_mongodb
node_auth_domain -->|"protected by"| node_backend_mw
node_project_domain -->|"lists via"| node_query_utils
node_task_domain -->|"lists via"| node_query_utils
node_backend_mw -->|"validated against"| node_mongodb
node_ci_tests -->|"verifies"| node_backend_app
node_ci_tests -->|"covers"| node_auth_domain

click node_ui_shell "https://github.com/koderkalash/teamops/tree/main/frontend/app"
click node_ui_auth "https://github.com/koderkalash/teamops/blob/main/frontend/app/login/page.js"
click node_ui_dashboard "https://github.com/koderkalash/teamops/blob/main/frontend/app/dashboard/page.js"
click node_ui_guard "https://github.com/koderkalash/teamops/blob/main/frontend/components/ProtectedRoute.js"
click node_ui_auth_state "https://github.com/koderkalash/teamops/blob/main/frontend/lib/auth.js"
click node_ui_api "https://github.com/koderkalash/teamops/blob/main/frontend/lib/api.js"
click node_proxy_layer "https://github.com/koderkalash/teamops/tree/main/frontend/app/api"
click node_proxy_auth "https://github.com/koderkalash/teamops/blob/main/frontend/app/api/auth/login/route.js"
click node_proxy_projects "https://github.com/koderkalash/teamops/blob/main/frontend/app/api/projects/route.js"
click node_backend_app "https://github.com/koderkalash/teamops/blob/main/backend/src/app.js"
click node_backend_server "https://github.com/koderkalash/teamops/blob/main/backend/src/server.js"
click node_backend_db "https://github.com/koderkalash/teamops/blob/main/backend/src/config/db.js"
click node_auth_domain "https://github.com/koderkalash/teamops/blob/main/backend/src/controllers/auth.controller.js"
click node_user_domain "https://github.com/koderkalash/teamops/blob/main/backend/src/controllers/user.controller.js"
click node_project_domain "https://github.com/koderkalash/teamops/blob/main/backend/src/controllers/project.controller.js"
click node_task_domain "https://github.com/koderkalash/teamops/blob/main/backend/src/controllers/task.controller.js"
click node_backend_mw "https://github.com/koderkalash/teamops/tree/main/backend/src/middleware"
click node_backend_models "https://github.com/koderkalash/teamops/tree/main/backend/src/models"
click node_query_utils "https://github.com/koderkalash/teamops/blob/main/backend/src/utils/apiFeatures.js"
click node_ci_tests "https://github.com/koderkalash/teamops/tree/main/backend/tests"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui_shell,node_ui_auth,node_ui_dashboard,node_ui_guard,node_ui_auth_state,node_ui_api,node_proxy_layer,node_proxy_auth,node_proxy_projects toneBlue
class node_backend_app,node_backend_server,node_backend_db,node_auth_domain,node_user_domain,node_project_domain,node_task_domain,node_backend_mw,node_backend_models,node_query_utils toneAmber
class node_mongodb,node_ci_tests toneMint
```

## Components

### Frontend

Next.js client and its API proxy layer

- [App Router](https://github.com/koderkalash/teamops/tree/main/frontend/app): Next.js UI · Top-level pages and layouts for login, signup, and dashboard · `frontend/app`
- [Auth Pages](https://github.com/koderkalash/teamops/blob/main/frontend/app/login/page.js): pages · Login and signup screens · `frontend/app/login/page.js`
- [Dashboard](https://github.com/koderkalash/teamops/blob/main/frontend/app/dashboard/page.js): protected page · Authenticated landing area for the app · `frontend/app/dashboard/page.js`
- [Route Guard](https://github.com/koderkalash/teamops/blob/main/frontend/components/ProtectedRoute.js): client auth · Protects private frontend routes based on auth state · `frontend/components/ProtectedRoute.js`
- [Auth State](https://github.com/koderkalash/teamops/blob/main/frontend/lib/auth.js): client session · Client-side auth handling and token/session state · `frontend/lib/auth.js`
- [API Client](https://github.com/koderkalash/teamops/blob/main/frontend/lib/api.js): network lib · Shared frontend request abstraction · `frontend/lib/api.js`
- [API Proxies](https://github.com/koderkalash/teamops/tree/main/frontend/app/api): Next.js routes · Server-side proxy endpoints that forward browser requests to the backend · `frontend/app/api`
- [Auth Proxy](https://github.com/koderkalash/teamops/blob/main/frontend/app/api/auth/login/route.js): proxy routes · Login and signup proxy handlers · `frontend/app/api/auth/login/route.js`
- [Project Proxy](https://github.com/koderkalash/teamops/blob/main/frontend/app/api/projects/route.js): proxy route · Project API proxy handler · `frontend/app/api/projects/route.js`

### Backend

Express API with routes, controllers, middleware, and models

- [Express App](https://github.com/koderkalash/teamops/blob/main/backend/src/app.js): HTTP app · Express application wiring for middleware and routes · `backend/src/app.js`
- [Server](https://github.com/koderkalash/teamops/blob/main/backend/src/server.js): entrypoint · Starts the HTTP server · `backend/src/server.js`
- [DB Connect](https://github.com/koderkalash/teamops/blob/main/backend/src/config/db.js): mongo setup · MongoDB connection bootstrap · `backend/src/config/db.js`
- [Auth API](https://github.com/koderkalash/teamops/blob/main/backend/src/controllers/auth.controller.js): auth domain · Login, signup, token issuance, and verification · `backend/src/controllers/auth.controller.js`
- [Users](https://github.com/koderkalash/teamops/blob/main/backend/src/controllers/user.controller.js): user domain · User resource endpoints and account rules · `backend/src/controllers/user.controller.js`
- [Projects](https://github.com/koderkalash/teamops/blob/main/backend/src/controllers/project.controller.js): project domain · Project resource logic and ownership checks · `backend/src/controllers/project.controller.js`
- [Tasks](https://github.com/koderkalash/teamops/blob/main/backend/src/controllers/task.controller.js): task domain · Task resource logic including project-scoped operations · `backend/src/controllers/task.controller.js`
- [Middleware](https://github.com/koderkalash/teamops/tree/main/backend/src/middleware): cross-cutting · Auth, role, rate limiting, async handling, and errors · `backend/src/middleware`
- [Models](https://github.com/koderkalash/teamops/tree/main/backend/src/models): mongoose schemas · User, project, and task persistence models · `backend/src/models`
- [Query Utils](https://github.com/koderkalash/teamops/blob/main/backend/src/utils/apiFeatures.js): api features · Shared filtering, search, sort, and pagination behavior · `backend/src/utils/apiFeatures.js`

### Infra

MongoDB and CI/testing boundaries

- **MongoDB**: database · System of record for users, projects, and tasks
- [Backend Tests](https://github.com/koderkalash/teamops/tree/main/backend/tests): jest/supertest · API integration tests run in CI · `backend/tests`

## Connections

- App Router → Auth Pages: renders · App Router serves the public auth pages
- App Router → Dashboard: renders · App Router serves the protected dashboard
- Auth Pages → API Client: submits via · Auth pages use the shared client request layer
- Dashboard → Route Guard: protected by · Dashboard is wrapped by client-side route guarding
- Route Guard → Auth State: reads · Guard checks the client auth/session state
- Auth State → API Client: supplies auth · Client auth state informs outgoing requests
- API Client → API Proxies: calls · Frontend requests are sent to Next.js API routes
- API Proxies → Auth Proxy: includes · Auth-specific proxy handlers
- API Proxies → Project Proxy: includes · Project proxy handler
- API Proxies → Express App: forwards to · Proxy routes forward requests to the Express API
- Server → Express App: boots · Server entrypoint starts the Express app
- Express App → Middleware: uses · Express app mounts shared middleware
- Express App → Auth API: routes to · Auth endpoints reach the auth controller layer
- Express App → Users: routes to · User endpoints reach the user controller layer
- Express App → Projects: routes to · Project endpoints reach the project controller layer
- Express App → Tasks: routes to · Task endpoints reach the task controller layer
- Auth API → Models: writes/reads · Auth logic uses user persistence and password hooks
- Users → Models: writes/reads · User controller works with user documents
- Projects → Models: writes/reads · Project controller works with project documents
- Tasks → Models: writes/reads · Task controller works with task documents
- Models → MongoDB: persists in · Mongoose stores data in MongoDB
- Auth API → Middleware: protected by · JWT and rate-limit middleware gate auth flows
- Projects → Query Utils: lists via · Project listing uses shared query behavior
- Tasks → Query Utils: lists via · Task listing uses shared query behavior
- Middleware → MongoDB: validated against · Middleware and controllers ultimately operate over persisted state
- Backend Tests → Express App: verifies · Integration tests exercise backend API behavior
- Backend Tests → Auth API: covers · Current test focus centers on authentication flows
