Perception Mapper AI is an enterprise-grade, high-fidelity cognitive bias, tone, and multilingual sentiment analysis platform. Designed for journalists, content teams, and enterprises, it processes text in English, Tamil (เฎคเฎฎเฎฟเฎดเฏ), and Sinhala (เทเทเถเทเถฝ) to identify cognitive distortions, deliver progress-metered emotional tone breakdowns, and suggest objective alternative rephrasings in real-time.
- Overview
- System Architecture
- Directory & Workspace Structure
- Features Breakdown
- Environment Configuration
- Quick Start & Setup
- Developer Integration API Spec
- Multi-Container Docker Deployment
- QA, Verification & Auditing
Perception Mapper AI operates as a containerized monorepo workspace to orchestrate its microservices: Next.js frontend, NestJS API gateway, and a Python FastAPI NLP engine. It uses Clerk for secure user authentication, Prisma for robust PostgreSQL database management, and zero-shot NLP models for high-accuracy linguistic parsing.
The following diagram illustrates the flow of requests from the user's web browser, through authentication, layout routing, gateway routing, and NLP evaluation:
graph TD
A[User Web Browser] -->|HTTPS / WebSockets| B(Next.js App Portal - Port 3009)
A -->|User Session Credentials| C[Clerk Authentication Provider]
B -->|Workspace API requests / JWT Token| D(NestJS Core Gateway - Port 3001)
D -->|Local Token Decoding| D
D -->|Prisma Client ORM| E[(PostgreSQL Database)]
D -->|Evaluation HTTP Pipelines| F(Python FastAPI NLP Sidecar - Port 8000)
F -->|Neural Classification| G[BART Zero-Shot Model]
F -->|Lexical Scans / spaCy| H[Linguistic Rules Engine]
Perception_Mapper_AI/
โโโ apps/
โ โโโ web/ # Next.js 14 Web Portal (Tailwind CSS, Clerk, next-intl for i18n)
โ โโโ api/ # NestJS Core Gateway API (Prisma ORM, Websocket telemetry stream)
โ โโโ nlp-engine/ # Python FastAPI NLP Sidecar (SpaCy tokenization, langdetect, zero-shot pipelines)
โโโ packages/
โ โโโ ui/ # Shared glassmorphic React components (Button, Card, Input, Badges)
โโโ docker-compose.yml # Multi-container local production orchestrator
โโโ turbo.json # Turborepo caching & parallel task execution configuration
โโโ package.json # Monorepo workspace declarations and primary scripts
- Multilingual Processing: Tailored natural language processing for English, Tamil (เฎคเฎฎเฎฟเฎดเฏ), and Sinhala (เทเทเถเทเถฝ).
- Cognitive Bias Classifier: Scans text against rule-based patterns and zero-shot classifiers to detect:
- Over-generalization: Absolute terms failing to respect context nuances (e.g. always, never, everyone).
- Confirmation Bias: Presenting assumptions as verified absolute facts to reinforce beliefs (e.g. obviously, clearly).
- Sensationalism: Dramatic phrasing to provoke emotional reactions rather than objective analysis (e.g. shocking, disaster, conspiracy).
- Tone Analytics: Dynamic tracking of emotional and communication tones (Informative, Formal, Assertive, Cooperative, Emotional).
- Interactive Rule Customization: Team subscribers can define regex patterns, custom classifications, and alternatives to adapt scans to specific target vocabularies.
- Secure Core Gateways: Dual-layer security featuring local JWT signature checks via Clerk (
ClerkGuard) for interactive clients and secure api-key tokens (ApiKeyGuard) for developer integrations. - Real-time WebSockets Telemetry: Emits telemetry events to update live dashboards and audit consoles dynamically.
- Print-optimized stylesheets: Enables users to generate and print clean, beautifully structured assessment PDF reports natively.
The workspace adapts its dashboard interface dynamically based on the current user's subscription tier:
- Free Plan (
FREE) - Acoustic Basic Gateway: Simple input editor with real-time word counting and baseline multilingual checks. - Basic Plan (
BASIC) - Pro Workspace Suite: Includes the advanced Rephrase Sandbox (generating multiple tones: journalistic, empathetic, professional), CSV data exporters, and the Batch Processor tool. - Pro Plan (
PRO) - Enterprise OS Telemetry: Full system suite including the Bias Network Graph (visual representation of bias node densities), TTS Readout (speech synthesis audio mode), and the Custom Bias Rules Configuration panel.
Ensure the appropriate variables are set in the respective workspace folders before booting development:
| Key | Type | Description / Fallback |
|---|---|---|
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY |
String | Clerk publishable key for React middleware |
CLERK_SECRET_KEY |
String | Clerk private key for backend session decoding |
NEXT_PUBLIC_API_URL |
URL | Target URL for the NestJS API gateway (e.g. http://localhost:3001/api) |
| Key | Type | Description / Fallback |
|---|---|---|
DATABASE_URL |
Postgres URL | Database connection string (e.g. postgresql://postgres:password@localhost:5432/...) |
CLERK_SECRET_KEY |
String | Private key matching the client credentials |
CLERK_JWKS_URI |
URL | Clerk JWKS verification URL (e.g. https://api.clerk.com/v1/jwks) |
PORT |
Integer | Application gateway execution port (default: 3001) |
Ensure you have Node.js 18+, pnpm/npm, and Python 3.10+ installed on your system.
From the monorepo root directory, install dependencies and start the development servers:
# Install root and workspace dependencies
npm install
# Start Next.js and NestJS servers in development mode
npm run dev- Interactive Web Portal: http://localhost:3009
- NestJS Core Gateway API: http://localhost:3001/api
Navigate to the nlp-engine directory, activate your environment, and run the Python service:
cd apps/nlp-engine
# Initialize and activate Python environment
python -m venv venv
source venv/bin/activate # Or venv\Scripts\activate on Windows
# Install Python requirements
pip install -r requirements.txt
# Start the FastAPI reload server
python -m uvicorn main:app --reload --port 8000- Interactive Swagger docs: http://localhost:8000/docs
- FastAPI Core health checks: http://localhost:8000/health
Subscribers can invoke analysis and rephrasing engines programmatically using standard API tokens.
- Path:
/api/analyze/developer - Method:
POST - Headers:
Content-Type: application/jsonX-API-Key: <your_developer_api_key>
Request Body:
{
"text": "This is an absolute disaster and completely unbelievable."
}Response Payload:
{
"success": true,
"source": "FastAPI Live Sidecar",
"language": "English",
"scores": {
"sentiment": 15,
"objectivity": 40,
"biasIndex": 75
},
"tones": [
{ "name": "Assertive", "score": 85, "color": "from-red-500 to-orange-500" },
{ "name": "Informative", "score": 30, "color": "from-blue-500 to-indigo-500" }
],
"biases": [
{
"quote": "This is an absolute disaster and completely unbelievable.",
"type": "Sensationalism",
"description": "Employs dramatic phrasing to provoke emotional reactions rather than objective analysis.",
"rephrase": "This is a significant / noteworthy event / challenging circumstance."
}
]
}- Path:
/api/analyze/rephrase - Method:
POST - Headers:
Content-Type: application/jsonAuthorization: Bearer <clerk_jwt_token>
Request Body:
{
"text": "This is obviously a mistake.",
"language": "en"
}Response Payload:
{
"success": true,
"source": "FastAPI Live Sidecar",
"alternatives": {
"journalistic": "Evidence suggests this is a mistake.",
"empathetic": "We understand this may be an error.",
"professional": "Indications point to this being a mistake."
}
}To spin up the backend production stack locally (NestJS API gateway, PostgreSQL, and FastAPI sidecar), use the root Docker Compose file:
Note: The Next.js web portal is currently not included in the compose file and should be run separately (e.g., via
npm run devor its ownDockerfile).
# Build and run containers in background mode
docker-compose up -d --build
# Confirm running containers
docker-compose ps- Automated Testing:
- NestJS API tests: Run
npm run testorturbo run testto run both UI and backend test suites. - Component validation: We run Storybook tests to verify isolated React widgets rendering in
apps/web/stories/. Runnpm run storybookto launch the local widget testing suite.
- NestJS API tests: Run
- E2E Browser Interaction Audits:
- Audits are automated via ui_audit.js. This checks hydration status, responsive breakpoints, route health codes, and CTA triggers.
- Run the audit manually via:
node ui_audit.js.
| Name | Role | Responsibilities |
|---|---|---|
| Suwedha Sivakumar | ๐ก Idea Planner | Concept & Planning |
| Abdulla Thaslim | ๐ป Software Developer | Development & Execution |