|
| 1 | +# Copilot / AI Agent Instructions for FileCodeBox |
| 2 | + |
| 3 | +Short, actionable guidance so an AI agent can be productive immediately in this repo. |
| 4 | + |
| 5 | +1) Big picture |
| 6 | +- Layered architecture: `routes -> handlers -> services -> repository -> database/storage`. |
| 7 | +- Key directories: `internal/routes/`, `internal/handlers/`, `internal/services/`, `internal/repository/`, `internal/storage/`, `internal/config/`, `internal/mcp/`, `docs/`. |
| 8 | +- Main entry: `main.go` initializes `ConfigManager`, `StorageManager`, and starts the HTTP server via `routes.CreateAndStartServer()`; DB initialization is deferred and can be triggered via `/setup/initialize`. |
| 9 | + |
| 10 | +2) Typical data & control flow |
| 11 | +- HTTP requests handled by `routes` -> call `handlers` -> call `services` -> use `repository` -> talk to DB/storage. |
| 12 | +- Storage is abstracted by `storage.NewStorageManager(manager)` and concrete implementations under `internal/storage/` (local, s3, webdav, onedrive). |
| 13 | +- MCP subsystem lives under `internal/mcp/` and is conditionally started when `manager.MCP.EnableMCPServer == 1`. |
| 14 | + |
| 15 | +3) Configuration & runtime |
| 16 | +- Config is centralized in `internal/config/manager.go` (use `config.InitManager()` to obtain `ConfigManager`). |
| 17 | +- Environment variables override config; `manager.SetDB(db)` is used to inject DB connection after initialization. |
| 18 | +- Common env vars: `PORT`, `DATA_PATH`, `ENABLE_MCP_SERVER`. |
| 19 | + |
| 20 | +4) Versioning & release patterns |
| 21 | +- Project version stored in the top-level `VERSION` file and echoed in `internal/models/service/system.go` (`Version` variable) and swagger docs under `docs/`. |
| 22 | +- Releases are created by updating those files and tagging the commit (e.g., `v1.8.2`). Avoid editing `go.sum` manually. |
| 23 | + |
| 24 | +5) Build, test, and release commands |
| 25 | +- Build: `make build` or `go build ./...`. |
| 26 | +- Tests: `make test` or `go test ./...` (many packages have no tests; run targeted packages if needed). |
| 27 | +- Docker: `./scripts/build-docker.sh` and `docker-compose.yml` present. |
| 28 | + |
| 29 | +6) Project-specific conventions |
| 30 | +- Handler constructors follow: `NewXxxHandler(service *services.XxxService, config *config.ConfigManager) *XxxHandler`. |
| 31 | +- Services are created with dependency injection in `routes` during server start: e.g., `services.NewUserService(daoManager, manager)`. |
| 32 | +- Repositories live under `internal/repository/` and expose `RepositoryManager` for DAOs (use `dmgr *repository.RepositoryManager`). |
| 33 | +- Error responses use helper functions in `internal/common/` (`common.SuccessResponse`, `common.ErrorResponse`, `common.BadRequestResponse`). |
| 34 | + |
| 35 | +7) Integration points to inspect when editing code |
| 36 | +- `internal/config/manager.go` — config lifecycle, hot reload hooks. |
| 37 | +- `internal/routes/setup.go` — server and route wiring, DI order. |
| 38 | +- `internal/mcp/manager.go` — MCP lifecycle and tools registration. |
| 39 | +- `internal/storage/*` — adding new storage backends: implement `storage.StorageInterface` and register in `storage.NewStorageManager`. |
| 40 | + |
| 41 | +8) Useful file examples to copy patterns from |
| 42 | +- `internal/services/*` shows DI, error wrapping and transaction handling (e.g., `internal/services/admin/*`). |
| 43 | +- `internal/routes/*` shows route grouping and middleware usage, look at `internal/routes/admin.go` for admin auth patterns. |
| 44 | + |
| 45 | +9) CSS / Frontend notes |
| 46 | +- Frontend themes under `themes/2025/`. Admin UI assets are served via protected routes — modifying admin CSS may require rebuilding or restarting server to pick static changes when not using hot reload. |
| 47 | + |
| 48 | +10) Safety & version control |
| 49 | +- Do not alter `go.sum` manually. |
| 50 | +- When creating tags, prefer not to overwrite remote tags; create a new semver or `-local.<sha>` tag if necessary. |
| 51 | + |
| 52 | +If any section is unclear or you want examples added (e.g., sample PR description, changelog generation command), tell me which part to expand. After your feedback I'll iterate. |
1 | 53 | # FileCodeBox AI Coding Agent Instructions |
2 | 54 |
|
3 | 55 | ## Project Overview |
|
0 commit comments