# oliver369x/volunteer_platform architecture

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

- Interactive diagram: https://gitdiagram.com/oliver369x/volunteer_platform
- Repository: https://github.com/oliver369x/volunteer_platform

## Overview

1. **Overall shape**
   - This is a **modular monolith API** built with **Node.js + Express** for a volunteer assignment platform.
   - The main request path is: **HTTP client → route → middleware stack → controller → service → database/external service**.

2. **Application bootstrap**
   - `src/server.js` starts the process, and `src/app.js` wires the Express app.
   - `src/routes/index.js` aggregates the module routers under the `/api` namespace.
   - `src/config/env.js` and `src/config/database.js` centralize runtime configuration and DB connection setup.

3. **Domain modules as bounded contexts**
   - The core business logic is split into feature modules under `src/modules/`: `auth`, `users`, `profiles`, `organizations`, `tasks`, `matching`, `events`, `gamification`, `payments`, `reports`, `tracking`, `incidents`, `broadcasts`, `certificates`, and `audit`.
   - Each module follows the same pattern: **controller + service + routes**, and some include **validators** for request-level contract checks.
   - For an architecture diagram, these modules should be shown as **separate internal subsystems** sharing the same database and infrastructure.

4. **Cross-cutting request pipeline**
   - `src/middlewares/` contains reusable concerns:
     - `auth` for JWT-based authorization,
     - `validator` for payload validation,
     - `error-handler` for centralized API error mapping,
     - `request-context` for per-request metadata,
     - `upload` for file-upload handling.
   - These sit between the router layer and the controllers, shaping the request before business logic runs.

5. **Authentication and identity**
   - The `auth` module handles **registration, login, and password reset**.
   - JWT helpers live in `src/utils/jwt.js`, password hashing in `src/utils/password.js`, and refresh-token persistence is modeled in the database.
   - User identity is normalized across roles such as volunteers, organizations, and administrators.

6. **Core operational workflows**
   - **Organizations and volunteers** are managed through `organizations`, `users`, and `profiles`.
   - **Tasks and assignments** are the central operational objects: organizations create tasks, and the system assigns volunteers through the matching subsystem.
   - **Tracking, incidents, and broadcasts** provide operational visibility and communication around active work.

7. **AI matching subsystem**
   - `src/modules/matching` is the platform’s AI-assisted allocation engine.
   - It combines **local heuristics** with the Gemini integration in `src/services/gemini-client.js`.
   - The readme indicates a fallback mode: if `GEMINI_API_KEY` is absent, matching still works using only the heuristic path.
   - The matching result is persisted as recommendation/assignment data, so the AI service is an **augmentation layer**, not the sole decision-maker.

8. **Gamification and badge issuance**
   - `src/modules/gamification` handles assignment completion, point accumulation, reputation updates, and badge issuance.
   - Supporting services include `badge-generator.js` and `blockchain-simulator.js`.
   - The blockchain layer is explicitly simulated, so the architecture should show it as an **emulated NFT/badge issuance boundary** that can later be replaced with a real chain integration.

9. **Payments, reporting, and certificates**
   - `payments` encapsulates monetization or transaction workflows; the repo includes Stripe-specific testing guidance, so Stripe is likely the external payment boundary.
   - `reports` provides organization-level dashboards and volunteer KPIs, reading from operational data rather than a separate analytics stack.
   - `certificates` and `pdf-generator.js` indicate document generation is part of the application layer, likely producing downloadable completion artifacts.

10. **Persistence layer**
   - The runtime data model is centered on PostgreSQL, with entities such as `user`, `organization`, `task`, `assignment`, `volunteer-profile`, `refresh-token`, `audit-log`, `point-transaction`, `badge`, `volunteer-badge`, and `ai-recommendation`.
   - The repository contains **two database toolchains**:
     - `src/database/` with models, associations, migrations, and seeders,
     - `prisma/` with Prisma schema, migrations, and seed scripts.
   - For diagramming, treat this as a **shared persistence boundary** with overlapping migration/seed workflows rather than two separate apps.

