# congminh2211/charityconnect architecture

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

- Interactive diagram: https://gitdiagram.com/congminh2211/charityconnect
- Repository: https://github.com/congminh2211/charityconnect

## Overview

1. **Overall shape**
   CharityConnect is a role-based donor/organization/admin platform split into a single-page React frontend and four backend capabilities behind an Nginx API gateway. The backend is intentionally decomposed by domain: identity, campaigns, donations, and assistant/content verification. Each core service owns its own database and migrations; there is no shared cross-service database access.

2. **Frontend as the user-facing shell**
   The frontend is a Vite + React + TypeScript app organized by feature area rather than by technical layer. It contains account, campaigns, donations, transparency, organization, admin, analytics, content, notifications, and engagement modules. `AuthContext` and `AuthGuard` enforce role-based access, while `src/lib/api.ts` switches between mock local data and real backend calls via `VITE_USE_MOCK_API`. This makes the UI usable both in demo mode and in full integrated deployment.

3. **Public ingress and routing**
   In deployed mode, Nginx is the public edge. It serves the web app and proxies `/api/v1` to the internal services. The README’s gateway mapping shows one public surface for the frontend, while backend services remain private. This keeps the architecture diagram clean: browser → gateway → domain services.

4. **Identity service**
   `backend/identity` is a Node/Express service in TypeScript with PostgreSQL. Its code is split into auth, sessions, tokens, passwords, notifications, rate limiting, security, and account/profile management. It is the source of truth for login, registration, password reset, session handling, user profiles, Google Sign-In, and admin user management. It also sends account-related notifications and enforces security/rate controls.

5. **Campaign service**
   `backend/campaign` is another Express/TypeScript service with its own database and state/stream/security/auth layers. It manages campaign lifecycle: organization-facing drafts, admin approval, financial plans, milestones, impact reports, and campaign state transitions. It also participates in Redis-stream-based integration events and exposes admin and organization endpoints for campaign moderation and reporting.

6. **Donation service**
   `backend/donation` is a FastAPI/Python service backed by PostgreSQL. It handles donation creation, receipts, donor-facing histories, organization donation views, and transparency endpoints. Its domain layer and schema layer are separated from auth and diagnostics, which makes it the clearest place to show the financial/audit boundary in a diagram.

7. **TrustChain and immutable ledger**
   Donation is the repository’s main integrity subsystem. It maintains a SHA-256 hash-chain in `ledger_entries`, where each entry depends on the previous hash, and it periodically aggregates hashes into Merkle roots for anchoring. The public payloads are designed to exclude sensitive donor identity data. This is not a blockchain network; it is an internal tamper-evident audit mechanism for receipts and ledger integrity.

8. **Assistant and content verification**
   `backend/assistant` is a FastAPI service for the chatbot plus content verification/knowledge features. The code split (`content_verify.py`, `knowledge.py`, `guides.py`, `main.py`) suggests it serves both conversational assistance and public verification/content analysis endpoints. The README states it prefers internal CharityConnect knowledge first and only falls back to optional web search if configured with an AI provider. This service is also where public content verification pages in the frontend get their data.

9. **Cross-service event flow**
   The main integrations are event-driven over Redis Streams, with idempotent `event_id` handling. A completed donation emits `donation.completed`, which Campaign consumes. Campaign can emit `transparency.record`, and Donation consumes `FUND_USAGE_VERIFIED` to update ledger/transparency state. This gives the system asynchronous propagation for financial and transparency state without coupling databases.

10. **Data ownership and boundaries**
   Each service owns its schema and migrations (`sql/001_...` onward in each backend). The repo repeatedly enforces the rule that services do not query each other’s databases directly. All inter-service communication is through HTTP APIs or Redis events. That boundary is important for any architecture diagram: the databases should be drawn as service-private assets, not shared infrastructure.

11. **External integrations**
   The system can connect to Google Sign-In, Gmail notifications, Anthropic/OpenAI for the assistant, and optional Sepolia anchoring for TrustChain. If these are not configured, the app falls back to local/demo behavior or internal simulation. Those integrations are optional but materially affect the deployment diagram because they introduce external trust boundaries and secret management.

12. **Observability and operations**
   Prometheus scrapes service metrics and Grafana visualizes them. SonarQube is available as a quality profile in the Docker stack. CI is defined in GitHub Actions. These are supporting subsystems rather than business logic, but they belong in an ops layer in the diagram because they sit beside the runtime services and validate availability, quality, and code health.

13. **Deployment topology**
   The repo supports two main modes: local/demo and full Dockerized stack. In local demo mode, the frontend can run alone with mock data. In full mode, Docker Compose brings up the web, gateway, three domain services, assistant, PostgreSQL instances, Redis, and observability tools. The frontend production build is static, while the backend services are independently deployable containers.

