Judge advocate

A Judge Advocate General (often shortened to JAG) within Starfleet is an officer who advises Starfleet on and administers courts martial, as well as oversees other Starfleet legal matters and personnel. Legal counsel within Starfleet report into the senior JAG as part of the department known as the Judge Advocate General's Office (or simply the "Judge Advocate's Office").

Areel Shaw was a JAG officer assigned to Starbase 11 in 2267. While there she prosecuted the court martial of Captain James T. Kirk on the charge of culpable negligence. {TOS: "Court Martial")

Phillipa Louvois was also a member of the Judge Advocate General's Office. In 2355 she presided over the investigation into the loss of the USS Stargazer. In 2365, as a captain, she was the commander of the JAG office of Sector 23. One of Captain Louvois' first rulings in 2365 was that Lieutenant Commander Data was not the property of Starfleet. 

The Judge Advocate General's Office was responsible for the investigation into the mutiny that occured aboard the USS Pegasus in 2358. 

Rear Admiral Bennett was the JAG in 2373 who ruled on Richard Bashir's criminal actions when he pled guilty to the resequencing of his son Julian's DNA. 

Non-Starfleet persons, including non-Federation citizens, can lodge formal complaints with the JAG that arise from actions taken by Starfleet personnel.