# ayfg/catlog architecture

> Architecture diagram of the GitHub repository ayfg/catlog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ayfg/catlog
- Repository: https://github.com/ayfg/catlog

## Overview

##### Project type and purpose
- CatLog is a full-stack mobile application for recording and viewing cat-related logs (daily activities, medical records, etc.).
- The frontend is an Expo-managed React Native app (using the new `app/`–directory router), and the backend is a TypeScript + Express REST API with MongoDB.

##### File-structure analysis
- Top level: two subprojects, `CatLog_front` and `CatLog_back`.
- `CatLog_back`:
- app.ts — Express entry point
- routes/ → controllers/ → models/ — a classic MVC layering
- middleware/ — auth checker & error handler
- types/ — shared request & error types
- bruno/ — Bruno DSL scripts for testing or BDD scenarios
- `CatLog_front`:
- app/ — Expo Router screens and layouts (tabbed navigation)
- components/ — reusable buttons
- store/ — Zustand state management
- utils/ — age calculation, date logic, API client, storage helpers
- types/ — shared data models (Cat, DailyLog, MedicalLog, Auth)
- ios/ & android/ — native project files for Expo

##### README insights
- Tech stack badges: TypeScript, Node.js, Express, MongoDB, React Native, Expo, TanStack Query, Zustand, NativeWind.

##### Main components & interactions
a. Frontend (Mobile App)
- Screens: Login, Signup, Tabs (Calendar, MyPage), Create/Edit/Delete modals
- State & data layer: Zustand store + TanStack Query for caching/fetching
- HTTP/API client: `utils/fetchApi.ts` calls backend endpoints
b. Backend (API Server)
- Express router layers: `/auth`, `/cat`, `/dailyLog`, `/medicalLog`
- Controllers implement business logic
- Models (Mongoose schemas) persist to MongoDB
- Middleware handles authentication (`authChecker`) and errors
- Bruno scripts for automated tests or API specification
c. Database
- MongoDB collections: users, cats, dailyLogs, medicalLogs
d. External Services
- OAuth/social login (via `components/socialButton.tsx`)
- Static assets (rives & images served by Expo bundle)

##### Architectural patterns & design principles
- Backend: MVC-like separation (routes → controllers → models)
- RESTful API design with stateless JWT sessions (checked in `authChecker`)
- Frontend: component-based UI, unidirectional data flow, React hooks + Zustand + React Query
- Clear separation of concerns: UI vs. networking vs. storage vs. native runtime