14. **Role-driven product flow**
   The business flow is: organization applies and gets verified, creates and submits campaigns, admin approves campaigns, donors donate and receive receipts, organizations submit impact reports, and admins verify impact to update transparency ledgers. Public users can browse verified content, campaigns, statistics, and receipt verification without logging in. The diagram should therefore show both public read paths and authenticated role-specific write paths.

Main entry points: [`backend/campaign/src/app.ts`](https://github.com/congminh2211/charityconnect/blob/main/backend/campaign/src/app.ts) (Campaign API), [`backend/donation/app/main.py`](https://github.com/congminh2211/charityconnect/blob/main/backend/donation/app/main.py) (Donation API), [`backend/assistant/app/main.py`](https://github.com/congminh2211/charityconnect/blob/main/backend/assistant/app/main.py) (Assistant API), [`nginx/nginx.conf`](https://github.com/congminh2211/charityconnect/blob/main/nginx/nginx.conf) (Nginx)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app_shell["App Shell<br/>react shell<br/>[App.tsx]"]
  node_auth_ui["Auth UI<br/>react auth<br/>[AuthContext.tsx]"]
  node_feature_hub["Feature Hub<br/>feature router"]
  node_api_client["API Client<br/>api adapter<br/>[api.ts]"]
end

subgraph group_gateway["Edge"]
  node_browser(("Browser<br/>user client"))
  node_nginx["Nginx<br/>edge gateway<br/>[nginx.conf]"]
  node_redis["Redis Streams<br/>event bus"]
end

subgraph group_identity["Identity"]
  node_identity_app["Identity API<br/>express service<br/>[app.ts]"]
  node_identity_store[("Identity DB<br/>postgres schema<br/>[001_init.sql]")]
end

subgraph group_campaign["Campaigns"]
  node_campaign_app["Campaign API<br/>express service<br/>[app.ts]"]
  node_campaign_state["Campaign State<br/>domain state<br/>[state.ts]"]
  node_campaign_store[("Campaign DB<br/>postgres schema<br/>[001_init.sql]")]
end

subgraph group_donation["Donations"]
  node_donation_app["Donation API<br/>fastapi service<br/>[main.py]"]
  node_trustchain{{"TrustChain<br/>audit ledger<br/>[trustchain.py]"}}
  node_donation_store[("Donation DB<br/>postgres schema<br/>[001_init.sql]")]
end

subgraph group_assistant["Assistant"]
  node_assistant_app["Assistant API<br/>fastapi service<br/>[main.py]"]
  node_content_verify["Content Verify<br/>verification module<br/>[content_verify.py]"]
  node_assistant_knowledge["Knowledge Base<br/>knowledge module<br/>[knowledge.py]"]
end

subgraph group_ops["Ops"]
  node_prometheus["Prometheus<br/>metrics"]
  node_grafana["Grafana<br/>dashboards"]
  node_github_actions["CI<br/>workflow<br/>[ci.yml]"]
end

subgraph group_external["External"]
  node_google(("Google Sign-In<br/>external auth"))
  node_ai_providers(("AI Providers<br/>external ai"))
end

node_browser -->|"browse /api"| node_nginx
node_nginx -->|"serve SPA"| node_app_shell
node_nginx -->|"proxy auth"| node_identity_app
node_nginx -->|"proxy campaigns"| node_campaign_app
node_nginx -->|"proxy donations"| node_donation_app
node_nginx -->|"proxy assistant"| node_assistant_app
node_app_shell -->|"role access"| node_auth_ui
node_app_shell -->|"routes"| node_feature_hub
node_feature_hub -->|"data access"| node_api_client
node_api_client -->|"auth calls"| node_identity_app
node_api_client -->|"campaign calls"| node_campaign_app
node_api_client -->|"donation calls"| node_donation_app
node_api_client -->|"verify calls"| node_assistant_app
node_identity_app -->|"owns"| node_identity_store
node_campaign_app -->|"orchestrates"| node_campaign_state
node_campaign_app -->|"owns"| node_campaign_store
node_donation_app -->|"anchors"| node_trustchain
node_donation_app -->|"owns"| node_donation_store
node_assistant_app -->|"verifies"| node_content_verify
node_assistant_app -->|"answers"| node_assistant_knowledge
node_campaign_app -->|"emit/consume"| node_redis
node_donation_app -->|"emit/consume"| node_redis
node_identity_app -.->|"oauth"| node_google
node_assistant_app -.->|"optional ai"| node_ai_providers
node_prometheus -->|"scrape"| node_identity_app
node_prometheus -->|"scrape"| node_campaign_app
node_prometheus -->|"scrape"| node_donation_app
node_prometheus -->|"scrape"| node_assistant_app
node_grafana -->|"visualize"| node_prometheus
node_github_actions -.->|"test"| node_app_shell
node_github_actions -.->|"test"| node_identity_app
node_github_actions -.->|"test"| node_campaign_app
node_github_actions -.->|"test"| node_donation_app
node_github_actions -.->|"test"| node_assistant_app

click node_nginx "https://github.com/congminh2211/charityconnect/blob/main/nginx/nginx.conf"
click node_app_shell "https://github.com/congminh2211/charityconnect/blob/main/frontend/src/App.tsx"
click node_auth_ui "https://github.com/congminh2211/charityconnect/blob/main/frontend/src/auth/AuthContext.tsx"
click node_feature_hub "https://github.com/congminh2211/charityconnect/tree/main/frontend/src/features"
click node_api_client "https://github.com/congminh2211/charityconnect/blob/main/frontend/src/lib/api.ts"
click node_identity_app "https://github.com/congminh2211/charityconnect/blob/main/backend/identity/src/app.ts"
click node_identity_store "https://github.com/congminh2211/charityconnect/blob/main/backend/identity/sql/001_init.sql"
click node_campaign_app "https://github.com/congminh2211/charityconnect/blob/main/backend/campaign/src/app.ts"
click node_campaign_state "https://github.com/congminh2211/charityconnect/blob/main/backend/campaign/src/state.ts"
click node_campaign_store "https://github.com/congminh2211/charityconnect/blob/main/backend/campaign/sql/001_init.sql"
click node_donation_app "https://github.com/congminh2211/charityconnect/blob/main/backend/donation/app/main.py"
click node_trustchain "https://github.com/congminh2211/charityconnect/blob/main/backend/donation/app/trustchain.py"
click node_donation_store "https://github.com/congminh2211/charityconnect/blob/main/backend/donation/sql/001_init.sql"
click node_assistant_app "https://github.com/congminh2211/charityconnect/blob/main/backend/assistant/app/main.py"
click node_content_verify "https://github.com/congminh2211/charityconnect/blob/main/backend/assistant/app/content_verify.py"
click node_assistant_knowledge "https://github.com/congminh2211/charityconnect/blob/main/backend/assistant/app/knowledge.py"
click node_github_actions "https://github.com/congminh2211/charityconnect/blob/main/.github/workflows/ci.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_app_shell,node_auth_ui,node_feature_hub,node_api_client,node_prometheus,node_grafana,node_github_actions toneBlue
class node_browser,node_nginx,node_redis,node_google,node_ai_providers toneAmber
class node_identity_app,node_identity_store toneMint
class node_campaign_app,node_campaign_state,node_campaign_store toneRose
class node_donation_app,node_trustchain,node_donation_store toneIndigo
class node_assistant_app,node_content_verify,node_assistant_knowledge toneTeal
```

## Components

### Frontend

React single-page app and feature modules

- [App Shell](https://github.com/congminh2211/charityconnect/blob/main/frontend/src/App.tsx): react shell · SPA routing, layout, and role workspace · `frontend/src/App.tsx`
- [Auth UI](https://github.com/congminh2211/charityconnect/blob/main/frontend/src/auth/AuthContext.tsx): react auth · Login, registration, guards, and role context · `frontend/src/auth/AuthContext.tsx`
- [Feature Hub](https://github.com/congminh2211/charityconnect/tree/main/frontend/src/features): feature router · User-facing modules for campaigns, donations, transparency, content, and admin · `frontend/src/features`
- [API Client](https://github.com/congminh2211/charityconnect/blob/main/frontend/src/lib/api.ts): api adapter · Switches between mock data and backend calls · `frontend/src/lib/api.ts`

### Edge

Public ingress and routing

- **Browser**: user client · Public and authenticated users of the platform
- [Nginx](https://github.com/congminh2211/charityconnect/blob/main/nginx/nginx.conf): edge gateway · Serves the web app and proxies API traffic · `nginx/nginx.conf`
- **Redis Streams**: event bus · Asynchronous cross-service events with idempotent handling

### Identity

Auth, sessions, profiles, and notifications

- [Identity API](https://github.com/congminh2211/charityconnect/blob/main/backend/identity/src/app.ts): express service · Login, registration, sessions, tokens, profiles, and notifications · `backend/identity/src/app.ts`
- [Identity DB](https://github.com/congminh2211/charityconnect/blob/main/backend/identity/sql/001_init.sql): postgres schema · Private identity data store and migrations · `backend/identity/sql/001_init.sql`

### Campaigns

Campaign lifecycle and moderation

- [Campaign API](https://github.com/congminh2211/charityconnect/blob/main/backend/campaign/src/app.ts): express service · Campaign drafts, approval, plans, milestones, and reporting · `backend/campaign/src/app.ts`
- [Campaign State](https://github.com/congminh2211/charityconnect/blob/main/backend/campaign/src/state.ts): domain state · Lifecycle rules, moderation flow, and stream integration · `backend/campaign/src/state.ts`
- [Campaign DB](https://github.com/congminh2211/charityconnect/blob/main/backend/campaign/sql/001_init.sql): postgres schema · Private campaign data store and migrations · `backend/campaign/sql/001_init.sql`

### Donations

Donation ledger and transparency

- [Donation API](https://github.com/congminh2211/charityconnect/blob/main/backend/donation/app/main.py): fastapi service · Donation creation, histories, receipts, and transparency views · `backend/donation/app/main.py`
- [TrustChain](https://github.com/congminh2211/charityconnect/blob/main/backend/donation/app/trustchain.py): audit ledger · Hash-chain and Merkle anchoring for tamper-evident receipts · `backend/donation/app/trustchain.py`
- [Donation DB](https://github.com/congminh2211/charityconnect/blob/main/backend/donation/sql/001_init.sql): postgres schema · Private donation ledger and transparency tables · `backend/donation/sql/001_init.sql`

### Assistant

Chatbot and content verification

- [Assistant API](https://github.com/congminh2211/charityconnect/blob/main/backend/assistant/app/main.py): fastapi service · Chatbot, knowledge, and content verification endpoints · `backend/assistant/app/main.py`
- [Content Verify](https://github.com/congminh2211/charityconnect/blob/main/backend/assistant/app/content_verify.py): verification module · Public content analysis and verification logic · `backend/assistant/app/content_verify.py`
- [Knowledge Base](https://github.com/congminh2211/charityconnect/blob/main/backend/assistant/app/knowledge.py): knowledge module · CharityConnect knowledge-first answering and guidance · `backend/assistant/app/knowledge.py`

### Ops

Observability and CI

- **Prometheus**: metrics · Scrapes service metrics
- **Grafana**: dashboards · Operational dashboards and visualization
- [CI](https://github.com/congminh2211/charityconnect/blob/main/.github/workflows/ci.yml): workflow · Automated tests and checks · `.github/workflows/ci.yml`

### External

Optional third-party integrations

- **Google Sign-In**: external auth · Optional OAuth identity provider
- **AI Providers**: external ai · Optional Anthropic/OpenAI integrations

## Connections

- Browser → Nginx: browse /api · Public users reach the platform through the edge
- Nginx → App Shell: serve SPA · Static frontend delivery
- Nginx → Identity API: proxy auth · API requests are routed to backend services
- Nginx → Campaign API: proxy campaigns · API requests are routed to backend services
- Nginx → Donation API: proxy donations · API requests are routed to backend services
- Nginx → Assistant API: proxy assistant · API requests are routed to backend services
- App Shell → Auth UI: role access · Auth context and guards gate role-specific views
- App Shell → Feature Hub: routes · Feature-oriented navigation inside the SPA
- Feature Hub → API Client: data access · Feature modules use the shared API adapter
- API Client → Identity API: auth calls · Login, sessions, profiles, and notifications
- API Client → Campaign API: campaign calls · Campaign browsing and moderation flows
- API Client → Donation API: donation calls · Donations, receipts, history, and transparency
- API Client → Assistant API: verify calls · Content verification and assistant requests
- Identity API → Identity DB: owns · Identity service owns its schema and migrations
- Campaign API → Campaign State: orchestrates · State machine and moderation flow
- Campaign API → Campaign DB: owns · Campaign service owns its schema and migrations
- Donation API → TrustChain: anchors · Tamper-evident ledger and Merkle aggregation
- Donation API → Donation DB: owns · Donation service owns its schema and migrations
- Assistant API → Content Verify: verifies · Public verification and analysis endpoints
- Assistant API → Knowledge Base: answers · Knowledge-first guidance and chatbot responses
- Campaign API → Redis Streams: emit/consume · Campaign integration events
- Donation API → Redis Streams: emit/consume · Donation completion and verification events
- Identity API → Google Sign-In: oauth · Optional Google Sign-In integration
- Assistant API → AI Providers: optional ai · Fallback external model and search integrations
- Prometheus → Identity API: scrape · Collects service metrics
- Prometheus → Campaign API: scrape · Collects service metrics
- Prometheus → Donation API: scrape · Collects service metrics
- Prometheus → Assistant API: scrape · Collects service metrics
- Grafana → Prometheus: visualize · Dashboards read metrics from Prometheus
- CI → App Shell: test · CI validates the frontend and services
- CI → Identity API: test · CI validates the frontend and services
- CI → Campaign API: test · CI validates the frontend and services
- CI → Donation API: test · CI validates the frontend and services
- CI → Assistant API: test · CI validates the frontend and services