11. **External integrations and infrastructure**
   - The main external services are:
     - **Gemini** for AI-assisted matching,
     - **Cloudinary** for media/storage-related flows,
     - **Pinata** for decentralized storage support,
     - a **notification service** for outbound user/org communications,
     - and likely **Stripe** for payment processing.
   - These integrations are isolated under `src/services/`, keeping the module services as the orchestration layer and the vendor clients as adapters.

12. **Auditability and observability**
   - `src/modules/audit` and `audit-log` persistence show that important actions are tracked explicitly.
   - `request-context` plus the logger utility suggest request correlation and traceable business events are part of the architecture, which matters for operational and compliance flows.

13. **Tooling, deployment, and verification**
   - The project is container-friendly via `Dockerfile`, with environment templates in `env.example` and `env.production.example`.
   - Database lifecycle is supported by scripts for migration, seeding, and reset operations.
   - Quality assurance includes **Jest + Supertest** tests in `src/tests/` and a Postman collection for API exploration.

14. **How to draw it**
   - A good architecture diagram would show:
     - external clients hitting the Express API,
     - the middleware boundary,
     - internal feature modules,
     - shared services for AI/storage/payments/docs,
     - and a PostgreSQL persistence layer.
   - Then add side-boundaries for **Gemini**, **Cloudinary/Pinata**, **Stripe**, and the **blockchain simulator**, all invoked indirectly through module services.

