# cos301-se-2024/writeme architecture

> Architecture diagram of the GitHub repository cos301-se-2024/writeme, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cos301-se-2024/writeme
- Repository: https://github.com/cos301-se-2024/writeme

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js application (apps/writeme)
- UI Component Library (wmc directory)
- Storybook for component documentation
- Progressive Web App capabilities (evident from public/sw.js)

b) Backend Layer:
- API Routes (/app/api/*)
- Authentication System (NextAuth)
- Database Layer (using Drizzle ORM)
- ML Backend (Python-based, in ml-backend directory)

c) External Services:
- AWS Infrastructure
- Cloudflare Services
- Party Kit for real-time collaboration

##### Key Architectural Patterns

a) Microservices Architecture:
- Main Next.js application service
- ML service for NLP features
- Real-time collaboration service

b) Data Flow Patterns:
- User authentication flow
- Story creation and collaboration flow
- AI assistance integration
- Real-time updates flow

##### Specific Components

Frontend:
**[User Interface Layer]**
- Story Editor
- Collaboration Tools
- User Dashboard
- Community Features

Backend:
**[API Layer]**
- Auth Services
- Story Management
- User Management
- Collaboration Services

**[Data Layer]**
- Database (Drizzle)
- File Storage

**[ML Services]**
- NLP Processing

##### Integration Points

Clear connections between:
- Frontend and API endpoints
- Real-time collaboration system
- ML backend integration
- Authentication flow
- Database interactions

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI[User Interface]:::frontend
        Editor[Story Editor]:::frontend
        Collab[Collaboration Tools]:::frontend
        Dashboard[User Dashboard]:::frontend
        Community[Community Features]:::frontend
        PWA[Progressive Web App]:::frontend
        CompLib[UI Component Library]:::frontend
    end

    subgraph Backend
        API[API Layer]:::backend
        Auth[Authentication Service]:::backend
        StoryMgmt[Story Management]:::backend
        UserMgmt[User Management]:::backend
        CollabService[Collaboration Service]:::backend
    end

    subgraph DataLayer
        DB[(Database)]:::database
        FileStore[(File Storage)]:::database
        Cache[(Cache Layer)]:::database
    end

    subgraph MLServices
        NLP[NLP Processing]:::ml
        AIAssist[AI Assistant]:::ml
    end

    subgraph ExternalServices
        AWS[AWS Infrastructure]:::external
        CloudFlare[Cloudflare Services]:::external
        PartyKit[Party Kit]:::external
    end

    UI --> API
    Editor --> StoryMgmt
    Collab --> CollabService
    Dashboard --> UserMgmt
    API --> Auth
    Auth --> DB
    StoryMgmt --> DB
    UserMgmt --> DB
    CollabService --> PartyKit
    API --> NLP
    NLP --> AIAssist
    FileStore --> AWS
    API --> CloudFlare

    %% Click Events
    click UI "https://github.com/COS301-SE-2024/WriteMe/tree/dev/apps/writeme"
    click CompLib "https://github.com/COS301-SE-2024/WriteMe/tree/dev/wmc/src/lib/ui"
    click PWA "https://github.com/COS301-SE-2024/WriteMe/blob/dev/apps/writeme/public/sw.js"
    click API "https://github.com/COS301-SE-2024/WriteMe/tree/dev/apps/writeme/app/api"
    click Auth "https://github.com/COS301-SE-2024/WriteMe/tree/dev/apps/writeme/app/api/auth"
    click DB "https://github.com/COS301-SE-2024/WriteMe/tree/dev/apps/writeme/db"
    click NLP "https://github.com/COS301-SE-2024/WriteMe/tree/dev/ml-backend/ml_backend"
    click CollabService "https://github.com/COS301-SE-2024/WriteMe/blob/dev/party/index.ts"
    click Editor "https://github.com/COS301-SE-2024/WriteMe/tree/dev/apps/writeme/app/myworks/[story]/write/[chapter]"
    click Auth "https://github.com/COS301-SE-2024/WriteMe/tree/dev/apps/writeme/app/auth"
    click DB "https://github.com/COS301-SE-2024/WriteMe/blob/dev/apps/writeme/db/schema.ts"
    click API "https://github.com/COS301-SE-2024/WriteMe/tree/dev/apps/writeme/services"
    click Collab "https://github.com/COS301-SE-2024/WriteMe/blob/dev/apps/writeme/app/s/e/[session]/CollabEditor.tsx"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef ml fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white

    %% Legend
    subgraph Legend
        Frontend_L[Frontend]:::frontend
        Backend_L[Backend]:::backend
        Database_L[Database]:::database
        ML_L[ML Services]:::ml
        External_L[External Services]:::external
    end
```
