# terence0-8/sq-main architecture

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

- Interactive diagram: https://gitdiagram.com/terence0-8/sq-main
- Repository: https://github.com/terence0-8/sq-main

## Overview

1. **Overall shape**
   - Solitiquo is a monolithic Node.js web app split into a backend API/server and a mostly static frontend built with HTML/CSS/vanilla JavaScript.
   - The frontend is page-oriented, not SPA-oriented: each major section has its own HTML entry point and page-specific CSS.

2. **Frontend presentation layer**
   - Top-level HTML pages cover the public site and back-office/editor views: articles, podcasts, emissions, parties, search, authentication, profile, payments, contact, legal pages, and admin/editor pages.
   - CSS is organized by page under `css/pages`, with a shared base stylesheet in `css/shared.css`.
   - Client-side JavaScript is modular and small in scope: `js/api.js` for server calls, `js/i18n.js` for language handling, `js/lazyload.js`, `js/urlBuilder.js`, and a general site script `js/solitiquo.js`.
   - PWA/offline behavior is present via `manifest.json`, `sw.js`, and `offline.html`.

3. **Backend server boundary**
   - The backend is an Express application under `backend/`, with `server.js` as the entry point.
   - It exposes route modules for domain areas rather than a single generic API: articles, auth, comments, search, subscriptions, analytics, language, translate, polls, podcasts, parties, emissions, contact, admin, and legacy redirects.
   - This makes the backend the central integration layer between browser pages, authentication, database, media storage, and payment services.

4. **Domain-oriented routes**
   - Content APIs are split by business object: `articles`, `podcasts`, `emissions`, `parties`, `polls`, and `comments`.
   - Platform functions live in separate routes: `auth`, `subscriptions`, `search`, `analytics`, `language`, `translate`, `contact`, and `admin`.
   - `legacyRedirects` suggests the app preserves older URLs and funnels them to current content routes, which matters for SEO and stable links.

5. **Middleware and request pipeline**
   - The request pipeline includes auth/session checks (`middleware/auth.js`), CSRF protection (`middleware/csrf.js`), input sanitization (`middleware/sanitize.js`), slug-based content resolution (`middleware/slugResolver.js`), and upload handling (`middleware/upload.js`).
   - This indicates a fairly defensive server boundary: requests are validated and normalized before reaching route handlers.
   - Passport-based authentication is configured separately in `backend/config/passport.js`, with OAuth support in addition to local login.

6. **Data layer**
   - PostgreSQL is the primary persistence layer, configured from `backend/config/database.js`.
   - Schema management is explicit: there is an initial schema migration plus later migrations for full-text search, OAuth columns, featured podcasts, and reading milestones.
   - There is also a `backend/database/` folder containing a schema dump and seed data, which suggests both bootstrapping and reference schema artifacts are tracked in-repo.

7. **Media and external storage**
   - Cloudinary is used for external media storage, configured in `backend/config/cloudinary.js`.
   - The presence of upload middleware and content editor pages implies that images or other assets are uploaded from the admin/editor interface and stored externally rather than in the app server.

8. **Authentication and identity**
   - Authentication uses Passport with local login plus Google and Facebook OAuth, as reflected in the README and the migration adding OAuth support.
   - Session security depends on environment configuration, especially `SESSION_SECRET`.
   - The auth subsystem is likely used by both public user accounts and privileged editorial/admin workflows.

9. **Payments and subscriptions**
   - Subscriptions are a separate subsystem, with dedicated routes and a payment utility in `backend/utils/fedapay.js`.
   - The repo also includes payment success and payment pages on the frontend, showing a user-facing checkout flow.
   - A migration for subscription payment IDs indicates subscriptions are persisted and reconciled with an external payment provider.

10. **Content enrichment and platform services**
   - `translationService.js` and translation-related routes/migrations indicate multilingual content support and translation caching.
   - Full-text search is supported at the database level and exposed through a search route.
   - Analytics has its own route and legacy migration scripts, implying tracked engagement metrics are a first-class subsystem rather than an afterthought.

