Loading...
Error loading Cell: {{ error.message }}
{{ cell.commonGood }}
```
## 8. Testing Requirements
Testing is critical for ensuring the integrity of the system.
* **Unit Tests:** We will use **Vitest** for unit testing. Every composable and service function must have unit tests covering its logic.
* **Component Tests:** We will use **`@vue/test-utils`** to test individual Vue components. Tests should verify that components render correctly based on props and that they emit events when interacted with.
* **Test Location:** All test files will be located alongside the file they are testing, with a `.spec.ts` extension (e.g., `useLedger.spec.ts`).
## 1. Introduction
This document outlines the complete fullstack architecture for Project SYSTEM, including the backend systems, frontend implementation, and their integration. It serves as the single source of truth for AI-driven development, ensuring consistency across the entire technology stack. This unified approach combines backend and frontend concerns to streamline development.
### Starter Template or Existing Project
* **Decision:** The project is based on the custom Nuxt 4 starter template provided by the user. No external templates are used. The architecture will be built upon this existing foundation.
### Change Log
| Date | Version | Description | Author |
| :--- | :--- | :--- | :--- |
| 2025-08-31 | 1.0 | Initial Fullstack Architecture draft | Architect (Winston) |
## 2. High Level Architecture
### Technical Summary
Project SYSTEM is a monolithic, self-hosted web application built on the Nuxt 4 framework. The architecture is designed for efficiency and transparency, running on a Raspberry Pi. It features a Vue-based frontend interacting with a PostgreSQL database via Nuxt's server-side API routes. The core of the system is an immutable, event-sourced "Main Ledger" where every action is a cryptographically signed transaction, ensuring data integrity and auditability. Identity management is decentralized, based on public/private key pairs.
### Platform and Infrastructure Choice
* **Platform:** Self-hosted on a user-provided **Raspberry Pi** (Model 4+).
* **Key Services:**
* **Application Server:** **Nuxt 4** running in Node.js mode.
* **Database:** **PostgreSQL**.
* **Containerization:** The entire stack will be managed and deployed via **Docker Compose**. This ensures a consistent and reproducible environment.
* **Deployment Host and Regions:** Single host, located within the "Община's" private network.
### Repository Structure
* **Structure:** **Monorepo**.
* **Monorepo Tool:** Not required for this level of simplicity. A single `package.json` at the root will manage all dependencies.
* **Package Organization:** A standard Nuxt 4 project structure will be used, as detailed in the Frontend Architecture. Server-side logic will reside within the `server/` directory.
### High Level Architecture Diagram
```mermaid
graph TD
subgraph "Browser"
A[Citizen's Browser]
end
subgraph "Raspberry Pi (Docker Compose)"
B[Nuxt 4 Server]
C[PostgreSQL Database]
B -- "Serves Frontend" --> A
A -- "API Calls ($fetch)" --> B
B -- "Reads/Writes" --> C
end
style B fill:#2D3748,stroke:#fff,stroke-width:2px,color:#fff
style C fill:#4A5568,stroke:#fff,stroke-width:2px,color:#fff
```
---
## 3. Tech Stack (Revised)
| Category | Technology | Version | Purpose & Rationale |
| :--- | :--- | :--- | :--- |
| **Fullstack Framework**| **Nuxt** | `^4.0.3` | Core framework for both frontend and backend (server routes). |
| **Database ORM** | **Prisma** | `latest` | Next-generation ORM for type-safe database access and automated migrations. |
| **Database** | **PostgreSQL** | `latest` | Robust, reliable SQL database managed by Prisma. |
| **Deployment** | **Docker Compose**| `latest` | For containerizing and managing the application stack. |
| ... | *(rest of the stack remains the same)* | ... | ... |
## 4. Database Architecture (Revised with Prisma)
The database schema will be defined declaratively using the Prisma schema language in a single source of truth file: `prisma/schema.prisma`. Prisma will be responsible for generating SQL migrations and providing a type-safe client for all database interactions.
### Prisma Schema (`prisma/schema.prisma`)
```prisma
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
// User-friendly metadata associated with a public key.
model Registry {
publicKey String @id
citizenName String
avatarUrl String?
isActive Boolean @default(true)
createdAt DateTime @default(now())
}
// The core, immutable data model.
// Once a row is written, it is never updated or deleted.
model LedgerEntry {
id BigInt @id @default(autoincrement())
previousHash String?
entryHash String @unique
citizenPublicKey String
signature String
actionType String
payload Json? // The actual data for the action, e.g., cell details
createdAt DateTime @default(now())
@@index([citizenPublicKey])
@@index([payload], name: "idx_ledger_payload_entity") // Example for indexing specific payload keys
}
```
### Migrations Workflow
Database migrations will be managed exclusively by Prisma Migrate.
1. **Development:** After any change to `schema.prisma`, a new migration will be created and applied using the command:
```bash
npx prisma migrate dev --name