##### Putting it all together
- Top-right: “API Client” node (`fetchApi.ts`)
- Center: “Express Server” composite node containing Routes, Controllers, Middleware
- Bottom: “MongoDB”
- Side: “Bruno Test Suite” connecting to API Server for automated test execution

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Mobile App (Expo React Native)"
        direction TB
        subgraph "Screens" 
            direction TB
            Login["Login Screen"]:::frontend
            click Login "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/Login.tsx"
            Signup["Signup Screen"]:::frontend
            click Signup "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/Signup.tsx"
            Calendar["Calendar Tab"]:::frontend
            click Calendar "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/(tabs)/CalendarScreen.tsx"
            MyPage["MyPage Tab"]:::frontend
            click MyPage "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/(tabs)/MyPage.tsx"
            subgraph "Cat Modals"
                direction TB
                CreateCat["CreateCat Modal"]:::frontend
                click CreateCat "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/CreateCat.tsx"
                EditCat["EditCat Modal"]:::frontend
                click EditCat "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/EditCatModal.tsx"
                DeleteCat["DeleteCat Modal"]:::frontend
                click DeleteCat "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/DeleteCatModal.tsx"
            end
            subgraph "DailyLog Modals"
                direction TB
                EditCalendar["EditCalendar Modal"]:::frontend
                click EditCalendar "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/EditCalendarModal.tsx"
                DeleteCalendar["DeleteCalendar Modal"]:::frontend
                click DeleteCalendar "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/DeleteCalendarModal.tsx"
            end
            MedicalLog["MedicalLog Screen"]:::frontend
            click MedicalLog "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/MedicalLog.tsx"
        end
        subgraph "Components"
            direction TB
            RouteButton["RouteButton"]:::frontend
            click RouteButton "https://github.com/ayfg/catlog/blob/main/CatLog_front/components/RouteButton.tsx"
            SubmitButton["SubmitButton"]:::frontend
            click SubmitButton "https://github.com/ayfg/catlog/blob/main/CatLog_front/components/SubmitButton.tsx"
            SocialButton["SocialButton"]:::frontend
            click SocialButton "https://github.com/ayfg/catlog/blob/main/CatLog_front/components/socialButton.tsx"
        end
        subgraph "State & Utils"
            direction TB
            Store["Zustand Store"]:::frontend
            click Store "https://github.com/ayfg/catlog/blob/main/CatLog_front/store/useCatStore.ts"
            CalcAge["calculateAge"]:::frontend
            click CalcAge "https://github.com/ayfg/catlog/blob/main/CatLog_front/utils/calculateAge.ts"
            CalcNext["calculateNextDate"]:::frontend
            click CalcNext "https://github.com/ayfg/catlog/blob/main/CatLog_front/utils/calculateNextDate.ts"
            Storage["storage Helpers"]:::frontend
            click Storage "https://github.com/ayfg/catlog/blob/main/CatLog_front/utils/storage.ts"
        end
        subgraph "Layouts & Routing"
            direction TB
            RootLayout["_layout.tsx"]:::frontend
            click RootLayout "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/_layout.tsx"
            TabsLayout["Tabs Layout"]:::frontend
            click TabsLayout "https://github.com/ayfg/catlog/blob/main/CatLog_front/app/(tabs)/_layout.tsx"
        end
    end

    %% Networking Layer
    FetchApi["fetchApi (HTTP Client)"]:::frontend
    click FetchApi "https://github.com/ayfg/catlog/blob/main/CatLog_front/utils/fetchApi.ts"

    %% Server Layer
    subgraph "Express Server (TypeScript + Express)" 
        direction TB
        App["app.ts"]:::server
        click App "https://github.com/ayfg/catlog/blob/main/CatLog_back/app.ts"
        subgraph "Middleware"
            direction TB
            AuthChecker["authChecker"]:::server
            click AuthChecker "https://github.com/ayfg/catlog/blob/main/CatLog_back/middleware/authChecker.ts"
            ErrorHandler["error Handler"]:::server
            click ErrorHandler "https://github.com/ayfg/catlog/blob/main/CatLog_back/middleware/error.ts"
        end
        subgraph "Routes"
            direction TB
            AuthRoute["/auth"]:::server
            click AuthRoute "https://github.com/ayfg/catlog/blob/main/CatLog_back/routes/auth.ts"
            CatRoute["/cat"]:::server
            click CatRoute "https://github.com/ayfg/catlog/blob/main/CatLog_back/routes/cat.ts"
            DailyRoute["/dailyLog"]:::server
            click DailyRoute "https://github.com/ayfg/catlog/blob/main/CatLog_back/routes/dailyLog.ts"
            MedRoute["/medicalLog"]:::server
            click MedRoute "https://github.com/ayfg/catlog/blob/main/CatLog_back/routes/medicalLog.ts"
        end
        subgraph "Controllers"
            direction TB
            AuthCtrl["Auth Controller"]:::server
            click AuthCtrl "https://github.com/ayfg/catlog/blob/main/CatLog_back/controllers/auth.ts"
            CatCtrl["Cat Controller"]:::server
            click CatCtrl "https://github.com/ayfg/catlog/blob/main/CatLog_back/controllers/cat.ts"
            DailyCtrl["DailyLog Controller"]:::server
            click DailyCtrl "https://github.com/ayfg/catlog/blob/main/CatLog_back/controllers/dailyLog.ts"
            MedCtrl["MedicalLog Controller"]:::server
            click MedCtrl "https://github.com/ayfg/catlog/blob/main/CatLog_back/controllers/medicalLog.ts"
        end
        subgraph "Models (Mongoose)"
            direction TB
            UserModel["User Schema"]:::server
            click UserModel "https://github.com/ayfg/catlog/blob/main/CatLog_back/models/user.ts"
            CatModel["Cat Schema"]:::server
            click CatModel "https://github.com/ayfg/catlog/blob/main/CatLog_back/models/cat.ts"
            DailyModel["DailyLog Schema"]:::server
            click DailyModel "https://github.com/ayfg/catlog/blob/main/CatLog_back/models/dailyLog.ts"
            MedModel["MedicalLog Schema"]:::server
            click MedModel "https://github.com/ayfg/catlog/blob/main/CatLog_back/models/medicalLog.ts"
        end
    end

    %% Database Layer
    MongoDB["MongoDB\n(users, cats, dailyLogs, medicalLogs)"]:::db

    %% External/Test Services
    Bruno["Bruno Test Suite"]:::external
    click Bruno "https://github.com/ayfg/catlog/tree/main/CatLog_back/bruno/CatLog/"

    %% Connections
    Login -->|"tap / form submit"| FetchApi
    Signup -->|"tap / form submit"| FetchApi
    Calendar -->|"fetch logs"| FetchApi
    MyPage -->|"fetch profile"| FetchApi
    CreateCat -->|"POST /cat"| FetchApi
    EditCat -->|"PUT /cat/:id"| FetchApi
    DeleteCat -->|"DELETE /cat/:id"| FetchApi
    EditCalendar -->|"PUT /dailyLog/:date"| FetchApi
    DeleteCalendar -->|"DELETE /dailyLog/:date"| FetchApi
    MedicalLog -->|"GET/POST /medicalLog"| FetchApi

    FetchApi -->|"HTTP"| AuthRoute
    FetchApi -->|"HTTP"| CatRoute
    FetchApi -->|"HTTP"| DailyRoute
    FetchApi -->|"HTTP"| MedRoute

    AuthRoute -->|calls| AuthCtrl
    CatRoute -->|calls| CatCtrl
    DailyRoute -->|calls| DailyCtrl
    MedRoute -->|calls| MedCtrl

    AuthCtrl -->|uses| UserModel
    CatCtrl -->|uses| CatModel
    DailyCtrl -->|uses| DailyModel
    MedCtrl -->|uses| MedModel

    UserModel -->|"CRUD"| MongoDB
    CatModel -->|"CRUD"| MongoDB
    DailyModel -->|"CRUD"| MongoDB
    MedModel -->|"CRUD"| MongoDB

    AuthChecker -->|validates JWT| AuthRoute
    ErrorHandler -->|catches errors| App

    App --> AuthChecker
    App --> ErrorHandler

    Bruno -->|"runs API tests"| AuthRoute
    Bruno -->|"runs API tests"| CatRoute
    Bruno -->|"runs API tests"| DailyRoute
    Bruno -->|"runs API tests"| MedRoute

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#000
    classDef server fill:#D0FFD8,stroke:#22863a,color:#000
    classDef db fill:#FFE0B2,stroke:#d2691e,color:#000
    classDef external fill:#E0E0E0,stroke:#6a737d,color:#000
```