Main entry points: [`src/routes/index.js`](https://github.com/oliver369x/volunteer_platform/blob/master/src/routes/index.js) (API routes), [`src/database`](https://github.com/oliver369x/volunteer_platform/tree/master/src/database) (PostgreSQL), [`src/services`](https://github.com/oliver369x/volunteer_platform/tree/master/src/services) (Adapters), [`src/app.js`](https://github.com/oliver369x/volunteer_platform/blob/master/src/app.js) (App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry & API"]
  node_server["Server<br/>bootstrap<br/>[server.js]"]
  node_app["App<br/>[app.js]"]
  node_routes["API routes<br/>router aggregator<br/>[index.js]"]
end

subgraph group_modules["Domain modules"]
  node_auth["Auth<br/>identity module"]
  node_users["Users<br/>user module"]
  node_profiles["Profiles<br/>profile module"]
  node_orgs["Organizations<br/>org module"]
  node_tasks["Tasks<br/>work module"]
  node_matching["Matching<br/>ai allocation"]
  node_events["Events<br/>event module"]
  node_tracking["Tracking<br/>ops module"]
  node_incidents["Incidents<br/>incident module"]
  node_broadcasts["Broadcasts<br/>communication module"]
  node_gamification["Gamification<br/>rewards module"]
  node_certificates["Certificates<br/>document module"]
  node_payments["Payments<br/>billing module"]
  node_reports["Reports<br/>analytics module"]
  node_audit["Audit"]
end

subgraph group_infra["Shared infra"]
  node_middleware["Middleware<br/>request pipeline"]
  node_config["Config"]
  node_services["Adapters<br/>vendor clients"]
end

subgraph group_data["Persistence"]
  node_db[("PostgreSQL<br/>shared datastore")]
  node_prisma["Prisma<br/>db toolchain"]
  node_sequelize["Sequelize<br/>db toolchain"]
end

node_server -->|"starts"| node_app
node_app -->|"mounts"| node_routes
node_app -->|"uses"| node_middleware
node_routes -->|"routes"| node_auth
node_routes -->|"routes"| node_users
node_routes -->|"routes"| node_profiles
node_routes -->|"routes"| node_orgs
node_routes -->|"routes"| node_tasks
node_routes -->|"routes"| node_matching
node_routes -->|"routes"| node_events
node_routes -->|"routes"| node_tracking
node_routes -->|"routes"| node_incidents
node_routes -->|"routes"| node_broadcasts
node_routes -->|"routes"| node_gamification
node_routes -->|"routes"| node_certificates
node_routes -->|"routes"| node_payments
node_routes -->|"routes"| node_reports
node_routes -->|"routes"| node_audit
node_auth -->|"uses"| node_services
node_users -->|"reads/writes"| node_db
node_profiles -->|"reads/writes"| node_db
node_orgs -->|"reads/writes"| node_db
node_tasks -->|"reads/writes"| node_db
node_matching -->|"uses"| node_services
node_events -->|"reads/writes"| node_db
node_tracking -->|"reads/writes"| node_db
node_incidents -->|"reads/writes"| node_db
node_broadcasts -->|"uses"| node_services
node_gamification -->|"uses"| node_services
node_gamification -->|"reads/writes"| node_db
node_certificates -->|"uses"| node_services
node_payments -->|"uses"| node_services
node_reports -->|"reads"| node_db
node_audit -->|"writes"| node_db
node_config -->|"configures"| node_db
node_prisma -.->|"manages"| node_db
node_sequelize -.->|"manages"| node_db

click node_server "https://github.com/oliver369x/volunteer_platform/blob/master/src/server.js"
click node_app "https://github.com/oliver369x/volunteer_platform/blob/master/src/app.js"
click node_routes "https://github.com/oliver369x/volunteer_platform/blob/master/src/routes/index.js"
click node_middleware "https://github.com/oliver369x/volunteer_platform/tree/master/src/middlewares"
click node_auth "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/auth"
click node_users "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/users"
click node_profiles "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/profiles"
click node_orgs "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/organizations"
click node_tasks "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/tasks"
click node_matching "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/matching"
click node_events "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/events"
click node_tracking "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/tracking"
click node_incidents "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/incidents"
click node_broadcasts "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/broadcasts"
click node_gamification "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/gamification"
click node_certificates "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/certificates"
click node_payments "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/payments"
click node_reports "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/reports"
click node_audit "https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/audit"
click node_config "https://github.com/oliver369x/volunteer_platform/tree/master/src/config"
click node_services "https://github.com/oliver369x/volunteer_platform/tree/master/src/services"
click node_db "https://github.com/oliver369x/volunteer_platform/tree/master/src/database"
click node_prisma "https://github.com/oliver369x/volunteer_platform/tree/master/prisma"
click node_sequelize "https://github.com/oliver369x/volunteer_platform/tree/master/src/database"

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_server,node_app,node_routes toneBlue
class node_auth,node_users,node_profiles,node_orgs,node_tasks,node_matching,node_events,node_tracking,node_incidents,node_broadcasts,node_gamification,node_certificates,node_payments,node_reports,node_audit toneAmber
class node_middleware,node_config,node_services toneMint
class node_db,node_prisma,node_sequelize toneRose
```

## Components

### Entry & API

Process bootstrap, Express wiring, and route aggregation.

- [Server](https://github.com/oliver369x/volunteer_platform/blob/master/src/server.js): bootstrap · Process entrypoint. · `src/server.js`
- [App](https://github.com/oliver369x/volunteer_platform/blob/master/src/app.js): express app · Express application wiring. · `src/app.js`
- [API routes](https://github.com/oliver369x/volunteer_platform/blob/master/src/routes/index.js): router aggregator · Mounts module routers under the API namespace. · `src/routes/index.js`

### Domain modules

Feature bounded contexts implemented as controller-service-route slices.

- [Auth](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/auth): identity module · Registration, login, and password reset flows. · `src/modules/auth`
- [Users](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/users): user module · User lifecycle and role management. · `src/modules/users`
- [Profiles](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/profiles): profile module · Volunteer profile data and preferences. · `src/modules/profiles`
- [Organizations](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/organizations): org module · Organization accounts and membership validation. · `src/modules/organizations`
- [Tasks](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/tasks): work module · Task creation and assignment objects. · `src/modules/tasks`
- [Matching](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/matching): ai allocation · Heuristics plus Gemini-assisted assignment recommendations. · `src/modules/matching`
- [Events](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/events): event module · Event coordination and scheduling. · `src/modules/events`
- [Tracking](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/tracking): ops module · Operational visibility for active work. · `src/modules/tracking`
- [Incidents](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/incidents): incident module · Issue reporting and response workflows. · `src/modules/incidents`
- [Broadcasts](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/broadcasts): communication module · Outbound communications to users and organizations. · `src/modules/broadcasts`
- [Gamification](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/gamification): rewards module · Points, reputation, and badge issuance. · `src/modules/gamification`
- [Certificates](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/certificates): document module · Completion documents and PDFs. · `src/modules/certificates`
- [Payments](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/payments): billing module · Monetization and transaction workflows. · `src/modules/payments`
- [Reports](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/reports): analytics module · Operational dashboards and KPIs. · `src/modules/reports`
- [Audit](https://github.com/oliver369x/volunteer_platform/tree/master/src/modules/audit): audit module · Explicit action tracking and compliance events. · `src/modules/audit`

### Shared infra

Cross-cutting middleware and vendor adapter services.

- [Middleware](https://github.com/oliver369x/volunteer_platform/tree/master/src/middlewares): request pipeline · Auth, validation, upload, context, and error handling. · `src/middlewares`
- [Config](https://github.com/oliver369x/volunteer_platform/tree/master/src/config): runtime config · Environment and database configuration. · `src/config`
- [Adapters](https://github.com/oliver369x/volunteer_platform/tree/master/src/services): vendor clients · Gemini, Cloudinary, Pinata, notifications, PDF, and blockchain simulation. · `src/services`

### Persistence

Database models, migrations, and seed workflows.

- [PostgreSQL](https://github.com/oliver369x/volunteer_platform/tree/master/src/database): shared datastore · Central persistence boundary for domain entities. · `src/database`
- [Prisma](https://github.com/oliver369x/volunteer_platform/tree/master/prisma): db toolchain · Schema, migrations, and seed workflow. · `prisma`
- [Sequelize](https://github.com/oliver369x/volunteer_platform/tree/master/src/database): db toolchain · Models, associations, migrations, and seeders. · `src/database`

## Connections

- Server → App: starts · Bootstraps the HTTP application.
- App → API routes: mounts · Registers API routes.
- App → Middleware: uses · Installs request pipeline and centralized errors.
- API routes → Auth: routes · Auth endpoints.
- API routes → Users: routes · User endpoints.
- API routes → Profiles: routes · Profile endpoints.
- API routes → Organizations: routes · Organization endpoints.
- API routes → Tasks: routes · Task endpoints.
- API routes → Matching: routes · Matching endpoints.
- API routes → Events: routes · Event endpoints.
- API routes → Tracking: routes · Tracking endpoints.
- API routes → Incidents: routes · Incident endpoints.
- API routes → Broadcasts: routes · Broadcast endpoints.
- API routes → Gamification: routes · Gamification endpoints.
- API routes → Certificates: routes · Certificate endpoints.
- API routes → Payments: routes · Payment endpoints.
- API routes → Reports: routes · Reporting endpoints.
- API routes → Audit: routes · Audit endpoints.
- Auth → Adapters: uses · Password, token, and external adapters.
- Users → PostgreSQL: reads/writes · Persists user records.
- Profiles → PostgreSQL: reads/writes · Persists volunteer profile data.
- Organizations → PostgreSQL: reads/writes · Persists organizations and memberships.
- Tasks → PostgreSQL: reads/writes · Persists tasks and assignments.
- Matching → Adapters: uses · Invokes Gemini and stores recommendations.
- Events → PostgreSQL: reads/writes · Persists event data.
- Tracking → PostgreSQL: reads/writes · Persists operational tracking.
- Incidents → PostgreSQL: reads/writes · Persists incident records.
- Broadcasts → Adapters: uses · Sends notifications through adapters.
- Gamification → Adapters: uses · Generates badges and simulates chain issuance.
- Gamification → PostgreSQL: reads/writes · Persists points and badges.
- Certificates → Adapters: uses · Produces PDF documents.
- Payments → Adapters: uses · Integrates with payment adapter boundary.
- Reports → PostgreSQL: reads · Builds dashboards from operational data.
- Audit → PostgreSQL: writes · Stores audit events.
- Config → PostgreSQL: configures · Initializes database connection and runtime settings.
- Prisma → PostgreSQL: manages · Alternative schema/migration toolchain.
- Sequelize → PostgreSQL: manages · Primary model/migration toolchain.
