From 346dd293da7c08ebe660080a4e1209af06383169 Mon Sep 17 00:00:00 2001 From: samantha Date: Fri, 27 Mar 2026 10:44:53 +0000 Subject: [PATCH] Add Project Structure --- Project-Structure.md | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Project-Structure.md diff --git a/Project-Structure.md b/Project-Structure.md new file mode 100644 index 0000000..4752675 --- /dev/null +++ b/Project-Structure.md @@ -0,0 +1,49 @@ +# Project Structure + +``` +. +├── main.go # Entry point — HTTP routes, CORS middleware, shell loop +├── app.db # SQLite database (auto-created on first run) +├── build.sh # Build script → outputs ./Portifolio binary +├── go.mod / go.sum +└── internal/ + ├── database/ + │ └── main.go # InitDB (all CREATE TABLE statements) + │ # GetTrades, UpdatePositions, and other DB helpers + ├── handlers/ + │ ├── main.go # HealthHandler + │ ├── company.go # AddCompanyHandler, GetCompaniesHandler, + │ │ # GetCompanyRevenueCategories + │ ├── currency.go # AddCurrencyHandler, GetCurrenciesHandler + │ ├── revenue.go # AddRevenueEntryHandler + │ └── trade.go # AddTradeHandler, GetTradeListHandler, + │ # GetPositionListHandler + ├── model/ + │ ├── company.go # Company struct + │ ├── currency.go # Currency struct + │ ├── periode.go # Period struct + QuarterPeriod, HalfYearPeriod, + │ │ # FullYearPeriod helpers + │ ├── portifolio.go # Position, Trade, TradeProduct, TradeType, + │ │ # AddTradeRequest (with Validate()), Portfolio + │ └── revenue.go # Revenue, RevenueReport, RevSum structs + ├── service/ + │ ├── currency.go # Currency business logic + │ └── portfolio.go # UpdatePositionByTradeList — rebuilds positions + │ # from full trade history + └── shell/ + ├── company.go # add-company, list-companies + ├── currency.go # add-currency, list-currency + └── revenue.go # add-revenue, list-revenue +``` + +## Key Design Points + +**`main.go`** wires together the HTTP mux and the shell loop. Both run concurrently — the HTTP server is started in a goroutine and the shell blocks on stdin. + +**`internal/database`** owns all SQL. Handlers and services call functions here rather than writing raw queries themselves. + +**`internal/model`** contains only structs, enums, and validation. No SQL lives here. + +**`internal/service`** contains business logic that spans multiple database calls. `UpdatePositionByTradeList` replays the full trade history to compute current positions, then writes them back to the database. + +**`internal/handlers`** are thin — they decode the request, call a service or database function, and encode the response. \ No newline at end of file