# tony-stark73/java-assignment architecture

> Architecture diagram of the GitHub repository tony-stark73/java-assignment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tony-stark73/java-assignment
- Repository: https://github.com/tony-stark73/java-assignment

## Overview

##### Project type and purpose
- This is a standalone backend REST API built with Spring Boot (Java).
- It manages stock portfolios: reading/writing a local JSON file, exposing endpoints to get portfolios and stock data, and fetching live stock details from an external API.

##### File structure
- Top-level build: `pom.xml`, Maven wrapper files → Java/Maven project.
- Entry point: `src/main/java/com/example/demo/DemoApplication.java` → Spring Boot application.
- Package breakdown under `src/main/java/portfolio`:
- `controllers` (REST endpoints)
- `services` (business logic, external API calls)
- `models` (Portfolio & Stock domain objects)
- `storage` (JSON file persistence)
- Resources: `application.properties` (Spring config) and `data/portfolio.json` (persistent store).
- Tests under `src/test/java`: Spring Boot test harness for application start-up.

##### README for additional insights
- Minimal README (`# java-assignment`) – no explicit architecture notes.
- We infer architecture solely from file tree and Spring conventions.

a. Main components
1) Client (e.g., web/mobile or curl)
2) API Layer (Controllers)
– StockController
– TestController
3) Service Layer
– PortfolioService (CRUD on portfolio.json)
– StockApiService (calls external stock quotes API)
4) Storage Layer
– JsonStorage (reads/writes `portfolio.json`)
5) External Services
– Third-party Stock Data API
b. Relationships & interactions
- Client → HTTP request → Controllers
- Controllers ↔ Service Layer (business orchestration)
- PortfolioService ↔ JsonStorage (read/write file)
- StockApiService → External Stock API (HTTP)
- Service results → Controller → HTTP response → Client
c. Architectural patterns & design principles
- Layered (Presentation → Service → Persistence)
- Separation of concerns (controllers only handle HTTP, services contain business logic, storage deals with persistence)
- Dependency injection (Spring Boot)
d. Key technologies/frameworks
- Spring Boot (embedded Tomcat, DI, MVC)
- Java 8+
- Maven (build)
- JSON file persistence (no RDBMS)
- External HTTP client (e.g., RestTemplate or WebClient in StockApiService)

##### Key reminders
- Be detailed: represent each layer and component from the package structure.
- Dependencies (e.g., StockController depends on both services).
- Don’t overcomplicate: the goal is a clear, layered overview matching the codebase’s packages and Spring Boot conventions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Web/Mobile/curl)"]:::external

    subgraph "API Layer"
        StockController["StockController"]:::controller
        TestController["TestController"]:::controller
    end

    subgraph "Service Layer"
        PortfolioService["PortfolioService"]:::service
        StockApiService["StockApiService"]:::service
    end

    subgraph "Storage & Persistence"
        JsonStorage["JsonStorage"]:::storage
        PortfolioJson["portfolio.json"]:::storage
    end

    ExternalAPI["External Stock Data API"]:::external

    subgraph "Domain Models"
        Portfolio["Portfolio"]:::model
        Stock["Stock"]:::model
    end

    Config["application.properties"]:::config
    DemoApplication["DemoApplication"]:::config
    Tests["DemoApplicationTests"]:::test

    Client -->|HTTP GET/POST| StockController
    Client -->|HTTP GET| TestController

    StockController -->|"calls"| PortfolioService
    StockController -->|"calls"| StockApiService
    TestController -->|"calls"| PortfolioService

    PortfolioService -->|"CRUD via JSON"| JsonStorage
    PortfolioService -->|"uses"| Portfolio
    PortfolioService -->|"uses"| Stock

    StockApiService -->|"REST call"| ExternalAPI
    StockApiService -->|"uses"| Stock

    JsonStorage -->|"reads/writes JSON"| PortfolioJson

    DemoApplication -->|boots| StockController
    DemoApplication -->|boots| TestController

    Tests -->|tests startup| DemoApplication

    click DemoApplication "https://github.com/tony-stark73/java-assignment/blob/main/src/main/java/com/example/demo/DemoApplication.java"
    click StockController "https://github.com/tony-stark73/java-assignment/blob/main/src/main/java/portfolio/controllers/StockController.java"
    click TestController "https://github.com/tony-stark73/java-assignment/blob/main/src/main/java/portfolio/controllers/TestController.java"
    click PortfolioService "https://github.com/tony-stark73/java-assignment/blob/main/src/main/java/portfolio/services/PortfolioService.java"
    click StockApiService "https://github.com/tony-stark73/java-assignment/blob/main/src/main/java/portfolio/services/StockApiService.java"
    click JsonStorage "https://github.com/tony-stark73/java-assignment/blob/main/src/main/java/portfolio/storage/JsonStorage.java"
    click Portfolio "https://github.com/tony-stark73/java-assignment/blob/main/src/main/java/portfolio/models/Portfolio.java"
    click Stock "https://github.com/tony-stark73/java-assignment/blob/main/src/main/java/portfolio/models/Stock.java"
    click Config "https://github.com/tony-stark73/java-assignment/blob/main/src/main/resources/application.properties"
    click PortfolioJson "https://github.com/tony-stark73/java-assignment/blob/main/src/main/resources/data/portfolio.json"
    click Tests "https://github.com/tony-stark73/java-assignment/blob/main/src/test/java/com/example/demo/DemoApplicationTests.java"

    classDef controller fill:#E0F7FA,stroke:#006064
    classDef service fill:#E8F5E9,stroke:#1B5E20
    classDef storage fill:#FFF3E0,stroke:#E65100
    classDef model fill:#F3E5F5,stroke:#6A1B9A
    classDef config fill:#E1F5FE,stroke:#0277BD
    classDef external fill:#ECEFF1,stroke:#37474F
    classDef test fill:#FFEBEE,stroke:#C62828
```