11. **SEO and publishing support**
   - `seoController.js`, slug resolution middleware, and legacy redirect handling point to SEO being a core architectural concern.
   - The `article.html` / editor pages and “reading milestones” migration suggest the platform tracks article consumption in addition to publishing content.
   - This is consistent with a media site where canonical URLs, translations, and content discoverability matter.

12. **Operations, automation, and quality gates**
   - The repo includes Docker support, GitHub Actions CI, ESLint/Prettier, and Node’s built-in test runner.
   - Test coverage is route-focused (`auth.test.js`, `subscriptions.test.js`) with a dummy test retained to satisfy CI globbing.
   - Maintenance scripts exist for migrations, translations, favicon/header injection, CSS minification, and status/data sync tasks, indicating a codebase with significant build-time content processing.

13. **How data moves through the system**
   - A browser loads a static page, then page JS calls the Express backend.
   - The backend authenticates the user, validates/sanitizes the request, resolves content by slug or ID, queries PostgreSQL, and may enrich data via translation/search/analytics logic.
   - For uploads or paid features, the backend also talks to Cloudinary and the payment provider before persisting final state in Postgres.

14. **What to draw as the main boundaries**
   - Draw three primary blocks: frontend presentation, Express backend/API, and PostgreSQL.
   - Add side integrations for Cloudinary, OAuth providers, and the payment gateway.
   - Inside the backend, separate content management, auth, subscriptions/payments, search/analytics, and translation as distinct subsystems because they are implemented as independent routes/services rather than a single generic API layer.

