How abdorabee/kanon works
Project Type and Purpose
• Kanon is a full-stack, server-rendered web application built on Next.js (v15) and React (v19).
• It serves as an AI-powered legal assistant, offering features like advanced legal research, document analysis, and case strategy development via AI/ML models.
• Containerized with Docker and orchestrated via docker-compose for local dev and production deployment.
File Structure Analysis
• src/app
• api/issues and api/session: Next.js API routes providing RESTful endpoints.
• components: Reusable UI building blocks (layout, ui).
• lib: Helper modules (api.ts for HTTP calls, sessionStorage.ts, translation.ts, type definitions).
• page.tsx and response/page.tsx: Main entrypoints for user workflows.
• middleware.ts: Cross-cutting logic (e.g., authentication, routing).
• public: Static assets, including translation JSON files.
• Configuration: next.config.ts, tsconfig.json, ESLint, PostCSS, Tailwind setup.
• DevOps: Dockerfile, docker-compose.yml, GitHub Actions workflows for CI/CD.
README Insights
• Emphasizes use of Next.js App Router, Tailwind CSS v4, Motion for animations.
• No built-in database folder—likely relies on external APIs or managed services (e.g., vector DB or OpenAI endpoints).
• Encourages environment variable configuration for secrets and endpoints.
Main Components to Model
a. Client Layer
• Browser (React components)
• Static assets CDN (public folder & translations)
b. Web Server Layer
• Next.js App Router (SSR & SSG pages)
• Next.js API Routes (/issues, /session)
• Middleware (authentication, routing)
c. Application Logic
• lib/api.ts: HTTP client to AI or legal data services
• lib/translation.ts: i18n loader
• lib/sessionStorage.ts: client-side session persistence
d. External Services
• AI/ML Service (OpenAI or custom endpoint)
• Legal Data Store (cases, statutes) or third-party APIs
• Logging/Monitoring (optional)
e. Infrastructure
• Docker Container
• Docker Compose (multi-service orchestration)
• CI/CD (GitHub Actions)
Relationships and Data Flow
• User → Browser: interact with React UI, choose actions.
• Browser → Next.js Server:
• Page requests (SSR/SSG) for landing, response screens.
• API calls→ /api/issues or /api/session.
• Next.js API Routes → Application Logic (lib/api.ts) → External AI/Data Services.
• Next.js Server → Browser: renders HTML + JSON payloads.
• Session Data flow: stored in browser sessionStorage, passed on subsequent requests.
• Docker Compose orchestrates local mock of any required ancillary services (e.g., local Key-Value store).
Architectural Patterns and Principles
• Component-Based UI (React + Next.js App Router).
• Thin API Layer: Next.js API Routes as micro-endpoints.
• Separation of Concerns: UI components vs. lib (domain logic) vs. external service adapters.
• Containerization: Immutable deployments via Docker.
• Internationalization: Static JSON translations served from public folder.