# ukutia/qualitrack architecture

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

- Interactive diagram: https://gitdiagram.com/ukutia/qualitrack
- Repository: https://github.com/ukutia/qualitrack

## Overview

1. **System purpose and scope**
   - Qualitrack is an MVP for managing and analyzing evidences for Chilean CNA institutional accreditation.
   - The repository is intentionally narrow in scope: one campus, up to three programs, and only **Criterio 9**.
   - The architecture centers on a single authenticated administrator who uploads, imports, classifies, and reviews evidences.

2. **Top-level structure**
   - The repo is split into three main runtime units:
     - `frontend/`: React SPA
     - `backend/`: Node.js + Express API
     - `docker-compose.yml`: local orchestration for database, API, and client
   - The app is designed to run either fully containerized or locally without Docker.

3. **Frontend boundary**
   - The frontend is a Vite-powered React single-page app using Tailwind, TanStack Query, and React Router.
   - It is organized around route-level pages such as dashboard, documents, upload, cloud connect, login, and criteria structure.
   - Shared UI/state pieces include:
     - `AuthContext` for session/auth state
     - `ProtectedRoute` to guard authenticated routes
     - `useApi` and `lib/api` as the API access boundary
     - `queryClient` for server-state caching and refetching

4. **Backend boundary**
   - The backend is an Express API split into controllers, services, middleware, and route registration.
   - `server.js` and `app.js` form the HTTP bootstrap layer.
   - `routes/index.js` aggregates feature routes, which then dispatch into controllers:
     - auth
     - documents
     - classification
     - compliance
     - criteria
     - cloud
   - This structure keeps HTTP concerns separate from domain logic.

5. **Persistence and data model**
   - Prisma is the ORM layer, with PostgreSQL 16 as the primary database.
   - `prisma/schema.prisma` defines the app’s persisted entities, and `seed.js` initializes the MVP baseline.
   - On startup, the backend syncs the schema, seeds:
     - the admin user
     - Criterio 9 data
     - the official report structure
   - This means the app assumes a controlled, pre-seeded accreditation context rather than a general multi-tenant system.

6. **Document ingestion flow**
   - Evidence upload starts in the frontend upload page and reaches the backend through authenticated API calls.
   - `multer` handles multipart file upload in middleware.
   - Uploaded files are validated for format/size and then stored via `storage.service.js`.
   - The repository explicitly treats storage as an abstraction layer, so the current local-volume approach can be replaced later by S3/GCS without changing the rest of the app.

7. **Text extraction and classification flow**
   - After ingestion, documents can be processed through:
     - `textExtraction.service.js` for content extraction
     - `classifier.service.js` for assigning evidence to the criterion/subcriterion
   - The classifier is a deterministic keyword-based mock, not a real AI call.
   - This is an important architectural seam: the app is built so an LLM integration can be swapped in later without changing controllers or UI contracts.

8. **Compliance computation**
   - `compliance.service.js` encapsulates the logic that turns evidence sets into compliance status.
   - The compliance result is per subcriterion and follows the repository’s documented rules:
     - Suficiente
     - Parcial
     - Insuficiente
   - There is a backend test file dedicated to these rules, which makes compliance logic a distinct domain boundary rather than a UI concern.

9. **Cloud integration**
   - `cloud.controller.js` and `googleDrive.service.js` implement Google Drive OAuth and file browsing/import.
   - This is the only external service integration in the MVP.
   - The app is designed to degrade gracefully: without credentials, the rest of the system still works and the UI exposes setup guidance.

10. **Authentication and request protection**
   - JWT-based auth is handled on the backend with `auth.controller.js` and `middleware/auth.js`.
   - The frontend login flow stores auth state in context and routes protected views through `ProtectedRoute`.
   - This creates a clear trust boundary: unauthenticated users can reach login, but document management and cloud operations are gated.

11. **Error handling and operational concerns**
   - `middleware/errorHandler.js` provides centralized API error translation.
   - Environment configuration is isolated in `config/env.js`, and Prisma access is centralized in `config/prisma.js`.
   - These modules indicate a clean separation between application logic and runtime configuration.

