How null-spectra/cognichain works
1. Overall shape
CogniChain is a Next.js 16 / React 19 application that combines a browser UI, server-side API routes, a realtime database layer, an AI analysis layer, and a blockchain anchoring layer. The architecture is centered on evidence and case management for law enforcement.
2. UI delivery layer
The app/ directory contains the user-facing routes: dashboard (app/page.tsx), login, case creation, and case detail views. app/layout.tsx likely wires global providers such as theming, while app/globals.css and Tailwind CSS v4 define the visual system. The UI is split into reusable components in components/, especially ChatWindow, BlockchainFeed, and theme controls.
3. Backend API boundary
The pages/api/ directory is the main server boundary. It exposes endpoints for case CRUD, case status updates, evidence upload and download, evidence analysis, image analysis, and AI chat generation. This keeps sensitive operations, file handling, and external-service calls off the client.
4. Realtime data layer
InstantDB is the primary application data store and collaboration layer. The schema in instant.schema.ts defines domain entities such as officers, cases, evidence, action logs, and file records. instant.perms.ts governs access control, and lib/db.ts / lib/db.admin.ts separate normal client access from privileged server/admin access.
5. Case management flow
Cases appear to be the core business object. The browser creates or updates a case through the case pages and API routes, while the API persists those changes to InstantDB. Status updates have a dedicated endpoint, suggesting a live workflow around investigation state changes and auditability.
6. Evidence pipeline
Evidence enters through pages/api/evidence.ts, then can be analyzed, downloaded, or image-processed via specialized evidence endpoints. The data model implies that each evidence item is linked to a case and a stored file reference, with metadata and derived results preserved in the database.
7. Blockchain verification layer
lib/blockchain.ts and the BlockchainFeed component indicate that evidence hashes are written to the opBNB network for immutability. The repo uses Ethers.js, so the blockchain layer is a server-side integration that anchors evidence integrity and exposes transaction activity back to the UI as an audit feed.
8. AI analysis layer
pages/api/chat/generate.ts, pages/api/evidence/analyze.ts, and pages/api/evidence/analyze-image.ts show Gemini-powered analysis as a separate service boundary. The UI sends case/evidence context to these endpoints, and the server returns generated insights, discrepancy detection, or image interpretation for investigators.
9. Identity and access control
The project describes role-based security for officers. In architectural terms, that implies authentication at the login route, authorization enforced through InstantDB permissions, and privileged server operations via db.admin.ts and secret environment variables.
10. Auditability and traceability
ActionLog in the schema, plus blockchain transaction history and status endpoints, form the audit trail. This means the system records both domain changes in InstantDB and tamper-resistant proof on-chain, which is important for evidentiary integrity.
11. Supporting utilities
lib/hash.ts and lib/id.ts handle low-level integrity and identifier concerns, which are important in evidence systems where stable IDs and hashes matter. These utilities sit below the business logic and are reused across API routes and storage/blockchain operations.
12. Storage and temporary files
The repo includes a temp/ directory and a storage-focused document, suggesting transient file handling before or during upload. InstantDB Storage appears to be the persistent file layer, while temp is likely used for intermediate processing such as analysis or hashing.
13. What to draw in an architecture diagram
A good diagram should show: browser UI routes on the left; Next.js API routes as the central server layer; InstantDB as the realtime datastore; opBNB as the immutable verification ledger; Gemini as the AI service; and supporting auth/permissions around database and API access. The main data flows are case creation, evidence upload, analysis, and blockchain anchoring, all feeding back into realtime UI updates.
Main entry points: instant.schema.ts Schema · page.tsx Case Detail · evidence.ts Evidence API · cases.ts Cases API
Components 19
UI
Browser-facing routes and shared components
- Dashboard · Main investigator dashboard
app/page.tsx - Login · Authentication entry screen
app/login/page.tsx - Create Case · Case creation workflow
app/create-case/page.tsx - Case Detail · Case and evidence view
app/cases/[caseId]/page.tsx - Chat Window · AI chat interface
components/ChatWindow.tsx - Blockchain Feed · On-chain activity view
components/BlockchainFeed.tsx - Theme UI · Theme controls and provider
components/ThemeProvider.tsx
Server
Next.js API routes and backend orchestration
- Cases API · Case CRUD boundary
pages/api/cases.ts - Status API · Case status updates
pages/api/cases/[caseId]/status.ts - Evidence API · Evidence upload and retrieval
pages/api/evidence.ts - Analyze API · Evidence analysis endpoint
pages/api/evidence/analyze.ts - Image API · Image interpretation endpoint
pages/api/evidence/analyze-image.ts - Chat API · AI response generation
pages/api/chat/generate.ts
Data
Realtime database schema and access control
- Schema · Cases, evidence, logs, files
instant.schema.ts - Permissions · Database authorization rules
instant.perms.ts - DB Clients · Client and admin database access
lib/db.ts
Integrations
External AI and blockchain services
- Blockchain · Evidence anchoring to opBNB
lib/blockchain.ts
Support
Shared utilities and app-wide styling
- Hash Utils · Integrity hashing helpers
lib/hash.ts - ID Utils · Stable identifier helpers
lib/id.ts
Connections 25
- Dashboard → Cases API: load cases · Dashboard fetches case data
- Dashboard → Blockchain Feed: show feed · Dashboard surfaces on-chain activity
- Login → Permissions: authz · Login participates in access control
- Create Case → Cases API: create · Creates new cases through the API
- Case Detail → Cases API: load/update · Reads and updates case records
- Case Detail → Evidence API: manage evidence · Uploads and retrieves evidence
- Case Detail → Chat Window: embed chat · Case view contains AI chat interaction
- Case Detail → Blockchain Feed: show proof · Case view shows anchoring history
- Chat Window → Chat API: send prompt · Chat UI calls generation endpoint
- Cases API → Schema: persist cases · Case data is stored in the realtime schema
- Status API → Schema: update status · Status changes are written to the database
- Status API → Permissions: enforce access · Status updates are permission-gated
- Evidence API → Schema: persist evidence · Evidence metadata and file refs are stored
- Evidence API → Hash Utils: hash file · Evidence handling computes integrity hashes
- Evidence API → ID Utils: assign ids · Evidence records use stable identifiers
- Analyze API → Blockchain: anchor result · Analysis can feed blockchain verification
- Analyze API → Schema: save findings · Derived analysis is stored with evidence
- Image API → Schema: save vision data · Image analysis results are persisted
- Chat API → Schema: read context · Chat generation uses case and evidence context
- Schema → Permissions: guard data · Schema works with permissions for role-based access
- DB Clients → Schema: connect · Client and admin helpers access the schema
- DB Clients → Permissions: apply rules · Database access is governed by permissions
- Blockchain → Hash Utils: verify hash · Anchoring depends on evidence hashes
- Blockchain → Blockchain Feed: surface txs · Transaction history is shown in the UI
- Theme UI → Dashboard: style app · Global theming applies across routes