Main entry points: [`server.js`](https://github.com/terence0-8/sq-main/blob/main/server.js) (Express app), [`backend/routes/articles.js`](https://github.com/terence0-8/sq-main/blob/main/backend/routes/articles.js) (Content API), [`backend/routes/auth.js`](https://github.com/terence0-8/sq-main/blob/main/backend/routes/auth.js) (Platform API), [`backend/config/database.js`](https://github.com/terence0-8/sq-main/blob/main/backend/config/database.js) (Postgres)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_public_pages["Pages<br/>[index.html]"]
  node_page_styles["Styles<br/>css system<br/>[shared.css]"]
  node_client_scripts["Client JS<br/>browser modules<br/>[api.js]"]
  node_pwa_shell["PWA shell<br/>offline support<br/>[manifest.json]"]
end

subgraph group_backend["Backend"]
  node_server_entry["Express app<br/>node server<br/>[server.js]"]
  node_request_pipeline["Pipeline<br/>middleware stack<br/>[auth.js]"]
  node_content_routes["Content API<br/>domain routes<br/>[articles.js]"]
  node_platform_routes["Platform API<br/>platform routes<br/>[auth.js]"]
  node_billing_routes["Billing<br/>payments<br/>[subscriptions.js]"]
  node_seo_controller["SEO<br/>controller<br/>[seoController.js]"]
  node_translation_service["Translation"]
end

subgraph group_data["Data"]
  node_db_config[("Postgres<br/>database config<br/>[database.js]")]
  node_schema_migrations["Migrations<br/>schema history"]
  node_schema_dump["Schema dump<br/>bootstrap data<br/>[schema.sql]"]
end

subgraph group_integrations["Integrations"]
  node_cloudinary["Cloudinary<br/>media storage<br/>[cloudinary.js]"]
  node_oauth_providers["OAuth<br/>identity providers<br/>[passport.js]"]
  node_payment_gateway["Fedapay<br/>payment provider<br/>[fedapay.js]"]
end

node_public_pages -->|"API calls"| node_server_entry
node_client_scripts -->|"fetch"| node_server_entry
node_pwa_shell -.->|"shell"| node_public_pages
node_page_styles -->|"style"| node_public_pages
node_server_entry -->|"uses"| node_request_pipeline
node_server_entry -->|"mounts"| node_content_routes
node_server_entry -->|"mounts"| node_platform_routes
node_server_entry -->|"mounts"| node_billing_routes
node_server_entry -->|"uses"| node_seo_controller
node_content_routes -->|"queries"| node_db_config
node_platform_routes -->|"queries"| node_db_config
node_billing_routes -->|"charges"| node_payment_gateway
node_content_routes -->|"uploads"| node_cloudinary
node_request_pipeline -->|"auth"| node_oauth_providers
node_platform_routes -->|"translate"| node_translation_service
node_platform_routes -.->|"evolves"| node_schema_migrations
node_db_config -->|"applies"| node_schema_migrations
node_db_config -.->|"bootstraps"| node_schema_dump
node_content_routes -->|"canonicalizes"| node_seo_controller

click node_public_pages "https://github.com/terence0-8/sq-main/blob/main/index.html"
click node_page_styles "https://github.com/terence0-8/sq-main/blob/main/css/shared.css"
click node_client_scripts "https://github.com/terence0-8/sq-main/blob/main/js/api.js"
click node_pwa_shell "https://github.com/terence0-8/sq-main/blob/main/manifest.json"
click node_server_entry "https://github.com/terence0-8/sq-main/blob/main/server.js"
click node_request_pipeline "https://github.com/terence0-8/sq-main/blob/main/backend/middleware/auth.js"
click node_content_routes "https://github.com/terence0-8/sq-main/blob/main/backend/routes/articles.js"
click node_platform_routes "https://github.com/terence0-8/sq-main/blob/main/backend/routes/auth.js"
click node_billing_routes "https://github.com/terence0-8/sq-main/blob/main/backend/routes/subscriptions.js"
click node_seo_controller "https://github.com/terence0-8/sq-main/blob/main/backend/controllers/seoController.js"
click node_translation_service "https://github.com/terence0-8/sq-main/blob/main/backend/services/translationService.js"
click node_db_config "https://github.com/terence0-8/sq-main/blob/main/backend/config/database.js"
click node_schema_migrations "https://github.com/terence0-8/sq-main/blob/main/backend/migrations/1_initial_schema.js"
click node_schema_dump "https://github.com/terence0-8/sq-main/blob/main/backend/database/schema.sql"
click node_cloudinary "https://github.com/terence0-8/sq-main/blob/main/backend/config/cloudinary.js"
click node_oauth_providers "https://github.com/terence0-8/sq-main/blob/main/backend/config/passport.js"
click node_payment_gateway "https://github.com/terence0-8/sq-main/blob/main/backend/utils/fedapay.js"

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_public_pages,node_page_styles,node_client_scripts,node_pwa_shell toneBlue
class node_server_entry,node_request_pipeline,node_content_routes,node_platform_routes,node_billing_routes,node_seo_controller,node_translation_service toneAmber
class node_db_config,node_schema_migrations,node_schema_dump toneMint
class node_cloudinary,node_oauth_providers,node_payment_gateway toneRose
```

## Components

### Frontend

Static pages, browser scripts, and offline shell.

- [Pages](https://github.com/terence0-8/sq-main/blob/main/index.html): static pages · Page-oriented HTML entry points for public, account, editor, and legal views. · `index.html`
- [Styles](https://github.com/terence0-8/sq-main/blob/main/css/shared.css): css system · Shared stylesheet plus page-specific CSS under css/pages. · `css/shared.css`
- [Client JS](https://github.com/terence0-8/sq-main/blob/main/js/api.js): browser modules · Small browser modules for API calls, i18n, lazy loading, and URL building. · `js/api.js`
- [PWA shell](https://github.com/terence0-8/sq-main/blob/main/manifest.json): offline support · Manifest, service worker, and offline fallback for installable/offline behavior. · `manifest.json`

### Backend

Express server, request pipeline, routes, and services.

- [Express app](https://github.com/terence0-8/sq-main/blob/main/server.js): node server · Backend entry point that wires middleware, routes, and startup. · `server.js`
- [Pipeline](https://github.com/terence0-8/sq-main/blob/main/backend/middleware/auth.js): middleware stack · Auth, CSRF, sanitization, slug resolution, and upload handling. · `backend/middleware/auth.js`
- [Content API](https://github.com/terence0-8/sq-main/blob/main/backend/routes/articles.js): domain routes · Articles, podcasts, emissions, parties, polls, comments, and legacy redirects. · `backend/routes/articles.js`
- [Platform API](https://github.com/terence0-8/sq-main/blob/main/backend/routes/auth.js): platform routes · Auth, search, language, translation, contact, admin, and analytics endpoints. · `backend/routes/auth.js`
- [Billing](https://github.com/terence0-8/sq-main/blob/main/backend/routes/subscriptions.js): payments · Subscription and payment flows backed by dedicated route logic and payment utility. · `backend/routes/subscriptions.js`
- [SEO](https://github.com/terence0-8/sq-main/blob/main/backend/controllers/seoController.js): controller · Canonicalization, redirect handling, and publishing-friendly URL behavior. · `backend/controllers/seoController.js`
- [Translation](https://github.com/terence0-8/sq-main/blob/main/backend/services/translationService.js): service · Translation logic and cache-oriented content enrichment. · `backend/services/translationService.js`

### Data

Database schema, migrations, and seed artifacts.

- [Postgres](https://github.com/terence0-8/sq-main/blob/main/backend/config/database.js): database config · Database connection and schema management setup. · `backend/config/database.js`
- [Migrations](https://github.com/terence0-8/sq-main/blob/main/backend/migrations/1_initial_schema.js): schema history · Initial schema plus later migrations for search, OAuth, featured podcasts, and reading milestones. · `backend/migrations/1_initial_schema.js`
- [Schema dump](https://github.com/terence0-8/sq-main/blob/main/backend/database/schema.sql): bootstrap data · Tracked schema and seed artifacts used for bootstrapping and reference. · `backend/database/schema.sql`

### Integrations

External services for identity, media, and payments.

- [Cloudinary](https://github.com/terence0-8/sq-main/blob/main/backend/config/cloudinary.js): media storage · External storage for uploaded media and editor assets. · `backend/config/cloudinary.js`
- [OAuth](https://github.com/terence0-8/sq-main/blob/main/backend/config/passport.js): identity providers · Passport-based local auth plus Google and Facebook login. · `backend/config/passport.js`
- [Fedapay](https://github.com/terence0-8/sq-main/blob/main/backend/utils/fedapay.js): payment provider · External payment provider used for subscriptions and checkout. · `backend/utils/fedapay.js`

## Connections

- Pages → Express app: API calls · Page scripts call the backend for data and actions.
- Client JS → Express app: fetch · Browser modules use the Express API boundary.
- PWA shell → Pages: shell · Manifest, service worker, and offline fallback wrap the static frontend.
- Styles → Pages: style · Shared and page-specific CSS style the site pages.
- Express app → Pipeline: uses · Requests pass through defensive middleware before handlers.
- Express app → Content API: mounts · Core content endpoints are mounted on the Express app.
- Express app → Platform API: mounts · Platform and utility endpoints are mounted on the Express app.
- Express app → Billing: mounts · Subscription and payment flows are exposed by the backend.
- Express app → SEO: uses · SEO and redirect handling are part of the server boundary.
- Content API → Postgres: queries · Content handlers persist and read data from Postgres.
- Platform API → Postgres: queries · Platform features depend on the primary database.
- Billing → Fedapay: charges · Subscription checkout and reconciliation use the payment provider.
- Content API → Cloudinary: uploads · Editor and content workflows store media externally.
- Pipeline → OAuth: auth · Passport and OAuth support are enforced at the request boundary.
- Platform API → Translation: translate · Translation endpoints delegate to translation logic.
- Platform API → Migrations: evolves · Search, OAuth, analytics, and other features are backed by migrations.
- Postgres → Migrations: applies · The configured database is shaped by tracked schema changes.
- Postgres → Schema dump: bootstraps · Schema and seed files support initial setup and reference data.
- Content API → SEO: canonicalizes · Content routes cooperate with slug and redirect logic for stable URLs.