12. **Deployment and infrastructure**
   - `docker-compose.yml` is the main deployment unit for local/staging-like use.
   - The system includes:
     - PostgreSQL database
     - backend API
     - frontend SPA
   - A backend Docker entrypoint initializes schema and seed data automatically, which is important for understanding startup order.

13. **What to show in an architecture diagram**
   - Main clients: browser user → frontend SPA → backend API.
   - Main backend dependencies: backend → PostgreSQL, backend → local file storage, backend → Google Drive API.
   - Main internal subsystems: auth, document management, classification, compliance, criteria/versioned structure, cloud import.
   - Cross-cutting layers: JWT auth, file upload middleware, centralized error handling, Prisma persistence, seeded baseline data.

14. **Key architectural constraint**
   - This is not a general-purpose content platform; it is a tightly bounded MVP with one admin role and one criterion domain.
   - That constraint explains why the services are narrow, the data model is seeded, and the classifier is intentionally mock-based.

Main entry points: [`frontend/src/App.jsx`](https://github.com/ukutia/qualitrack/blob/main/frontend/src/App.jsx) (SPA), [`docker-compose.yml`](https://github.com/ukutia/qualitrack/blob/main/docker-compose.yml) (Compose stack), [`backend/src/services`](https://github.com/ukutia/qualitrack/tree/main/backend/src/services) (Domain services), [`backend/src/controllers`](https://github.com/ukutia/qualitrack/tree/main/backend/src/controllers) (Controllers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client app"]
  node_frontend["SPA<br/>React/Vite app<br/>[App.jsx]"]
  node_auth_context["Auth state<br/>React context<br/>[AuthContext.jsx]"]
  node_protected_route["Route guard<br/>React guard<br/>[ProtectedRoute.jsx]"]
  node_api_client["API client<br/>fetch wrapper<br/>[api.js]"]
  node_query_client["Query cache<br/>TanStack Query<br/>[queryClient.js]"]
  node_pages["Pages<br/>route views"]
end

subgraph group_api["Backend API"]
  node_server["HTTP server<br/>Node bootstrap<br/>[server.js]"]
  node_routes["Routes<br/>route registry<br/>[index.js]"]
  node_controllers["Controllers<br/>HTTP handlers"]
  node_services["Domain services<br/>business logic"]
  node_middleware["Middleware<br/>cross-cutting layer"]
  node_env_config["Env config<br/>runtime config<br/>[env.js]"]
  node_prisma_config["Prisma config<br/>db client setup<br/>[prisma.js]"]
end

subgraph group_data["Data layer"]
  node_schema["Schema<br/>Prisma model<br/>[schema.prisma]"]
  node_seed["Seed data<br/>bootstrap data<br/>[seed.js]"]
  node_postgres[("PostgreSQL<br/>database")]
  node_storage[("File storage<br/>local volume<br/>[storage.service.js]")]
  node_drive["Google Drive<br/>external integration"]
end

subgraph group_infra["Local runtime"]
  node_compose["Compose stack<br/>docker-compose<br/>[docker-compose.yml]"]
end

node_browser(("Administrator<br/>user"))

node_browser -->|"uses"| node_frontend
node_frontend -->|"state"| node_auth_context
node_frontend -->|"guards"| node_protected_route
node_frontend -->|"calls"| node_api_client
node_frontend -->|"caches"| node_query_client
node_frontend -->|"renders"| node_pages
node_pages -->|"requests"| node_api_client
node_server -->|"mounts"| node_routes
node_routes -->|"dispatches"| node_controllers
node_controllers -->|"uses"| node_middleware
node_controllers -->|"delegates"| node_services
node_services -->|"persists via"| node_prisma_config
node_prisma_config -->|"maps to"| node_schema
node_schema -->|"stored in"| node_postgres
node_seed -->|"initializes"| node_postgres
node_services -->|"stores files"| node_storage
node_services -->|"imports from"| node_drive
node_middleware -->|"reads"| node_env_config
node_compose -->|"starts"| node_server
node_compose -->|"starts"| node_frontend
node_compose -->|"provisions"| node_postgres
node_compose -->|"boots with"| node_seed

click node_frontend "https://github.com/ukutia/qualitrack/blob/main/frontend/src/App.jsx"
click node_auth_context "https://github.com/ukutia/qualitrack/blob/main/frontend/src/context/AuthContext.jsx"
click node_protected_route "https://github.com/ukutia/qualitrack/blob/main/frontend/src/components/ProtectedRoute.jsx"
click node_api_client "https://github.com/ukutia/qualitrack/blob/main/frontend/src/lib/api.js"
click node_query_client "https://github.com/ukutia/qualitrack/blob/main/frontend/src/lib/queryClient.js"
click node_pages "https://github.com/ukutia/qualitrack/tree/main/frontend/src/pages"
click node_server "https://github.com/ukutia/qualitrack/blob/main/backend/src/server.js"
click node_routes "https://github.com/ukutia/qualitrack/blob/main/backend/src/routes/index.js"
click node_controllers "https://github.com/ukutia/qualitrack/tree/main/backend/src/controllers"
click node_services "https://github.com/ukutia/qualitrack/tree/main/backend/src/services"
click node_middleware "https://github.com/ukutia/qualitrack/tree/main/backend/src/middleware"
click node_env_config "https://github.com/ukutia/qualitrack/blob/main/backend/src/config/env.js"
click node_prisma_config "https://github.com/ukutia/qualitrack/blob/main/backend/src/config/prisma.js"
click node_schema "https://github.com/ukutia/qualitrack/blob/main/backend/prisma/schema.prisma"
click node_seed "https://github.com/ukutia/qualitrack/blob/main/backend/prisma/seed.js"
click node_storage "https://github.com/ukutia/qualitrack/blob/main/backend/src/services/storage.service.js"
click node_drive "https://github.com/ukutia/qualitrack/blob/main/backend/src/services/googleDrive.service.js"
click node_compose "https://github.com/ukutia/qualitrack/blob/main/docker-compose.yml"

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_frontend,node_auth_context,node_protected_route,node_api_client,node_query_client,node_pages toneBlue
class node_server,node_routes,node_controllers,node_services,node_middleware,node_env_config,node_prisma_config toneAmber
class node_schema,node_seed,node_postgres,node_storage,node_drive toneMint
class node_compose toneRose
class node_browser toneNeutral
```

## Components

### Client app

React SPA and its route-level UI/state boundary

- [SPA](https://github.com/ukutia/qualitrack/blob/main/frontend/src/App.jsx): React/Vite app · Single-page client for login, upload, documents, criteria, and cloud setup · `frontend/src/App.jsx`
- [Auth state](https://github.com/ukutia/qualitrack/blob/main/frontend/src/context/AuthContext.jsx): React context · Client session and login state · `frontend/src/context/AuthContext.jsx`
- [Route guard](https://github.com/ukutia/qualitrack/blob/main/frontend/src/components/ProtectedRoute.jsx): React guard · Blocks authenticated views until session is present · `frontend/src/components/ProtectedRoute.jsx`
- [API client](https://github.com/ukutia/qualitrack/blob/main/frontend/src/lib/api.js): fetch wrapper · Frontend request boundary and API helpers · `frontend/src/lib/api.js`
- [Query cache](https://github.com/ukutia/qualitrack/blob/main/frontend/src/lib/queryClient.js): TanStack Query · Server-state caching and refetch coordination · `frontend/src/lib/queryClient.js`
- [Pages](https://github.com/ukutia/qualitrack/tree/main/frontend/src/pages): route views · Dashboard, documents, upload, login, cloud connect, and criteria structure screens · `frontend/src/pages`

### Backend API

Express HTTP layer, domain services, and middleware

- [HTTP server](https://github.com/ukutia/qualitrack/blob/main/backend/src/server.js): Node bootstrap · Backend entrypoint and app bootstrap · `backend/src/server.js`
- [Routes](https://github.com/ukutia/qualitrack/blob/main/backend/src/routes/index.js): route registry · Aggregates feature routes into the API surface · `backend/src/routes/index.js`
- [Controllers](https://github.com/ukutia/qualitrack/tree/main/backend/src/controllers): HTTP handlers · Auth, documents, classification, compliance, criteria, and cloud endpoints · `backend/src/controllers`
- [Domain services](https://github.com/ukutia/qualitrack/tree/main/backend/src/services): business logic · Storage, text extraction, classification, compliance, and Drive integration · `backend/src/services`
- [Middleware](https://github.com/ukutia/qualitrack/tree/main/backend/src/middleware): cross-cutting layer · JWT auth, uploads, and centralized error handling · `backend/src/middleware`
- [Env config](https://github.com/ukutia/qualitrack/blob/main/backend/src/config/env.js): runtime config · Environment loading and deployment settings · `backend/src/config/env.js`
- [Prisma config](https://github.com/ukutia/qualitrack/blob/main/backend/src/config/prisma.js): db client setup · Centralized Prisma access to PostgreSQL · `backend/src/config/prisma.js`

### Data layer

Persistent models, seeded baseline data, and storage targets

- [Schema](https://github.com/ukutia/qualitrack/blob/main/backend/prisma/schema.prisma): Prisma model · Persisted entities for the MVP accreditation domain · `backend/prisma/schema.prisma`
- [Seed data](https://github.com/ukutia/qualitrack/blob/main/backend/prisma/seed.js): bootstrap data · Admin user, Criterio 9 baseline, and report structure initialization · `backend/prisma/seed.js`
- **PostgreSQL**: database · Primary relational store for application state
- [File storage](https://github.com/ukutia/qualitrack/blob/main/backend/src/services/storage.service.js): local volume · Pluggable evidence file storage abstraction · `backend/src/services/storage.service.js`
- [Google Drive](https://github.com/ukutia/qualitrack/blob/main/backend/src/services/googleDrive.service.js): external integration · OAuth-backed evidence import and browsing · `backend/src/services/googleDrive.service.js`

### Local runtime

Container orchestration and startup wiring

- [Compose stack](https://github.com/ukutia/qualitrack/blob/main/docker-compose.yml): docker-compose · Local orchestration for frontend, backend, and database · `docker-compose.yml`

### Other components

- **Administrator**: user · Single authenticated operator of the MVP

## Connections

- Administrator → SPA: uses · Admin works through the SPA
- SPA → Auth state: state · Login/session state flows through context
- SPA → Route guard: guards · Authenticated views are wrapped by route protection
- SPA → API client: calls · Pages reach backend APIs through the client boundary
- SPA → Query cache: caches · Server state is coordinated through query caching
- SPA → Pages: renders · Route-level screens make up the UI surface
- Pages → API client: requests · Screens trigger authenticated backend operations
- HTTP server → Routes: mounts · Bootstrap layer registers the route tree
- Routes → Controllers: dispatches · Feature endpoints map to HTTP handlers
- Controllers → Middleware: uses · Handlers rely on auth, upload, and error handling layers
- Controllers → Domain services: delegates · Controllers keep domain logic in services
- Domain services → Prisma config: persists via · Domain logic reads and writes through Prisma
- Prisma config → Schema: maps to · Prisma client reflects the defined schema
- Schema → PostgreSQL: stored in · App state is persisted in PostgreSQL
- Seed data → PostgreSQL: initializes · Seed script loads the controlled MVP baseline
- Domain services → File storage: stores files · Evidence files are written through the storage abstraction
- Domain services → Google Drive: imports from · Cloud import and browsing integrate with Google Drive
- Middleware → Env config: reads · Runtime behavior is driven by environment configuration
- Compose stack → HTTP server: starts · Compose brings up the backend service
- Compose stack → SPA: starts · Compose brings up the SPA service
- Compose stack → PostgreSQL: provisions · Compose includes the database service
- Compose stack → Seed data: boots with · Startup includes schema sync and baseline seed
